Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
inputs = { };

outputs = inputs: {
nixosModules = {
homeManagerModules = {
nvimdots = ./nixos;
};
};
Expand Down
93 changes: 57 additions & 36 deletions nixos/neovim/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ in
Activate "ayamir/nvimdots".
Have a look at https://github.com/ayamir/nvimdots for details
'';
bindLazyLock = mkEnableOption ''
Bind lazy-lock.json in your repository to $XDG_CONFIG_HOME/nvim.
Very powerful in terms of keeping the environment consistent, but has the following side effects.
You cannot update it even if you run the Lazy command, because it binds read-only.
'';
setBuildEnv = mkEnableOption ''
Sets environment variables that resolve build dependencies as required by `mason.nvim` and `nvim-treesitter`
Environment variables are only visible to `nvim` and have no effect on any parent sessions.
Expand Down Expand Up @@ -66,10 +71,13 @@ in
# Inspired from https://github.com/NixOS/nixpkgs/blob/nixos-unstable/nixos/modules/programs/nix-ld.nix
build-dependent-pkgs = with pkgs;
[
# manylinux
acl
attr
bzip2
curl
glibc
libgcc.lib
libsodium
libssh
libxml2
Expand All @@ -89,32 +97,21 @@ in
makePkgConfigPath = x: makeSearchPathOutput "dev" "lib/pkgconfig" x;
makeIncludePath = x: makeSearchPathOutput "dev" "include" x;

nvim-depends-library = pkgs.buildEnv {
name = "nvim-depends-library";
paths = map lib.getLib build-dependent-pkgs;
extraPrefix = "/lib/nvim-depends";
pathsToLink = [ "/lib" ];
ignoreCollisions = true;
};
nvim-depends-include = pkgs.buildEnv {
name = "nvim-depends-include";
paths = splitString ":" (makeIncludePath build-dependent-pkgs);
extraPrefix = "/lib/nvim-depends/include";
ignoreCollisions = true;
};
nvim-depends-pkgconfig = pkgs.buildEnv {
name = "nvim-depends-pkgconfig";
paths = splitString ":" (makePkgConfigPath build-dependent-pkgs);
extraPrefix = "/lib/nvim-depends/pkgconfig";
neovim-build-deps = pkgs.buildEnv {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qq: why do we have to build neovim from scratch again?

Can we utilize something like neovim-nightly or sth?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i can add that, but i'm half way on completing my nix config.
i'll check this pr once i'm done.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sg. I have yet to migrate all my neovim to nix yet so haven't tested it extensively.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess i'm wrong, it's not the same as adding overlays in home manager's home.nix.

name = "neovim-build-deps";
paths = build-dependent-pkgs;
extraOutputsToInstall = [ "dev" ];
pathsToLink = [ "/lib" "/include" ];
ignoreCollisions = true;
};

buildEnv = [
"CPATH=${config.home.profileDirectory}/lib/nvim-depends/include"
"CPLUS_INCLUDE_PATH=${config.home.profileDirectory}/lib/nvim-depends/include/c++/v1"
"LD_LIBRARY_PATH=${config.home.profileDirectory}/lib/nvim-depends/lib"
"LIBRARY_PATH=${config.home.profileDirectory}/lib/nvim-depends/lib"
"NIX_LD_LIBRARY_PATH=${config.home.profileDirectory}/lib/nvim-depends/lib"
"PKG_CONFIG_PATH=${config.home.profileDirectory}/lib/nvim-depends/pkgconfig"
''CPATH=''${CPATH:+''${CPATH}:}${neovim-build-deps}/include''
''CPLUS_INCLUDE_PATH=''${CPLUS_INCLUDE_PATH:+''${CPLUS_INCLUDE_PATH}:}:${neovim-build-deps}/include/c++/v1''
''LD_LIBRARY_PATH=''${LD_LIBRARY_PATH:+''${LD_LIBRARY_PATH}:}${neovim-build-deps}/lib''
''LIBRARY_PATH=''${LIBRARY_PATH:+''${LIBRARY_PATH}:}${neovim-build-deps}/lib''
''NIX_LD_LIBRARY_PATH=''${NIX_LD_LIBRARY_PATH:+''${NIX_LD_LIBRARY_PATH}:}${neovim-build-deps}/lib''
''PKG_CONFIG_PATH=''${PKG_CONFIG_PATH:+''${PKG_CONFIG_PATH}:}${neovim-build-deps}/include/pkgconfig''
];
in
mkIf cfg.enable
Expand All @@ -124,24 +121,50 @@ in
"nvim/lua".source = ../../lua;
"nvim/snips".source = ../../snips;
"nvim/tutor".source = ../../tutor;
} // lib.optionalAttrs cfg.bindLazyLock {
"nvim/lazy-lock.json".source = ../../lazy-lock.json;
};
home = {
packages = with pkgs; [
ripgrep
];
shellAliases = optionalAttrs (cfg.setBuildEnv && (lib.versionOlder config.home.stateVersion "24.05")) {
nvim = concatStringsSep " " buildEnv + " nvim";
};
};
home.packages = with pkgs; [
ripgrep
] ++ optionals cfg.setBuildEnv [
nvim-depends-include
nvim-depends-library
nvim-depends-pkgconfig
patchelf
];
home.extraOutputsToInstall = optional cfg.setBuildEnv "nvim-depends";
home.shellAliases.nvim = optionalString cfg.setBuildEnv (concatStringsSep " " buildEnv) + " nvim";

programs.neovim = {
enable = true;

withNodeJs = true;
withPython3 = true;
withRuby = true;
extraWrapperArgs = optionals (cfg.setBuildEnv && (lib.versionAtLeast config.home.stateVersion "24.05")) [
"--suffix"
"CPATH"
":"
"${neovim-build-deps}/include"
"--suffix"
"CPLUS_INCLUDE_PATH"
":"
"${neovim-build-deps}/include/c++/v1"
"--suffix"
"LD_LIBRARY_PATH"
":"
"${neovim-build-deps}/lib"
"--suffix"
"LIBRARY_PATH"
":"
"${neovim-build-deps}/lib"
"--suffix"
"PKG_CONFIG_PATH"
":"
"${neovim-build-deps}/include/pkgconfig"
"--suffix"
"NIX_LD_LIBRARY_PATH"
":"
"${neovim-build-deps}/lib"
];

extraPackages = with pkgs;
[
Expand All @@ -166,9 +189,7 @@ in
exec "${pkgs.stack}/bin/stack" "--extra-include-dirs=${config.home.profileDirectory}/lib/nvim-depends/include" "--extra-lib-dirs=${config.home.profileDirectory}/lib/nvim-depends/lib" "$@"
'';
})
(haskellPackages.ghcWithPackages (ps: [
# ghcup # ghcup is broken
] ++ cfg.extraHaskellPackages pkgs.haskellPackages))
(haskellPackages.ghcWithPackages (ps: cfg.extraHaskellPackages pkgs.haskellPackages))
];

extraPython3Packages = ps: with ps; [
Expand Down