-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnix.mod.nix
261 lines (243 loc) · 7.24 KB
/
nix.mod.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
{
self,
nix-monitored,
elements,
...
}: let
caches = {
# "https://nixpkgs-wayland.cachix.org" = "nixpkgs-wayland.cachix.org-1:3lwxaILxMRkVhehr5StQprHdEo4IrE8sRho9R9HOLYA=";
};
garbage-collection-module = {lib, ...}: {
programs.nh.clean = {
enable = true;
extraArgs = "--keep 3 --keep-since 7d";
# this is somewhere in the middle of my commute to school.
# and if i'm not at school, i'm likely asleep.
dates = "Mon..Fri *-*-* 07:00:00";
};
nix.optimise = {
automatic = true;
# why is that a list?
dates = ["Mon..Fri *-*-* 07:30:00"];
};
# I don't want these to be persistent or have any delay.
# They don't need to run daily; if they miss a day, it's fine.
# And i don't want them to ever delay until e.g. i'm at school
# because that will impact my workflow if i want to remote in.
systemd.timers = let
fuck-off.timerConfig = {
Persistent = lib.mkForce false;
RandomizedDelaySec = lib.mkForce 0;
};
in {
nh-clean = fuck-off;
nix-optimise = fuck-off;
};
};
in {
universal.modules = [
{
system.stateVersion = "23.11";
nixpkgs.config.allowUnfree = true;
nix.settings.experimental-features = ["nix-command" "flakes"];
}
({config, ...}: {
nix.settings = {
substituters = builtins.attrNames caches;
trusted-public-keys = builtins.attrValues caches;
};
# access-token-prelude contains:
# access-token = github.com=$SECRET
nix.extraOptions = ''
!include ${config.sops.secrets.access-token-prelude.path}
'';
})
({pkgs, ...}: {
nixpkgs.overlays = [
nix-monitored.overlays.default
(final: prev: {
nix-monitored = prev.nix-monitored.override {
# I find the notifications annoying.
withNotify = false;
};
})
(final: prev: {
nixos-rebuild = prev.nixos-rebuild.override {
nix = prev.nix-monitored;
};
nix-direnv = pkgs.runCommand "nix-direnv-monitored" {} ''
cp -R ${prev.nix-direnv.override {
# Okay, so what's happening here is that `nix-direnv` doesn't just use `nix` from PATH.
# However, it also doesn't use `nix` from nix store. It uses both.
# So what i'm doing here, is setting the "fallback path" to nix, being nix-monitored.
nix = prev.nix-monitored;
}} $out
chmod -R +w $out
${
# And then, i'm replacing the command that it uses to find nix with `false`.
# This makes it think there's no nix in PATH, and it will use the fallback path.
# And voila, i get nom output in direnv.
"sed -i 's/command -v nix/false/' $out/share/nix-direnv/direnvrc"
}
'';
nixmon = prev.runCommand "nixmon" {} ''
mkdir -p $out/bin
ln -s ${prev.nix-monitored}/bin/nix $out/bin/nixmon
'';
})
];
environment.systemPackages = [pkgs.nixmon];
programs.nh.enable = true;
})
({
config,
pkgs,
lib,
...
}: {
programs.ssh.extraConfig = ''
${builtins.concatStringsSep "" (lib.mapAttrsToList (name: n: ''
Host ${name}
HostName ${name}.wg
User remote-builder
IdentityFile ${config.sops.secrets.remote-build-ssh-id.path}
'')
elements)}
'';
users.users.remote-builder = {
isSystemUser = true;
group = "remote-builder";
description = "trusted remote builder user";
openssh.authorizedKeys.keys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBIwHeeSm7ten3Rxqj90xaBWgyRw1xYqBjKBj8nevFOD remote-builder"
];
shell = pkgs.runtimeShell;
};
users.groups.remote-builder = {};
nix.settings.trusted-users = ["remote-builder"];
})
({
config,
lib,
...
}: {
options.personal-binary-cache-url = lib.mkOption {
type = lib.types.str;
default = "https://cache.sodi.boo";
};
config =
lib.mkIf (
# Don't make iridium a substitute for itself. That would be silly.
config.networking.hostName != "iridium"
) {
nix.settings = {
substituters = [config.personal-binary-cache-url];
trusted-public-keys = ["sodiboo/system:N1cJgHSRSRKvlItFJDjXQBCgAhRo7hvTNw8TqyrhCUw="];
};
};
})
];
sodium.modules = [
garbage-collection-module
{
personal-binary-cache-url = let
port = toString self.nixosConfigurations.iridium.config.services.nix-serve.port;
# sodium and iridium are on the same network, so let's not go through a hop to germany.
in "http://iridium.lan:${port}";
}
];
personal.modules = [
{
# AMD gpu, basically. used for e.g. resource monitoring with btop
nixpkgs.config.rocmSupport = true;
}
];
iridium.modules = [
({
config,
pkgs,
lib,
...
}: {
# This is publicly served from https://cache.sodi.boo
# That's proxied through oxygen from nginx.
services.nix-serve = {
enable = true;
port = 5020;
openFirewall = true;
secretKeyFile = config.sops.secrets.binary-cache-secret.path;
};
systemd.timers."auto-update-rebuild" = {
wantedBy = ["timers.target"];
timerConfig = {
OnBootSec = "5m";
OnUnitInactiveSec = "1h";
Unit = "auto-update-rebuild.service";
};
};
systemd.services."auto-update-rebuild" = {
script = ''
mkdir -p /tmp/auto-update-rebuild && cd /tmp/auto-update-rebuild
export PATH=${lib.makeBinPath (with pkgs; [nix git coreutils])}
nix build github:sodiboo/system#all-systems --recreate-lock-file --no-write-lock-file
'';
serviceConfig = {
Restart = "on-failure";
RestartSec = "15m";
Type = "oneshot";
};
};
})
garbage-collection-module
];
nitrogen.modules = [
({config, ...}: {
nix.distributedBuilds = true;
nix.buildMachines = [
{
hostName = "iridium";
system = "x86_64-linux";
maxJobs = 4;
}
];
})
];
universal.home_modules = [
({
pkgs,
lib,
...
}: {
home.packages = with pkgs; [
cachix
nil
nurl
nix-diff
nix-output-monitor
nvd
# nix-init
];
programs.fish.shellAliases = let
conf = ''env NIX_CONFIG="warn-dirty = false"'';
rebuild = verb: dry: "fish -c '${builtins.concatStringsSep " && " [
"cd /etc/nixos"
"${conf} nix fmt -- --quiet *"
"${conf} nix flake update"
"git add ."
(
if dry
then "${conf} nh os ${verb} --dry ."
else "${conf} nh os ${verb} ."
)
]}'";
in
lib.mergeAttrsList (map (verb: {
"nix.${verb}" = rebuild verb false;
"nix+${verb}" = rebuild verb true;
}) ["switch" "boot" "test"])
// {
nix-shell = "nix-shell --run fish";
};
})
];
}