btw i use nix
1{
2 inputs = {
3 nixpkgs-compat.url = "github:nixos/nixpkgs/nixos-24.05";
4 nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
5 nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
6 nixpkgs-element.url = "github:nixos/nixpkgs/b91f647a35c4e18a73adf617e6ef9eb5f3baa503";
7 nixpkgs-flaresolverr.url = "github:nixos/nixpkgs/ebbc0409688869938bbcf630da1c1c13744d2a7b";
8 nixpkgs-sonarr.url = "github:nixos/nixpkgs/394571358ce82dff7411395829aa6a3aad45b907";
9 nixos-hardware.url = "github:nixos/nixos-hardware";
10 home-manager.url = "github:nix-community/home-manager/release-24.11";
11 agenix.url = "github:ryantm/agenix";
12 deploy-rs.url = "github:serokell/deploy-rs";
13 nix-on-droid.url = "github:nix-community/nix-on-droid/release-24.05";
14 eon.url = "github:RyanGibb/eon";
15 eilean.url = "github:RyanGibb/eilean-nix/main";
16 alec-website.url = "github:alexanderhthompson/website";
17 fn06-website.url = "github:RyanGibb/fn06";
18 colour-guesser.url = "git+ssh://git@github.com/ryangibb/colour-guesser.git?ref=develop";
19 i3-workspace-history.url = "github:RyanGibb/i3-workspace-history";
20 hyperbib-eeg.url = "github:RyanGibb/hyperbib?ref=nixify";
21 nix-rpi5.url = "gitlab:vriska/nix-rpi5?ref=main";
22 nur.url = "github:nix-community/NUR/e9e77b7985ef9bdeca12a38523c63d47555cc89b";
23 emacs-overlay.url = "github:nix-community/emacs-overlay";
24
25 # deduplicate flake inputs
26 eilean.inputs.nixpkgs.follows = "nixpkgs";
27 eilean.inputs.eon.follows = "eon";
28 home-manager.inputs.nixpkgs.follows = "nixpkgs";
29 deploy-rs.inputs.nixpkgs.follows = "nixpkgs";
30 nix-on-droid.inputs.nixpkgs.follows = "nixpkgs";
31 nix-on-droid.inputs.home-manager.follows = "home-manager";
32 alec-website.inputs.nixpkgs.follows = "nixpkgs";
33 fn06-website.inputs.nixpkgs.follows = "nixpkgs";
34 eon.inputs.nixpkgs.follows = "nixpkgs";
35 colour-guesser.inputs.nixpkgs.follows = "nixpkgs";
36 i3-workspace-history.inputs.nixpkgs.follows = "nixpkgs";
37 hyperbib-eeg.inputs.nixpkgs.follows = "nixpkgs";
38 nix-rpi5.inputs.nixpkgs.follows = "nixpkgs";
39 nur.inputs.nixpkgs.follows = "nixpkgs";
40 emacs-overlay.inputs.nixpkgs.follows = "nixpkgs";
41 };
42
43 outputs =
44 {
45 self,
46 nixpkgs-compat,
47 nixpkgs,
48 nixpkgs-unstable,
49 nixpkgs-element,
50 home-manager,
51 agenix,
52 deploy-rs,
53 nix-on-droid,
54 eilean,
55 nur,
56 nixpkgs-flaresolverr,
57 nixpkgs-sonarr,
58 ...
59 }@inputs:
60 let
61 getSystemOverlays = system: nixpkgsConfig: [
62 (final: prev: {
63 # https://github.com/mautrix/whatsapp/issues/749
64 overlay-compat = import nixpkgs-compat {
65 inherit system;
66 # follow stable nixpkgs config
67 config = nixpkgsConfig;
68 };
69 overlay-unstable = import nixpkgs-unstable {
70 inherit system;
71 # follow stable nixpkgs config
72 config = nixpkgsConfig;
73 };
74 # to use an unstable version of a package
75 #package = final.overlay-unstable.package;
76 # to use an custom version of a package
77 #package = prev.callPackage ./pkgs/package.nix { };
78 # to use an unstable custom version of a package
79 #package = final.callPackage ./pkgs/package.nix { };
80 # to override attributes of a package
81 # package = prev.package.overrideAttrs
82 # (_: { patches = [ ./pkgs/package.patch ]; });
83 opam = final.overlay-unstable.opam.overrideAttrs (_: {
84 src = final.fetchurl {
85 url = "http://ryan.freumh.org/software/opam-full-2.3.0-nixos-depexts.tar.gz";
86 sha256 = "sha256-mRxxZtWFgQ8v1szVq5g5+qVqa+OffoG1aHzGUiMMvT0=";
87 };
88 version = "2.3.0";
89 });
90 immich = final.overlay-unstable.immich;
91 mautrix-whatsapp = final.overlay-compat.mautrix-whatsapp;
92 element-desktop =
93 (import nixpkgs-element {
94 inherit system;
95 config = nixpkgsConfig;
96 }).element-desktop;
97 # https://github.com/NixOS/nixpkgs/issues/332776
98 flaresolverr =
99 (import nixpkgs-flaresolverr {
100 inherit system;
101 config = nixpkgsConfig;
102 }).flaresolverr;
103 sonarr =
104 (import nixpkgs-sonarr {
105 inherit system;
106 config = nixpkgsConfig;
107 }).sonarr;
108 })
109 nur.overlays.default
110 ];
111 in
112 {
113 nixosConfigurations =
114 let
115 mkMode =
116 mode: host:
117 let
118 host-nixpkgs = nixpkgs;
119 host-home-manager = home-manager;
120 in
121 host-nixpkgs.lib.nixosSystem {
122 # use system from config.localSystem
123 # see https://github.com/NixOS/nixpkgs/blob/5297d584bcc5f95c8e87c631813b4e2ab7f19ecc/nixos/lib/eval-config.nix#L55
124 system = null;
125 pkgs = null;
126 specialArgs = inputs;
127 modules = [
128 ./hosts/${host}/${mode}.nix
129 ./modules/default.nix
130 (
131 { config, ... }:
132 {
133 networking.hostName = "${host}";
134 # pin nix command's nixpkgs flake to the system flake to avoid unnecessary downloads
135 nix.registry.nixpkgs.flake = host-nixpkgs;
136 system.stateVersion = "24.05";
137 # record git revision (can be queried with `nixos-version --json)
138 system.configurationRevision = host-nixpkgs.lib.mkIf (self ? rev) self.rev;
139 nixpkgs = {
140 config.allowUnfree = true;
141 config.permittedInsecurePackages = [
142 # https://github.com/nix-community/nixd/issues/357
143 "nix-2.16.2"
144 # https://github.com/mautrix/go/issues/262
145 "olm-3.2.16"
146 "aspnetcore-runtime-6.0.36"
147 "aspnetcore-runtime-wrapped-6.0.36"
148 "dotnet-sdk-6.0.428"
149 "dotnet-sdk-wrapped-6.0.428"
150 ];
151 overlays = getSystemOverlays config.nixpkgs.hostPlatform.system config.nixpkgs.config;
152 # uncomment for cross compilation (https://github.com/NixOS/nix/issues/3843)
153 #buildPlatform.system = "cpu-os";
154 };
155 security.acme-eon.acceptTerms = true;
156 }
157 )
158 host-home-manager.nixosModule
159 eilean.nixosModules.default
160 agenix.nixosModules.default
161 ];
162 };
163 readModes =
164 dir:
165 let
166 files = builtins.readDir dir;
167 in
168 let
169 filtered = nixpkgs.lib.attrsets.filterAttrs (
170 n: v: v == "regular" && (n == "default.nix" || n == "minimal.nix")
171 ) files;
172 in
173 let
174 names = nixpkgs.lib.attrNames filtered;
175 in
176 builtins.map (f: nixpkgs.lib.strings.removeSuffix ".nix" f) names;
177 mkModes =
178 host: modes:
179 builtins.map (mode: {
180 name = "${host}${if mode == "default" then "" else "-${mode}"}";
181 value = mkMode mode host;
182 }) modes;
183 mkHosts =
184 hosts:
185 let
186 nestedList = builtins.map (host: mkModes host (readModes ./hosts/${host})) hosts;
187 in
188 let
189 list = nixpkgs.lib.lists.flatten nestedList;
190 in
191 builtins.listToAttrs list;
192 hosts = builtins.attrNames (builtins.readDir ./hosts);
193 in
194 mkHosts hosts;
195
196 deploy = {
197 user = "root";
198 nodes = builtins.listToAttrs (
199 builtins.map
200 (
201 name:
202 let
203 machine = self.nixosConfigurations.${name};
204 system = machine.pkgs.system;
205 pkgs = import nixpkgs { inherit system; };
206 # nixpkgs with deploy-rs overlay but force the nixpkgs package
207 deployPkgs = import nixpkgs {
208 inherit system;
209 overlays = [
210 deploy-rs.overlay
211 (self: super: {
212 deploy-rs = {
213 inherit (pkgs) deploy-rs;
214 lib = super.deploy-rs.lib;
215 };
216 })
217 ];
218 };
219 in
220 {
221 inherit name;
222 value = {
223 # if we're on a different system build on the remote
224 #remoteBuild = machine.config.nixpkgs.hostPlatform.system == builtins.currentSystem;
225 remoteBuild = true;
226 sshUser = "root";
227 hostname = if name == "swan" then "eeg.cl.cam.ac.uk" else machine.config.networking.hostName;
228 profiles.system = {
229 user = "root";
230 path = deployPkgs.deploy-rs.lib.activate.nixos machine;
231 };
232 };
233 }
234 )
235 [
236 "capybara"
237 "duck"
238 "elephant"
239 "gecko"
240 "owl"
241 "shrew"
242 "swan"
243 ]
244 );
245 };
246
247 nixOnDroidConfigurations.default = nix-on-droid.lib.nixOnDroidConfiguration {
248 modules = [ ./nix-on-droid/default.nix ];
249 pkgs = import nixpkgs {
250 overlays = getSystemOverlays "aarch64-linux" { };
251 config.permittedInsecurePackages = [
252 # https://github.com/nix-community/nixd/issues/357
253 "nix-2.16.2"
254 ];
255 };
256 };
257
258 homeConfigurations = {
259 rtg24 =
260 let
261 system = "x86_64-linux";
262 pkgs = nixpkgs.legacyPackages.${system};
263 in
264 home-manager.lib.homeManagerConfiguration {
265 inherit pkgs;
266 modules = [
267 ./home/default.nix
268 {
269 nix.package = pkgs.nix;
270 nixpkgs.overlays = getSystemOverlays system { };
271 home.username = "rtg24";
272 home.homeDirectory = "/home/rtg24";
273 home.packages = with pkgs; [ home-manager ];
274 custom = {
275 machineColour = "red";
276 nvim-lsps = true;
277 };
278 }
279 ];
280 };
281 };
282
283 legacyPackages = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed (system: {
284 nixpkgs = import nixpkgs {
285 inherit system;
286 overlays = getSystemOverlays system { };
287 };
288 });
289
290 formatter = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed (
291 system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style
292 );
293
294 templates.host.path = ./templates/host;
295 };
296}