From e55b8ee0f7073b46fb343a97ee744a95ec40d2ed Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Fri, 24 Oct 2025 09:02:29 -0700 Subject: simplify hosts management --- flake/hosts.nix | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) (limited to 'flake') diff --git a/flake/hosts.nix b/flake/hosts.nix index ef2b28b..b2dac30 100644 --- a/flake/hosts.nix +++ b/flake/hosts.nix @@ -15,6 +15,7 @@ let mkIf nixosSystem readDir + replaceStrings substring ; @@ -32,25 +33,37 @@ let mapHosts = foldl' ( hosts: system: hosts - // (mapAttrs' (name: _: { - inherit name; - value = { - inherit system; - hostconf = "${self}/machines/nixos/${system}/${name}"; - }; - }) (builtins.readDir "${self}/machines/nixos/${system}")) + // (mapAttrs' ( + filename: _: + let + name = replaceStrings [ ".nix" ] [ "" ] filename; + in + { + inherit name; + value = { + inherit system; + hostconf = "${self}/machines/nixos/${system}/${filename}"; + }; + } + ) (builtins.readDir "${self}/machines/nixos/${system}")) ) { }; mapMacs = foldl' ( hosts: system: hosts - // (mapAttrs' (name: _: { - inherit name; - value = { - inherit system; - hostconf = "${self}/machines/darwin/${system}/${name}"; - }; - }) (builtins.readDir "${self}/machines/darwin/${system}")) + // (mapAttrs' ( + filename: _: + let + name = replaceStrings [ ".nix" ] [ "" ] filename; + in + { + inherit name; + value = { + inherit system; + hostconf = "${self}/machines/darwin/${system}/${filename}"; + }; + } + ) (builtins.readDir "${self}/machines/darwin/${system}")) ) { }; defaultModules = [ -- cgit v1.2.3