-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
146 lines (144 loc) · 6.67 KB
/
Copy pathflake.nix
File metadata and controls
146 lines (144 loc) · 6.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-26.05";
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
home-manager = {
url = "github:nix-community/home-manager/release-26.05";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils = {
url = "github:numtide/flake-utils";
inputs.systems.follows = "systems";
};
systems.url = "github:nix-systems/default-linux";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{ self, flake-utils, ... }@inputs:
flake-utils.lib.eachDefaultSystem (
system:
let
stable = import inputs.nixpkgs {
inherit system;
};
unstable = import inputs.nixpkgs-unstable {
inherit system;
};
neovim = stable.neovim;
dependencies = import ./dependencies { inherit stable unstable; };
treefmtEval = inputs.treefmt-nix.lib.evalModule stable ./treefmt.nix;
getExe = stable.lib.getExe;
in
rec {
devShells.default = stable.mkShell {
buildInputs = dependencies ++ [ neovim ];
};
packages = rec {
# neovim with all dependencies required by config
nvim_with_deps = stable.writeShellApplication {
name = "nvim";
runtimeInputs = dependencies;
text = ''${neovim}/bin/nvim "$@"'';
};
# a tool which unloads any .envrc previously loaded via direnv before spawning the wrapped
# program
with_unloaded_direnv = stable.writeShellApplication {
name = "nvim";
runtimeInputs = [ stable.coreutils ];
text = builtins.readFile ./with_unloaded_direnv.sh;
};
# Unload any previously loaded direnv, as neovim manages direnv itself
#
# The "hack" below is specific to the design of this neovim configuration where neovim is
# a nix package that contains its executable dependencies (LSPs, rg, etc.) as
# `runtimeInputs` which essentially makes it a wrapper that extends PATH before spawning
# original nvim. This causes problems if the nix package is started in a direnv-enabled
# environment, as the environment likely overrides PATH (especially with `use flake`).
#
# Not doing the unloading would cause direnv reloading inside NotAShelf/direnv.nvim to
# break runtimeInputs in direnv directories with `use flake` (or any PATH
# appending/prepending):
# - .envrc in current directory appends to PATH,
# - neovim wrapped in a subshell appending deps to PATH spawned (*),
# - :Direnv reload restores environment state serialized by direnv before entering current
# directory causing changes to PATH introduced in (*) to be lost,
# - direnv applies new (or updated) .envrc,
# - result: neovim does not recognize dependencies: LSPs, basic tools, etc.
#
# Unloading the changes currently applied by direnv before spawning nvim wrapped with its
# dependencies (whether it's a package or devshell) makes sure that the dependencies
# provided by this flake are the starting point for any direnv reloads happening inside
# neovim and will not be lost. `autoload_direnv` makes sure that the current directory's
# .envrc will be immediately loaded anyway.
nvim_with_deps_unloaded_direnv = stable.writeShellApplication {
name = "nvim";
text = ''${getExe with_unloaded_direnv} ${getExe nvim_with_deps} "$@"'';
};
default = nvim_with_deps_unloaded_direnv;
};
homeManagerModules.default =
args:
import ./hm-module.nix (
args
// {
nvim = packages.nvim_with_deps_unloaded_direnv;
pkgs = stable;
}
);
# A dummy home-manager configuration used to produce the built configuration from the
# currently checked out tree of this repository.
#
# The standard use-case is to use homeManagerModules.default as a home-manager module to
# include this neovim configuration in a home-manager configuration, locking a specific
# commit of this flake. The home-manager configuration below is used by
# nix_run_nvim_with_here_config.sh to produce an ad-hoc configuration without using the
# provided home-manager module. It allows to test the configuration without installing it
# user-wide and to switch between the installed configuration and the configuration in this
# directory as it develops using nvim_wrapper.
#
# As opposed to the HM module, using this home-manager configuration requires impure
# evaluation to resolve the values of the environment variables:
# - USER: the user name of the user running the produced configuration,
# - BUILT_HERE_CONFIG_ROOT: the absolute path where the configuration shall be applied;
# this directory will contain the whole home-directory-like structure.
# Non mandatory environment variables include:
# - DOT_NVIM_GIT_BRANCH_SYMBOL: the value of dot-nvim.quirks.gitBranchSymbol to use for the
# generated configuration,
# - LAZY_NVIM_UNLOCKED: if "true", omit the default check that verifies if lazy-lock.json
# is in sync with the plugin spec; this is the only way to actually perform a
# lazy-lock.json update using lazy.nvim in headless mode.
homeConfigurations.hereConfig =
let
getEnvOrDie =
env:
let
val = builtins.getEnv env;
in
if val == "" then throw "missing required env ${env}" else val;
in
inputs.home-manager.lib.homeManagerConfiguration {
pkgs = stable;
modules = [
homeManagerModules.default
{
home.username = getEnvOrDie "USER";
home.homeDirectory = getEnvOrDie "BUILT_HERE_CONFIG_ROOT";
home.stateVersion = "25.11";
dot-nvim.quirks.gitBranchSymbol = builtins.getEnv "DOT_NVIM_GIT_BRANCH_SYMBOL";
dot-nvim.lazy.locked = builtins.getEnv "LAZY_NVIM_UNLOCKED" != "true";
}
];
};
formatter = treefmtEval.config.build.wrapper;
checks = {
formatting = treefmtEval.config.build.check self;
typos = stable.runCommand "typos-check" {
nativeBuildInputs = [ stable.typos ];
} "cd ${self} && typos . && touch $out";
};
}
);
}