-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
301 lines (280 loc) Β· 9.66 KB
/
flake.nix
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
{
inputs = {
# Candidate channels
# - https://github.com/kachick/anylang-template/issues/17
# - https://discourse.nixos.org/t/differences-between-nix-channels/13998
# How to update the revision
# - `nix flake update --commit-lock-file` # https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake-update.html
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
edge-nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# https://github.com/nix-community/home-manager/blob/release-24.05/docs/manual/nix-flakes.md
home-manager = {
url = "github:nix-community/home-manager/release-24.05";
inputs.nixpkgs.follows = "nixpkgs";
};
nixos-wsl = {
url = "github:nix-community/NixOS-WSL/2405.5.4";
# https://github.com/nix-community/NixOS-WSL/blob/5a965cb108fb1f30b29a26dbc29b473f49e80b41/flake.nix#L5
inputs.nixpkgs.follows = "nixpkgs";
};
# https://github.com/xremap/nix-flake/blob/master/docs/HOWTO.md
xremap-flake = {
url = "github:xremap/nix-flake";
# https://github.com/xremap/nix-flake/blob/2c55335d6509702b0d337b8da697d7048e36123d/flake.nix#L6
inputs.nixpkgs.follows = "edge-nixpkgs";
};
selfup = {
url = "github:kachick/selfup/v1.1.6";
# https://github.com/kachick/selfup/blob/991afc21e437a449c9bd4237b4253f8da407f569/flake.nix#L8
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
edge-nixpkgs,
home-manager,
...
}@inputs:
let
inherit (self) outputs;
# Candidates: https://github.com/NixOS/nixpkgs/blob/release-24.05/lib/systems/flake-systems.nix
forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed;
mkApp = pkg: {
type = "app";
program = nixpkgs.lib.getExe pkg;
};
homemade-packages = forAllSystems (
system:
(nixpkgs.legacyPackages.${system}.callPackage ./pkgs {
edge-pkgs = edge-nixpkgs.legacyPackages.${system};
})
);
in
{
# nixfmt will be official
# - https://github.com/NixOS/nixfmt/issues/153
# - https://github.com/NixOS/nixfmt/issues/129
# - https://github.com/NixOS/rfcs/pull/166
# - https://github.com/NixOS/nixfmt/blob/a81f922a2b362f347a6cbecff5fb14f3052bc25d/README.md#L19
formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style);
devShells = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
edge-pkgs = edge-nixpkgs.legacyPackages.${system};
homemade-pkgs = homemade-packages.${system};
in
{
default = pkgs.mkShellNoCC {
# Realize nixd pkgs version inlay hints for stable channel instead of latest
NIX_PATH = "nixpkgs=${pkgs.path}";
TYPOS_LSP_PATH = pkgs.lib.getExe pkgs.typos-lsp; # For vscode typos extension
buildInputs =
(with pkgs; [
# https://github.com/NixOS/nix/issues/730#issuecomment-162323824
bashInteractive
nixfmt-rfc-style
nixpkgs-lint-community
nix-init
nurl
shellcheck
shfmt
gitleaks
cargo-make
dprint
stylua
typos
typos-lsp # For zed-editor typos extension
go_1_23
goreleaser
trivy
(ruby_3_3.withPackages (ps: with ps; [ rubocop ]))
])
++ (with edge-pkgs; [
nixd
# Don't use treefmt(treefmt1) that does not have crucial feature to cover hidden files
# https://github.com/numtide/treefmt/pull/250
treefmt2
markdownlint-cli2
])
++ (with homemade-pkgs; [ nix-hash-url ])
++ [ inputs.selfup.packages.${system}.default ];
};
}
);
packages = forAllSystems (system: {
cozette = homemade-packages.${system}.cozette;
micro-kdl = homemade-packages.${system}.micro-kdl;
micro-nordcolors = homemade-packages.${system}.micro-nordcolors;
micro-everforest = homemade-packages.${system}.micro-everforest;
micro-catppuccin = homemade-packages.${system}.micro-catppuccin;
envs = homemade-packages.${system}.envs;
});
apps = forAllSystems (
system:
builtins.listToAttrs (
(map
(name: {
inherit name;
value = mkApp homemade-packages.${system}.${name};
})
[
"bump_completions"
"bump_gomod"
"check_no_dirty_xz_in_nix_store"
"check_nixf"
"bench_shells"
"walk"
"ir"
"todo"
"la"
"lat"
"zed"
"ghqf"
"git-delete-merged-branches"
"git-log-fzf"
"git-log-simple"
"git-resolve-conflict"
"gh-prs"
"envs"
"nix-hash-url"
"reponame"
"gredit"
"renmark"
"preview"
"p"
]
)
++ [
# example: `nix run .#home-manager -- switch -n -b backup --flake .#user@linux-cli`
# https://github.com/NixOS/nix/issues/6448#issuecomment-1132855605
{
name = "home-manager";
value = mkApp home-manager.defaultPackage.${system};
}
]
)
);
nixosConfigurations =
let
system = "x86_64-linux";
edge-pkgs = import edge-nixpkgs {
inherit system;
config = {
allowUnfree = true;
};
};
homemade-pkgs = homemade-packages.${system};
shared = {
inherit system;
specialArgs = {
inherit
inputs
outputs
homemade-pkgs
edge-pkgs
;
};
};
in
{
"moss" = nixpkgs.lib.nixosSystem (shared // { modules = [ ./nixos/hosts/moss ]; });
"algae" = nixpkgs.lib.nixosSystem (shared // { modules = [ ./nixos/hosts/algae ]; });
"wsl" = nixpkgs.lib.nixosSystem (shared // { modules = [ ./nixos/hosts/wsl ]; });
};
homeConfigurations =
let
x86-Linux = {
pkgs = nixpkgs.legacyPackages.x86_64-linux;
extraSpecialArgs = {
homemade-pkgs = homemade-packages.x86_64-linux;
edge-pkgs = edge-nixpkgs.legacyPackages.x86_64-linux;
};
};
x86-macOS = {
pkgs = nixpkgs.legacyPackages.x86_64-darwin;
extraSpecialArgs = {
homemade-pkgs = homemade-packages.x86_64-darwin;
edge-pkgs = edge-nixpkgs.legacyPackages.x86_64-darwin;
};
};
aarch64-macOS = {
pkgs = nixpkgs.legacyPackages.aarch64-darwin;
extraSpecialArgs = {
homemade-pkgs = homemade-packages.aarch64-darwin;
edge-pkgs = edge-nixpkgs.legacyPackages.aarch64-darwin;
};
};
in
{
"kachick@desktop" = home-manager.lib.homeManagerConfiguration (
x86-Linux
// {
modules = [
./home-manager/kachick.nix
./home-manager/systemd.nix
./home-manager/gnome.nix
];
}
);
"kachick@wsl" = home-manager.lib.homeManagerConfiguration (
x86-Linux
// {
modules = [
./home-manager/kachick.nix
./home-manager/wsl.nix
];
}
);
"kachick@macbook" = home-manager.lib.homeManagerConfiguration (
x86-macOS // { modules = [ ./home-manager/kachick.nix ]; }
);
"[email protected]" = home-manager.lib.homeManagerConfiguration (
x86-Linux
// {
# Prefer "kachick" over "common" only here.
# Using values as much as possible as actual values to create a robust CI
modules = [
./home-manager/kachick.nix
{ home.username = "runner"; }
./home-manager/systemd.nix
];
}
);
"github-actions@macos-13" = home-manager.lib.homeManagerConfiguration (
x86-macOS
// {
# Prefer "kachick" over "common" only here.
# Using values as much as possible as actual values to create a robust CI
modules = [
./home-manager/kachick.nix
{ home.username = "runner"; }
];
}
);
"github-actions@macos-15" = home-manager.lib.homeManagerConfiguration (
aarch64-macOS
// {
# Prefer "kachick" over "common" only here.
# Using values as much as possible as actual values to create a robust CI
modules = [
./home-manager/kachick.nix
{ home.username = "runner"; }
];
}
);
"user@linux-cli" = home-manager.lib.homeManagerConfiguration (
x86-Linux
// {
modules = [
./home-manager/common.nix
{ home.username = "user"; }
./home-manager/systemd.nix
];
}
);
};
};
}