-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
329 lines (304 loc) Β· 10.5 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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
{
description = "kachick's dotfiles that can be placed in the public repository";
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.11";
# darwin does not have desirable channel for that purpose. See https://github.com/NixOS/nixpkgs/issues/107466
edge-nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nixpkgs-darwin.url = "github:NixOS/nixpkgs/nixpkgs-24.11-darwin";
# https://github.com/nix-community/home-manager/blob/release-24.11/docs/manual/nix-flakes.md
home-manager-linux = {
url = "github:nix-community/home-manager/release-24.11";
inputs.nixpkgs.follows = "nixpkgs";
};
home-manager-darwin = {
url = "github:nix-community/home-manager/release-24.11";
inputs.nixpkgs.follows = "nixpkgs-darwin";
};
nixos-wsl = {
url = "github:nix-community/NixOS-WSL/main"; # TODO: Pin to 2411.?.? if 24.11 conpat channel will be introduced
# 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
# TODO: Prefer nixpkgs version after https://github.com/NixOS/nixpkgs/pull/283278 merged
xremap-flake = {
url = "github:xremap/nix-flake";
inputs.nixpkgs.follows = "nixpkgs";
};
selfup = {
url = "github:kachick/selfup/v1.1.7";
# https://github.com/kachick/selfup/blob/v1.1.7/flake.nix#L8
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
edge-nixpkgs,
nixpkgs-darwin,
home-manager-linux,
home-manager-darwin,
...
}@inputs:
let
inherit (self) outputs;
# Candidates: https://github.com/NixOS/nixpkgs/blob/release-24.11/lib/systems/flake-systems.nix
forAllSystems = nixpkgs.lib.genAttrs (
nixpkgs.lib.intersectLists [
"x86_64-linux"
"x86_64-darwin"
] nixpkgs.lib.systems.flakeExposed
);
mkNixpkgs =
system: if (nixpkgs.lib.strings.hasSuffix "-darwin" system) then nixpkgs-darwin else nixpkgs;
overlays = import ./overlays { inherit edge-nixpkgs; };
mkPkgs =
system:
import (mkNixpkgs system) {
inherit system overlays;
};
mkHomeManager =
system:
if (nixpkgs.lib.strings.hasSuffix "-darwin" system) then
home-manager-darwin
else
home-manager-linux;
mkApp =
{ system, pkg }:
{
type = "app";
program = (mkNixpkgs system).lib.getExe pkg;
};
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: (mkPkgs system).nixfmt-rfc-style);
devShells = forAllSystems (
system:
let
pkgs = mkPkgs 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
gitleaks
cargo-make
])
++ (pkgs.lib.optionals pkgs.stdenv.isLinux (
(with pkgs; [
nixfmt-rfc-style
nixd
nixf # `nixf-tidy`
nixpkgs-lint-community
nix-init
nurl
hydra-check # Background and how to use: https://github.com/kachick/dotfiles/pull/909#issuecomment-2453389909
shellcheck
shfmt
# Don't use treefmt(treefmt1) that does not have crucial feature to cover hidden files
# https://github.com/numtide/treefmt/pull/250
treefmt2
dprint
stylua
typos
typos-lsp # For zed-editor typos extension
go_1_23
goreleaser
trivy
markdownlint-cli2
(ruby_3_3.withPackages (ps: with ps; [ rubocop ]))
])
++ (with pkgs.my; [ nix-hash-url ])
++ [ inputs.selfup.packages.${system}.default ]
));
};
}
);
packages = forAllSystems (
system:
let
pkgs = mkPkgs system;
in
{
cozette = pkgs.my.cozette;
micro-kdl = pkgs.my.micro-kdl;
micro-nordcolors = pkgs.my.micro-nordcolors;
micro-everforest = pkgs.my.micro-everforest;
micro-catppuccin = pkgs.my.micro-catppuccin;
envs = pkgs.my.envs;
}
);
apps = forAllSystems (
system:
builtins.listToAttrs (
(map
(name: {
inherit name;
value = mkApp {
system = system;
pkg = (mkPkgs system).my.${name};
};
})
[
"bump_completions"
"bump_gomod"
"check_nixf"
"bench_shells"
"walk"
"ir"
"todo"
"la"
"lat"
"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 {
system = system;
pkg = (mkHomeManager system).defaultPackage.${system};
};
}
]
)
);
nixosConfigurations =
let
system = "x86_64-linux";
shared = {
inherit system;
specialArgs = {
inherit
inputs
outputs
overlays
;
};
};
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 = mkPkgs "x86_64-linux";
x86-macOS-pkgs = mkPkgs "x86_64-darwin";
in
{
"kachick@nixos-desktop" = home-manager-linux.lib.homeManagerConfiguration {
pkgs = x86-Linux-pkgs;
modules = [
./home-manager/kachick.nix
./home-manager/linux.nix
{ targets.genericLinux.enable = false; }
./home-manager/lima-host.nix
./home-manager/systemd.nix
./home-manager/desktop.nix
./home-manager/firefox.nix
];
};
"kachick@wsl-ubuntu" = home-manager-linux.lib.homeManagerConfiguration {
pkgs = x86-Linux-pkgs;
modules = [
./home-manager/kachick.nix
./home-manager/linux.nix
./home-manager/genericLinux.nix
./home-manager/wsl.nix
];
};
"nixos@wsl-nixos" = home-manager-linux.lib.homeManagerConfiguration {
pkgs = x86-Linux-pkgs;
modules = [
./home-manager/kachick.nix
./home-manager/linux.nix
{
home.username = "nixos";
targets.genericLinux.enable = false;
}
./home-manager/wsl.nix
];
};
"kachick@macbook" = home-manager-darwin.lib.homeManagerConfiguration {
pkgs = x86-macOS-pkgs;
modules = [
./home-manager/kachick.nix
./home-manager/darwin.nix
];
};
"kachick@lima" = home-manager-darwin.lib.homeManagerConfiguration {
pkgs = x86-Linux-pkgs;
modules = [
./home-manager/kachick.nix
./home-manager/linux.nix
./home-manager/genericLinux.nix
./home-manager/lima-guest.nix
];
};
"github-actions@ubuntu-24.04" = home-manager-linux.lib.homeManagerConfiguration {
pkgs = x86-Linux-pkgs;
# 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-manager/linux.nix
{ home.username = "runner"; }
./home-manager/genericLinux.nix
./home-manager/systemd.nix
];
};
"github-actions@macos-13" = home-manager-darwin.lib.homeManagerConfiguration {
pkgs = x86-macOS-pkgs;
# 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-manager/darwin.nix
{ home.username = "runner"; }
];
};
"user@linux-cli" = home-manager-linux.lib.homeManagerConfiguration {
pkgs = x86-Linux-pkgs;
modules = [
./home-manager/common.nix
{ home.username = "user"; }
./home-manager/linux.nix
./home-manager/genericLinux.nix
./home-manager/systemd.nix
];
};
};
};
}