Skip to content

Commit

Permalink
Initial setup (#1)
Browse files Browse the repository at this point in the history
* feat: initial logic commit

* feat: add build files

* fix(lua): added init.lua for loading

* fix(flake): use root of repo for plugin

* feat(flake): more work on logic

* feat(workflows): added flake jobs

* docs(README)

* docs(README)

* docs(README)

* docs(README)

* docs(README)

* docs(README)

* docs(README)
  • Loading branch information
erikreinert authored Jan 14, 2024
1 parent c705b4e commit af70b9d
Show file tree
Hide file tree
Showing 18 changed files with 750 additions and 0 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
31 changes: 31 additions & 0 deletions .github/workflows/flake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Test flake

on:
pull_request:
push:
branches:
- main

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- uses: actions/checkout@v3
- run: nix flake check

build:
needs: check
runs-on: ubuntu-latest
strategy:
matrix:
profile:
- default
- neovim
steps:
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- uses: extractions/setup-just@v1
- uses: actions/checkout@v3
- run: just build "${{ matrix.profile }}"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.direnv
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,64 @@
# thealtf4stream.nvim
Neovim configuration for TheAltF4Stream as a plugin.

[![Test flake](https://github.com/ALT-F4-LLC/thealtf4stream.nvim/actions/workflows/flake.yml/badge.svg)](https://github.com/ALT-F4-LLC/thealtf4stream.nvim/actions/workflows/flake.yml)

![Preview](https://github.com/ALT-F4-LLC/thealtf4stream.nvim/blob/main/lib/preview.webp)

## Install

### Neovim

> [!WARNING]
> By default, this setup was designed for Nix and needs a stable example Lua configuration.
- WIP

### Nix

This flake provides a `neovim` derivation that can be used as a packge on any Nix supported system. This is a "wrapped" variant of Neovim which includes configuration and dependencies (language servers, formatters, etc).

> [!NOTE]
> The `neovim` derivation provides an identical editor expierence on any `nix` supported host.
#### Run in shell

- Run `neovim` directly with:

```shell
$ nix run github:ALT-F4-LLC/thealtf4stream.nvim#neovim
```

- Run `neovim` in new shell with:

```shell
$ nix shell github:ALT-F4-LLC/thealtf4stream.nvim#neovim
$ neovim
```

#### Add to flake

- Add to `flake.nix` as an input:

```nix
inputs = {
thealtf4stream-nvim.url = "github:ALT-F4-LLC/thealtf4stream.nvim";
};
```

- (option a): Add to `environment.systemPackages` configuration:

```nix
environment.systemPackages = [
inputs.thealtf4stream-nvim.packages.${pkgs.system}.neovim
];
```

- (option b): Add to `home-manager` configuration:

```nix
programs.neovim = {
enable = true;
package = inputs.thealtf4stream-nvim.packages.${pkgs.system}.neovim;
};
```
63 changes: 63 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
description = "Neovim configuration for TheAltF4Stream as a plugin";

inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

outputs = inputs@{ self, flake-parts, nixpkgs, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
flake = {
lib = import ./lib { inherit inputs; };
};

systems = [ "aarch64-darwin" "aarch64-linux" "x86_64-darwin" "x86_64-linux" ];

perSystem = { config, self', inputs', pkgs, system, ... }:
let
inherit (pkgs) just mkShell writeShellApplication;
neovim = self.lib.mkNvim { inherit system; };
neovimRuntimeInputs = self.lib.mkNvimRuntimeInputs { inherit system; };
in
{
devShells = {
default = mkShell {
buildInputs = [ just ];
};
};

packages = {
default = self.lib.mkNvimConfig { inherit system; };

neovim = writeShellApplication
{
runtimeInputs = [ neovim ] ++ neovimRuntimeInputs;
name = "nvim";
text = ''
${neovim}/bin/nvim "$@"
'';
};
};
};
};
}
1 change: 1 addition & 0 deletions init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'TheAltF4Stream'.init()
2 changes: 2 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build profile="default":
nix build --json --no-link --print-build-logs ".#{{ profile }}"
125 changes: 125 additions & 0 deletions lib/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{ inputs }:

rec {
mkNvimConfig = { system }:
let
pkgs = inputs.nixpkgs.legacyPackages.${system};
in
pkgs.vimUtils.buildVimPlugin {
name = "TheAltF4Stream";
postInstall = ''
rm -rf $out/.envrc
rm -rf $out/.gitignore
rm -rf $out/LICENSE
rm -rf $out/README.md
rm -rf $out/flake.lock
rm -rf $out/flake.nix
rm -rf $out/justfile
rm -rf $out/lib
'';
src = ../.;
};

mkNvimPlugins = { system }:
let
pkgs = inputs.nixpkgs.legacyPackages.${system};
thealtf4stream-nvim = mkNvimConfig { inherit system; };
in
with pkgs; [
# languages
vimPlugins.nvim-lspconfig
vimPlugins.nvim-treesitter.withAllGrammars
vimPlugins.rust-tools-nvim
vimPlugins.vim-just

# telescope
vimPlugins.plenary-nvim
vimPlugins.telescope-nvim

# theme
vimPlugins.oxocarbon-nvim

# floaterm
vimPlugins.vim-floaterm

# extras
vimPlugins.ChatGPT-nvim
vimPlugins.copilot-lua
vimPlugins.gitsigns-nvim
vimPlugins.lualine-nvim
vimPlugins.nerdcommenter
vimPlugins.nui-nvim
vimPlugins.nvim-colorizer-lua
vimPlugins.nvim-notify
vimPlugins.nvim-treesitter-context
vimPlugins.nvim-web-devicons
vimPlugins.omnisharp-extended-lsp-nvim
vimPlugins.rainbow-delimiters-nvim

# configuration
thealtf4stream-nvim
];

mkNvimRuntimeInputs = { system }:
let
pkgs = (import inputs.nixpkgs {
inherit system;
config.allowUnfree = true;
});
in
with pkgs; [
# language servers
cuelsp
gopls
haskell-language-server
jsonnet-language-server
lua-language-server
nil
nodePackages."bash-language-server"
nodePackages."diagnostic-languageserver"
nodePackages."dockerfile-language-server-nodejs"
nodePackages."pyright"
nodePackages."typescript"
nodePackages."typescript-language-server"
nodePackages."vscode-langservers-extracted"
nodePackages."yaml-language-server"
ocaml-ng.ocamlPackages_5_1.ocaml-lsp
ocaml-ng.ocamlPackages_5_1.ocamlformat
omnisharp-roslyn
rust-analyzer
terraform-ls

# formatters
nixpkgs-fmt
gofumpt
golines
python310Packages.black
rustfmt
terraform
];

mkNvim = { system }:
let
pkgs = inputs.nixpkgs.legacyPackages.${system};
in
pkgs.neovim.override {
configure = {
customRC = ''
lua << EOF
require 'TheAltF4Stream'.init()
EOF
'';
packages.main =
let
plugins = mkNvimPlugins { inherit system; };
in
{
start = plugins;
};
};

withNodeJs = true;
withPython3 = true;
withRuby = true;
};
}
Binary file added lib/preview.webp
Binary file not shown.
3 changes: 3 additions & 0 deletions lua/.luarc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"workspace.checkThirdParty": false
}
27 changes: 27 additions & 0 deletions lua/TheAltF4Stream/chatgpt.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
local chatgpt = require 'chatgpt'

local function init()
local api_key_cmd = "doppler secrets get OPENAI_API_KEY --plain"
local model = "gpt-3.5-turbo"
local edit_model = "code-davinci-edit-001"

chatgpt.setup({
api_key_cmd = api_key_cmd,
openai_params = { model = model },
openai_edit_params = { model = edit_model }
})

local map = vim.api.nvim_set_keymap
local options = { noremap = true }

map('n', '<leader>ga', '<CMD>ChatGPTActAs<CR>', options)
map('n', '<leader>gg', '<CMD>ChatGPT<CR>', options)
map('v', '<leader>ge', '<CMD>ChatGPTEditWithInstructions<CR>', options)
map('v', '<leader>go', '<CMD>ChatGPTRun optimize_code<CR>', options)
map('v', '<leader>gs', '<CMD>ChatGPTRun summarize<CR>', options)
map('v', '<leader>gt', '<CMD>ChatGPTRun add_tests<CR>', options)
end

return {
init = init
}
16 changes: 16 additions & 0 deletions lua/TheAltF4Stream/floaterm.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
local function init()
local map = vim.api.nvim_set_keymap

local options = { noremap = true }

map('n', '<leader>bb', '<CMD>FloatermNew --autoclose=2 --height=0.9 --width=0.9 btm<CR>', options)
map('n', '<leader>k9', '<CMD>FloatermNew --autoclose=2 --height=0.9 --width=0.9 k9s<CR>', options)
map('n', '<leader>ld', '<CMD>FloatermNew --autoclose=2 --height=0.9 --width=0.9 lazydocker<CR>', options)
map('n', '<leader>lg', '<CMD>FloatermNew --autoclose=2 --height=0.9 --width=0.9 lazygit<CR>', options)
map('n', '<leader>nn', '<CMD>FloatermNew --autoclose=2 --height=0.75 --width=0.75 nnn -Hde<CR>', options)
map('n', '<leader>tt', '<CMD>FloatermNew --autoclose=2 --height=0.9 --width=0.9 zsh<CR>', options)
end

return {
init = init,
}
Loading

0 comments on commit af70b9d

Please sign in to comment.