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 @@ -124,7 +124,7 @@ source by.
| `nixos-minimal` | `nixpkgs` | the `nixos` class under the minimal evaluator (no NixOS base modules); a second integration over the class `nixos` owns |
| `home-manager` | `home-manager` | Home Manager configurations |
| `home-manager-minimal` | `home-manager` | the `homeManager` class with Home Manager's necessary modules alone, the configuration importing what it uses from `modulesPath`; a second integration over the class `home-manager` owns |
| `hjem` | `hjem` | the files and packages of a user, as hjem manifests; activated by the NixOS configuration they are declared inside, or applied with `hjem standalone` |
| `hjem` | `hjem` | the files and packages of a user, as hjem manifests; activated by the NixOS, darwin or system-manager configuration they are declared inside, or applied with `hjem standalone` |
| `terranix` | `terranix` | Terraform configurations written as terranix modules, published as `terranixConfigurations` of the `config.tf.json` files Terraform reads |
| `caisson-colmena` | `colmena` | colmena configurations whose machines are NixOS configurations declared inside them, published as the hive colmena's command reads; the colmena integration we recommend for new configurations |
| `colmena` | `colmena` | a hive written for colmena, taken as it is, with each node a NixOS configuration; for porting an existing hive and the modules written for it |
Expand All @@ -138,7 +138,7 @@ source by.
| `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 |
| `system-manager` | `system-manager` | the systems of machines running another Linux distribution, published as the `systemConfigs` that `system-manager switch` reads; they activate the homes and hjem configurations declared inside them |
| `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 |

Each integration finds its ecosystem in this order: the `ecosystemSrc`
Expand Down
28 changes: 21 additions & 7 deletions lib-overlays/hjem/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,37 @@
null;

# The machine the configuration is declared inside, when there
# is one: the childless evaluation of the nearest NixOS or
# darwin configuration above it, which hjem's modules receive
# as `osConfig`, null when there is none.
# is one: the childless evaluation of the nearest NixOS,
# darwin or system-manager configuration above it, which hjem's
# modules receive as `osConfig`, null when there is none. A
# system-manager evaluation is its system, with the
# configuration and the options in its `passthru`.
machine = selection.nearestOf [
"nixos"
"darwin"
"system-manager"
] manifest;
osConfig = if machine != null then machine.value.config else null;

# A user hjem's NixOS module embeds also imports hjem's
# `modules/nixos/systemd.nix`, which declares the user's
# systemd units and links them into the user's files, with the
# `utils` and the options of the machine. A configuration inside
# a NixOS machine that has `utils` gets the same; the minimal
# NixOS evaluator gives none.
machineArgs = if machine != null then (machine.value._module or { }).args or { } else { };
nixosUser = machine != null && machine.type == "nixos" && machineArgs ? utils;
# a NixOS or system-manager machine that has `utils` gets the
# same; the minimal NixOS evaluator gives none.
machineArgs =
if machine == null then
{ }
else
(machine.value._module or { }).args
or (((machine.value.options or { })._module or { }).args.value or { });
nixosUser =
machine != null
&& builtins.elem machine.type [
"nixos"
"system-manager"
]
&& machineArgs ? utils;

# What hjem's OS modules set on a user that caisson sets too:
# the user's name from the name the configuration is declared
Expand Down
4 changes: 3 additions & 1 deletion lib-overlays/home-manager/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@
};

# The machine the home is declared inside, when there is one:
# the nearest NixOS or darwin configuration above the home, so
# the nearest NixOS, darwin or system-manager configuration
# above the home, so
# a structural configuration between the two changes nothing.
# The manifest holds the childless evaluation of that machine,
# which is the evaluation that leaves out the configurations
Expand Down Expand Up @@ -476,6 +477,7 @@
machineTypes = [
"nixos"
"darwin"
"system-manager"
];

# A home is published as `homeConfigurations.<name>`, the
Expand Down
11 changes: 8 additions & 3 deletions modules/darwin/hjem-activation/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ let
isActivatedHere =
entry:
entry.manifest.type == "hjem"
&& !(builtins.any (segment: segment.type == "nixos" || segment.type == "darwin") (
lib.lists.init entry.path
))
&& !(builtins.any (
segment:
builtins.elem segment.type [
"nixos"
"darwin"
"system-manager"
]
) (lib.lists.init entry.path))
&& entry.manifest.system == evalManifest.system;

