start new dynamic apply function
This commit is contained in:
parent
3ed2f2e1a8
commit
76b5ac628d
3 changed files with 68 additions and 5 deletions
|
|
@ -23,6 +23,8 @@ let
|
||||||
|
|
||||||
subOpts = lib.mapAttrs (_: metaAttr: metaAttr.configuration.options) options.dynamicism.for.valueMeta.attrs;
|
subOpts = lib.mapAttrs (_: metaAttr: metaAttr.configuration.options) options.dynamicism.for.valueMeta.attrs;
|
||||||
|
|
||||||
|
seqTrue = v: lib.seq v true;
|
||||||
|
|
||||||
finalSettingsFor = { ... }@submod: recUpdateFoldl (optPath:
|
finalSettingsFor = { ... }@submod: recUpdateFoldl (optPath:
|
||||||
lib.setAttrByPath optPath (lib.getAttrFromPath optPath config)
|
lib.setAttrByPath optPath (lib.getAttrFromPath optPath config)
|
||||||
) submod.source-options;
|
) submod.source-options;
|
||||||
|
|
@ -55,7 +57,9 @@ in
|
||||||
type = t.attrsOf (t.submoduleWith {
|
type = t.attrsOf (t.submoduleWith {
|
||||||
modules = [ ./submodule.nix ];
|
modules = [ ./submodule.nix ];
|
||||||
shorthandOnlyDefinesConfig = false;
|
shorthandOnlyDefinesConfig = false;
|
||||||
specialArgs = { inherit pkgs; };
|
specialArgs = {
|
||||||
|
host = { inherit pkgs options config; };
|
||||||
|
};
|
||||||
});
|
});
|
||||||
default = { };
|
default = { };
|
||||||
};
|
};
|
||||||
|
|
@ -69,6 +73,12 @@ in
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
applyDynamicConfiguration = mkOption {
|
||||||
|
#type = t.functionTo t.pathInStore;
|
||||||
|
type = t.functionTo t.raw;
|
||||||
|
readOnly = true;
|
||||||
|
};
|
||||||
|
|
||||||
doChange = mkOption {
|
doChange = mkOption {
|
||||||
type = t.functionTo t.pathInStore;
|
type = t.functionTo t.pathInStore;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
|
|
@ -95,6 +105,45 @@ in
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
config.dynamicism = {
|
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 = {
|
doChange = {
|
||||||
option,
|
option,
|
||||||
value,
|
value,
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,12 @@
|
||||||
t = lib.types;
|
t = lib.types;
|
||||||
in lib.fix (self: {
|
in lib.fix (self: {
|
||||||
/** Perform module-system type checking and resolving on a single option value. */
|
/** Perform module-system type checking and resolving on a single option value. */
|
||||||
typeCheck = loc: option: value:
|
typeCheck = loc: optionType: value:
|
||||||
assert lib.isOptionType option;
|
assert lib.isOptionType optionType;
|
||||||
assert lib.isList loc;
|
assert lib.isList loc;
|
||||||
assert lib.all lib.isString loc;
|
assert lib.all lib.isString loc;
|
||||||
let
|
let
|
||||||
merged = lib.modules.mergeDefinitions loc option [ {
|
merged = lib.modules.mergeDefinitions loc optionType [ {
|
||||||
inherit value;
|
inherit value;
|
||||||
file = "«inline»";
|
file = "«inline»";
|
||||||
} ];
|
} ];
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
{
|
{
|
||||||
name,
|
name,
|
||||||
pkgs,
|
|
||||||
lib,
|
lib,
|
||||||
config,
|
config,
|
||||||
|
host,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
|
|
@ -19,6 +19,12 @@ let
|
||||||
;
|
;
|
||||||
t = lib.types;
|
t = lib.types;
|
||||||
|
|
||||||
|
inherit (import ./lib.nix { inherit lib; })
|
||||||
|
recUpdateFoldl
|
||||||
|
;
|
||||||
|
|
||||||
|
pkgs = host.pkgs;
|
||||||
|
|
||||||
/** Either a list of strings, or a dotted string that will be split. */
|
/** Either a list of strings, or a dotted string that will be split. */
|
||||||
convenientAttrPath = t.coercedTo t.str (lib.splitString ".") (t.listOf t.str);
|
convenientAttrPath = t.coercedTo t.str (lib.splitString ".") (t.listOf t.str);
|
||||||
|
|
||||||
|
|
@ -59,6 +65,14 @@ in
|
||||||
default = lib.attrNames config.unitDropins;
|
default = lib.attrNames config.unitDropins;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
finalSettings = mkOption {
|
||||||
|
type = t.attrsOf t.raw;
|
||||||
|
internal = true;
|
||||||
|
default = recUpdateFoldl (optPath:
|
||||||
|
lib.setAttrByPath optPath (lib.getAttrFromPath optPath host.config)
|
||||||
|
) config.source-options;
|
||||||
|
};
|
||||||
|
|
||||||
configFile = mkOption {
|
configFile = mkOption {
|
||||||
type = t.pathInStore;
|
type = t.pathInStore;
|
||||||
internal = true;
|
internal = true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue