Manage neovim configuration

This commit is contained in:
Jeremy Wall 2022-04-17 16:02:03 -04:00
parent 8be833a2ce
commit 8e5ac5bd2f
4 changed files with 465 additions and 36 deletions

View File

@ -1,33 +1,69 @@
{ config, pkgs, ... }:
{ config, pkgs, inputs, ... }:
{
imports = [
./program-neovim.nix
];
# I'm not a zealot about this one.
nixpkgs.config.allowUnfree = true;
nixpkgs.overlays = [
(self: super: {
neovim = super.neovim.override {
viAlias = true;
vimAlias = true;
};
})
];
environment.variables = {
EDITOR="nvim";
PAGER="less -R";
};
# TODO(jwall): We need to do this some other way.
programs = with pkgs; {
neovim.enable = true;
neovim.configure = {
packages.myVimPackage = with pkgs.vimPlugins; {
start = [
nerdtree
vim-nix
coc-rust-analyzer
coc-git
coc-vimlsp
coc-python
coc-clangd
coc-go
coc-html
coc-css
coc-yaml
coc-json
coc-nvim
vim-toml
hoon-vim
];
};
};
zsh.enable = true; # default shell on catalina
};
# List packages installed in system profile. To search by name, run:
# $ nix-env -qaP | grep wget
environment.systemPackages =
with pkgs; [
neovim
vimPlugins.nerdtree
vimPlugins.vim-nix
vimPlugins.coc-rust-analyzer
vimPlugins.coc-git
vimPlugins.coc-vimlsp
vimPlugins.coc-python
vimPlugins.coc-clangd
vimPlugins.coc-go
vimPlugins.coc-html
vimPlugins.coc-css
vimPlugins.coc-yaml
vimPlugins.coc-json
vimPlugins.coc-nvim
vimPlugins.vim-toml
vimPlugins.hoon-vim
tmux
inputs.runwhen
gnumake
clang
clang-tools
lld
libiconv # this is frequently needed when compiling something
rustup
rust-analyzer
rustc
cargo
cargo-deps
#rustc
#cargo
#cargo-deps
# TODO find a version of the julia package that will install
# on darwin and add it as an overlay
python
@ -35,17 +71,18 @@
git
mercurial
bash
podman
curl
wget
jq
# TODO(jwall): Find a non broken sile package version and add it as an overlay
spacebar
coreutils
watch
vscode
iterm2
# TODO add sonic-pi here if it supports the arch
podman
qemu
curl
wget
jq
# TODO(jwall): Find a non broken sile package version and add it as an overlay
spacebar
coreutils
watch
vscode
iterm2
# TODO add sonic-pi here if it supports the arch
];
# Use a custom configuration.nix location.
@ -61,7 +98,6 @@
# Create /etc/bashrc that loads the nix-darwin environment.
# programs.bash.enable = true; # default shell on catalina
programs.zsh.enable = true; # default shell on catalina
# programs.fish.enable = true;
# Used for backwards compatibility, please read the changelog before changing.

224
nix/darwin/flake.lock generated
View File

@ -20,7 +20,154 @@
"type": "github"
}
},
"durnitisp": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"naersk": "naersk"
},
"locked": {
"lastModified": 1646347522,
"narHash": "sha256-9FmfD+maojx6WXGqnfznBi6noeqZJVqbNAahdarmalo=",
"owner": "zaphar",
"repo": "durnitisp",
"rev": "26ac114f8855b1206c9a9df4bf461a1a0b643ce5",
"type": "github"
},
"original": {
"owner": "zaphar",
"repo": "durnitisp",
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1641205782,
"narHash": "sha256-4jY7RCWUoZ9cKD8co0/4tFARpWB+57+r1bLLvXNJliY=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "b7547d3eed6f32d06102ead8991ec52ab0a4f1a7",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-compat_2": {
"flake": false,
"locked": {
"lastModified": 1648199409,
"narHash": "sha256-JwPKdC2PoVBkG6E+eWw3j6BMR6sL3COpYWfif7RVb8Y=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "64a525ee38886ab9028e6f61790de0832aa3ef03",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-utils": {
"locked": {
"lastModified": 1644229661,
"narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"locked": {
"lastModified": 1649676176,
"narHash": "sha256-OWKJratjt2RW151VUlJPRALb7OU2S5s+f0vLj4o1bHM=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "a4b154ebbdc88c8498a5c7b01589addc9e9cb678",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_3": {
"locked": {
"lastModified": 1637014545,
"narHash": "sha256-26IZAc5yzlD9FlDT54io1oqG/bBoyka+FJk5guaX4x4=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "bba5dcc8e0b20ab664967ad83d24d64cb64ec4f4",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"naersk": {
"inputs": {
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1639947939,
"narHash": "sha256-pGsM8haJadVP80GFq4xhnSpNitYNQpaXk4cnA796Cso=",
"owner": "nix-community",
"repo": "naersk",
"rev": "2fc8ce9d3c025d59fee349c1f80be9785049d653",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "naersk",
"type": "github"
}
},
"naersk_2": {
"inputs": {
"nixpkgs": "nixpkgs_3"
},
"locked": {
"lastModified": 1650101877,
"narHash": "sha256-IYxYc5Z1ZHQDTQbTWsOZ9HlZepsVjgV5oZwmbKzxSJs=",
"owner": "nix-community",
"repo": "naersk",
"rev": "8cc379478819e6a22ce7595a761fe1e17c8d7458",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "naersk",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1645937171,
"narHash": "sha256-n9f9GZBNMe8UMhcgmmaXNObkH01jjgp7INMrUgBgcy4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "22dc22f8cedc58fcb11afe1acb08e9999e78be9c",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1650155902,
"narHash": "sha256-UFqkwGceA/CGNbWSleACF/KTTosDzk/8ESjRV3Y70S0=",
@ -35,10 +182,85 @@
"type": "github"
}
},
"nixpkgs_3": {
"locked": {
"lastModified": 1650109093,
"narHash": "sha256-tqlnKrAdJktRLXTou9le0oTqrYBAFpGscV5RADdpArU=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "faad370edcb37162401be50d45526f52bb16a713",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs_4": {
"locked": {
"lastModified": 1650222748,
"narHash": "sha256-AHh/goEfG5hlhIMVgGQwACbuv5Wit2ND9vrcB4QthJs=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "ba88a5afa6fff7710c17b5423ff9d721386c4164",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"darwin": "darwin",
"nixpkgs": "nixpkgs"
"durnitisp": "durnitisp",
"nixpkgs": "nixpkgs_2",
"runwhen": "runwhen"
}
},
"runwhen": {
"inputs": {
"flake-compat": "flake-compat_2",
"flake-utils": "flake-utils_2",
"naersk": "naersk_2",
"nixpkgs": "nixpkgs_4",
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1650223151,
"narHash": "sha256-9qyT3VFCWC6MRAPo3Wf5RTJvpDKl0qK+OgLmp4Y6754=",
"owner": "zaphar",
"repo": "runwhen",
"rev": "69f6334dc8c17537eb9af798cd7fb9561b905f09",
"type": "github"
},
"original": {
"owner": "zaphar",
"repo": "runwhen",
"type": "github"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": "flake-utils_3",
"nixpkgs": [
"runwhen",
"nixpkgs"
]
},
"locked": {
"lastModified": 1650162887,
"narHash": "sha256-e23LlN7NQGxrsSWNNAjyvrWlZ3kwFSav9kXbayibKWc=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "26b570500cdd7a359526524e9abad341891122a6",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
}
},

View File

@ -1,20 +1,24 @@
{
inputs = {
# TODO(jwall): Use the oxalica rust overlay here
nixpkgs.url = "github:nixos/nixpkgs";
darwin.url = "github:lnl7/nix-darwin";
darwin.inputs.nixpkgs.follows = "nixpkgs";
runwhen.url = "github:zaphar/runwhen";
durnitisp.url = "github:zaphar/durnitisp";
};
outputs = {self, nixpkgs, darwin, ...}:
outputs = {self, nixpkgs, darwin, runwhen, durnitisp, ...}:
{
darwinConfigurations."jeremys-mbp" = darwin.lib.darwinSystem {
darwinConfigurations."jeremys-mbp" = darwin.lib.darwinSystem rec {
system = "aarch64-darwin";
modules = [
./darwin-configuration.nix
];
inputs = {
pkgs = nixpkgs;
runwhen = runwhen.defaultPackage."${system}";
durnitisp = durnitisp.defaultPackage."${system}";
};
};
};

View File

@ -0,0 +1,167 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.neovim;
runtime' = filter (f: f.enable) (attrValues cfg.runtime);
runtime = pkgs.linkFarm "neovim-runtime" (map (x: { name = x.target; path = x.source; }) runtime');
in {
options.programs.neovim = {
enable = mkEnableOption "Neovim";
defaultEditor = mkOption {
type = types.bool;
default = false;
description = ''
When enabled, installs neovim and configures neovim to be the default editor
using the EDITOR environment variable.
'';
};
viAlias = mkOption {
type = types.bool;
default = false;
description = ''
Symlink <command>vi</command> to <command>nvim</command> binary.
'';
};
vimAlias = mkOption {
type = types.bool;
default = false;
description = ''
Symlink <command>vim</command> to <command>nvim</command> binary.
'';
};
withRuby = mkOption {
type = types.bool;
default = true;
description = "Enable Ruby provider.";
};
withPython3 = mkOption {
type = types.bool;
default = true;
description = "Enable Python 3 provider.";
};
withNodeJs = mkOption {
type = types.bool;
default = false;
description = "Enable Node provider.";
};
configure = mkOption {
type = types.attrs;
default = {};
example = literalExpression ''
{
customRC = '''
" here your custom configuration goes!
''';
packages.myVimPackage = with pkgs.vimPlugins; {
# loaded on launch
start = [ fugitive ];
# manually loadable by calling `:packadd $plugin-name`
opt = [ ];
};
}
'';
description = ''
Generate your init file from your list of plugins and custom commands.
Neovim will then be wrapped to load <command>nvim -u /nix/store/<replaceable>hash</replaceable>-vimrc</command>
'';
};
package = mkOption {
type = types.package;
default = pkgs.neovim-unwrapped;
defaultText = literalExpression "pkgs.neovim-unwrapped";
description = "The package to use for the neovim binary.";
};
finalPackage = mkOption {
type = types.package;
visible = false;
readOnly = true;
description = "Resulting customized neovim package.";
};
runtime = mkOption {
default = {};
example = literalExpression ''
{ "ftplugin/c.vim".text = "setlocal omnifunc=v:lua.vim.lsp.omnifunc"; }
'';
description = ''
Set of files that have to be linked in <filename>runtime</filename>.
'';
type = with types; attrsOf (submodule (
{ name, config, ... }:
{ options = {
enable = mkOption {
type = types.bool;
default = true;
description = ''
Whether this /etc file should be generated. This
option allows specific /etc files to be disabled.
'';
};
target = mkOption {
type = types.str;
description = ''
Name of symlink. Defaults to the attribute
name.
'';
};
text = mkOption {
default = null;
type = types.nullOr types.lines;
description = "Text of the file.";
};
source = mkOption {
type = types.path;
description = "Path of the source file.";
};
};
config = {
target = mkDefault name;
source = mkIf (config.text != null) (
let name' = "neovim-runtime" + baseNameOf name;
in mkDefault (pkgs.writeText name' config.text));
};
}));
};
};
config = mkIf cfg.enable {
environment.systemPackages = [
cfg.finalPackage
];
environment.variables.EDITOR = mkIf cfg.defaultEditor (mkOverride 900 "nvim");
programs.neovim.finalPackage = pkgs.wrapNeovim cfg.package {
inherit (cfg) viAlias vimAlias withPython3 withNodeJs withRuby;
configure = cfg.configure // {
customRC = (cfg.configure.customRC or "") + ''
set runtimepath^=${runtime}/etc
'';
};
};
};
}