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