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