-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflake.nix
296 lines (288 loc) · 10.9 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
{
inputs = {
nixpkgs-compat.url = "github:nixos/nixpkgs/nixos-24.05";
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
nixpkgs-element.url = "github:nixos/nixpkgs/b91f647a35c4e18a73adf617e6ef9eb5f3baa503";
nixpkgs-flaresolverr.url = "github:nixos/nixpkgs/ebbc0409688869938bbcf630da1c1c13744d2a7b";
nixpkgs-sonarr.url = "github:nixos/nixpkgs/394571358ce82dff7411395829aa6a3aad45b907";
nixos-hardware.url = "github:nixos/nixos-hardware";
home-manager.url = "github:nix-community/home-manager/release-24.11";
agenix.url = "github:ryantm/agenix";
deploy-rs.url = "github:serokell/deploy-rs";
nix-on-droid.url = "github:nix-community/nix-on-droid/release-24.05";
eon.url = "github:RyanGibb/eon";
eilean.url = "github:RyanGibb/eilean-nix/main";
alec-website.url = "github:alexanderhthompson/website";
fn06-website.url = "github:RyanGibb/fn06";
colour-guesser.url = "git+ssh://[email protected]/ryangibb/colour-guesser.git?ref=develop";
i3-workspace-history.url = "github:RyanGibb/i3-workspace-history";
hyperbib-eeg.url = "github:RyanGibb/hyperbib?ref=nixify";
nix-rpi5.url = "gitlab:vriska/nix-rpi5?ref=main";
nur.url = "github:nix-community/NUR/e9e77b7985ef9bdeca12a38523c63d47555cc89b";
emacs-overlay.url = "github:nix-community/emacs-overlay";
# deduplicate flake inputs
eilean.inputs.nixpkgs.follows = "nixpkgs";
eilean.inputs.eon.follows = "eon";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
deploy-rs.inputs.nixpkgs.follows = "nixpkgs";
nix-on-droid.inputs.nixpkgs.follows = "nixpkgs";
nix-on-droid.inputs.home-manager.follows = "home-manager";
alec-website.inputs.nixpkgs.follows = "nixpkgs";
fn06-website.inputs.nixpkgs.follows = "nixpkgs";
eon.inputs.nixpkgs.follows = "nixpkgs";
colour-guesser.inputs.nixpkgs.follows = "nixpkgs";
i3-workspace-history.inputs.nixpkgs.follows = "nixpkgs";
hyperbib-eeg.inputs.nixpkgs.follows = "nixpkgs";
nix-rpi5.inputs.nixpkgs.follows = "nixpkgs";
nur.inputs.nixpkgs.follows = "nixpkgs";
emacs-overlay.inputs.nixpkgs.follows = "nixpkgs";
};
outputs =
{
self,
nixpkgs-compat,
nixpkgs,
nixpkgs-unstable,
nixpkgs-element,
home-manager,
agenix,
deploy-rs,
nix-on-droid,
eilean,
nur,
nixpkgs-flaresolverr,
nixpkgs-sonarr,
...
}@inputs:
let
getSystemOverlays = system: nixpkgsConfig: [
(final: prev: {
# https://github.com/mautrix/whatsapp/issues/749
overlay-compat = import nixpkgs-compat {
inherit system;
# follow stable nixpkgs config
config = nixpkgsConfig;
};
overlay-unstable = import nixpkgs-unstable {
inherit system;
# follow stable nixpkgs config
config = nixpkgsConfig;
};
# to use an unstable version of a package
#package = final.overlay-unstable.package;
# to use an custom version of a package
#package = prev.callPackage ./pkgs/package.nix { };
# to use an unstable custom version of a package
#package = final.callPackage ./pkgs/package.nix { };
# to override attributes of a package
# package = prev.package.overrideAttrs
# (_: { patches = [ ./pkgs/package.patch ]; });
opam = final.overlay-unstable.opam.overrideAttrs (_: {
src = final.fetchurl {
url = "http://ryan.freumh.org/software/opam-full-2.3.0-nixos-depexts.tar.gz";
sha256 = "sha256-mRxxZtWFgQ8v1szVq5g5+qVqa+OffoG1aHzGUiMMvT0=";
};
version = "2.3.0";
});
immich = final.overlay-unstable.immich;
mautrix-whatsapp = final.overlay-compat.mautrix-whatsapp;
element-desktop =
(import nixpkgs-element {
inherit system;
config = nixpkgsConfig;
}).element-desktop;
# https://github.com/NixOS/nixpkgs/issues/332776
flaresolverr =
(import nixpkgs-flaresolverr {
inherit system;
config = nixpkgsConfig;
}).flaresolverr;
sonarr =
(import nixpkgs-sonarr {
inherit system;
config = nixpkgsConfig;
}).sonarr;
})
nur.overlays.default
];
in
{
nixosConfigurations =
let
mkMode =
mode: host:
let
host-nixpkgs = nixpkgs;
host-home-manager = home-manager;
in
host-nixpkgs.lib.nixosSystem {
# use system from config.localSystem
# see https://github.com/NixOS/nixpkgs/blob/5297d584bcc5f95c8e87c631813b4e2ab7f19ecc/nixos/lib/eval-config.nix#L55
system = null;
pkgs = null;
specialArgs = inputs;
modules = [
./hosts/${host}/${mode}.nix
./modules/default.nix
(
{ config, ... }:
{
networking.hostName = "${host}";
# pin nix command's nixpkgs flake to the system flake to avoid unnecessary downloads
nix.registry.nixpkgs.flake = host-nixpkgs;
system.stateVersion = "24.05";
# record git revision (can be queried with `nixos-version --json)
system.configurationRevision = host-nixpkgs.lib.mkIf (self ? rev) self.rev;
nixpkgs = {
config.allowUnfree = true;
config.permittedInsecurePackages = [
# https://github.com/nix-community/nixd/issues/357
"nix-2.16.2"
# https://github.com/mautrix/go/issues/262
"olm-3.2.16"
"aspnetcore-runtime-6.0.36"
"aspnetcore-runtime-wrapped-6.0.36"
"dotnet-sdk-6.0.428"
"dotnet-sdk-wrapped-6.0.428"
];
overlays = getSystemOverlays config.nixpkgs.hostPlatform.system config.nixpkgs.config;
# uncomment for cross compilation (https://github.com/NixOS/nix/issues/3843)
#buildPlatform.system = "cpu-os";
};
security.acme-eon.acceptTerms = true;
}
)
host-home-manager.nixosModule
eilean.nixosModules.default
agenix.nixosModules.default
];
};
readModes =
dir:
let
files = builtins.readDir dir;
in
let
filtered = nixpkgs.lib.attrsets.filterAttrs (
n: v: v == "regular" && (n == "default.nix" || n == "minimal.nix")
) files;
in
let
names = nixpkgs.lib.attrNames filtered;
in
builtins.map (f: nixpkgs.lib.strings.removeSuffix ".nix" f) names;
mkModes =
host: modes:
builtins.map (mode: {
name = "${host}${if mode == "default" then "" else "-${mode}"}";
value = mkMode mode host;
}) modes;
mkHosts =
hosts:
let
nestedList = builtins.map (host: mkModes host (readModes ./hosts/${host})) hosts;
in
let
list = nixpkgs.lib.lists.flatten nestedList;
in
builtins.listToAttrs list;
hosts = builtins.attrNames (builtins.readDir ./hosts);
in
mkHosts hosts;
deploy = {
user = "root";
nodes = builtins.listToAttrs (
builtins.map
(
name:
let
machine = self.nixosConfigurations.${name};
system = machine.pkgs.system;
pkgs = import nixpkgs { inherit system; };
# nixpkgs with deploy-rs overlay but force the nixpkgs package
deployPkgs = import nixpkgs {
inherit system;
overlays = [
deploy-rs.overlay
(self: super: {
deploy-rs = {
inherit (pkgs) deploy-rs;
lib = super.deploy-rs.lib;
};
})
];
};
in
{
inherit name;
value = {
# if we're on a different system build on the remote
#remoteBuild = machine.config.nixpkgs.hostPlatform.system == builtins.currentSystem;
remoteBuild = true;
sshUser = "root";
hostname = if name == "swan" then "eeg.cl.cam.ac.uk" else machine.config.networking.hostName;
profiles.system = {
user = "root";
path = deployPkgs.deploy-rs.lib.activate.nixos machine;
};
};
}
)
[
"capybara"
"duck"
"elephant"
"gecko"
"owl"
"shrew"
"swan"
]
);
};
nixOnDroidConfigurations.default = nix-on-droid.lib.nixOnDroidConfiguration {
modules = [ ./nix-on-droid/default.nix ];
pkgs = import nixpkgs {
overlays = getSystemOverlays "aarch64-linux" { };
config.permittedInsecurePackages = [
# https://github.com/nix-community/nixd/issues/357
"nix-2.16.2"
];
};
};
homeConfigurations = {
rtg24 =
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
in
home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [
./home/default.nix
{
nix.package = pkgs.nix;
nixpkgs.overlays = getSystemOverlays system { };
home.username = "rtg24";
home.homeDirectory = "/home/rtg24";
home.packages = with pkgs; [ home-manager ];
custom = {
machineColour = "red";
nvim-lsps = true;
};
}
];
};
};
legacyPackages = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed (system: {
nixpkgs = import nixpkgs {
inherit system;
overlays = getSystemOverlays system { };
};
});
formatter = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed (
system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style
);
templates.host.path = ./templates/host;
};
}