-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathflake.nix
More file actions
255 lines (230 loc) · 10.7 KB
/
flake.nix
File metadata and controls
255 lines (230 loc) · 10.7 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# Docs on flakes:
# - https://nixos.wiki/wiki/Flakes
# - https://www.tweag.io/blog/2020-05-25-flakes/
# - https://www.tweag.io/blog/2020-07-31-nixos-flakes/
#
# Example configs:
# - https://github.com/mjlbach/nix-dotfiles/blob/master/nixpkgs/flake.nix
# - https://discourse.nixos.org/t/example-use-nix-flakes-with-home-manager-on-non-nixos-systems/10185
{
description = "Nix flake packaging bew's dotfiles";
# NOTE: inputs url can be written using the flake reference syntax,
# documented at https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-flake.html#flake-references
# We use specific branches to get most/all packages from the official cache.
inputs = {
nixpkgsStable.url = "github:nixos/nixpkgs/nixos-25.11";
nixpkgsBleedingEdge.url = "github:nixos/nixpkgs/nixpkgs-unstable";
officialTemplates.url = "github:nixos/templates";
myTemplates.url = "github:bew/my-nix-templates";
homeManager.url = "github:nix-community/home-manager/release-25.11";
homeManager.inputs.nixpkgs.follows = "nixpkgsStable";
systems.url = "github:nix-systems/default";
};
# TO-EXPERIMENT(?): flake-parts (https://github.com/hercules-ci/flake-parts) to
# define my toplevel flake in multiples files & auto-merge packages, homeConfig, homeModules, {tool,…}ConfigModules...
outputs = { self, systems, ... }@flakeInputs: let
lib = flakeInputs.nixpkgsStable.lib;
eachSystem = lib.genAttrs (import systems);
# FIXME: This should be configured in each 'home' config,
# and injected in tool configs with an override 🤔
editableConfigOverride = {
editable.config = {
nixStorePath = self;
realPath = "/home/bew/.dot"; # FIXME: hardcoded $USER 😬
};
};
pkgsForSys = system: {
myPkgs = self.packages.${system};
stablePkgs = flakeInputs.nixpkgsStable.legacyPackages.${system};
bleedingedgePkgs = flakeInputs.nixpkgsBleedingEdge.legacyPackages.${system};
};
forSys = system: let
inherit (pkgsForSys system) myPkgs stablePkgs bleedingedgePkgs;
in rec {
inherit myPkgs stablePkgs bleedingedgePkgs;
directSymlinker = stablePkgs.callPackage ./nix/mylib/editable-symlinker.nix {};
lib = stablePkgs.lib;
mybuilders = stablePkgs.callPackage ./nix/mylib/mybuilders.nix {};
# IDEA: rename to `pkglib`?
# (to show it's a lib but about packages (so not system-agnostic))
kitsys = import ./nix/kit-system { inherit lib; };
zsh-kit = kitsys.newKit (import ./nix/kits/zsh-toolkit/kit.nix);
toolConfigs.zsh-bew = zsh-kit.eval {
pkgs = stablePkgs;
config = ./zsh/zsh-bew.zsh-config.nix;
};
toolConfigs.zsh-bew-bins-from-PATH = toolConfigs.zsh-bew.lib.extendWith {
deps.bins = {
fzf.pkg = lib.mkForce "from-PATH";
eza.pkg = lib.mkForce "from-PATH";
};
};
nvim-kit = kitsys.newKit (import ./nix/kits/nvim-toolkit/kit.nix);
toolConfigs.nvim-minimal = nvim-kit.eval {
pkgs = stablePkgs;
config = ./nvim/nvim-minimal.nvim-config.nix;
configOverride = editableConfigOverride;
};
toolConfigs.nvim-bew = nvim-kit.eval {
pkgs = stablePkgs;
config = ./nvim/nvim-bew.nvim-config.nix;
configOverride = {
imports = [editableConfigOverride];
# Override python lsp to use more recent python
# (Attempting to fix FREQUENT crashes with dmypy 1.11.x)
deps.bins.python-lsp-server.extra.pyPkg = lib.mkForce bleedingedgePkgs.python313;
# Require v0.15.0+ to avoid this issue:
# ref: https://github.com/LuaLS/lua-language-server/issues/3175
# ref: https://github.com/LuaLS/lua-language-server/pull/3182 (PR)
deps.bins.lua-language-server.pkg = lib.mkForce bleedingedgePkgs.lua-language-server;
# Always use latest to ensure editing my projects using Rust from unstable work well
# (e.g. when proc-macro-server is more recent in a project, generating errors)
deps.bins.rust-analyzer.pkg = lib.mkForce bleedingedgePkgs.rust-analyzer;
};
};
tmux-kit = kitsys.newKit (import ./nix/kits/tmux-toolkit/kit.nix);
toolConfigs.tmux-bew = tmux-kit.eval {
pkgs = stablePkgs;
config = ./tmux/bew.tmux-config.nix;
configOverride = editableConfigOverride;
};
};
in {
# note: force system
homeConfig = with (forSys "x86_64-linux"); import "${flakeInputs.homeManager}/modules" {
pkgs = stablePkgs;
configuration = import ./nix/homes/main.nix {
inherit flakeInputs;
system = "x86_64-linux";
username = "bew";
};
# Pkgs channels from flakeInputs
# => Allows to have a stable sharing point for multiple pkgs sets
#
# NOTE: `pkgsChannels` CANNOT be set through `_module.args` without a major limitation:
# Using `_module.args...` somewhere in `imports` is NOT possible because evaluating
# an option like `_module` needs to resolve all imports _first_.
# (e.g. to use `callPackage` to dynamically fill/configure a function that returns a module,
# like `(pkgsChannels.fooPkgs.callPackage ./bar.nix {}).someBarSpecificModule`)
#
# => Setting `pkgsChannels` via `specialArgs` of the underlying `evalModules` function works
# because it statically sets module arguments from OUTSIDE of the module system,
# without going through all of the fixpoint stuff and resolving all imports.
#
# (Thank you `Lily Foster` on Matrix for quickly helping me find the recursion issue! ❤️)
extraSpecialArgs.pkgsChannels = {
stable = stablePkgs;
bleedingedge = bleedingedgePkgs;
myPkgs = myPkgs;
};
# Expose to home modules various tool configs.
# (but not exposed out of the dotfiles flake')
#
# Must be in `extraSpecialArgs` since it's going to be used in modules' imports.
extraSpecialArgs.kitConfigs = let
makeEditable = config: config.lib.extendWith {
# Make the config editable if it's supported
editable.try_enable = true;
};
in {
zsh-bew = toolConfigs.zsh-bew-bins-from-PATH;
nvim-minimal = makeEditable toolConfigs.nvim-minimal;
nvim-bew = makeEditable toolConfigs.nvim-bew;
tmux-bew = makeEditable toolConfigs.tmux-bew;
};
};
# --- Stuff I want to be able to do with binaries & packages:
# In my packages:
# - a `zsh-bew` full pkg with the full `zsh` pkg + `zsh` binary wrapped to use my config (using fzf-bew)
# - a `fzf-bew` full pkg with the full `fzf` pkg + `fzf` binary wrapped to use my config
# - a `zsh-bew-bin` pkg with only `${zsh-bew}/bin/zsh`
# - a `fzf-bew-bin` pkg with only `${fzf-bew}/bin/fzf`
# - ...
# => Installing `zsh-bew` or `fzf-bew` should also make `man zsh` & `man fzf` available!
# (`man` will auto discover man pages based on binary in `$PATH`, see `man 5 manpath`!)
#
# In my CLI env:
# - a `zsh` bin, with my config (may be editable?)
# - a `zsh-special-config` bin, for a zsh with a specialized config (bin only)
# - a `fzf` bin, for fzf with my config
packages = eachSystem (system: with (forSys system); let
useStandalonePkg = config: config.outputs.toolPkg.standalone;
in {
zsh-bew = useStandalonePkg toolConfigs.zsh-bew;
zsh-bew-zdotdir = toolConfigs.zsh-bew.outputs.zdotdir;
zsh-bew-bin = mybuilders.linkSingleBin (
lib.getExe (useStandalonePkg toolConfigs.zsh-bew)
);
fzf-bew = stablePkgs.callPackage ./nix/pkgs/fzf-with-bew-cfg.nix {
fzf = stablePkgs.fzf;
replaceBinsInPkg = mybuilders.replaceBinsInPkg;
};
fzf-bew-bin = mybuilders.linkSingleBin (lib.getExe myPkgs.fzf-bew);
nvim-minimal = useStandalonePkg toolConfigs.nvim-minimal;
nvim-bew = useStandalonePkg toolConfigs.nvim-bew;
tmux-bew = useStandalonePkg toolConfigs.tmux-bew;
});
apps = eachSystem (system: with (forSys system); {
# An env with all 'core' cli tools :)
default = {
type = "app";
program = let
tmux-config = toolConfigs.tmux-bew;
env = stablePkgs.buildEnv {
name = "cli-base-env";
paths = let
useStandalonePkg = config: config.outputs.toolPkg.standalone;
in [
# note: cannot use `toolConfigs.zsh-bew`, otherwise my fzf-bew custom pkg isn't used
# (packages in myPkgs are not cross-referenced yet..)
(useStandalonePkg toolConfigs.zsh-bew-bins-from-PATH)
myPkgs.nvim-minimal
myPkgs.nvim-bew
myPkgs.fzf-bew
(useStandalonePkg tmux-config)
(mybuilders.linkBins "nvim-default" {
nvim = lib.getExe myPkgs.nvim-bew;
})
stablePkgs.less # ensure modern pager
];
meta.mainProgram = "zsh";
};
entrypoint = stablePkgs.writeShellScript "cli-base-entrypoint" /* sh */ ''
if [[ -z "''${PATH_BEFORE_MY_NIX_CLI_ENV:-}" ]]; then
export PATH_BEFORE_MY_NIX_CLI_ENV=$PATH
# note: Do _not_ re-set it to ensure its content is not 'infected' by Nix paths
fi
export PATH=${env}/bin:$PATH_BEFORE_MY_NIX_CLI_ENV
# MAYBE: Move to tmux kit (?)
if [[ -n "''${TMUX:-}" ]]; then
# We are in TMUX!
echo
echo "--------------------------------------------------------------------------------"
echo '!! Tmux needs the new cli env !!'
echo "To ensure new tmux panes spawn apps from the NEW cli env, update tmux's \$PATH:"
echo
echo "👉 tmux set-environment -g PATH '$PATH'"
echo
echo "--------------------------------------------------------------------------------"
echo
previous_tmux_config_env=$(tmux show-environment -g TMUX_CONFIG_ENTRYPOINT 2>/dev/null)
new_tmux_config_env=TMUX_CONFIG_ENTRYPOINT=${tmux-config.outputs.cfgEntrypoint}
if [[ "$previous_tmux_config_env" != "$new_tmux_config_env" ]]; then
echo "!! Tmux config changed !!"
echo
echo "Update target config:"
echo "👉 tmux set-environment -g TMUX_CONFIG_ENTRYPOINT '${tmux-config.outputs.cfgEntrypoint}'"
echo
echo "Then reload the config"
echo
echo "--------------------------------------------------------------------------------"
echo
fi
fi
exec ${lib.getExe env} "$@"
'';
in entrypoint.outPath;
};
});
};
}