Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ source by.
| `facter` | none | a `facter.json` as nixos-facter writes it, with the NixOS configurations that run on it declared inside it; a machine gets it as `hardware.facter.reportPath` |
| `caisson-microvm` | `microvm` | microvm.nix guests declared inside the NixOS host that runs them, each guest a NixOS configuration declared inside it that sets its own `microvm.*` options and gets microvm.nix's guest module by default; the host selects caisson's `microvm-host` NixOS module, which defines microvm.nix's `microvm.vms.<guest>` from them; the microvm integration we recommend for new configurations |
| `microvm` | `microvm` | a microvm.nix guest written as microvm.nix reads it, a NixOS configuration that sets its `microvm.*` options itself, declared inside the NixOS host that runs it; for porting an existing guest |
| `treefmt` | `treefmt-nix` | the formatters of a tree, as treefmt-nix modules; the configuration named `default` is published as the `formatter.<system>` that `nix fmt` runs |
| `treefmt` | `treefmt-nix` | the formatters of a tree, as treefmt-nix modules; the configuration named `formatter` is published as the `formatter.<system>` that `nix fmt` runs |
| `nvf` | `nvf` | a Neovim written as nvf modules, published as `nvfConfigurations.<system>.<name>`, in the shape `neovimConfiguration` returns, kept in a separate Nix profile that the machine, home-manager configuration or hjem configuration it is declared inside activates |
| `nixvim` | `nixvim` | a Neovim written as nixvim modules, published as `nixvimConfigurations.<system>.<name>`, kept in a profile as an nvf configuration is |
| `topology` | `nix-topology` | the diagram of the NixOS configurations declared inside it, as nix-topology renders it; the configuration named `default` is published as `topology.<system>` |
| `topology` | `nix-topology` | the diagram of the NixOS configurations declared inside it, as nix-topology renders it; the configuration named `topology` is published as `topology.<system>` |
| `kubenix` | `kubenix` | Kubernetes resources written as kubenix modules, published as `kubenixConfigurations.<system>.<name>`, the evaluation, whose `config.kubernetes.result` is the JSON `kubectl apply -f` reads |
| `nixidy` | `nixidy` | an Argo CD environment written as nixidy modules, evaluated with nixidy's `mkEnv` and published as the `nixidyEnvs.<system>.<name>` the nixidy CLI reads |
| `system-manager` | `system-manager` | the systems of machines running another Linux distribution, published as the `systemConfigs` that `system-manager switch` reads; they activate the home-manager configurations and hjem configurations declared inside them, and the profiles of the nvf and nixvim configurations declared inside them |
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib-overlays/caisson-colmena/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
# `meta.nixpkgs`): every node is an evaluated NixOS configuration.
#
# A colmena configuration is published as `colmenaHive`, an output that
# holds a single value, so the configuration declared under the name
# `default` fills it. The nodes are published as well, as the NixOS
# holds a single value, so the configuration declared under the name of
# that output, `colmenaHive`, fills it. The nodes are published as well, as the NixOS
# configurations they are, so `nixos-rebuild` and `colmena apply` build
# the same machine.
{
Expand Down
40 changes: 27 additions & 13 deletions lib-overlays/colmena/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
# configuration the node also gets what caisson's NixOS evaluator gives
# any configuration: the framework modules and the default selection.
#
# `nodes` is what colmena hands its nodes: every node, evaluated again
# with type checking off, for one node to read another. A configuration
# never reads a sibling in the tree, so these evaluations are tops of
# their own, made only when a module reads them.
# `nodes` is what colmena hands its nodes: every node, for one node to
# read another. The colmena configuration sets
# `unsafeCrossChildReferences` for its nearest NixOS configurations, so
# each node reads the full evaluation of the colmena configuration and
# `nodes` is the nodes themselves. A loop among nodes that read each
# other is a Nix infinite recursion, as it is in colmena.
#
# The colmena configuration builds the hive from the NixOS
# configurations it passes up, as caisson-colmena does, and is
Expand Down Expand Up @@ -166,19 +168,31 @@
src: hive:
{ lib, ... }:
let
# Every node again, with type checking off, for the `nodes`
# special argument.
uncheckedNodes = builtins.mapAttrs (
name: _:
lib.caisson.nixos.mkTopConfiguration (
nodeArgs src hive uncheckedNodes name [ { _module.check = false; } ]
)
) hive.nodes;
# The nodes as the `nodes` special argument: the NixOS
# configurations declared beneath this colmena configuration,
# each evaluated, from the full evaluation of this
# configuration. A node reads that evaluation through
# `unsafeCrossChildReferences`, set below, which records the
# read on each node; it is the configuration this module runs
# in, so its manifest here holds the same children.
full = lib.caisson-core.evalManifest;
nodes =
builtins.foldl'
(
found: system:
found
// builtins.mapAttrs (_: node: node.value) (full.children.system.${system}.children.nixos or { })
)
(builtins.mapAttrs (_: node: node.value) (full.children.nixos or { }))
(builtins.attrNames (full.children.system or { }));
in
{
meta = builtins.removeAttrs hive.meta evaluationMetaKeys;
# Colmena hands every node the other nodes, so the nodes read
# the full evaluation of this configuration.
caisson.forNearestChildren.unsafeCrossChildReferences.nixos = true;
caisson.nixos.configurations = builtins.mapAttrs (
name: _: lib.caisson.nixos.mkConfiguration (nodeArgs src hive uncheckedNodes name [ ])
name: _: lib.caisson.nixos.mkConfiguration (nodeArgs src hive nodes name [ ])
) hive.nodes;
};

Expand Down
48 changes: 36 additions & 12 deletions lib-overlays/integrations/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -830,11 +830,19 @@
extraDefaultModuleImports = additionsOf options.caisson.forChildren config.caisson.forChildren;
defaultPkgs = config.caisson.forChildren.defaultPkgs;
systems = config.caisson.forChildren.systems;
inherit (config.caisson.forChildren) unsafeCrossChildReferences;
};
# What the modules give the nearest configurations of a
# class beneath (`caisson.forNearestChildren`).
forNearestChildren = {
extraDefaultModuleImports = additionsOf options.caisson.forNearestChildren config.caisson.forNearestChildren;
inherit (config.caisson.forNearestChildren) unsafeCrossChildReferences;
};
# What the modules give the configurations of a class
# declared directly beneath (`caisson.forDirectChildren`).
forDirectChildren = {
extraDefaultModuleImports = additionsOf options.caisson.forDirectChildren config.caisson.forDirectChildren;
inherit (config.caisson.forDirectChildren) unsafeCrossChildReferences;
};
# What the evaluator received, as `declaration` events:
# the integration's `evaluate` returns `modules`, the list
Expand Down Expand Up @@ -1041,16 +1049,26 @@
finalize =
childName: child:
let
finalized = lib.caisson-core.finalizeChild {
name = childName;
what = what childName;
parent = manifest.childlessManifest;
} child;
# A deferred configuration is held as an entry, finalized
# when its args are supplied.
finalized =
(
if lib.caisson-core.isDeferredConfiguration child then
lib.caisson-core.deferChild
else
lib.caisson-core.finalizeChild
)
{
name = childName;
what = what childName;
parent = manifest.childlessManifest;
}
child;
# The integration of what was declared: of the
# manifest, or of the evaluations of a configuration
# evaluated per system, null where it has none.
declaredType =
if isManifest finalized then
if isManifest finalized || lib.caisson-core.isDeferred finalized then
finalized.type
else if finalized == { } then
null
Expand Down Expand Up @@ -1685,7 +1703,10 @@
name = system;
};
beneath =
if isManifest finalized then
# A deferred child passes nothing up at flake time.
if final.caisson-core.isDeferred finalized then
[ ]
else if isManifest finalized then
[
{
prefix = [ (segmentOf name) ];
Expand Down Expand Up @@ -1736,8 +1757,8 @@
# paths.
#
# An output that holds a single value (`colmenaHive`) is the value
# of the entry named `default`, the entry whose `exportsTo` says
# `single`. Any other entry for that output is refused, since the
# of the entry named for that output, `colmenaHive`, the entry
# whose `exportsTo` says `single`. Any other entry for that output is refused, since the
# output has no names to hold it under.
#
# An output whose entries' `exportsTo` says `bySystem` is keyed by
Expand Down Expand Up @@ -1807,15 +1828,18 @@
name: builtins.length (builtins.filter (other: other == name) names) > 1
) (unique names);
single = builtins.any (entry: entry.single or false) members;
notDefault = builtins.filter (entry: (last entry.path).name != "default") members;
# A configuration with a single output is named for that
# output.
misnamed = builtins.filter (entry: (last entry.path).name != entry.attrset) members;
singleName = (builtins.head members).attrset;
in
if single then
if builtins.length members == 1 && notDefault == [ ] then
if builtins.length members == 1 && misnamed == [ ] then
of (builtins.head members)
else
throw ''
${attrset}: this output holds a single value, the configuration
declared under the name `default`, but these configurations would
declared under the name `${singleName}`, but these configurations would
be published there:
${builtins.concatStringsSep "\n" (builtins.map (entry: " ${showPath entry.path}") members)}
''
Expand Down
4 changes: 2 additions & 2 deletions lib-overlays/topology/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@
outputs.output = value.config.output;
};

