Skip to content

Commit

Permalink
feat!: implement NixOS support (#906)
Browse files Browse the repository at this point in the history
* 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 fe88597.

* 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 361abf0.

* 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 <dragon511southern@gmail.com>

* 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 <dragon511southern@gmail.com>
Co-authored-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com>
  • Loading branch information
misumisumi and aarnphm authored Aug 19, 2023
1 parent 10e2e49 commit 3a51040
Show file tree
Hide file tree
Showing 6 changed files with 260 additions and 7 deletions.
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -50,7 +50,7 @@ Branch info:

</div>

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).

Expand Down Expand Up @@ -89,25 +89,31 @@ It's strongly recommended to read [Wiki: Prerequisites](https://github.com/ayami
<h3 align="center">
🗺️ Keybindings
</h3>
<p align="center">Refer to <a href="https://github.com/ayamir/nvimdots/wiki/Keybindings" rel="nofollow">Wiki: Keybindings</a></p>
<p align="center">See <a href="https://github.com/ayamir/nvimdots/wiki/Keybindings" rel="nofollow">Wiki: Keybindings</a> for details</p>
<br>

<h3 align="center">
🔌 Plugins & Deps
</h3>
<p align="center">Refer to <a href="https://github.com/ayamir/nvimdots/wiki/Plugins" rel="nofollow">Wiki: Plugins</a> <br><em>(You can also find a deps diagram there!)</em></p>
<p align="center">See <a href="https://github.com/ayamir/nvimdots/wiki/Plugins" rel="nofollow">Wiki: Plugins</a> for details <br><em>(You can also find a deps diagram there!)</em></p>
<br>

<h3 align="center">
🔧 Usage & Customization
</h3>
<p align="center">Refer to <a href="https://github.com/ayamir/nvimdots/wiki/Usage" rel="nofollow">Wiki: Usage</a></p>
<p align="center">See <a href="https://github.com/ayamir/nvimdots/wiki/Usage" rel="nofollow">Wiki: Usage</a> for details</p>
<br>

<h3 align="center" id="nixos-support" name="nixos-support">
❄️ NixOS Support
</h3>
<p align="center">See <a href="https://github.com/ayamir/nvimdots/wiki/NixOS-Support" rel="nofollow">Wiki: NixOS Support</a> for details</p>
<br>

<h3 align="center">
🤔 FAQ
</h3>
<p align="center">Refer to <a href="https://github.com/ayamir/nvimdots/wiki/Issues" rel="nofollow">Wiki: FAQ</a></p>
<p align="center">See <a href="https://github.com/ayamir/nvimdots/wiki/Issues" rel="nofollow">Wiki: FAQ</a> for details</p>

## ✨ Features

Expand Down
14 changes: 14 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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;
};
};
}
6 changes: 5 additions & 1 deletion lua/core/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions nixos/default.nix
Original file line number Diff line number Diff line change
@@ -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
];
}
43 changes: 43 additions & 0 deletions nixos/dotnet/default.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}
179 changes: 179 additions & 0 deletions nixos/neovim/default.nix
Original file line number Diff line number Diff line change
@@ -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
];
};
};
}

0 comments on commit 3a51040

Please sign in to comment.