IT WORKS
This commit is contained in:
parent
da509d97c7
commit
3765e918d6
18 changed files with 348 additions and 226 deletions
|
|
@ -11,7 +11,6 @@ let
|
|||
|
||||
inherit (import ./lib.nix { inherit lib; })
|
||||
typeCheck
|
||||
convenientAttrPath
|
||||
concatFoldl
|
||||
recUpdateFoldl
|
||||
recUpdateFoldlAttrs
|
||||
|
|
@ -64,6 +63,13 @@ in
|
|||
default = { };
|
||||
};
|
||||
|
||||
finalEnabledSubmodules = mkOption {
|
||||
type = options.dynamicism.for.type;
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default = lib.filterAttrs (lib.const (lib.getAttr "enable")) config.dynamicism.for;
|
||||
};
|
||||
|
||||
finalSettings = mkOption {
|
||||
type = t.attrsOf t.raw;
|
||||
internal = true;
|
||||
|
|
@ -78,14 +84,6 @@ in
|
|||
type = t.functionTo t.raw;
|
||||
readOnly = true;
|
||||
};
|
||||
|
||||
doChange = mkOption {
|
||||
type = t.functionTo t.pathInStore;
|
||||
readOnly = true;
|
||||
description = ''
|
||||
The function to call to Do The Thing.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
# Assertions.
|
||||
|
|
@ -94,27 +92,49 @@ in
|
|||
#
|
||||
# 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
|
||||
|
||||
config.system.activationScripts = config.dynamicism.for
|
||||
|> lib.filterAttrs (lib.const (lib.getAttr "enable"))
|
||||
|> lib.mapAttrs' (name: submod: let
|
||||
forUnit = unitName: assert lib.isString unitName; let
|
||||
dropinDir = "/run/systemd/system/${unitName}.d";
|
||||
systemctl = lib.getExe' pkgs.systemd "systemctl";
|
||||
in ''
|
||||
if [[ -d "${dropinDir}" ]]; then
|
||||
echo "Removing files in "${dropinDir}" >&2
|
||||
|
||||
rm -rvf "${dropinDir}/"*
|
||||
rmdir "${dropinDir}"
|
||||
|
||||
${systemctl} daemon-reload
|
||||
${systemctl} try-reload-or-restart "${unitName}"
|
||||
fi
|
||||
'';
|
||||
};
|
||||
|
||||
in {
|
||||
name = "dynix-reset-dynamicism-for-${name}";
|
||||
value.deps = [ "etc" "stdio" "specialfs" "binsh" "usrbinenv" "var" "udevd" ];
|
||||
value.text = ''
|
||||
echo "Removing existing dynamic overrides for ${name}" >&2
|
||||
${submod.systemd-services-updated |> lib.map forUnit |> lib.concatStringsSep "\n"}
|
||||
'';
|
||||
});
|
||||
|
||||
config.dynamicism = {
|
||||
|
||||
applyDynamicConfiguration = {
|
||||
baseConfiguration ? builtins.getEnv "NIXOS_CONFIG",
|
||||
newConfiguration ? baseConfiguration + "/dynamic.nix",
|
||||
newConfiguration ? (lib.filesystem.dirOf baseConfiguration) + "/dynamic.nix",
|
||||
}: let
|
||||
locFor = appendage: lib.concatLists [
|
||||
opts.applyDynamicConfiguration.loc
|
||||
[ "(function argument)" ]
|
||||
(lib.toList appendage)
|
||||
];
|
||||
in
|
||||
assert seqTrue (typeCheck (locFor "baseConfiguration") t.deferredModule baseConfiguration);
|
||||
assert seqTrue (typeCheck (locFor "newConfiguration") t.deferredModule newConfiguration);
|
||||
let
|
||||
|
||||
_file = "«inline module in ${showOption opts.applyDynamicConfiguration.loc}»";
|
||||
|
||||
|
|
@ -132,49 +152,25 @@ in
|
|||
};
|
||||
};
|
||||
|
||||
submodulesChanged = lib.filter (submodName:
|
||||
submodulesChanged = nixosAfter.config.dynamicism.finalEnabledSubmodules
|
||||
|> lib.filterAttrs (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,
|
||||
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
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
runAllActivationScripts = nixosAfter.config.dynamicism.for
|
||||
|> lib.filterAttrs (lib.const (lib.getAttr "enable"))
|
||||
|> lib.mapAttrsToList (name: submod: ''
|
||||
runForSubmodCalled = name: ''
|
||||
echo "Activating dynamic configuration for ${name}"
|
||||
${lib.getExe submod.activate}
|
||||
'')
|
||||
${lib.getExe nixosAfter.config.dynamicism.for.${name}.activate}
|
||||
'';
|
||||
|
||||
runForChanged = submodulesChanged
|
||||
|> lib.mapAttrsToList (name: _: runForSubmodCalled name)
|
||||
|> lib.concatStringsSep "\n";
|
||||
|
||||
in pkgs.writeShellApplication {
|
||||
name = "dynamicism-activate";
|
||||
text = runAllActivationScripts;
|
||||
text = runForChanged;
|
||||
passthru.configuration = nixosAfter;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue