diff options
Diffstat (limited to 'parts/lib')
| -rw-r--r-- | parts/lib/configs.nix | 56 | ||||
| -rw-r--r-- | parts/lib/default.nix | 6 | ||||
| -rw-r--r-- | parts/lib/utils.nix | 36 |
3 files changed, 98 insertions, 0 deletions
diff --git a/parts/lib/configs.nix b/parts/lib/configs.nix new file mode 100644 index 0000000..31524e2 --- /dev/null +++ b/parts/lib/configs.nix @@ -0,0 +1,56 @@ +{inputs, ...}: let + inherit (builtins) attrNames elemAt map; + inherit (inputs.nixpkgs.lib) flatten genAttrs optional splitString; + + archs = ["x86_64" "aarch64"]; + os' = ["linux" "darwin"]; + mkSystems = systems: flatten (map (sys: map (arch: ["${arch}-${sys}" "${arch}-${sys}"]) archs) systems); + systems = mkSystems os'; + + mkSystemCfg = name: { + profile, + modules ? profile.modules, + system ? profile.system, + specialArgs ? profile.specialArgs, + }: + profile.builder { + inherit specialArgs system; + modules = + [../../hosts/${name}] + ++ ( + if modules == profile.modules + then modules + else modules ++ profile.modules + ); + }; +in { + inherit mkSystemCfg; + mapSystems = builtins.mapAttrs mkSystemCfg; + + genHMCfgs = users: let + names = flatten (map (user: map (system: "${user}@${system}") systems) (attrNames users)); + in + genAttrs names (name: let + getPart = elemAt (splitString "@" name); + username = getPart 0; + system = getPart 1; + in + inputs.home-manager.lib.homeManagerConfiguration rec { + pkgs = import (users.${username}.nixpkgs or inputs.nixpkgs) ( + {inherit system;} // users.${username}.nixpkgsArgs or {} + ); + + extraSpecialArgs = users.${username}.extraSpecialArgs or inputs; + + modules = + [ + { + _module.args.osConfig = {}; + programs.home-manager.enable = true; + } + ../../users/${username}/home.nix + ] + ++ optional pkgs.stdenv.isDarwin ../../users/${username}/darwin.nix + ++ users.${username}.modules or []; + }); +} diff --git a/parts/lib/default.nix b/parts/lib/default.nix new file mode 100644 index 0000000..bdc485c --- /dev/null +++ b/parts/lib/default.nix @@ -0,0 +1,6 @@ +{withSystem, ...} @ args: { + flake.lib = { + configs = import ./configs.nix args; + utils = import ./utils.nix ({inherit withSystem;} // args); + }; +} diff --git a/parts/lib/utils.nix b/parts/lib/utils.nix new file mode 100644 index 0000000..f830b1c --- /dev/null +++ b/parts/lib/utils.nix @@ -0,0 +1,36 @@ +{ + self, + inputs, + withSystem, + ... +}: let + deployPkgs = import inputs.nixpkgs rec { + system = "x86_64-linux"; + overlays = [ + inputs.deploy-rs.overlay + (_: prev: { + deploy-rs = { + inherit (withSystem system (p: p.pkgs)) deploy-rs; + inherit (prev.deploy-rs) lib; + }; + }) + ]; + }; +in { + mkDeployNodes = hosts: let + inherit (builtins) attrNames listToAttrs map; + vals = + map (name: let + system = self.nixosConfigurations.${name}; + in { + inherit name; + value = { + sshUser = "root"; + hostname = system.config.networking.hostName; + profiles.system.path = deployPkgs.deploy-rs.lib.activate.nixos system; + }; + }) + (attrNames hosts); + in + listToAttrs vals; +} |