# The configuration named `default` is published as
# `topology.<system>`, the evaluation.
# The configuration named `topology`, for the output it fills, is
# published as `topology.<system>`, the evaluation.
exportsTo = {
attrset = "topology";
single = true;
Expand Down
18 changes: 9 additions & 9 deletions lib-overlays/treefmt/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -157,27 +157,27 @@
};
};

# Only the configuration named `default` is published: as
# `formatter.<system>`, its wrapper, which `nix fmt` reads, and,
# in a tree that knows its root, as `checks.<system>.treefmt`,
# its check over that tree, which fails `nix flake check` when
# the tree is not formatted.
isDefault = manifest: (manifest.name or null) == "default";
# Only the configuration named `formatter`, for the output it
# fills, is published: as `formatter.<system>`, its wrapper,
# which `nix fmt` reads, and, in a tree that knows its root, as
# `checks.<system>.treefmt`, its check over that tree, which
# fails `nix flake check` when the tree is not formatted.
isFormatter = manifest: (manifest.name or null) == "formatter";
exportsTo = [
{
attrset = "formatter";
single = true;
bySystem = true;
only = isDefault;
only = isFormatter;
value = manifest: manifest.outputs.wrapper;
}
{
attrset = "checks";
bySystem = true;
only = manifest: isDefault manifest && (manifest.root or null) != null;
only = manifest: isFormatter manifest && (manifest.root or null) != null;
name = _: {
value = "treefmt";
description = "named `treefmt`, the check of the configuration named `default`";
description = "named `treefmt`, the check of the configuration named `formatter`";
};
value = manifest: manifest.outputs.check manifest.root;
}
Expand Down
1 change: 1 addition & 0 deletions modules/generic/core/caisson/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
./configurations.nix
./exports.nix
./forChildren.nix
./forDirectChildren.nix
./forNearestChildren.nix
./libOverlays.nix
./modules.nix
Expand Down
22 changes: 22 additions & 0 deletions modules/generic/core/caisson/forChildren.nix
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,27 @@
'';
};

