minimal working state
This commit is contained in:
parent
855430ef16
commit
6c1a0a5d33
26 changed files with 331 additions and 326 deletions
|
|
@ -12,7 +12,7 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
{
|
||||
_snow,
|
||||
_snowFlake,
|
||||
lib,
|
||||
specialArgs,
|
||||
...
|
||||
|
|
@ -39,7 +39,7 @@
|
|||
|
||||
config = {
|
||||
nodes = {
|
||||
base = _snow.inputs.nixpkgs;
|
||||
base = _snowFlake.inputs.nixpkgs;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,73 +0,0 @@
|
|||
# # Copyright 2025-2026 _cry64 (Emile Clark-Boman)
|
||||
# #
|
||||
# # Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# # you may not use this file except in compliance with the License.
|
||||
# # You may obtain a copy of the License at
|
||||
# #
|
||||
# # http://www.apache.org/licenses/LICENSE-2.0
|
||||
# #
|
||||
# # Unless required by applicable law or agreed to in writing, software
|
||||
# # distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# # See the License for the specific language governing permissions and
|
||||
# # limitations under the License.
|
||||
{nt, ...}: let
|
||||
inherit
|
||||
(builtins)
|
||||
concatLists
|
||||
elem
|
||||
filter
|
||||
isAttrs
|
||||
mapAttrs
|
||||
pathExists
|
||||
typeOf
|
||||
;
|
||||
|
||||
rootGroupName = "all";
|
||||
in {
|
||||
parseGroupsDecl = groups: let
|
||||
validGroup = g:
|
||||
isAttrs g
|
||||
|| throw ''
|
||||
Snow node groups must be provided as attribute sets, got "${typeOf g}" instead!
|
||||
Ensure all the group definitions are attribute sets under your call to `snow.flake`.
|
||||
NOTE: Groups can be accessed via `self.groups.PATH.TO.YOUR.GROUP`
|
||||
'';
|
||||
delegate = parent: gName: g: let
|
||||
result =
|
||||
(g
|
||||
// {
|
||||
_name = gName;
|
||||
_parent = parent;
|
||||
})
|
||||
|> mapAttrs (name: value:
|
||||
if elem name ["_name" "_parent"]
|
||||
# ignore metadata fields
|
||||
then value
|
||||
else assert validGroup value; (delegate result name value));
|
||||
in
|
||||
result;
|
||||
in
|
||||
assert validGroup groups;
|
||||
delegate null rootGroupName groups;
|
||||
|
||||
getGroupModules = root: groups:
|
||||
# ensure root group is always added
|
||||
groups
|
||||
# add all inherited groups via _parent
|
||||
|> map (let
|
||||
delegate = g:
|
||||
if g._parent == null
|
||||
then [g]
|
||||
else [g] ++ delegate (g._parent);
|
||||
in
|
||||
delegate)
|
||||
# flatten recursion result
|
||||
|> concatLists
|
||||
# find import location
|
||||
|> map (group: nt.findImport /${root}/groups/${group._name})
|
||||
# filter by uniqueness
|
||||
|> nt.prim.unique
|
||||
# ignore missing groups
|
||||
|> filter pathExists;
|
||||
}
|
||||
|
|
@ -14,8 +14,9 @@
|
|||
{
|
||||
lib,
|
||||
systems,
|
||||
config,
|
||||
nodesConfig,
|
||||
groups,
|
||||
groupLibs,
|
||||
...
|
||||
}: {
|
||||
options = let
|
||||
|
|
@ -25,6 +26,11 @@
|
|||
types
|
||||
;
|
||||
|
||||
inherit
|
||||
(groupLibs)
|
||||
resolveGroupsInheritance
|
||||
;
|
||||
|
||||
flakeRef = types.either types.str types.path;
|
||||
in {
|
||||
enabled = lib.mkOption {
|
||||
|
|
@ -113,8 +119,8 @@
|
|||
A function from the `groups` hierarchy to a list of groups this node inherits from.
|
||||
'';
|
||||
|
||||
apply = groupsFn:
|
||||
groupsFn nodesConfig.groups;
|
||||
# apply = groupsFn:
|
||||
# groupsFn nodesConfig.groups |> resolveGroupsInheritance;
|
||||
};
|
||||
|
||||
deploy = {
|
||||
|
|
@ -266,32 +272,32 @@
|
|||
};
|
||||
};
|
||||
|
||||
config = let
|
||||
throwGotNull = name:
|
||||
throw ''
|
||||
[snow] `nodes.<name>.${name}` must be set for all nodes! (got: <null>)
|
||||
'';
|
||||
givenSystem =
|
||||
(config.system != null)
|
||||
|| throwGotNull "system";
|
||||
# config = let
|
||||
# throwGotNull = name:
|
||||
# throw ''
|
||||
# [snow] `nodes.<name>.${name}` must be set for all nodes! (got: <null>)
|
||||
# '';
|
||||
# givenSystem =
|
||||
# (config.system != null)
|
||||
# || throwGotNull "system";
|
||||
|
||||
givenBase =
|
||||
(config.base != null)
|
||||
|| throwGotNull "base";
|
||||
# givenBase =
|
||||
# (config.base != null)
|
||||
# || throwGotNull "base";
|
||||
|
||||
givenHomeManager =
|
||||
(config.homeManager != null)
|
||||
|| throwGotNull "homeManager";
|
||||
# givenHomeManager =
|
||||
# (config.homeManager != null)
|
||||
# || throwGotNull "homeManager";
|
||||
|
||||
givenDeployHost =
|
||||
(config.deploy.ssh.host != null)
|
||||
|| throwGotNull "deploy.ssh.host";
|
||||
in
|
||||
assert givenSystem
|
||||
&& givenBase
|
||||
&& givenHomeManager
|
||||
&& givenDeployHost; {
|
||||
# extend these from the nodes configuration
|
||||
inherit (nodesConfig) modules args;
|
||||
};
|
||||
# givenDeployHost =
|
||||
# (config.deploy.ssh.host != null)
|
||||
# || throwGotNull "deploy.ssh.host";
|
||||
# in
|
||||
# assert givenSystem
|
||||
# && givenBase
|
||||
# && givenHomeManager
|
||||
# && givenDeployHost; {
|
||||
# # extend these from the nodes configuration
|
||||
# inherit (nodesConfig) modules args;
|
||||
# };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
{
|
||||
_snow,
|
||||
_snowFlake,
|
||||
snow,
|
||||
root,
|
||||
lib,
|
||||
config,
|
||||
specialArgs,
|
||||
|
|
@ -26,7 +28,10 @@
|
|||
|
||||
flakeRef = types.either types.str types.path;
|
||||
|
||||
groupLibs = import ./groups.nix {inherit (_snow.inputs) nt;};
|
||||
groupLibs = import ./groups.nix {
|
||||
inherit snow root;
|
||||
inherit (_snowFlake.inputs) nt;
|
||||
};
|
||||
in {
|
||||
options = {
|
||||
base = lib.mkOption {
|
||||
|
|
@ -94,8 +99,6 @@ in {
|
|||
description = ''
|
||||
Hierarchical groups that nodes can be a member of.
|
||||
'';
|
||||
|
||||
apply = groupLibs.parseGroupsDecl;
|
||||
};
|
||||
|
||||
nodes = mkOption {
|
||||
|
|
@ -103,7 +106,8 @@ in {
|
|||
specialArgs =
|
||||
specialArgs
|
||||
// {
|
||||
nodeConfig = config;
|
||||
nodesConfig = config;
|
||||
inherit groupLibs;
|
||||
};
|
||||
modules = [./node.nix];
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue