From 1ec9561919dc4d4c37d55abf5a77a952e3c69074 Mon Sep 17 00:00:00 2001 From: Charlie Root Date: Tue, 29 Oct 2024 18:44:22 +0100 Subject: [PATCH] hosts/default.nix: change mkSystem --- hosts/default.nix | 68 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 49 insertions(+), 19 deletions(-) diff --git a/hosts/default.nix b/hosts/default.nix index d2dd2e5..776ca81 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -3,42 +3,72 @@ inputs, ... }: let - inherit (inputs.self) lib; - inherit (lib.extendedLib.builders) mkSystem; - inherit (lib.extendedLib.modules) mkModuleTree'; + inherit (inputs) self; + inherit (self) lib; + # inherit (lib.extendedLib.builders) mkSystem; + # inherit (lib.extendedLib.modules) mkModuleTree'; inherit (lib.lists) concatLists flatten singleton; - + inherit (lib) mkDefault nixosSystem recursiveUpdate; + inherit (builtins) filter map toString; + inherit (lib.filesystem) listFilesRecursive; + inherit (lib.strings) hasSuffix; # NOTE: This was inspired by raf, and I find this # to be quite a sane way of managing all modules in my flake. - mkModulesFor = hostname: - flatten ( - concatLists [ - # Derive host specific module path from the first argument of the - # function. Should be a string, obviously. - (singleton ./${hostname}/default.nix) - - # Recursively import all module trees (i.e. directories with a `module.nix`) - # for given moduleTree directories - (mkModuleTree' {path = ../modules;}) - ] + mkSystem = { + withSystem, + system, + hostname, + ... + } @ args: + withSystem system ( + { + inputs', + self', + ... + }: + nixosSystem { + inherit system; + specialArgs = + recursiveUpdate + { + inherit lib; + inherit inputs inputs'; + inherit self self'; + } + (args.specialArgs or {}); + modules = concatLists [ + # This is used to pre-emptively set the hostPlatform for nixpkgs. + # Also, we set the system hostname here. + (singleton { + networking.hostName = args.hostname; + nixpkgs.hostPlatform = mkDefault args.system; + }) + (flatten ( + concatLists [ + (singleton ./${hostname}/default.nix) + ( + filter (hasSuffix "module.nix") ( + map toString (listFilesRecursive ../modules) + ) + ) + ] + )) + ]; + } ); in { flake.nixosConfigurations = { temperance = mkSystem { inherit withSystem; system = "x86_64-linux"; - hostname = "temperance"; - modules = mkModulesFor "temperance"; }; hermit = mkSystem { inherit withSystem; system = "x86_64-linux"; - hostname = "hermit"; - modules = mkModulesFor "hermit"; }; }; }