From e97e916521b2bbd3605350fe1a1e50dbbc8902b5 Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 1 May 2021 17:46:30 -0700 Subject: [PATCH] lib: init generators section --- lib/generators.nix | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 lib/generators.nix diff --git a/lib/generators.nix b/lib/generators.nix new file mode 100644 index 0000000..86f9d4d --- /dev/null +++ b/lib/generators.nix @@ -0,0 +1,46 @@ +{ lib }: +{ + mkHomeConfigurations = nixosConfigurations: + with lib; + let + mkHomes = host: config: + mapAttrs' (user: v: nameValuePair "${user}@${host}" v.home) + config.config.system.build.homes; + + hmConfigs = mapAttrs mkHomes nixosConfigurations; + + in + foldl recursiveUpdate { } (attrValues hmConfigs); + + mkDeployNodes = + /** + Synopsis: mkNodes _nixosConfigurations_ + + Generate the `nodes` attribute expected by deploy-rs + where _nixosConfigurations_ are `nodes`. + **/ + + deploy: lib.mapAttrs (_: config: { + hostname = config.config.networking.hostName; + + profiles.system = { + user = "root"; + path = deploy.lib.x86_64-linux.activate.nixos config; + }; + }); + + mkSuites = { suites, profiles }: + let + profileSet = lib.genAttrs' profiles (path: { + name = baseNameOf path; + value = lib.mkProfileAttrs (toString path); + }); + + definedSuites = suites profileSet; + + allProfiles = lib.collectProfiles profileSet; + in + lib.mapAttrs (_: v: lib.profileMap v) definedSuites // { + inherit allProfiles; + }; +}