From f412bca98a5ed47578062494bb90754581df0a46 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Sat, 10 Dec 2022 11:27:47 -0500 Subject: [PATCH] feat: add darwin's cider --- src/bee-module.nix | 42 ++++++++++++++++++++++++++++++++++++++++++ src/collect-darwin.nix | 22 ++++++++++++++++++++++ src/collect.nix | 7 +++++++ 3 files changed, 71 insertions(+) create mode 100644 src/collect-darwin.nix diff --git a/src/bee-module.nix b/src/bee-module.nix index 7f278fc..605929e 100644 --- a/src/bee-module.nix +++ b/src/bee-module.nix @@ -60,6 +60,14 @@ }; description = "divnix/hive requires you to set the home-manager input via 'config.bee.home = inputs.home-22-05;'"; }; + 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"; @@ -130,6 +138,39 @@ imports = [beeModule locatedConfig extraConfig] ++ nixosModules; }; + tranformToDarwinConfig = evaled: locatedConfig: let + darwinModules = + import (evaled.config.bee.darwin + "/modules/module-list.nix") + ++ [ + evaled.options.bee.darwin.darwinModules.flakeOverrides + ]; + extraConfig = { + # seemlessly integrate hm if desired + imports = l.optionals evaled.options.bee.home.isDefined [ + evaled.config.bee.home.darwinModules.home-manager + { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + } + ]; + }; + eval = extra: + evaled.config.bee.darwin.lib.darwinSystem { + inherit (evaled.config.bee) system pkgs; + modules = [beeModule locatedConfig extraConfig extra]; + }; + bee = + evaled.config.bee + // { + _evaled = eval {config._module.check = true;}; + _unchecked = eval {config._module.check = false;}; + }; + in { + inherit bee; + # complete module set, can be lib.evalModuled as-is + imports = [beeModule locatedConfig extraConfig] ++ darwinModules; + }; + tranformToHomeManagerConfig = evaled: locatedConfig: let lib = import (evaled.config.bee.home + /modules/lib/stdlib-extended.nix) l; hmModules = import (evaled.config.bee.home + /modules/modules.nix) { @@ -163,6 +204,7 @@ in { beeModule checkBeeAnd tranformToNixosConfig + tranformToDarwinConfig tranformToHomeManagerConfig ; } diff --git a/src/collect-darwin.nix b/src/collect-darwin.nix new file mode 100644 index 0000000..a1222cb --- /dev/null +++ b/src/collect-darwin.nix @@ -0,0 +1,22 @@ +{ + inputs, # unused for now + nixpkgs, + cellBlock, +}: renamer: let + l = nixpkgs.lib // builtins; + inherit (import ./walk.nix {inherit nixpkgs cellBlock;}) walkPaisano; + inherit (import ./bee-module.nix {inherit nixpkgs;}) beeModule checkBeeAnd tranformToDarwinConfig; + + walk = self: + walkPaisano self (system: cell: [ + (l.mapAttrs (target: config: { + _file = "Cell: ${cell} - Block: ${cellBlock} - Target: ${target}"; + imports = [config]; + })) + (l.mapAttrs (_: checkBeeAnd tranformToDarwinConfig)) + (l.filterAttrs (_: config: config.bee.system == system)) + (l.mapAttrs (_: config: config.bee._evaled)) + ]) + renamer; +in + walk diff --git a/src/collect.nix b/src/collect.nix index 10bccb9..8a41295 100644 --- a/src/collect.nix +++ b/src/collect.nix @@ -7,6 +7,7 @@ /* Modules declare an interface into a problem domain */ + darwinModules = throw "not implemented yet"; nixosModules = throw "not implemented yet"; homeModules = throw "not implemented yet"; shellModules = throw "not implemented yet"; @@ -14,18 +15,24 @@ Profiles define values on that interface */ hardwareProfiles = throw "not implemented yet"; + darwinProfiles = throw "not implemented yet"; nixosProfiles = throw "not implemented yet"; homeProfiles = throw "not implemented yet"; shellProfiles = throw "not implemented yet"; /* Suites aggregate profiles into groups */ + darwinSuites = throw "not implemented yet"; nixosSuites = throw "not implemented yet"; homeSuites = throw "not implemented yet"; shellSuites = throw "not implemented yet"; /* Configurations have an init-sequence and can be deployed */ + darwinConfigurations = import ./collect-darwin.nix { + cellBlock = "darwinConfigurations"; + inherit nixpkgs inputs; + }; nixosConfigurations = import ./collect-nixos.nix { cellBlock = "nixosConfigurations"; inherit nixpkgs inputs;