-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
277 lines (263 loc) · 8.42 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
{
description = "my very own special snowflake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
nixpkgs-2305.url = "github:NixOS/nixpkgs/nixos-23.05";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
nixos-hardware.url = "github:NixOS/nixos-hardware/master";
nixos-generators = {
url = "github:nix-community/nixos-generators";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
home-manager = {
url = "github:nix-community/home-manager/release-24.05";
inputs.nixpkgs.follows = "nixpkgs";
};
nixos-wsl = {
url = "github:nix-community/NixOS-WSL";
# url = "/home/nzbr/Projekte/NixOS-WSL";
inputs.flake-compat.follows = "flake-compat";
inputs.flake-utils.follows = "flake-utils";
inputs.nixpkgs.follows = "nixpkgs";
};
base = {
url = "github:nix-basement/nix-basement/24.05";
# url = "/home/nzbr/devsaur/nixos-base";
# url = "/storage/nzbr/devsaur/nixos-base";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
naersk = {
# rust package builder
url = "github:nix-community/naersk";
inputs.nixpkgs.follows = "nixpkgs";
};
agenix = {
url = "github:ryantm/agenix";
inputs.nixpkgs.follows = "nixpkgs";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
nirgenx = {
url = "github:nzbr/nirgenx";
inputs.flake-compat.follows = "flake-compat";
inputs.flake-utils.follows = "flake-utils";
inputs.nixpkgs.follows = "nixpkgs";
};
xyno-experiments = {
url = "github:thexyno/x";
inputs.nixpkgs.follows = "nixpkgs-2305";
};
disko = {
url = "github:nix-community/disko";
inputs.nixpkgs.follows = "nixpkgs";
};
nixd = {
url = "github:nix-community/nixd";
inputs.nixpkgs.follows = "nixpkgs-unstable";
};
argocd = {
url = "github:argoproj/argo-cd/stable";
flake = false;
};
dotfiles = {
url = "github:nzbr/dotfiles";
# TODO: submodules = true; (once that is supported)
flake = false;
};
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
razer-nari = {
flake = false;
url = "github:imustafin/razer-nari-pulseaudio-profile";
};
wsld = {
flake = false;
url = "github:nbdd0121/wsld";
};
cert-manager-desec = {
flake = false;
url = "github:kmorning/cert-manager-webhook-desec";
};
# ceph-csi = {
# flake = false;
# url = "github:ceph/ceph-csi/release-v3.4";
# };
syncthing-key-generator = {
flake = false;
url = "github:mtreece/syncthing-key-generator";
};
};
outputs =
inputs @ { self
, flake-utils
, nixpkgs
, ...
}:
let
baseLib = import ./lib/base.nix { lib = nixpkgs.lib; };
lib = with nixpkgs.lib; foldl recursiveUpdate nixpkgs.lib ((map (x: import x { inherit lib; }) (baseLib.findModules ".nix" ./lib)) ++ [ inputs.nirgenx.lib ]);
in
with builtins; with lib; {
inherit lib;
nixosModules =
let
modulesPath = "${self}/module";
in
listToAttrs (
map
(file:
nameValuePair'
(removePrefix "${modulesPath}/" file)
(import file)
)
(lib.findModules ".nix" modulesPath)
);
nixosConfigurations =
let
allConfigs = system:
let
mkDefaultSystem = hostName: mkSystem hostName [ ];
mkSystem = hostName: extraModules: (nixosSystem {
inherit system;
specialArgs = {
inherit lib inputs system hostName extraModules;
};
modules =
[
{
imports = mapAttrsToList
(name: type: "${self}/core/${name}")
(readDir "${self}/core");
nzbr.flake = {
root = "${inputs.self}";
assets = "${inputs.self}/asset";
host = "${inputs.self}/host/${hostName}";
};
}
];
});
in
(listToAttrs (map
(hostName:
lib.nameValuePair
hostName
(
(
mkDefaultSystem hostName
) // (
mapAttrs'
(n: v: nameValuePair' (removeSuffix ".nix" n) (mkSystem hostName [ "${self}/host/${hostName}/${n}" ]))
(
filterAttrs
(n: v: (v == "regular") && (hasSuffix ".nix" n) && (n != "default.nix"))
(readDir "${self}/host/${hostName}")
)
)
)
)
(mapAttrsToList (name: type: name) (readDir "${self}/host"))
));
in
mapAttrs
(n: v: (allConfigs v.config.nzbr.system).${n})
(allConfigs "x86_64-linux");
} //
(flake-utils.lib.eachSystem
lib.systems.flakeExposed
(system:
let
pkgs = (import "${inputs.nixpkgs}" { inherit system; });
naersk = pkgs.callPackage "${inputs.naersk}" { };
python3 = pkgs.python3.withPackages (pypi: with pypi; [
pygraphviz
]);
scripts = (
# legacy scripts.nix
mapAttrs (name: script: pkgs.writeShellScriptBin name script) ((import ./scripts.nix) { inherit lib self; pkgs = (pkgs // self.packages.${system}); })
) // (
# collect from script directory
listToAttrs (
map
(file: rec {
name = unsafeDiscardStringContext (replaceStrings [ "/" ] [ "-" ] (removePrefix "${self}/script/" file)); # this is safe, actually
value = pkgs.substituteAll {
inherit name;
src = file;
dir = "bin";
isExecutable = true;
inherit python3;
# packages that are available to the scripts
inherit (pkgs)
bash
gnused
findutils
jq
nix
openssh
parallel
powershell
rage
;
wireguard = pkgs.wireguard-tools;
nom = pkgs.nix-output-monitor;
nixpkgs = toString inputs.nixpkgs;
};
})
(findModules "" "${self}/script")
)
);
in
(with builtins; with nixpkgs; with lib; rec {
devShell = pkgs.mkShell {
buildInputs =
let
ifAvailable = collection: package: (orElse collection system { ${package} = [ ]; }).${package};
in
with pkgs; (flatten [
(ifAvailable inputs.agenix.packages "agenix")
graphviz
morph
nixpkgs-fmt
rage
(ifAvailable inputs.nirgenx.packages "helm-update")
(ifAvailable inputs.nirgenx.packages "yaml2nix")
python3
])
++
mapAttrsToList
(name: drv: pkgs.writeShellScriptBin name "set -ex\nexec ${pkgs.nix}/bin/nix run .#${name} \"$@\"")
scripts;
};
checks = {
nixpkgs-fmt = pkgs.runCommand "check-nixpkgs-fmt" { nativeBuildInputs = [ pkgs.nixpkgs-fmt ]; } ''
nixpkgs-fmt --check ${./.}
touch $out
'';
};
apps = mapAttrs'
(name: value:
nameValuePair'
name
(flake-utils.lib.mkApp
{
inherit name;
drv = value;
}
)
)
scripts // packages;
packages =
filterAttrs
(name: pkg: (elem system (orElse pkg.meta "platforms" [ system ])))
(
loadPackages pkgs { inherit inputs naersk; } ".pkg.nix" ./package # import all packages from pkg directory
);
}))
);
}