Skip to content

Commit

Permalink
refactor(pops.hive): add a few funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
GTrunSec committed Apr 24, 2024
1 parent 2e0edc9 commit f8b120d
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 65 deletions.
8 changes: 0 additions & 8 deletions src/hive/beeModule.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
11 changes: 7 additions & 4 deletions src/hive/collectors/colmenaConfigurations.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
root,
super,
}:
renamer:
{ ... }@hiveArgs:
let
l = lib // builtins;

inherit (hiveArgs) inputs;

inherit (root.hive) transformers;

colmenaTopLevelCliSchema =
Expand All @@ -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
)
9 changes: 7 additions & 2 deletions src/hive/collectors/walk.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,6 +22,7 @@ let
[
(hostConfig: hostConfig.${renamer} or hostConfig.meta.${renamer})
checks.bee
(c: c // { inherit inputs; })
transformer
]
++ extraPipe
Expand Down
8 changes: 6 additions & 2 deletions src/hive/transformers/colmenaConfiguration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 5 additions & 1 deletion src/hive/transformers/darwinConfiguration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

{ lib, root }:

{ evaled, locatedConfig }:
{
evaled,
locatedConfig,
inputs ? { },
}:
let
l = lib // builtins;

Expand Down
6 changes: 5 additions & 1 deletion src/hive/transformers/nixosConfiguration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
# SPDX-License-Identifier: Unlicense

{ lib, root }:
{ evaled, locatedConfig }:
{
evaled,
locatedConfig,
inputs ? { },
}:
let
inherit (root.hive) beeModule;

Expand Down
93 changes: 53 additions & 40 deletions src/pops/hive.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = { };
# };
# };
};
};
};
})
2 changes: 2 additions & 0 deletions tests/_snapshots/hive
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#pretty
{ }
16 changes: 9 additions & 7 deletions tests/hive/example.nix → tests/hive/expr.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
let
inherit (inputs) nixpkgs;
hosts = {
hosts1 = rec {
host1 = rec {
colmena = {
nixpkgs = { };
};
system = "x86_64-linux";
nixosConfiguration = {
bee.pkgs = import nixpkgs { system = system; };
bee.system = system;
bee.colmena = inputs.colmena;
imports = [ omnibus.flake.inputs.disko.nixosModules.default ];
};
asd = nixosConfiguration;
Expand All @@ -28,7 +27,7 @@ let
inherit (nixosConfiguration) bee imports;
};
};
hosts2 = rec {
host2 = rec {
colmena = {
nixpkgs = { };
};
Expand All @@ -40,10 +39,13 @@ let
};
};
};
hive = omnibus.pops.hive.setHosts hosts;
hivePop = omnibus.pops.hive.setHosts hosts;
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;
# hivePop = (((hive.setSystem "x86_64-linux").setNixosConfigurationsRenamer "asd").addInputs {
# inherit (omnibus.flake.inputs) nixpkgs colemna;
# };
}

0 comments on commit f8b120d

Please sign in to comment.