rename /cerulean -> /nix
This commit is contained in:
parent
dc769da2bd
commit
89e36243b2
14 changed files with 0 additions and 0 deletions
191
nix/snow/default.nix
Normal file
191
nix/snow/default.nix
Normal file
|
|
@ -0,0 +1,191 @@
|
|||
# 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.
|
||||
{
|
||||
this,
|
||||
self,
|
||||
inputs,
|
||||
systems,
|
||||
nt,
|
||||
mix,
|
||||
...
|
||||
} @ args: let
|
||||
inherit
|
||||
(builtins)
|
||||
all
|
||||
attrNames
|
||||
elem
|
||||
mapAttrs
|
||||
warn
|
||||
;
|
||||
|
||||
inherit (inputs.nixpkgs) lib;
|
||||
|
||||
inherit (nt) findImport;
|
||||
in
|
||||
mix.newMixture args (mixture: let
|
||||
inherit (mixture) mapNodes;
|
||||
in {
|
||||
includes.private = [
|
||||
./lib/nodes.nix
|
||||
];
|
||||
|
||||
inherit findImport;
|
||||
|
||||
# snow.flake
|
||||
flake = flakeInputs: root: let
|
||||
module = lib.evalModules {
|
||||
class = "snowflake";
|
||||
# TODO: abort if inputs contains reserved names
|
||||
specialArgs =
|
||||
(flakeInputs
|
||||
// {
|
||||
inherit systems root;
|
||||
inherit (this) snow;
|
||||
inputs = flakeInputs;
|
||||
})
|
||||
|> (x: builtins.removeAttrs x ["self" "nodes"]);
|
||||
|
||||
modules = [
|
||||
./module.nix
|
||||
({config, ...}: {
|
||||
_module.args = {
|
||||
self = config;
|
||||
nodes = config.nodes.nodes;
|
||||
};
|
||||
})
|
||||
];
|
||||
};
|
||||
|
||||
nodes = module.config.nodes;
|
||||
in rec {
|
||||
nixosConfigurations = mapNodes nodes (
|
||||
{
|
||||
base,
|
||||
lib,
|
||||
name,
|
||||
node,
|
||||
groupModules,
|
||||
...
|
||||
}: let
|
||||
homeManager =
|
||||
if node.homeManager != null
|
||||
then node.homeManager
|
||||
else if nodes.homeManager != null
|
||||
then nodes.homeManager
|
||||
else
|
||||
warn ''
|
||||
[snowflake] Neither `nodes.homeManager` nor `nodes.nodes.${name}.homeManager` were specified!
|
||||
[snowflake] home-manager will NOT be used! User configuration will be ignored!
|
||||
''
|
||||
null;
|
||||
|
||||
userArgs = nodes.args // node.args;
|
||||
ceruleanArgs = {
|
||||
inherit systems root base nodes node;
|
||||
inherit (node) system;
|
||||
inherit (this) snow;
|
||||
hostname = name;
|
||||
|
||||
_cerulean = {
|
||||
inherit inputs userArgs ceruleanArgs homeManager;
|
||||
specialArgs = userArgs // ceruleanArgs;
|
||||
};
|
||||
};
|
||||
specialArgs = assert (userArgs
|
||||
|> attrNames
|
||||
|> all (argName:
|
||||
! ceruleanArgs ? argName
|
||||
|| abort ''
|
||||
`specialArgs` are like super important to Cerulean my love... </3
|
||||
But `args.${argName}` is a reserved argument name :(
|
||||
''));
|
||||
ceruleanArgs._cerulean.specialArgs;
|
||||
in
|
||||
lib.nixosSystem {
|
||||
inherit (node) system;
|
||||
inherit specialArgs;
|
||||
modules =
|
||||
[
|
||||
self.nixosModules.default
|
||||
(findImport /${root}/hosts/${name})
|
||||
]
|
||||
++ (groupModules root)
|
||||
++ node.modules
|
||||
++ nodes.modules;
|
||||
}
|
||||
);
|
||||
|
||||
deploy.nodes = mapNodes nodes ({
|
||||
name,
|
||||
node,
|
||||
...
|
||||
}: let
|
||||
inherit
|
||||
(node.deploy)
|
||||
ssh
|
||||
user
|
||||
interactiveSudo
|
||||
remoteBuild
|
||||
rollback
|
||||
autoRollback
|
||||
magicRollback
|
||||
activationTimeout
|
||||
confirmTimeout
|
||||
;
|
||||
|
||||
nixosFor = system: inputs.deploy-rs.lib.${system}.activate.nixos;
|
||||
in {
|
||||
hostname =
|
||||
if ssh.host != null
|
||||
then ssh.host
|
||||
else "";
|
||||
|
||||
profilesOrder = ["default"]; # profiles priority
|
||||
profiles.default = {
|
||||
path = nixosFor node.system nixosConfigurations.${name};
|
||||
|
||||
user = user;
|
||||
sudo = "sudo -u";
|
||||
interactiveSudo = interactiveSudo;
|
||||
|
||||
fastConnection = false;
|
||||
|
||||
autoRollback = autoRollback -> rollback;
|
||||
magicRollback = magicRollback -> rollback;
|
||||
activationTimeout = activationTimeout;
|
||||
confirmTimeout = confirmTimeout;
|
||||
|
||||
remoteBuild = remoteBuild;
|
||||
sshUser = ssh.user;
|
||||
sshOpts =
|
||||
ssh.opts
|
||||
++ (
|
||||
if elem "-p" ssh.opts
|
||||
then []
|
||||
else ["-p" (toString ssh.port)]
|
||||
)
|
||||
++ (
|
||||
if elem "-A" ssh.opts
|
||||
then []
|
||||
else ["-A"]
|
||||
);
|
||||
};
|
||||
});
|
||||
|
||||
checks =
|
||||
inputs.deploy-rs.lib
|
||||
|> mapAttrs (system: deployLib:
|
||||
deployLib.deployChecks deploy);
|
||||
};
|
||||
})
|
||||
96
nix/snow/lib/nodes.nix
Normal file
96
nix/snow/lib/nodes.nix
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
# 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";
|
||||
|
||||
parseGroupsDecl = groups: let
|
||||
validGroup = g:
|
||||
isAttrs g
|
||||
|| throw ''
|
||||
Cerulean Nexus groups must be provided as attribute sets, got "${typeOf g}" instead!
|
||||
Ensure all the group definitions are attribute sets under your call to `cerulean.mkNexus`.
|
||||
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;
|
||||
in {
|
||||
mapNodes = nodes: f:
|
||||
nodes.nodes
|
||||
|> mapAttrs (name: node: let
|
||||
# use per-node base or default to nodes' base
|
||||
base =
|
||||
if node.base != null
|
||||
then node.base
|
||||
else if nodes.base != null
|
||||
then nodes.base
|
||||
else
|
||||
abort ''
|
||||
Cerulean cannot construct nodes node "${name}" without a base package source.
|
||||
Ensure `nodes.nodes.*.base` or `nodes.base` is a flake reference to the github:NixOS/nixpkgs repository.
|
||||
'';
|
||||
in
|
||||
f rec {
|
||||
inherit name node base;
|
||||
inherit (base) lib;
|
||||
|
||||
groups = node.groups (parseGroupsDecl nodes.groups);
|
||||
groupModules = root: getGroupModules root groups;
|
||||
});
|
||||
}
|
||||
23
nix/snow/module.nix
Normal file
23
nix/snow/module.nix
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# 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.
|
||||
{
|
||||
root,
|
||||
snow,
|
||||
...
|
||||
}: {
|
||||
imports = [
|
||||
./nodes
|
||||
(snow.findImport /${root}/snow)
|
||||
];
|
||||
}
|
||||
62
nix/snow/nodes/default.nix
Normal file
62
nix/snow/nodes/default.nix
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
# 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.
|
||||
{
|
||||
lib,
|
||||
specialArgs,
|
||||
...
|
||||
}: {
|
||||
options.nodes = let
|
||||
inherit
|
||||
(lib)
|
||||
mkOption
|
||||
types
|
||||
;
|
||||
in
|
||||
mkOption {
|
||||
description = ''
|
||||
Cerulean node declarations.
|
||||
'';
|
||||
type = types.submoduleWith {
|
||||
inherit specialArgs;
|
||||
|
||||
modules = [
|
||||
{
|
||||
imports = [./shared.nix];
|
||||
|
||||
options = {
|
||||
groups = mkOption {
|
||||
type = types.attrs;
|
||||
default = {};
|
||||
example = lib.literalExpression "{ servers = { staging = {}; production = {}; }; }";
|
||||
description = ''
|
||||
Hierarchical groups that nodes can be a member of.
|
||||
'';
|
||||
};
|
||||
|
||||
nodes = mkOption {
|
||||
type = types.attrsOf (types.submoduleWith {
|
||||
inherit specialArgs;
|
||||
modules = [(import ./submodule.nix)];
|
||||
});
|
||||
# example = { ... }; # TODO
|
||||
description = ''
|
||||
Node (host systems) declarations.
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
82
nix/snow/nodes/shared.nix
Normal file
82
nix/snow/nodes/shared.nix
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
# 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.
|
||||
{lib, ...}: let
|
||||
inherit
|
||||
(lib)
|
||||
mkOption
|
||||
types
|
||||
;
|
||||
|
||||
flakeRef = types.either types.str types.path;
|
||||
in {
|
||||
options = {
|
||||
base = lib.mkOption {
|
||||
# In newer Nix versions, particularly with lazy trees, outPath of
|
||||
# flakes becomes a Nix-language path object. We deliberately allow this
|
||||
# to gracefully come through the interface in discussion with @roberth.
|
||||
#
|
||||
# See: https://github.com/NixOS/nixpkgs/pull/278522#discussion_r1460292639
|
||||
type = types.nullOr flakeRef;
|
||||
|
||||
default = null;
|
||||
defaultText = "if (using nixpkgsFlake.lib.nixosSystem) then self.outPath else null";
|
||||
|
||||
example = lib.literalExpression "inputs.nixpkgs";
|
||||
|
||||
description = ''
|
||||
The path to the nixpkgs source used to build a system. A `base` package set
|
||||
is required to be set, and can be specified via either:
|
||||
1. `options.nodes.base` (default `base` used for all systems)
|
||||
2. `options.nodes.nodes.<name>.base` (takes prescedence over `options.nodes.base`)
|
||||
|
||||
This can also be optionally set if the NixOS system is not built with a flake but still uses
|
||||
pinned sources: set this to the store path for the nixpkgs sources used to build the system,
|
||||
as may be obtained by `fetchTarball`, for example.
|
||||
|
||||
Note: the name of the store path must be "source" due to
|
||||
<https://github.com/NixOS/nix/issues/7075>.
|
||||
'';
|
||||
};
|
||||
|
||||
modules = mkOption {
|
||||
type = types.listOf types.raw;
|
||||
default = [];
|
||||
example = lib.literalExpression "[ { environment.systemPackages = [ pkgs.git ]; } ]";
|
||||
description = ''
|
||||
Shared modules to import; equivalent to the NixOS module system's `extraModules`.
|
||||
'';
|
||||
};
|
||||
|
||||
args = mkOption {
|
||||
type = types.attrs;
|
||||
default = {};
|
||||
example = lib.literalExpression "{ inherit inputs; }";
|
||||
description = ''
|
||||
Shared args to provided for each node; equivalent to the NixOS module system's `specialArgs`.
|
||||
'';
|
||||
};
|
||||
|
||||
homeManager = mkOption {
|
||||
type = types.nullOr flakeRef;
|
||||
default = null;
|
||||
example = lib.literalExpression "inputs.home-manager";
|
||||
description = ''
|
||||
The path to the home-manager source. A `homeManager` flake reference
|
||||
is required to be set for `homes/` to be evaluated, and can be specified via either:
|
||||
1. `options.nodes.homeManager` (default `homManager` used for all systems)
|
||||
2. `options.nodes.nodes.<name>.homeManager` (takes prescedence over `options.nodes.homeManager`)
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
204
nix/snow/nodes/submodule.nix
Normal file
204
nix/snow/nodes/submodule.nix
Normal file
|
|
@ -0,0 +1,204 @@
|
|||
# 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.
|
||||
{
|
||||
lib,
|
||||
systems,
|
||||
...
|
||||
}: {
|
||||
imports = [./shared.nix];
|
||||
|
||||
options = let
|
||||
inherit
|
||||
(lib)
|
||||
mkOption
|
||||
types
|
||||
;
|
||||
in {
|
||||
enabled = lib.mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
example = true;
|
||||
description = ''
|
||||
Whether to enable this node. Nodes are enabled by default.
|
||||
'';
|
||||
};
|
||||
|
||||
system = mkOption {
|
||||
type = types.nullOr (types.enum systems);
|
||||
default = null;
|
||||
example = "x86_64-linux";
|
||||
description = ''
|
||||
The target system architecture to compile for.
|
||||
'';
|
||||
};
|
||||
|
||||
groups = mkOption {
|
||||
# TODO: write a custom group type that validates better than types.attrs lol
|
||||
type = types.functionTo (types.listOf types.attrs);
|
||||
default = groups: [];
|
||||
example = lib.literalExpression "( groups: [ groups.servers groups.secure-boot ] )";
|
||||
description = ''
|
||||
A function from the `groups` hierarchy to a list of groups this node inherits from.
|
||||
'';
|
||||
};
|
||||
|
||||
deploy = {
|
||||
user = mkOption {
|
||||
type = types.str;
|
||||
default = "root";
|
||||
example = "admin";
|
||||
description = ''
|
||||
The user that the system derivation will be built with. The command specified in
|
||||
`<node>.deploy.sudoCmd` will be used if `<node>.deploy.user` is not the
|
||||
same as `<node>.deploy.ssh.user` the same as above).
|
||||
'';
|
||||
};
|
||||
|
||||
warnNonstandardDeployUser = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
example = false;
|
||||
description = ''
|
||||
Disables the warning that shows when `deploy.ssh.user` is set to a non-standard value.
|
||||
'';
|
||||
};
|
||||
|
||||
# sudoCmd = mkOption {
|
||||
# type = types.str;
|
||||
# default = "sudo -u";
|
||||
# example = "doas -u";
|
||||
# description = ''
|
||||
# Which sudo command to use. Must accept at least two arguments:
|
||||
# 1. the user name to execute commands as
|
||||
# 2. the rest is the command to execute
|
||||
# '';
|
||||
# };
|
||||
|
||||
interactiveSudo = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
example = false;
|
||||
description = ''
|
||||
Whether to enable interactive sudo (password based sudo).
|
||||
NOT RECOMMENDED. Use one of Cerulean's recommended auth methods instead.
|
||||
'';
|
||||
};
|
||||
|
||||
remoteBuild = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
example = false;
|
||||
description = ''
|
||||
Whether to build the system derivation on the target system.
|
||||
Will also fetch all external dependencies from the target system's substituters.
|
||||
'';
|
||||
};
|
||||
|
||||
rollback = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
example = true;
|
||||
description = ''
|
||||
Enables both `autoRollback` and `magicRollback`.
|
||||
'';
|
||||
};
|
||||
|
||||
autoRollback = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
example = true;
|
||||
description = ''
|
||||
If the previous system derivation should be re-activated if activation fails.
|
||||
'';
|
||||
};
|
||||
|
||||
magicRollback = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
example = true;
|
||||
description = ''
|
||||
TODO: im fucking lazy
|
||||
'';
|
||||
};
|
||||
|
||||
activationTimeout = mkOption {
|
||||
type = types.int;
|
||||
default = 500;
|
||||
example = 30;
|
||||
description = ''
|
||||
Time window in seconds allowed for system derivation activation.
|
||||
If timeout occurs, remote deployment is considered to have failed.
|
||||
'';
|
||||
};
|
||||
|
||||
confirmTimeout = mkOption {
|
||||
type = types.int;
|
||||
default = 30;
|
||||
example = 15;
|
||||
description = ''
|
||||
Time window in seconds allowed for activation confirmation.
|
||||
If timeout occurs, remote deployment is considered to have failed.
|
||||
'';
|
||||
};
|
||||
|
||||
ssh = {
|
||||
host = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
example = "dobutterfliescry.net";
|
||||
description = ''
|
||||
The host to connect to over ssh during deployment
|
||||
'';
|
||||
};
|
||||
|
||||
user = mkOption {
|
||||
type = types.str;
|
||||
default = "cerubld";
|
||||
example = "custom-user";
|
||||
description = ''
|
||||
The user to connect to over ssh during deployment.
|
||||
'';
|
||||
};
|
||||
|
||||
port = mkOption {
|
||||
type = types.int;
|
||||
default = 22;
|
||||
example = 2222;
|
||||
description = ''
|
||||
The port to connect to over ssh during deployment.
|
||||
'';
|
||||
};
|
||||
|
||||
publicKeys = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [];
|
||||
example = ["ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIeyZuUUmyUYrYaEJwEMvcXqZFYm1NaZab8klOyK6Imr me@puter"];
|
||||
description = ''
|
||||
SSH public keys that will be authorized to the deployment user.
|
||||
This key is intended solely for deployment, allowing for fine-grained permission control.
|
||||
'';
|
||||
};
|
||||
|
||||
opts = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [];
|
||||
example = ["-i" "~/.ssh/id_rsa"];
|
||||
description = ''
|
||||
Extra ssh arguments to use during deployment.
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue