-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
274 lines (254 loc) · 9.36 KB
/
Copy pathflake.nix
File metadata and controls
274 lines (254 loc) · 9.36 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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
{
description = "System config flake";
inputs = {
nixos-hardware.url = "github:NixOS/nixos-hardware/master";
nixpkgs_prepatch.url = "nixpkgs/nixos-unstable";
#nixpkgs.url = "nixpkgs/nixpkgs-unstable";
nur = {
url = "github:nix-community/NUR";
inputs.nixpkgs.follows = "nixpkgs_prepatch";
};
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs_prepatch";
};
drynomore = {
url = "github:7FM/DryNoMore";
inputs.nixpkgs.follows = "nixpkgs_prepatch";
};
tmdbot = {
url = "github:7FM/TMDBot";
inputs.nixpkgs.follows = "nixpkgs_prepatch";
inputs.flake-utils.follows = "drynomore/flake-utils";
};
nix-index-database = {
url = "github:nix-community/nix-index-database";
inputs.nixpkgs.follows = "nixpkgs_prepatch";
};
};
outputs =
{
self,
nixos-hardware,
nixpkgs_prepatch,
home-manager,
nur,
drynomore,
tmdbot,
nix-index-database,
...
}@inputs:
{
nixosConfigurations =
let
mkSys =
{
deviceName,
system ? "x86_64-linux",
userName ? "tm",
customModules ? [ ],
nixpkgsOverlays ? [ ],
nixpkgsPatches ? [ ],
forceNoSecrets ? false,
}:
let
patches = [
]
++ nixpkgsPatches;
# Patching requires building the patched tree (import from derivation)
# and re-evaluating nixpkgs' flake.nix, which is expensive. Skip all of
# that and use the input as-is when there is nothing to patch.
nixpkgs-src =
if patches == [ ] then
inputs.nixpkgs_prepatch
else
(import nixpkgs_prepatch {
inherit system;
}).applyPatches
{
name = "nixpkgs-patched";
src = inputs.nixpkgs_prepatch;
inherit patches;
};
nixpkgs =
if patches == [ ] then
nixpkgs_prepatch
else
(import "${nixpkgs-src}/flake.nix").outputs { self = inputs.self; };
in
nixpkgs.lib.nixosSystem {
inherit system;
modules = [
{
nixpkgs.overlays = [
# NUR overlay
nur.overlays.default
#nur.modules.nixos.default
# my custom tools
(final: prev: {
myTools = import ./common/lib deviceName;
drynomore = drynomore.packages."${system}".default;
tmdbot = tmdbot.packages."${system}".default;
# waybar: enable experimental features + pulseaudio slider source target support
waybar = prev.waybar.overrideAttrs (oldAttrs: {
mesonFlags = oldAttrs.mesonFlags ++ [ "-Dexperimental=true" ];
patches = (oldAttrs.patches or [ ]) ++ [
(prev.fetchpatch {
url = "https://github.com/Alexays/Waybar/pull/4908.patch";
hash = "sha256-bGweDV7E1f1ht7+tB3Z2R77KF0z8SRWm8A7JVuCJI1c=";
})
];
});
# fix mattermost in wayland mode
mattermost-desktop = prev.mattermost-desktop.overrideAttrs (oldAttrs: {
runtimeDependencies = (oldAttrs.runtimeDependencies or [ ]) ++ [ prev.wayland ];
});
})
]
++ nixpkgsOverlays;
# Source: https://github.com/NixOS/nix/issues/3803#issuecomment-1181667475
# Hack to support legacy worklows that use `<nixpkgs>` etc.
nix.nixPath = [
"nixpkgs=${nixpkgs-src}"
];
}
(import ./nixos/configuration.nix forceNoSecrets deviceName userName)
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.backupFileExtension = "backup"; # Avoid activation failures due to .htoprc changes
home-manager.users."${userName}" = import ./home-manager/home.nix;
home-manager.extraSpecialArgs = {
inherit deviceName;
inherit userName;
inherit nix-index-database;
};
}
]
++ customModules;
};
mkSystems =
sysDescs:
builtins.listToAttrs (
map (desc: {
name = "nixos-" + desc.deviceName + (desc.confNameSuffix or "");
value = (mkSys desc);
}) sysDescs
);
in
mkSystems [
# Define systems
{
deviceName = "lenovo-laptop";
customModules = [ nixos-hardware.nixosModules.lenovo-thinkpad-x1-yoga ];
}
{
deviceName = "lenovo-laptop";
confNameSuffix = "no-sec";
customModules = [ nixos-hardware.nixosModules.lenovo-thinkpad-x1-yoga ];
forceNoSecrets = true;
}
{
deviceName = "work-laptop";
customModules = [ nixos-hardware.nixosModules.lenovo-thinkpad-x1-11th-gen ];
}
{ deviceName = "desktop"; }
{
deviceName = "desktop";
confNameSuffix = "no-sec";
forceNoSecrets = true;
}
{
deviceName = "rpi4";
system = "aarch64-linux";
customModules = [ nixos-hardware.nixosModules.raspberry-pi-4 ];
}
{
deviceName = "tmserver-x86";
nixpkgsOverlays = [
# Option-A experiment: build OpenVINO's Intel-GPU plugin WITH
# oneDNN-for-GPU. nixpkgs sets ENABLE_ONEDNN_FOR_GPU=OFF; Intel's
# prebuilt OpenVINO (the working immich ML container) builds it ON.
# onnxruntime's OpenVINO EP + immich-machine-learning rebuild against
# this, so the native iGPU ML path exercises the oneDNN GPU kernels.
(final: prev: {
openvino = prev.openvino.overrideAttrs (old: {
cmakeFlags =
(builtins.filter (f: !(prev.lib.hasInfix "ENABLE_ONEDNN_FOR_GPU" f)) old.cmakeFlags)
++ [ (prev.lib.cmakeBool "ENABLE_ONEDNN_FOR_GPU" true) ];
});
})
];
}
{
deviceName = "octoprint";
system = "aarch64-linux";
customModules = [ nixos-hardware.nixosModules.raspberry-pi-4 ];
}
{
deviceName = "virtualbox";
forceNoSecrets = true;
}
{
deviceName = "iso-image";
forceNoSecrets = true;
customModules = [
(
{ pkgs, modulesPath, ... }:
{
imports = [ (modulesPath + "/installer/cd-dvd/installation-cd-minimal.nix") ];
}
)
];
}
];
# `nix fmt`. The tree is formatted with nixfmt (RFC style); declaring it
# here makes that explicit instead of something you have to infer from the
# existing files. Covers both architectures used by the systems above.
#
# Wrapped rather than using pkgs.nixfmt directly because nixfmt aborts on
# git-crypt blobs ("hGetContents: invalid argument (cannot decode byte
# sequence)") — and since no single machine holds every device key, some
# secret is always still encrypted. Those are skipped by magic header.
formatter =
nixpkgs_prepatch.lib.genAttrs
[
"x86_64-linux"
"aarch64-linux"
]
(
system:
let
pkgs = nixpkgs_prepatch.legacyPackages.${system};
in
pkgs.writeShellApplication {
name = "nixfmt-skip-encrypted";
runtimeInputs = with pkgs; [
nixfmt
findutils
coreutils
];
text = ''
flags=()
paths=()
for arg in "$@"; do
case "$arg" in
-*) flags+=("$arg") ;;
*) paths+=("$arg") ;;
esac
done
[ ''${#paths[@]} -gt 0 ] || paths=(.)
files=()
while IFS= read -r f; do
# git-crypt blobs start with a NUL byte then "GITCRYPT"
[ "$(head -c 9 "$f" | tr -d '\0')" = "GITCRYPT" ] && continue
files+=("$f")
done < <(find "''${paths[@]}" -type f -name '*.nix' -not -path '*/.git/*' | sort)
[ ''${#files[@]} -gt 0 ] || exit 0
exec nixfmt ''${flags[@]+"''${flags[@]}"} "''${files[@]}"
'';
}
);
};
}