unsafeCrossChildReferences = lib.mkOption {
type = lib.types.attrsOf lib.types.bool;
default = { };
example = {
nixos = true;
};
description = ''
By class, whether the configurations of that class beneath this
configuration, at any depth, read the full evaluation of this
configuration, with its children, in place of the childless
view of their parent (`lib.caisson-core.evalManifest.crossChildLevel`).
They can then reach every configuration beneath this one, and
a loop between them is a Nix infinite recursion, which the
childless view otherwise rules out.

A setting through `caisson.forDirectChildren` beats one through
`caisson.forNearestChildren`, which beats this one, and within
one container the nearest parent that sets it wins. This
reaches every depth, so it is rarely the one to use.
'';
};

};
}
61 changes: 61 additions & 0 deletions modules/generic/core/caisson/forDirectChildren.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# SPDX-License-Identifier: MIT
#
# What this configuration gives the configurations of a class declared
# directly beneath it: additions to the default selection of that
# class, and whether they read the full evaluation of this
# configuration. A configuration evaluated per system and declared here
# is a direct child, since a system is no level of its own. Nothing
# here passes through a configuration of another class, and the
# configurations beneath a direct child do not get it. It is read from
# the childless view, which the configurations beneath are built
# against.
{ lib, ... }:
{
options.caisson.forDirectChildren = {

extraDefaultModuleImports = lib.mkOption {
type = lib.types.attrsOf (lib.types.functionTo (lib.types.listOf lib.types.raw));
default = { };
example = lib.literalExpression ''
{
nixos = lib: [ lib.caisson.modules.nixos.site-base ];
}
'';
description = ''
Additions to the default selection of a class for the
configurations of that class declared directly beneath this
configuration: by class, a function of the lib of such a
configuration returning registered modules. A direct child that
passes no `moduleImports` gets every entry named `default`, then
the additions of `caisson.forChildren.extraDefaultModuleImports`
of the levels above it, then those of
`caisson.forNearestChildren.extraDefaultModuleImports`, then
these. Definitions from several modules are concatenated.

A module listed here is a module registered in the
composition, on `mkLib` or by a project.
'';
};

unsafeCrossChildReferences = lib.mkOption {
type = lib.types.attrsOf lib.types.bool;
default = { };
example = {
caisson-nixops4-resource = true;
};
description = ''
By class, whether the configurations of that class declared
directly beneath this configuration read the full evaluation
of this configuration, with its children, in place of its
childless view (`lib.caisson-core.evalManifest.crossChildLevel`).
They can then reach every configuration beneath this one, and
a loop between them is a Nix infinite recursion, which the
childless view otherwise rules out.

This setting beats one through `caisson.forNearestChildren` or
`caisson.forChildren`.
'';
};

};
}
26 changes: 26 additions & 0 deletions modules/generic/core/caisson/forNearestChildren.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,31 @@
'';
};

unsafeCrossChildReferences = lib.mkOption {
type = lib.types.attrsOf lib.types.bool;
default = { };
example = {
nixos = true;
};
description = ''
By class, whether the nearest configurations of that class
beneath this configuration read the full evaluation of this
configuration, with its children, in place of the childless
view of their parent (`lib.caisson-core.evalManifest.crossChildLevel`).
It passes through configurations of other classes, as the
additions above do, so a machine inside a structural group or a
disk layout beneath this configuration is reached. A
configuration it reaches can read every configuration beneath
this one, and a loop between them is a Nix infinite recursion,
which the childless view otherwise rules out.

A setting through `caisson.forDirectChildren` beats this one,
which beats one through `caisson.forChildren`, and within one
container the nearest parent that sets it wins. This setting
connects at the nearest configurations of its class whether or
not it wins there.
'';
};

};
}
6 changes: 3 additions & 3 deletions tests/dependencies/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading