start new dynamic apply function

This commit is contained in:
Qyriad 2026-02-16 18:02:39 +01:00
parent 3ed2f2e1a8
commit 76b5ac628d
3 changed files with 68 additions and 5 deletions

View file

@ -23,6 +23,8 @@ let
subOpts = lib.mapAttrs (_: metaAttr: metaAttr.configuration.options) options.dynamicism.for.valueMeta.attrs;
seqTrue = v: lib.seq v true;
finalSettingsFor = { ... }@submod: recUpdateFoldl (optPath:
lib.setAttrByPath optPath (lib.getAttrFromPath optPath config)
) submod.source-options;
@ -55,7 +57,9 @@ in
type = t.attrsOf (t.submoduleWith {
modules = [ ./submodule.nix ];
shorthandOnlyDefinesConfig = false;
specialArgs = { inherit pkgs; };
specialArgs = {
host = { inherit pkgs options config; };
};
});
default = { };
};
@ -69,6 +73,12 @@ in
'';
};
applyDynamicConfiguration = mkOption {
#type = t.functionTo t.pathInStore;
type = t.functionTo t.raw;
readOnly = true;
};
doChange = mkOption {
type = t.functionTo t.pathInStore;
readOnly = true;
@ -95,6 +105,45 @@ in
'';
};
config.dynamicism = {
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;
};
doChange = {
option,
value,