From dd28edacbb04b3326d12861c7be90f335b2752c7 Mon Sep 17 00:00:00 2001 From: guangtao Date: Tue, 23 Apr 2024 22:56:26 -0700 Subject: [PATCH] refactor(pops.hive): add a few funcs --- src/hive/beeModule.nix | 8 -- src/hive/collectors/colmenaConfigurations.nix | 11 ++- src/hive/collectors/walk.nix | 9 +- .../transformers/colmenaConfiguration.nix | 8 +- src/hive/transformers/darwinConfiguration.nix | 6 +- src/hive/transformers/nixosConfiguration.nix | 6 +- src/pops/hive.nix | 93 +++++++++++-------- tests/_snapshots/hive | 2 + tests/hive/{example.nix => expr.nix} | 17 ++-- 9 files changed, 95 insertions(+), 65 deletions(-) create mode 100644 tests/_snapshots/hive rename tests/hive/{example.nix => expr.nix} (73%) diff --git a/src/hive/beeModule.nix b/src/hive/beeModule.nix index 3e6f146..ff4b12a 100644 --- a/src/hive/beeModule.nix +++ b/src/hive/beeModule.nix @@ -52,14 +52,6 @@ in }; description = "omnibus/hive requires you to set the darwin input via 'config.bee.darwin = inputs.darwin;'"; }; - colmena = l.mkOption { - type = l.mkOptionType { - name = "input"; - description = "colmena input"; - check = x: (l.isAttrs x) && (l.hasAttr "sourceInfo" x); - }; - description = "omnibus/hive requires you to set the colmena input via 'config.bee.colmena = inputs.colmena;'"; - }; pkgs = l.mkOption { type = l.mkOptionType { name = "packages"; diff --git a/src/hive/collectors/colmenaConfigurations.nix b/src/hive/collectors/colmenaConfigurations.nix index d484184..4edf689 100644 --- a/src/hive/collectors/colmenaConfigurations.nix +++ b/src/hive/collectors/colmenaConfigurations.nix @@ -7,9 +7,13 @@ root, super, }: +renamer: +{ ... }@hiveArgs: let l = lib // builtins; + inherit (hiveArgs) inputs; + inherit (root.hive) transformers; colmenaTopLevelCliSchema = @@ -34,13 +38,12 @@ let introspect = f: f { - # lib = nixpkgs.lib // builtins; - # pkgs = nixpkgs.legacyPackages.${builtins.currentSystem}; + lib = inputs.nixpkgs.lib // builtins; + pkgs = inputs.nixpkgs.legacyPackages.${builtins.currentSystem}; nodes = comb; }; }); in -renamer: self: system: colmenaTopLevelCliSchema ( - super.walk transformers.colmenaConfiguration [ ] renamer self system + super.walk transformers.colmenaConfiguration [ ] renamer hiveArgs ) diff --git a/src/hive/collectors/walk.nix b/src/hive/collectors/walk.nix index 0baaac6..cfbe19f 100644 --- a/src/hive/collectors/walk.nix +++ b/src/hive/collectors/walk.nix @@ -3,8 +3,12 @@ # SPDX-License-Identifier: Unlicense { lib, root }: -transformer: extraPipe: renamer: hosts: system: - +transformer: extraPipe: renamer: +{ + hosts ? { }, + system ? "", + inputs ? { }, +}@a: let l = lib // builtins; inherit (l) pipe; @@ -18,6 +22,7 @@ let [ (hostConfig: hostConfig.${renamer} or hostConfig.meta.${renamer}) checks.bee + (c: c // { inherit inputs; }) transformer ] ++ extraPipe diff --git a/src/hive/transformers/colmenaConfiguration.nix b/src/hive/transformers/colmenaConfiguration.nix index 14d54e2..6184d5a 100644 --- a/src/hive/transformers/colmenaConfiguration.nix +++ b/src/hive/transformers/colmenaConfiguration.nix @@ -7,9 +7,13 @@ super, lib, }: -{ evaled, locatedConfig }: +{ + evaled, + locatedConfig, + inputs ? { }, +}@args: let - inherit (evaled.config.bee) colmena; + inherit (args.inputs) colmena; l = lib // builtins; diff --git a/src/hive/transformers/darwinConfiguration.nix b/src/hive/transformers/darwinConfiguration.nix index 044c8e1..278b0f5 100644 --- a/src/hive/transformers/darwinConfiguration.nix +++ b/src/hive/transformers/darwinConfiguration.nix @@ -4,7 +4,11 @@ { lib, root }: -{ evaled, locatedConfig }: +{ + evaled, + locatedConfig, + inputs ? { }, +}: let l = lib // builtins; diff --git a/src/hive/transformers/nixosConfiguration.nix b/src/hive/transformers/nixosConfiguration.nix index d289a1a..5eecb0c 100644 --- a/src/hive/transformers/nixosConfiguration.nix +++ b/src/hive/transformers/nixosConfiguration.nix @@ -3,7 +3,11 @@ # SPDX-License-Identifier: Unlicense { lib, root }: -{ evaled, locatedConfig }: +{ + evaled, + locatedConfig, + inputs ? { }, +}: let inherit (root.hive) beeModule; diff --git a/src/pops/hive.nix b/src/pops/hive.nix index bdf4b76..12be06c 100644 --- a/src/pops/hive.nix +++ b/src/pops/hive.nix @@ -29,57 +29,70 @@ in nixosProfiles = { }; nixosModules = { }; }; + inputs = { + inherit (super.flake.inputs) colmena nixpkgs; + }; system = ""; nixosConfigurationRenamer = "nixosConfiguration"; + darwinConfigurationRenamer = "darwinConfiguration"; + colmenaConfigurationRenamer = "colmenaConfiguration"; exports = { hosts = { }; }; }; - extension = final: prev: { - colmena = final.genColmenaFromHosts ( - lib.filterAttrs (n: v: v.bee ? "colmena") prev.hosts - ); - genColmenaFromHosts = hosts: { - meta = { - nodes = lib.mapAttrs (hostName: hostConfig: { - inherit (hostConfig.meta.colmena) imports deployment; - }) hosts; - nodeNixpkgs = lib.mapAttrs ( - hostName: hostConfig: (super.types.hive.colmena hostConfig.meta.colmena).nixpkgs - ) hosts; + extension = + final: prev: + let + hostsArgs = { + inherit (final) hosts system inputs; }; - }; - setHosts = - setHosts: extendPop final (_: superP: { hosts = superP.hosts // setHosts; }); - setSystem = system: extendPop final (_: _: { inherit system; }); + in + { + colmena = final.genColmenaFromHosts ( + lib.filterAttrs (n: v: v.bee ? "colmena") prev.hosts + ); + genColmenaFromHosts = hosts: { + meta = { + nodes = lib.mapAttrs (hostName: hostConfig: { + inherit (hostConfig.meta.colmena) imports deployment; + }) hosts; + nodeNixpkgs = lib.mapAttrs ( + hostName: hostConfig: (super.types.hive.colmena hostConfig.meta.colmena).nixpkgs + ) hosts; + }; + }; + setHosts = + setHosts: extendPop final (_: superP: { hosts = superP.hosts // setHosts; }); + setSystem = system: extendPop final (_: _: { inherit system; }); - addMapLoadToPops = load: { }; + addMapLoadToPops = load: { }; - setNixosConfigurationsRenamer = - renamer: extendPop final (_: _: { nixosConfigurationRenamer = renamer; }); + addInputs = inputs: extendPop final (_: _: { inputs = prev.inputs // inputs; }); - pops = { }; - exports = { - darwinConfiguraitons = - root.hive.collectors.darwinConfigurations "darwinConfiguration" final.hosts - final.system; + setNixosConfigurationsRenamer = + renamer: extendPop final (_: _: { nixosConfigurationRenamer = renamer; }); + + setDarwinConfigurationsRenamer = + renamer: extendPop final (_: _: { darwinConfigurationRenamer = renamer; }); - colmenaHive = - root.hive.collectors.colmenaConfigurations "colmenaConfiguration" final.hosts - final.system; + setColmenaConfigurationsRenamer = + renamer: extendPop final (_: _: { colmenaConfigurationRenamer = renamer; }); - nixosConfigurations = - root.hive.collectors.nixosConfigurations final.nixosConfigurationRenamer - final.hosts - final.system; - # hosts = lib.omnibus.mkHosts { - # # hostsDir = projectRoot + "/units/nixos/hosts"; - # hostsDir = ./.; - # pops = super.hostsInterface; - # addLoadExtender = { - # load = { }; - # }; - # }; + pops = { }; + exports = { + darwinConfiguraitons = root.hive.collectors.darwinConfigurations final.colmenaConfigurationRenamer hostsArgs; + + colmenaHive = root.hive.collectors.colmenaConfigurations final.colmenaConfigurationRenamer hostsArgs; + + nixosConfigurations = root.hive.collectors.nixosConfigurations final.nixosConfigurationRenamer hostsArgs; + # hosts = lib.omnibus.mkHosts { + # # hostsDir = projectRoot + "/units/nixos/hosts"; + # hostsDir = ./.; + # pops = super.hostsInterface; + # addLoadExtender = { + # load = { }; + # }; + # }; + }; }; - }; }) diff --git a/tests/_snapshots/hive b/tests/_snapshots/hive new file mode 100644 index 0000000..9c6aede --- /dev/null +++ b/tests/_snapshots/hive @@ -0,0 +1,2 @@ +#pretty +{ } \ No newline at end of file diff --git a/tests/hive/example.nix b/tests/hive/expr.nix similarity index 73% rename from tests/hive/example.nix rename to tests/hive/expr.nix index 5955688..7ab845a 100644 --- a/tests/hive/example.nix +++ b/tests/hive/expr.nix @@ -8,7 +8,7 @@ let inherit (inputs) nixpkgs; hosts = { - hosts1 = rec { + host1 = rec { colmena = { nixpkgs = { }; }; @@ -16,7 +16,6 @@ let nixosConfiguration = { bee.pkgs = import nixpkgs { system = system; }; bee.system = system; - bee.colmena = inputs.colmena; imports = [ omnibus.flake.inputs.disko.nixosModules.default ]; }; asd = nixosConfiguration; @@ -28,7 +27,7 @@ let inherit (nixosConfiguration) bee imports; }; }; - hosts2 = rec { + host2 = rec { colmena = { nixpkgs = { }; }; @@ -40,10 +39,14 @@ let }; }; }; - hive = omnibus.pops.hive.setHosts hosts; + hivePop = + ((omnibus.pops.hive.setHosts hosts).addInputs { + inherit (omnibus.flake.inputs) colmena nixpkgs; + }).setNixosConfigurationsRenamer + "asd"; + inherit (hivePop.exports) darwinConfiguraitons colmenaHive; in { - darwin = hive.darwinConfiguraitons.darwin.config.system; - inherit hive; - hivePop = ((hive.setSystem "x86_64-linux").setNixosConfigurationsRenamer "asd"); + # inherit colmenaHive; + # inherit hivePop; }