a flake module to ease creating and managing multiple hosts in your nix flake.

feat: add key & _file

+50 -24
+12 -3
flake-module.nix
··· 1 + { easy-hosts }: 1 2 { 2 3 lib, 3 4 inputs, ··· 9 10 inherit (builtins) concatLists attrNames; 10 11 inherit (lib.options) mkOption mkEnableOption literalExpression; 11 12 inherit (lib) types; 12 - inherit (lib.modules) mkRenamedOptionModule; 13 13 14 - inherit (import ./lib.nix { inherit lib inputs withSystem; }) 14 + inherit 15 + (import ./lib.nix { 16 + inherit 17 + lib 18 + inputs 19 + withSystem 20 + easy-hosts 21 + ; 22 + }) 15 23 constructSystem 16 24 mkHosts 17 25 buildHosts ··· 255 263 deployable = mkEnableOption "Is this host deployable" // { 256 264 default = false; 257 265 }; 258 - } // (mkBasicParams name); 266 + } 267 + // (mkBasicParams name); 259 268 } 260 269 ) 261 270 );
+22 -20
flake.nix
··· 1 1 { 2 2 inputs = { }; 3 3 4 - outputs = _: { 5 - flakeModule = ./flake-module.nix; 6 - flakeModules.default = ./flake-module.nix; 4 + outputs = 5 + { self }: 6 + { 7 + flakeModule = import ./flake-module.nix { easy-hosts = self; }; 8 + flakeModules.default = import ./flake-module.nix { easy-hosts = self; }; 7 9 8 - templates = { 9 - multi = { 10 - path = ./examples/multi; 11 - description = "A multi-system flake with auto construction enabled, but only using x86_64-linux."; 12 - }; 10 + templates = { 11 + multi = { 12 + path = ./examples/multi; 13 + description = "A multi-system flake with auto construction enabled, but only using x86_64-linux."; 14 + }; 13 15 14 - multi-specialised = { 15 - path = ./examples/multi-specialised; 16 - description = "A multi-system flake with auto construction enabled, using the custom class system of easy-hosts"; 17 - }; 16 + multi-specialised = { 17 + path = ./examples/multi-specialised; 18 + description = "A multi-system flake with auto construction enabled, using the custom class system of easy-hosts"; 19 + }; 18 20 19 - not-auto = { 20 - path = ./examples/not-auto; 21 - description = "A flake with auto construction disabled, using only the `easyHosts.hosts` attribute."; 22 - }; 21 + not-auto = { 22 + path = ./examples/not-auto; 23 + description = "A flake with auto construction disabled, using only the `easyHosts.hosts` attribute."; 24 + }; 23 25 24 - only = { 25 - path = ./examples/only; 26 - description = "A flake with auto construction enabled, with only one class and a more 'flat' structure."; 26 + only = { 27 + path = ./examples/only; 28 + description = "A flake with auto construction enabled, with only one class and a more 'flat' structure."; 29 + }; 27 30 }; 28 31 }; 29 - }; 30 32 }
+16 -1
lib.nix
··· 2 2 lib, 3 3 inputs, 4 4 withSystem, 5 + easy-hosts, 5 6 ... 6 7 }: 7 8 let ··· 261 262 # recall `specialArgs` would take be preferred when resolving module structure 262 263 # well this is how we do it use it for all args that don't need to rosolve module structure 263 264 (singleton { 265 + key = "easy-hosts#specialArgs"; 266 + _file = "${easy-hosts.outPath}/lib.nix"; 267 + 264 268 _module.args = withSystem system ( 265 269 { self', inputs', ... }: 266 270 { ··· 272 276 # here we make some basic assumptions about the system the person is using 273 277 # like the system type and the hostname 274 278 (singleton { 279 + key = "easy-hosts#hostname"; 280 + _file = "${easy-hosts.outPath}/lib.nix"; 281 + 275 282 # we set the systems hostname based on the host value 276 283 # which should be a string that is the hostname of the system 277 284 networking.hostName = mkDefault name; 285 + }) 286 + 287 + (singleton { 288 + key = "easy-hosts#nixpkgs"; 289 + _file = "${easy-hosts.outPath}/lib.nix"; 278 290 279 291 nixpkgs = { 280 292 # you can also do this as `inherit system;` with the normal `lib.nixosSystem` ··· 292 304 # if we are on darwin we need to import the nixpkgs source, its used in some 293 305 # modules, if this is not set then you will get an error 294 306 (optionals (class == "darwin") (singleton { 307 + key = "easy-hosts#nixpkgs-darwin"; 308 + _file = "${easy-hosts.outPath}/lib.nix"; 309 + 295 310 # without supplying an upstream nixpkgs source, nix-darwin will not be able to build 296 311 # and will complain and log an error demanding that you must set this value 297 312 nixpkgs.source = mkDefault nixpkgs; ··· 386 401 ; 387 402 388 403 modules = concatLists (builtins.map (x: x.modules) sources); 389 - specialArgs = builtins.foldl' recursiveUpdate {} (builtins.map (x: x.specialArgs) sources); 404 + specialArgs = builtins.foldl' recursiveUpdate { } (builtins.map (x: x.specialArgs) sources); 390 405 }; 391 406 } 392 407 ))