users =
Expand Down
9 changes: 8 additions & 1 deletion modules/darwin/home-manager-activation/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ let
above = lib.lists.init entry.path;
in
entry.manifest.type == "home-manager"
&& !(builtins.any (segment: segment.type == "nixos" || segment.type == "darwin") above)
&& !(builtins.any (
segment:
builtins.elem segment.type [
"nixos"
"darwin"
"system-manager"
]
) above)
&& entry.manifest.system == evalManifest.system;

homes = builtins.map (entry: {
Expand Down
37 changes: 22 additions & 15 deletions modules/hjem/nixos-parent/default.nix
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
# SPDX-License-Identifier: MIT
#
# A hjem module for a hjem configuration declared inside a NixOS
# configuration. It sets the home directory of the user from the
# account the machine declares, as hjem's NixOS module does for the
# users it embeds, and refuses a user the machine has no account for.
# A hjem module for a hjem configuration declared inside a NixOS or
# system-manager configuration. It sets the home directory of the user
# from the account the machine declares, as hjem's NixOS module does for
# the users it embeds, and refuses a user the machine has no account
# for.
#
# caisson does not use hjem's NixOS module. A NixOS configuration adds
# this module to the modules that the hjem configurations declared
# inside it import by default; caisson's `default` NixOS module does
# that, through `caisson.forChildren`. A hjem configuration that
# passes `moduleImports` selects its modules itself, and gets this
# caisson does not use hjem's NixOS module. A NixOS or system-manager
# configuration adds this module to the modules that the hjem
# configurations declared inside it import by default; caisson's
# `default` module of either class does that, through
# `caisson.forChildren`. The module is registered as `nixos-parent` and,
# for the same file, as `system-manager-parent`. A hjem configuration
# that passes `moduleImports` selects its modules itself, and gets this
# module only if it lists it.
#
# The module reads the machine through the manifest of the hjem
# configuration, so it can only be imported by a hjem configuration
# that has a NixOS configuration above it.
# that has a NixOS or system-manager configuration above it.
{ ... }:
# `lib` is the library of the hjem configuration, and `config` is its
# configuration.
{ lib, config, ... }:
let
# The configuration of the NixOS configuration the hjem configuration
# is declared inside, in its childless evaluation, which leaves out
# the configurations declared inside it.
machine = lib.caisson.evalManifest.nearest.nixos.value.config;
# The configuration of the machine the hjem configuration is declared
# inside, in its childless evaluation, which leaves out the
# configurations declared inside it.
machine =
(lib.caisson.integrations.nearestOf [
"nixos"
"system-manager"
] lib.caisson.evalManifest).value.config;

# The account of the user, when the machine declares one.
account = (machine.users.users or { }).${config.user} or null;
Expand All @@ -34,7 +41,7 @@ in
assertions = [
{
assertion = config.enable -> account != null && (account.enable or true);
message = "The hjem user `${config.user}` has no enabled account in `users.users` of the NixOS configuration it is declared inside.";
message = "The hjem user `${config.user}` has no enabled account in `users.users` of the machine it is declared inside.";
}
];
}
Expand Down
1 change: 1 addition & 0 deletions modules/hjem/system-manager-parent
24 changes: 15 additions & 9 deletions modules/homeManager/nixos-parent/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,28 @@
# homes declared inside it import by default. caisson's `default`
# NixOS module does that, through `caisson.forChildren`. A home that
# passes `moduleImports` selects its modules itself, and gets this
# module only if it lists it.
# module only if it lists it. A system-manager configuration does the
# same with this file, registered also as `system-manager-parent`.
#
# The module reads the machine through the manifest of the home, so it
# can only be imported by a home that has a NixOS configuration above
# it.
# can only be imported by a home that has a NixOS or system-manager
# configuration above it.
{ ... }:
# `lib` is the library of the home, and `config` is the configuration
# of the home.
{ lib, config, ... }:
let
# The configuration of the NixOS configuration the home is declared
# inside. The home reads the childless evaluation of the NixOS
# configuration, which is the evaluation that leaves out the
# configurations declared inside it. The home is one of those
# configurations, so it cannot read an evaluation that includes it.
machine = lib.caisson.evalManifest.nearest.nixos.value.config;
# The configuration of the machine the home is declared inside, the
# nearest NixOS or system-manager configuration above it. The home
# reads the childless evaluation of the machine, which is the
# evaluation that leaves out the configurations declared inside it.
# The home is one of those configurations, so it cannot read an
# evaluation that includes it.
machine =
(lib.caisson.integrations.nearestOf [
"nixos"
"system-manager"
] lib.caisson.evalManifest).value.config;

# The account of the user of the home, when the NixOS configuration
# declares one in `users.users`. It is null when the NixOS
Expand Down
1 change: 1 addition & 0 deletions modules/homeManager/system-manager-parent
51 changes: 39 additions & 12 deletions modules/nixos/hjem-activation/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
# The module reads the hjem configurations from the full evaluation of
# the NixOS configuration; in the childless evaluation, and in an
# evaluation without systemd options, it defines nothing.
#
# The same module is registered for the `systemManager` class, under
# the same name, and a system-manager machine activates the hjem
# configurations declared inside it the same way. system-manager has no
# `system.extraDependencies`, so there the module keeps no extra
# dependencies in the system. The module reads
# `config.caisson.exports.configurations`, which the core module
# declares; it imports the core module of the class of the evaluation,
# read from its manifest.
{ closure-lib, ... }:
{
config,
Expand All @@ -52,17 +61,33 @@ let

# True when this evaluation declares the options the module defines.
hasUnits =
options ? systemd
&& options.systemd ? services
&& options.systemd ? targets
&& options ? users
&& options ? system
&& options.system ? extraDependencies;
options ? systemd && options.systemd ? services && options.systemd ? targets && options ? users;

# True when the evaluation keeps extra dependencies in the system.
hasExtraDependencies = options ? system && options.system ? extraDependencies;

# The core module of the class of this evaluation: of the
# `systemManager` class in a system-manager evaluation, else of the
# `nixos` class. The registered core modules of the two classes are
# one file under two names, so a module imports the one its
# evaluation already holds.
coreModule =
if (lib.caisson-core.evalManifest.type or null) == "system-manager" then
closure-lib.caisson.modules.systemManager.core
else
closure-lib.caisson.modules.nixos.core;

# The integrations whose configurations are machines.
machineTypes = [
"nixos"
"darwin"
"system-manager"
];

isActivatedHere =
entry:
entry.manifest.type == "hjem"
&& !(builtins.any (segment: segment.type == "nixos") (lib.lists.init entry.path))
&& !(builtins.any (segment: builtins.elem segment.type machineTypes) (lib.lists.init entry.path))
&& entry.manifest.system == evalManifest.system;

# What the units need of each enabled hjem configuration.
Expand Down Expand Up @@ -119,9 +144,9 @@ let
);
in
{
# The module reads `config.caisson.exports.configurations`. The core
# module declares that option.
imports = [ closure-lib.caisson.modules.nixos.core ];
# The core module of the class of this evaluation, which declares
# `config.caisson.exports.configurations`.
imports = [ coreModule ];

# `optionalAttrs` and not `mkIf` decides whether the options are
# defined at all: NixOS refuses a definition, even under `mkIf false`,
Expand All @@ -131,7 +156,7 @@ in
assertions = [
{
assertion = repeated == [ ];
message = "caisson: this NixOS configuration activates more than one hjem configuration for ${lib.concatStringsSep ", " repeated}.";
message = "caisson: this machine activates more than one hjem configuration for ${lib.concatStringsSep ", " repeated}.";
}
];

Expand All @@ -142,7 +167,9 @@ in
}) users
);

system.extraDependencies = builtins.concatMap (user: user.extraDependencies) users;
system = lib.optionalAttrs hasExtraDependencies {
extraDependencies = builtins.concatMap (user: user.extraDependencies) users;
};

systemd.targets.hjem = {
description = "hjem file management";
Expand Down
Loading
Loading