From 3a51040490d56ad9f3272728b92cd72b88540ffd Mon Sep 17 00:00:00 2001 From: MiSumiSumi Date: Sat, 19 Aug 2023 17:33:02 +0900 Subject: [PATCH] feat!: implement NixOS support (#906) * add(nixos): add build dependencies for mason.nvim on NixOS * update(options,setting): merged dont_set_python_host_prog * add(nixos/neovim): Extend home-manager's programs.neovim. * add(flake): Providing the home-manager module. * add(nixos/dotnet): Provide dotnet NixOS module * feat(nixos/neovim): Correspondence to DotNET. * feat(nixos/neovim): enabled `nix-ld`, your need install `nix-ld` without using NixOS. * Revert "feat(nixos/neovim): enabled `nix-ld`, your need install `nix-ld` without" This reverts commit fe8859790357596b96db3dd4287dbe2d6d4fbf2e. * feat(nixos/neovim): Inspired by "nixos/modules/programs/nix-ld.nix". * fix(nixos/neovim) rename option "extraBuildDependentPackages" to "extraDependentPackages" * feat(option): Set sqlite_clib_path from environment variable. * fix(nixos/neovim): add prefix "nvim-" to extraPrefix of buildEnv and fix alias * add(nixos/neovim): add `nix-ld` to extraPackages * Revert "add(nixos/neovim): add `nix-ld` to extraPackages" This reverts commit 361abf017ae92db1ccbb7c52b21d81ed3d793f8e. * feat(nixos/neovim): add 'setBuildEnv' option * style(nixos): Change key of dotnet module * feat(nixos/neovim): Set NIX_LD_LIBRARY_PATH myself. Including packages included in `nix-ld`'s NixOSModule * feat(flake.nix): Change module name. * fix(nixos/neovim): Remove deno and option to install build tools such as gcc * fix(nixos/neovim): Removed clipboard and neovim-remote, changed ripgrep install location, set sqlite environment variable to default * fix(nixos/neovim): Change submodule name. * Update nixos/default.nix Co-authored-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com> Signed-off-by: MiSumiSumi * feat(neovim/default.nix): Clean up language support * feat(nixos): Include `snips` and `tutor` under `$XDG_CONFIG_HOME/nvim` * fix(nixos): Fix `stack` `extra-include-dirs` and `extra-lib-dirs` * remove(nixos): Remove some language support * fix(nixos): Remove alias settings * fixups after merging 'main' * (nix) update docs * (readme) update docs * fixup! (readme) update docs --------- Signed-off-by: MiSumiSumi Co-authored-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com> --- README.md | 18 ++-- flake.nix | 14 +++ lua/core/options.lua | 6 +- nixos/default.nix | 7 ++ nixos/dotnet/default.nix | 43 ++++++++++ nixos/neovim/default.nix | 179 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 260 insertions(+), 7 deletions(-) create mode 100644 flake.nix create mode 100644 nixos/default.nix create mode 100644 nixos/dotnet/default.nix create mode 100644 nixos/neovim/default.nix diff --git a/README.md b/README.md index 4caf7d73e..59286771d 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ ## πŸͺ· Introduction -This repo hosts my [NeoVim](https://neovim.io/) configuration for Linux, macOS, and Windows. `init.lua` is the config entry point. +This repo hosts our [NeoVim](https://neovim.io/) configuration for Linux [(with NixOS support)](#nixos-support), macOS, and Windows. `init.lua` is the config entry point. Branch info: @@ -50,7 +50,7 @@ Branch info: -I use [lazy.nvim](https://github.com/folke/lazy.nvim) to manage plugins. +We currently manage plugins using [lazy.nvim](https://github.com/folke/lazy.nvim). Chinese introduction is [here](https://zhuanlan.zhihu.com/p/382092667). @@ -89,25 +89,31 @@ It's strongly recommended to read [Wiki: Prerequisites](https://github.com/ayami

πŸ—ΊοΈ Keybindings

-

Refer to Wiki: Keybindings

+

See Wiki: Keybindings for details


πŸ”Œ Plugins & Deps

-

Refer to Wiki: Plugins
(You can also find a deps diagram there!)

+

See Wiki: Plugins for details
(You can also find a deps diagram there!)


πŸ”§ Usage & Customization

-

Refer to Wiki: Usage

+

See Wiki: Usage for details

+
+ +

+ ❄️ NixOS Support +

+

See Wiki: NixOS Support for details


πŸ€” FAQ

-

Refer to Wiki: FAQ

+

See Wiki: FAQ for details

## ✨ Features diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..77e2746db --- /dev/null +++ b/flake.nix @@ -0,0 +1,14 @@ +{ + # This provides only NixOS module + # As of 2023/08/19, you need to depend on nixpkgs-unstable. + # because "doq" is not included in the stable version. + description = "Provide nixosModules for ayamir/nvimdots"; + + inputs = { }; + + outputs = inputs: { + nixosModules = { + nvimdots = ./nixos; + }; + }; +} diff --git a/lua/core/options.lua b/lua/core/options.lua index 7545f48e4..529c77f0e 100644 --- a/lua/core/options.lua +++ b/lua/core/options.lua @@ -125,8 +125,12 @@ local function load_options() vim.o[name] = value end + local sqlite_clib_path = os.getenv("SQLITE_CLIB_PATH") + -- Try environment variable first + if not isempty(sqlite_clib_path) then + vim.g.sqlite_clib_path = sqlite_clib_path -- Fix sqlite3 missing-lib issue on Windows - if global.is_windows then + elseif global.is_windows then -- Download the DLLs form https://www.sqlite.org/download.html vim.g.sqlite_clib_path = global.home .. "/Documents/sqlite-dll-win64-x64-3400200/sqlite3.dll" end diff --git a/nixos/default.nix b/nixos/default.nix new file mode 100644 index 000000000..c0e5e052d --- /dev/null +++ b/nixos/default.nix @@ -0,0 +1,7 @@ +# NOTE: to add more language support, make a directory under `nixos`, followed by the language name and `default.nix`. See `dotnet/default.nix` for example. +{ + imports = [ + ./dotnet + ./neovim + ]; +} diff --git a/nixos/dotnet/default.nix b/nixos/dotnet/default.nix new file mode 100644 index 000000000..af671e1d3 --- /dev/null +++ b/nixos/dotnet/default.nix @@ -0,0 +1,43 @@ +# This module provides DOTNET_ROOT, with a different way to install dotnet locally. +# This module is modified from the NixOS module `programs.dotnet` + +{ config, lib, pkgs, ... }: +with lib; +let + cfg = config.programs.dotnet.dev; +in +{ + options = { + programs.dotnet.dev = { + enable = mkEnableOption "" // { + description = '' + Install the DotNet runtime and set the + {env}`DOTNET_ROOT` variable. + ''; + }; + environmentVariables = mkOption { + type = with types; lazyAttrsOf (oneOf [ str path int float ]); + default = { }; + example = { DOTNET_SYSTEM_GLOBALIZATION_INVARIANT = "0"; }; + description = '' + An attribute set an environment variable for DotNET. + ''; + }; + package = mkOption { + type = types.package; + default = pkgs.dotnet-sdk_7; + defaultText = literalExpression "pkgs.dotnet-sdk_7"; + description = "DotNET package to install."; + }; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + + # Please see https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-environment-variables#dotnet_root-dotnet_rootx86 + home.sessionVariables = { + DOTNET_ROOT = "${cfg.package}"; + } // cfg.environmentVariables; + }; +} diff --git a/nixos/neovim/default.nix b/nixos/neovim/default.nix new file mode 100644 index 000000000..e80d84c8d --- /dev/null +++ b/nixos/neovim/default.nix @@ -0,0 +1,179 @@ +# home-manager module of neovim setup +{ config +, lib +, pkgs +, ... +}: +with lib; let + cfg = config.programs.neovim.nvimdots; +in +{ + options = { + programs.neovim = { + nvimdots = { + enable = mkEnableOption '' + Activate "ayamir/nvimdots". + Have a look at https://github.com/ayamir/nvimdots for details + ''; + 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. + Required for NixOS. + ''; + withBuildTools = mkEnableOption '' + Include basic build tools like `gcc` and `pkg-config`. + Required for NixOS. + ''; + withHaskell = mkEnableOption '' + Enable the Haskell compiler. Set to `true` to + use Haskell plugins. + ''; + extraHaskellPackages = mkOption { + type = with types; + let fromType = listOf package; + in + coercedTo fromType + (flip warn const '' + Assigning a plain list to extraRPackages is deprecated. + Please assign a function taking a package set as argument, so + extraHaskellPackages = [ pkgs.haskellPackages.xxx ]; + should be + extraHaskellPackages = hsPkgs: with hsPkgs; [ xxx ]; + '') + (functionTo fromType); + default = _: [ ]; + defaultText = literalExpression "ps: [ ]"; + example = + literalExpression "hsPkgs: with hsPkgs; [ haskell-language-server ]"; + description = '' + The extra Haskell packages required for your plugins to work. + This option accepts a function that takes a Haskell package set as an argument, + and selects the required Haskell packages from this package set. + See the example for more info. + ''; + }; + extraDependentPackages = mkOption { + type = with types; listOf package; + default = [ ]; + example = literalExpression "[ pkgs.openssl ]"; + description = "Extra build depends to add `LIBRARY_PATH` and `CPATH`."; + }; + }; + }; + }; + config = + let + # Inspired from https://github.com/NixOS/nixpkgs/blob/nixos-unstable/nixos/modules/programs/nix-ld.nix + build-dependent-pkgs = with pkgs; + [ + zlib + zstd + stdenv.cc.cc + curl + openssl + attr + libssh + bzip2 + libxml2 + acl + libsodium + util-linux + xz + systemd + # Packages not included in `nix-ld`'s NixOSModule + glib + libcxx + ] + ++ cfg.extraDependentPackages; + + 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"; + 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" + ]; + in + mkIf cfg.enable + { + xdg.configFile = { + "nvim/init.lua".source = ../../init.lua; + "nvim/lua".source = ../../lua; + "nvim/snips".source = ../../snips; + "nvim/tutor".source = ../../tutor; + }; + home.packages = with pkgs; [ + ripgrep + ] ++ optionals cfg.setBuildEnv [ patchelf nvim-depends-library nvim-depends-include nvim-depends-pkgconfig ]; + home.extraOutputsToInstall = optional cfg.setBuildEnv "nvim-depends"; + home.shellAliases.nvim = optionalString cfg.setBuildEnv (concatStringsSep " " buildEnv) + " SQLITE_CLIB_PATH=${pkgs.sqlite.out}/lib/libsqlite3.so " + "nvim"; + + programs.neovim = { + enable = true; + + withNodeJs = true; + withPython3 = true; + withRuby = true; + + extraPackages = with pkgs; + [ + # Dependent packages used by default plugins + doq + sqlite + ] + ++ optionals cfg.withBuildTools [ + pkg-config + clang + gcc + cmake + gnumake + ninja + cargo + yarn + ] + ++ optionals cfg.withHaskell [ + (pkgs.writeShellApplication { + name = "stack"; + text = '' + 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)) + ]; + + extraPython3Packages = ps: with ps; [ + isort + docformatter + pynvim + ]; + extraLuaPackages = ls: with ls; [ + luarocks + ]; + }; + }; +}