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 21 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
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/07/24, 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;
};
};
}
17 changes: 12 additions & 5 deletions lua/core/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,33 @@ local function load_options()
wrapscan = true,
writebackup = false,
}

local function isempty(s)
return s == nil or s == ""
end
local function use_if_defined(val, fallback)
return val ~= nil and val or fallback
end

-- custom python provider
local conda_prefix = os.getenv("CONDA_PREFIX")
if not isempty(conda_prefix) then
vim.g.python_host_prog = conda_prefix .. "/bin/python"
vim.g.python3_host_prog = conda_prefix .. "/bin/python"
vim.g.python_host_prog = use_if_defined(vim.g.python_host_prog, conda_prefix .. "/bin/python")
vim.g.python3_host_prog = use_if_defined(vim.g.python3_host_prog, conda_prefix .. "/bin/python")
else
vim.g.python_host_prog = "python"
vim.g.python3_host_prog = "python3"
vim.g.python_host_prog = use_if_defined(vim.g.python_host_prog, "python")
vim.g.python3_host_prog = use_if_defined(vim.g.python3_host_prog, "python3")
end

for name, value in pairs(global_local) do
vim.o[name] = value
end

local sqlite_clib_path = os.getenv("SQLITE_CLIB_PATH")
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
2 changes: 1 addition & 1 deletion lua/core/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ settings["load_big_files_faster"] = true
-- Settings will complete their replacement at initialization.
-- Parameters will be automatically completed as you type.
-- Example: { sky = "#04A5E5" }
---@type palette[]
---@type palette
settings["palette_overwrite"] = {}

-- Set the colorscheme to use here.
Expand Down
6 changes: 6 additions & 0 deletions nixos/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
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;
};
}
275 changes: 275 additions & 0 deletions nixos/neovim/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,275 @@
# 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".
Please see details https://github.com/ayamir/nvimdots
'';
setBuildEnv = mkEnableOption ''
Sets environment variables that resolve build dependencies needed by `mason.nvim` and `nvim-treesitter`
Environment variables are only visible to `nvim` and have no effect on the session.
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
withDotNET = mkEnableOption ''
Enable dotnet provider. Set to `true` to
use DotNET plugins.
'';
withErlang = mkEnableOption ''
Enable Erlang provider. Set to `true` to
use Erlang plugins.
'';
withGo = mkEnableOption ''
Enable Go provider. Set to `true` to
use Go plugins.
'';
withHaskell = mkEnableOption ''
Enable Haskell compiler. Set to `true` to
use Haskell plugins.
'';
withHaxe = mkEnableOption ''
Enable Haxe provider. Set to `true` to
use Haxe plugins.
'';
withJava = mkEnableOption ''
Enable Java provider. Set to `true` to
use Java plugins.
'';
withJulia = mkEnableOption ''
Enable Julia provider. Set to `true` to
use Julia plugins.
'';
withNim = mkEnableOption ''
Enable nim provider. Set to `true` to
use nim plugins.
'';
withOpam = mkEnableOption ''
Enable Opam provider. Set to `true` to
use Opam plugins.
'';
withPHP = mkEnableOption ''
Enable PHP provider. Set to `true` to
use PHP plugins.
'';
withR = mkEnableOption ''
Enable R provider. Set to `true` to
use R plugins.
'';
withRust = mkEnableOption ''
Enable Rust provider. Set to `true` to
use Rust plugins.
'';
withVala = mkEnableOption ''
Enable Vala provider. Set to `true` to
use Vala plugins.
'';
extraRPackages = 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
extraRPackages = [ pkgs.rPackages.xxx ];
should become
extraRPackages = rPkgs: with rPkgs; [ xxx ];
'')
(functionTo fromType);
default = _: [ ];
defaultText = literalExpression "ps: [ ]";
example =
literalExpression "rPkgs: with rPkgs; [ xml2 ]";
description = ''
The extra R packages required for your plugins to work.
This option accepts a function that takes a R package set as an argument,
and selects the required R packages from this package set.
See the example for more info.
'';
};
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 become
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
++ optional cfg.withGo hunspell
++ optionals cfg.withVala [ vala jsonrpc-glib ];

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/lua".source = ../../lua;
"nvim/init.lua".source = ../../init.lua;
};
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.java.enable = cfg.withJava;
programs.dotnet.dev.enable = cfg.withDotNET;

programs.neovim = {
enable = true;
viAlias = true; # Replace from vi&vim to neovim
misumisumi marked this conversation as resolved.
Show resolved Hide resolved
vimAlias = true;
vimdiffAlias = true;

withNodeJs = true;
withPython3 = true;
withRuby = true;

extraPackages = with pkgs;
[
# Dependent packages used by default plugins
doq
sqlite

yarn
]
++ optionals cfg.withBuildTools [
pkg-config
clang
gcc
cmake
gnumake
ninja
]
++ optional cfg.withErlang rebar3
++ optional cfg.withGo go
++ optionals cfg.withHaskell [
ghc
(pkgs.writeShellApplication {
name = "stack";
text = ''
exec "${pkgs.stack}/bin/stack" "--extra-include-dirs=${config.home.profileDirectory}/lib/include" "--extra-lib-dirs=${config.home.profileDirectory}/lib" "$@"
'';
})
(haskellPackages.ghcWithPackages (ps: [
# ghcup # ghcup is broken
] ++ cfg.extraHaskellPackages pkgs.haskellPackages))
]
++ optional cfg.withHaxe haxe
++ optional cfg.withJulia julia-bin
++ optional cfg.withNim nim
++ optional cfg.withOpam opam
++ optionals cfg.withPHP [
php
phpPackages.composer # php
]
++ optional cfg.withR (rWrapper.override {
packages = with pkgs.rPackages;
[ xml2 lintr roxygen2 ]
++ cfg.extraRPackages pkgs.rPackages;
})
++ optional cfg.withRust cargo
++ optionals cfg.withVala [ meson vala ];

extraPython3Packages = ps: with ps; [
isort
docformatter
pynvim
];
extraLuaPackages = ls: with ls; [
luarocks
];
};
};
}