Skip to content

Commit

Permalink
feat: split checks and transformers, make use of haumea folder structure
Browse files Browse the repository at this point in the history
  • Loading branch information
hoppla20 authored and blaggacao committed Aug 8, 2023
1 parent 703f2cc commit 551626b
Show file tree
Hide file tree
Showing 10 changed files with 265 additions and 244 deletions.
227 changes: 0 additions & 227 deletions src/bee-module.nix

This file was deleted.

89 changes: 89 additions & 0 deletions src/beeModule.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{nixpkgs}: {config, ...}: let
l = nixpkgs.lib // builtins;

erase = optionName: instruction: {options, ...}: let
opt = l.getAttrFromPath optionName options;
in {
options = l.setAttrByPath optionName (l.mkOption {visible = false;});
config.bee._alerts = [
{
assertion = !opt.isDefined;
message = ''
The option `${l.showOption optionName}' is not supported.
Location: ${l.showFiles opt.files}
${
if instruction != null
then instruction
else ""
}
'';
}
];
};
in {
imports = [
(erase ["nixpkgs" "config"] "Please set 'config.bee.pkgs' to a fully configured nixpkgs.")
(erase ["nixpkgs" "overlays"] "Please set 'config.bee.pkgs' to a nixpkgs - overlays included.")
(erase ["nixpkgs" "system"] "Please set 'config.bee.system', instead.")
(erase ["nixpkgs" "localSystem"] "Please set 'config.bee.system', instead.")
(erase ["nixpkgs" "crossSystem"] "Please set 'config.bee.system', instead.")
(erase ["nixpkgs" "pkgs"] "Please set 'config.bee.pkgs' to an instantiated version of nixpkgs.")
];
options.bee = {
_alerts = l.mkOption {
type = l.types.listOf l.types.unspecified;
internal = true;
default = [];
};
_evaled = l.mkOption {
type = l.types.attrs;
internal = true;
default = {};
};
_unchecked = l.mkOption {
type = l.types.attrs;
internal = true;
default = {};
};
system = l.mkOption {
type = l.types.str;
description = "divnix/hive requires you to set the host's system via 'config.bee.system = \"x86_64-linux\";'";
};
home = l.mkOption {
type = l.mkOptionType {
name = "input";
description = "home-manager input";
check = x: (l.isAttrs x) && (l.hasAttr "sourceInfo" x);
};
description = "divnix/hive requires you to set the home-manager input via 'config.bee.home = inputs.home-22-05;'";
};
wsl = l.mkOption {
type = l.mkOptionType {
name = "input";
description = "nixos-wsl input";
check = x: (l.isAttrs x) && (l.hasAttr "sourceInfo" x);
};
description = "divnix/hive requires you to set the nixos-wsl input via 'config.bee.wsl = inputs.nixos-wsl;'";
};
darwin = l.mkOption {
type = l.mkOptionType {
name = "input";
description = "darwin input";
check = x: (l.isAttrs x) && (l.hasAttr "sourceInfo" x);
};
description = "divnix/hive requires you to set the darwin input via 'config.bee.darwin = inputs.darwin;'";
};
pkgs = l.mkOption {
type = l.mkOptionType {
name = "packages";
description = "instance of nixpkgs";
check = x: (l.isAttrs x) && (l.hasAttr "path" x);
};
description = "divnix/hive requires you to set the nixpkgs instance via 'config.bee.pkgs = inputs.nixos-22.05.legacyPackages;'";
apply = x:
if (l.hasAttr "${config.bee.system}" x)
then x.${config.bee.system}
else x;
};
};
}
30 changes: 30 additions & 0 deletions src/checks/bee.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{nixpkgs}: let
l = nixpkgs.lib // builtins;

inherit (root) beeModule;

check = locatedConfig: let
checked = l.nixos.evalModules {
modules = [
locatedConfig
beeModule
{
config._module.check = true;
config._module.freeformType = l.types.unspecified;
}
];
};

failedAsserts = map (x: x.message) (l.filter (x: !x.assertion) checked.config.bee._alerts);

asserted =
if failedAsserts != []
then throw "\nHive's layer sanitation boundary: \n${l.concatStringsSep "\n" (map (x: "- ${x}") failedAsserts)}"
else checked;
in
assert l.isAttrs asserted; {
inherit locatedConfig;
evaled = asserted;
};
in
check
13 changes: 5 additions & 8 deletions src/collectors/colmenaConfigurations.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

l = nixpkgs.lib // builtins;

inherit (root) requireInput walkPaisano bee-module;
inherit (root) requireInput walkPaisano checks transformers;
inherit (inputs) colmena;
inherit (bee-module) beeModule checkBeeAnd tranformToNixosConfig;

colmenaModules = l.map (l.setDefaultModuleLocation (./collect-colmena.nix + ":colmenaModules")) [
# these modules are tied to the below schemaversion
Expand All @@ -27,24 +26,22 @@
}
];

tranformToNixosConfig' = name: evaled: locatedConfig: let
transformToNixosConfigurations = name: evaled: locatedConfig: let
config = {
imports = [locatedConfig] ++ colmenaModules;
_module.args = {inherit name;};
};
in
tranformToNixosConfig evaled config;
transformers.nixosConfigurations {inherit evaled config;};

walk = self:
walkPaisano self cellBlock (system: cell: [
(l.mapAttrs (target: config: {
_file = "Cell: ${cell} - Block: ${cellBlock} - Target: ${target}";
imports = [config];
}))
(l.mapAttrs (target:
checkBeeAnd (
tranformToNixosConfig' (renamer cell target)
)))
(l.mapAttrs (_: checks.bee))
(l.mapAttrs (target: transformToNixosConfigurations (renamer cell target)))
(l.filterAttrs (_: config: config.bee.system == system))
])
renamer;
Expand Down
Loading

0 comments on commit 551626b

Please sign in to comment.