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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ source by.
| `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 |
| `nvf` | `nvf` | a Neovim written as nvf modules, published as `nvfConfigurations.<system>.<name>`, in the shape `neovimConfiguration` returns |
| `nixvim` | `nixvim` | a Neovim written as nixvim modules, published as `nixvimConfigurations.<system>.<name>` |
| `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>` |
| `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 |
| `structural` | none | a configuration that only exports and holds configurations beneath it: the top of a repository whose point is what it exports, such as caisson itself, or a layer at any depth |

Expand Down
3 changes: 3 additions & 0 deletions configs/structural/impl/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
treefmt
nvf
nixvim
topology
kubenix
nixidy
;
};

Expand Down
3 changes: 2 additions & 1 deletion docs/development/repository-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ The layer users reach for: the integrations (`structural`,
`flake-parts`, `nixpkgs`, `nixos`, `nixos-minimal`, `home-manager`,
`home-manager-minimal`, `darwin`, `hjem`, `caisson-colmena`, `colmena`,
`caisson-disko`, `disko`, `caisson-facter`, `facter`, `terranix`,
`system-manager`, `treefmt`, `nvf`, `nixvim`), each
`system-manager`, `treefmt`, `nvf`, `nixvim`, `topology`, `kubenix`,
`nixidy`), each
a library overlay
contributing its `lib.caisson` namespace, registering its module
class where it has a class (`nixos-minimal` and `home-manager-minimal`
Expand Down
6 changes: 3 additions & 3 deletions lib-overlays/darwin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#
# The darwin integration: it owns the `darwin` class and evaluates it
# with nix-darwin's `eval-config.nix`, over the composed library. A
# darwin configuration is a macOS machine, evaluated at every system
# in force where it is declared, as a NixOS configuration is, and
# darwin configuration is a macOS machine, evaluated per system,
# once for each system in force where it is declared, as a NixOS configuration is, and
# published as `darwinConfigurations.<name>`, the value `darwin-rebuild`
# reads: the evaluated configuration with its `system` beside it.
#
Expand Down Expand Up @@ -159,7 +159,7 @@
args:
final.caisson.integrations.mkModuleConfiguration {
type = "darwin";
# A darwin configuration is evaluated at a system: it has an
# A darwin configuration is evaluated per system: it has an
# evaluation for every system in force where it is declared.
perSystem = true;
defaultPkgs = args.defaultPkgs or null;
Expand Down
4 changes: 2 additions & 2 deletions lib-overlays/hjem/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# The hjem integration: it owns the `hjem` class, hjem's class for the
# files and packages of a user. A hjem configuration is the home of a
# user, evaluated at every system in force where it is declared.
# user, evaluated per system, once for each system in force where it is declared.
#
# hjem itself evaluates a user only inside its NixOS and nix-darwin
# modules, as a submodule of `hjem.users`; its standalone CLI evaluates
Expand Down Expand Up @@ -273,7 +273,7 @@
args:
final.caisson.integrations.mkModuleConfiguration {
type = "hjem";
# A hjem configuration is evaluated at a system: it has an
# A hjem configuration is evaluated per system: it has an
# evaluation for every system in force where it is declared.
perSystem = true;
defaultPkgs = args.defaultPkgs or null;
Expand Down
6 changes: 3 additions & 3 deletions lib-overlays/home-manager/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# contributes the declared home-manager's library to the composition
# as `lib.hm`, and evaluates the class over the composed library with
# home-manager's module list. A home is a configuration: it is
# evaluated at every system in force where it is declared, on the
# evaluated per system, once for each system in force where it is declared, on the
# package set in force there, and a top publishes it under
# `homeConfigurations`.
#
Expand Down Expand Up @@ -509,7 +509,7 @@
variant: args:
selection.mkModuleConfiguration {
type = "home-manager";
# A home is evaluated at a system: it has an evaluation for
# A home is evaluated per system: it has an evaluation for
# every system in force where it is declared.
perSystem = true;
defaultPkgs = args.defaultPkgs or null;
Expand All @@ -531,7 +531,7 @@
# `caisson.home-manager.configurations.<name>` finalizes it,
# and `mkTopConfiguration` finalizes it at a top.
# `lib.caisson.home-manager-minimal` takes the same arguments.
# The home is evaluated at every system in force where it is
# The home is evaluated per system, once for each system in force where it is
# declared, and its package sets come from the composition,
# through the manifest; `defaultPkgs` selects the set it runs
# on.
Expand Down
11 changes: 6 additions & 5 deletions lib-overlays/integrations/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@

# A configuration that is a module evaluation. `type` is the
# name of the integration and `perSystem` whether it evaluates a
# configuration at a system, as caisson-core.mkConfiguration
# configuration per system, as caisson-core.mkConfiguration
# takes them. `evaluate` is the evaluator step of the
# integration: it takes the view being evaluated, `{ lib,
# manifest }`, and returns `value`, the evaluation as the
Expand Down Expand Up @@ -467,7 +467,7 @@
} child;
# The integration of what was declared: of the
# manifest, or of the evaluations of a configuration
# evaluated at a system, null where it has none.
# evaluated per system, null where it has none.
declaredType =
if isManifest finalized then
finalized.type
Expand Down Expand Up @@ -676,8 +676,9 @@
# declared beneath it, nested ones included: for each, its
# manifest, the output attribute set it is published under, the
# value published, and its path from here, a list of
# `{ type, name }` segments. A configuration evaluated at a
# system has that system above its name on the path. `selected`
# `{ type, name }` segments. An evaluation of a configuration
# evaluated per system has its system above its name on the
# path. `selected`
# is what each integration's `exported` selected, by integration
# and then name, each value a manifest or the evaluations of a
# configuration by system. A configuration whose manifest
Expand Down Expand Up @@ -822,7 +823,7 @@
genAttrs attrsets publishIn;

# What a tool reads from a top that is a configuration evaluated
# at a system, given its evaluations by system. They are named
# per system, given its evaluations by system. They are named
# like anything published, by `caisson-core.elide` over their
# paths; the top is addressed by the file that returns it, so the
# name of the top is left out of each. Where that leaves a single
Expand Down
242 changes: 242 additions & 0 deletions lib-overlays/kubenix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
# SPDX-License-Identifier: MIT
#
# The kubenix integration: it owns the `kubenix` class, the class of
# kubenix's modules. A kubenix configuration is a set of Kubernetes
# resources written as kubenix modules, which import the kubenix modules
# they use from the `kubenix` argument (`kubenix.modules.k8s`). It is
# evaluated per system, once for each system in force where it is declared, on the
# package set selected for it.
#
# kubenix evaluates its modules with its `evalModules`: `evalModules` on
# the library of the package set extended with kubenix's
# `upstreamables.nix`, with the special argument `kubenix` holding its
# library, its `evalModules` and its modules. caisson makes that
# evaluation on the composed library extended the same way.
#
# The output is `result`, the resources as a JSON file, which
# `kubectl apply -f` reads; it is the `kubernetes.result` of kubenix's
# `k8s` module, so a configuration that imports that module has it. A
# configuration is published as `kubenixConfigurations.<system>.<name>`,
# the evaluation, whose `config.kubernetes.result` is the result.
{
mkLibOverlay,
...
}:
{

imports = [
# The library of nixpkgs, which this overlay calls through the
# composed library, imported by key so it is composed wherever
# this is.
((mkLibOverlay ../nixpkgs-lib) // { key = "nixpkgs-lib"; })
# What an integration is written from, imported by key so it is
# composed wherever this integration is.
((mkLibOverlay ../integrations) // { key = "integrations"; })
];

overlay =
final: prev:
let
context = "lib.caisson.kubenix.mkConfiguration";

resolveEcosystemSrc = final.caisson.integrations.resolveEcosystemSrc {
name = "kubenix";
context = "caisson.kubenix";
};

# A kubenix source: the kubenix flake or source tree, which holds
# its library at `lib` and its modules at `modules`.
assertKubenixSrc =
ecosystemSrc:
let
path = if builtins.isAttrs ecosystemSrc then ecosystemSrc.outPath or null else ecosystemSrc;
in
if
path != null
&& builtins.pathExists "${path}/lib/upstreamables.nix"
&& builtins.pathExists "${path}/lib/eval-modules.nix"
&& builtins.pathExists "${path}/modules/default.nix"
then
ecosystemSrc
else
throw "${context} requires `ecosystemSrc` to be a kubenix flake or source tree (holding lib/upstreamables.nix, lib/eval-modules.nix and modules).";

evaluate =
args:
{ lib, manifest }:
let
selection = lib.caisson.integrations;
src = assertKubenixSrc (resolveEcosystemSrc {
explicit = args.ecosystemSrc or null;
manifest = lib.caisson-core.libManifest or { };
});

name = manifest.name or null;
inherit (manifest) system;
what =
if name != null then
"the kubenix configuration `${name}` at ${system}"
else
"this kubenix configuration at ${system}";

pkgSets = selection.pkgSetsAt { inherit context what; } manifest system;
pkgs = selection.pkgSetOf { inherit context what; } manifest pkgSets;

# The composed library extended with kubenix's
# `upstreamables.nix`, as kubenix extends the library of the
# package set. `extend` extends the library of nixpkgs, so the
# composed library is laid over it again, with the module
# system of the extension.
kubenixLib = lib.extend (
self: super:
lib
// {
inherit (super) modules types evalModules;
}
// import "${src}/lib/upstreamables.nix" {
lib = self;
inherit pkgs;
}
);

registry = lib.caisson.modules.kubenix or { };
frameworkModules = selection.frameworkModules "kubenix" registry;
moduleImports = selection.moduleImportsOf "kubenix" { inherit lib manifest; } args;

# The configuration's module: the module passed, else the
# configuration registered under the configuration's name
# (`configs/kubenix/<name>`), else none.
registered = lib.caisson.configs.kubenix or { };
configModule =
if (args.configModule or null) != null then
args.configModule
else if name != null then
registered.${name} or null
else
null;

value = kubenixLib.evalModules (
{
class = "kubenix";
specialArgs = {
inherit pkgs pkgSets;
lib = kubenixLib;
kubenix = {
lib = import "${src}/lib" {
inherit pkgs;
inherit (pkgs) lib;
};
evalModules = import "${src}/lib/eval-modules.nix" { inherit pkgs; };
modules = import "${src}/modules";
};
}
// (if (args.specialArgs or null) != null then args.specialArgs else { });
modules =
frameworkModules
++ moduleImports registry
++ (if configModule == null then [ ] else [ configModule ])
++ [
{
_file = "caisson-kubenix:args";
config._module.args = {
inherit pkgs;
name = "default";
};
}
];
}
// (if (args.ecosystemArgs or null) != null then args.ecosystemArgs else { })
);
in
{
inherit value;
outputs.result =
value.config.kubernetes.result
or (throw "${what} has no `kubernetes.result`; it imports kubenix's `k8s` module from `kubenix.modules.k8s` to have one.");
};

# A kubenix configuration is published as
# `kubenixConfigurations.<system>.<name>`, the evaluation kubenix's
# `evalModules` returns, whose `config.kubernetes.result` is its
# result.
exportsTo = {
attrset = "kubenixConfigurations";
bySystem = true;
value = manifest: manifest.value;
};

configuration =
args:
final.caisson.integrations.mkModuleConfiguration {
type = "kubenix";
# A kubenix configuration is evaluated per system: it has an
# evaluation for every system in force where it is declared.
perSystem = true;
defaultPkgs = args.defaultPkgs or null;
inherit exportsTo;
evaluate = evaluate args;
};

integration = final.caisson.integrations.mkIntegration {
name = "kubenix";
class = "kubenix";
# A kubenix configuration that is a top, as a tool reads it: the
# evaluation, or the evaluations by system where several are in
# force.
top = final.caisson.integrations.topValue;
# What these return is a configuration, a function of
# `{ name, parent }`: a parent that declares it under
# `caisson.kubenix.configurations.<name>` finalizes it, and
# `mkTopConfiguration` finalizes it at a top.
mkConfiguration =
{
# The configuration's module. When absent, the configuration
# registered under the configuration's name
# (`lib.caisson.configs.kubenix.<name>`), if any. Further
# modules of the class are selected with `moduleImports`,
# from the registry.
configModule ? null,
# The kubenix flake or source tree; resolved from the
# composition's declarations when absent.
ecosystemSrc ? null,
# The package set the configuration runs on: a function
# that receives the package sets available where it is
# declared, by package config name, each at the system of
# the evaluation, and returns the set to run on. When
# absent, the selection of the nearest configuration above,
# and the set named `default` where none above selects.
defaultPkgs ? null,
# The selection over the kubenix class of the registry. It
# replaces the default of the class, which is every entry
# named `default` followed by what the configurations
# above added.
moduleImports ? null,
# A selection added to that selection, whichever it is.
extraModuleImports ? null,
# Extra module arguments, merged over those the framework
# supplies.
specialArgs ? null,
}@args:
configuration args;
# The same arguments and `ecosystemArgs`, the evaluator's
# arguments merged over the composed call last.
mkConfigurationWithEcosystemArgs =
{
configModule ? null,
ecosystemSrc ? null,
defaultPkgs ? null,
moduleImports ? null,
extraModuleImports ? null,
specialArgs ? null,
ecosystemArgs ? null,
}@args:
configuration args;
};
in
{
caisson = (prev.caisson or { }) // {
kubenix = integration.namespace;
};
};

}
Loading
Loading