Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NixOS support #906

Merged
merged 32 commits into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
72b54ba
add(nixos): add build dependencies for mason.nvim on NixOS
misumisumi Jul 26, 2023
813ebac
update(options,setting): merged dont_set_python_host_prog
misumisumi Jul 26, 2023
4580c2f
add(nixos/neovim): Extend home-manager's programs.neovim.
misumisumi Jul 26, 2023
24c49d6
add(flake): Providing the home-manager module.
misumisumi Jul 26, 2023
2ec0bbb
add(nixos/dotnet): Provide dotnet NixOS module
misumisumi Jul 26, 2023
a13d983
feat(nixos/neovim): Correspondence to DotNET.
misumisumi Jul 26, 2023
dbadf18
feat(nixos/neovim): enabled `nix-ld`, your need install `nix-ld` without
misumisumi Jul 26, 2023
af35feb
Revert "feat(nixos/neovim): enabled `nix-ld`, your need install `nix-…
misumisumi Jul 26, 2023
6baf424
feat(nixos/neovim): Inspired by "nixos/modules/programs/nix-ld.nix".
misumisumi Jul 26, 2023
2e2d3c9
fix(nixos/neovim) rename option "extraBuildDependentPackages" to "ext…
misumisumi Jul 26, 2023
b65dc57
feat(option): Set sqlite_clib_path from environment variable.
misumisumi Jul 26, 2023
e9731fe
fix(nixos/neovim): add prefix "nvim-" to extraPrefix of buildEnv and fix
misumisumi Jul 28, 2023
361abf0
add(nixos/neovim): add `nix-ld` to extraPackages
misumisumi Jul 28, 2023
e1c1cd8
Revert "add(nixos/neovim): add `nix-ld` to extraPackages"
misumisumi Jul 28, 2023
ce311e4
feat(nixos/neovim): add 'setBuildEnv' option
misumisumi Jul 28, 2023
d809af5
style(nixos): Change key of dotnet module
misumisumi Jul 28, 2023
49caa70
feat(nixos/neovim): Set NIX_LD_LIBRARY_PATH myself. Including package…
misumisumi Jul 28, 2023
98bbe98
feat(flake.nix): Change module name.
misumisumi Jul 28, 2023
d58caff
fix(nixos/neovim): Remove deno and option to install build tools such…
misumisumi Jul 28, 2023
08d43cc
fix(nixos/neovim): Removed clipboard and neovim-remote, changed ripgr…
misumisumi Jul 28, 2023
36d0b3d
fix(nixos/neovim): Change submodule name.
misumisumi Jul 29, 2023
c390f5d
Update nixos/default.nix
misumisumi Aug 9, 2023
be7a1bf
feat(neovim/default.nix): Clean up language support
misumisumi Aug 9, 2023
b310ddd
feat(nixos): Include `snips` and `tutor` under `$XDG_CONFIG_HOME/nvim`
misumisumi Aug 12, 2023
645846f
fix(nixos): Fix `stack` `extra-include-dirs` and `extra-lib-dirs`
misumisumi Aug 13, 2023
ddc2dce
remove(nixos): Remove some language support
misumisumi Aug 13, 2023
3e6da56
fix(nixos): Remove alias settings
misumisumi Aug 19, 2023
38a0f33
Merge branch 'main' into nixos-support-using-mason
Jint-lzxy Aug 19, 2023
d145ef0
fixups after merging 'main'
Jint-lzxy Aug 19, 2023
5ce0a8c
(nix) update docs
Jint-lzxy Aug 19, 2023
1728366
(readme) update docs
Jint-lzxy Aug 19, 2023
92b3150
fixup! (readme) update docs
Jint-lzxy Aug 19, 2023
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
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.
{
misumisumi marked this conversation as resolved.
Show resolved Hide resolved
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.
'';
aarnphm marked this conversation as resolved.
Show resolved Hide resolved
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
];
};
};
}