2026-02-11 13:19:59 +01:00
|
|
|
{ pkgs, lib, config, options, ... }:
|
|
|
|
|
let
|
|
|
|
|
inherit (lib.options)
|
|
|
|
|
mkOption
|
|
|
|
|
showOption
|
|
|
|
|
;
|
|
|
|
|
inherit (lib.asserts)
|
|
|
|
|
checkAssertWarn
|
|
|
|
|
;
|
|
|
|
|
t = lib.types;
|
|
|
|
|
|
|
|
|
|
inherit (import ./lib.nix { inherit lib; })
|
|
|
|
|
typeCheck
|
|
|
|
|
convenientAttrPath
|
|
|
|
|
concatFoldl
|
|
|
|
|
recUpdateFoldl
|
|
|
|
|
recUpdateFoldlAttrs
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
evalNixos = import (pkgs.path + "/nixos");
|
|
|
|
|
|
|
|
|
|
opts = options.dynamicism;
|
|
|
|
|
|
|
|
|
|
subOpts = lib.mapAttrs (_: metaAttr: metaAttr.configuration.options) options.dynamicism.for.valueMeta.attrs;
|
|
|
|
|
|
2026-02-16 18:02:39 +01:00
|
|
|
seqTrue = v: lib.seq v true;
|
|
|
|
|
|
2026-02-11 13:19:59 +01:00
|
|
|
finalSettingsFor = { ... }@submod: recUpdateFoldl (optPath:
|
|
|
|
|
lib.setAttrByPath optPath (lib.getAttrFromPath optPath config)
|
|
|
|
|
) submod.source-options;
|
|
|
|
|
|
|
|
|
|
ourAssertions = lib.concatAttrValues {
|
|
|
|
|
unitsExist = subOpts
|
|
|
|
|
|> lib.attrValues
|
|
|
|
|
|> concatFoldl (submod: submod.systemd-services-updated.value
|
|
|
|
|
|> lib.map (unit: {
|
|
|
|
|
assertion = config.systemd.units.${unit}.enable or false;
|
|
|
|
|
message = ''
|
|
|
|
|
${showOption submod.systemd-services-updated.loc}' specified non-existent unit '${unit}'
|
|
|
|
|
'';
|
|
|
|
|
})
|
|
|
|
|
|> lib.optionals submod.enable.value
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
optsExist = concatFoldl (submod: lib.optionals submod.enable.value (lib.map (optPath: {
|
|
|
|
|
assertion = lib.hasAttrByPath optPath options;
|
|
|
|
|
message = "'${showOption submod.source-options.loc}' specified non-existent option '${showOption optPath}'";
|
|
|
|
|
}) submod.source-options.value)) (lib.attrValues subOpts);
|
|
|
|
|
};
|
|
|
|
|
in
|
|
|
|
|
{
|
|
|
|
|
#
|
|
|
|
|
# Interface.
|
|
|
|
|
#
|
|
|
|
|
options.dynamicism = {
|
|
|
|
|
for = mkOption {
|
|
|
|
|
type = t.attrsOf (t.submoduleWith {
|
|
|
|
|
modules = [ ./submodule.nix ];
|
|
|
|
|
shorthandOnlyDefinesConfig = false;
|
2026-02-16 18:02:39 +01:00
|
|
|
specialArgs = {
|
|
|
|
|
host = { inherit pkgs options config; };
|
|
|
|
|
};
|
2026-02-11 13:19:59 +01:00
|
|
|
});
|
|
|
|
|
default = { };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
finalSettings = mkOption {
|
|
|
|
|
type = t.attrsOf t.raw;
|
|
|
|
|
internal = true;
|
|
|
|
|
readOnly = true;
|
|
|
|
|
description = ''
|
|
|
|
|
Attrset of each `source-options` tree to their actual values.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-16 18:02:39 +01:00
|
|
|
applyDynamicConfiguration = mkOption {
|
|
|
|
|
#type = t.functionTo t.pathInStore;
|
|
|
|
|
type = t.functionTo t.raw;
|
|
|
|
|
readOnly = true;
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-11 13:19:59 +01:00
|
|
|
doChange = mkOption {
|
|
|
|
|
type = t.functionTo t.pathInStore;
|
|
|
|
|
readOnly = true;
|
|
|
|
|
description = ''
|
|
|
|
|
The function to call to Do The Thing.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
# Assertions.
|
|
|
|
|
config.assertions = ourAssertions;
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Generic implementation.
|
|
|
|
|
#
|
|
|
|
|
config.system.activationScripts."dynamicism-reset" = {
|
|
|
|
|
deps = [ "etc" "stdio" "specialfs" ];
|
|
|
|
|
text = ''
|
|
|
|
|
echo "DYNIX: removing existing systemd dropins"
|
|
|
|
|
# FIXME: do for each enabled submodule
|
|
|
|
|
if [[ -d /run/systemd/system ]]; then
|
|
|
|
|
rm -v /run/systemd/system/*/dynix-*.conf || true
|
|
|
|
|
fi
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
config.dynamicism = {
|
2026-02-16 18:02:39 +01:00
|
|
|
|
|
|
|
|
applyDynamicConfiguration = {
|
|
|
|
|
baseConfiguration ? builtins.getEnv "NIXOS_CONFIG",
|
|
|
|
|
newConfiguration ? baseConfiguration + "/dynamic.nix",
|
|
|
|
|
}: let
|
|
|
|
|
locFor = appendage: lib.concatLists [
|
|
|
|
|
opts.applyDynamicConfiguration.loc
|
|
|
|
|
[ "(function argument)" ]
|
|
|
|
|
(lib.toList appendage)
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
_file = "«inline module in ${showOption opts.applyDynamicConfiguration.loc}»";
|
|
|
|
|
|
|
|
|
|
nixosBefore = evalNixos {
|
|
|
|
|
configuration = { ... }: {
|
|
|
|
|
inherit _file;
|
|
|
|
|
imports = [ baseConfiguration ];
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
nixosAfter = evalNixos {
|
|
|
|
|
configuration = { ... }: {
|
|
|
|
|
inherit _file;
|
|
|
|
|
imports = [ baseConfiguration newConfiguration ];
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
submodulesChanged = lib.filter (submodName:
|
|
|
|
|
nixosBefore.config.dynamicism.for.${submodName}.finalSettings
|
|
|
|
|
!=
|
|
|
|
|
nixosAfter.config.dynamicism.for.${submodName}.finalSettings
|
|
|
|
|
) (lib.attrNames config.dynamicism.for);
|
|
|
|
|
in
|
|
|
|
|
assert seqTrue (typeCheck (locFor "baseConfiguration") t.deferredModule baseConfiguration);
|
|
|
|
|
assert seqTrue (typeCheck (locFor "newConfiguration") t.deferredModule newConfiguration);
|
|
|
|
|
{
|
|
|
|
|
inherit submodulesChanged;
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-11 13:19:59 +01:00
|
|
|
doChange = {
|
|
|
|
|
option,
|
|
|
|
|
value,
|
|
|
|
|
configuration ? builtins.getEnv "NIXOS_CONFIG",
|
|
|
|
|
}: let
|
|
|
|
|
loc = opts.doChange.loc ++ [ "(function argument)" "value" ];
|
|
|
|
|
option' = typeCheck loc convenientAttrPath option;
|
|
|
|
|
nixosAfter = evalNixos {
|
|
|
|
|
configuration = { config, ... }: {
|
|
|
|
|
imports = [
|
|
|
|
|
configuration
|
|
|
|
|
(lib.setAttrByPath option' (lib.mkOverride (-999) value))
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
environment.systemPackages = [
|
|
|
|
|
config.dynamicism.for.gotosocial.activate
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-13 20:03:17 +01:00
|
|
|
runAllActivationScripts = nixosAfter.config.dynamicism.for
|
|
|
|
|
|> lib.filterAttrs (lib.const (lib.getAttr "enable"))
|
|
|
|
|
|> lib.mapAttrsToList (name: submod: ''
|
|
|
|
|
echo "Activating dynamic configuration for ${name}"
|
|
|
|
|
${lib.getExe submod.activate}
|
|
|
|
|
'')
|
|
|
|
|
|> lib.concatStringsSep "\n";
|
|
|
|
|
|
|
|
|
|
in pkgs.writeShellApplication {
|
|
|
|
|
name = "dynamicism-activate";
|
|
|
|
|
text = runAllActivationScripts;
|
|
|
|
|
passthru.configuration = nixosAfter;
|
|
|
|
|
};
|
2026-02-11 13:19:59 +01:00
|
|
|
|
|
|
|
|
finalSettings = config.dynamicism.for
|
|
|
|
|
|> recUpdateFoldlAttrs (name: { ... }@submod: finalSettingsFor submod)
|
|
|
|
|
|> checkAssertWarn ourAssertions [ ];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
# Implementations.
|
|
|
|
|
imports = [
|
|
|
|
|
./gotosocial.nix
|
|
|
|
|
./harmonia.nix
|
2026-02-13 21:12:55 +01:00
|
|
|
./distccd.nix
|
2026-02-11 13:19:59 +01:00
|
|
|
];
|
|
|
|
|
}
|