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;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ in
|
|||
text = ''
|
||||
[Service]
|
||||
ExecStart=
|
||||
ExecStart=${lib.getExe' pkgs.gotosocial "gotosocial"} --config-path ${configFile} start
|
||||
ExecStart=${lib.getExe' pkgs.gotosocial "gotosocial"} --config-path ${configFile} server start
|
||||
'';
|
||||
passthru = { inherit configFile; };
|
||||
};
|
||||
|
|
|
|||
|
|
@ -18,6 +18,19 @@ in lib.fix (self: {
|
|||
/** Either a list of strings, or a dotted string that will be split. */
|
||||
convenientAttrPath = t.coercedTo t.str (lib.splitString ".") (t.listOf t.str);
|
||||
|
||||
executablePathInStore = lib.mkOptionType {
|
||||
name = "exepath";
|
||||
description = "executable path in the Nix store";
|
||||
descriptionClass = "noun";
|
||||
merge = lib.mergeEqualOption;
|
||||
functor = lib.defaultFunctor "exepath";
|
||||
check = x: if lib.isDerivation x then (
|
||||
x.meta.mainProgram or null != null
|
||||
) else (
|
||||
lib.pathInStore.check x
|
||||
);
|
||||
};
|
||||
|
||||
concatFoldl = f: list: lib.foldl' (acc: value: acc ++ (f value)) [ ] list;
|
||||
recUpdateFoldl = f: list: lib.foldl' (acc: value: lib.recursiveUpdate acc (f value)) { } list;
|
||||
recUpdateFoldlAttrs = f: attrs: lib.foldlAttrs (acc: name: value: lib.recursiveUpdate acc (f name value)) { } attrs;
|
||||
|
|
|
|||
|
|
@ -14,32 +14,15 @@ let
|
|||
mkEnableOption
|
||||
literalExpression
|
||||
;
|
||||
inherit (lib.types)
|
||||
mkOptionType
|
||||
;
|
||||
t = lib.types;
|
||||
|
||||
inherit (import ./lib.nix { inherit lib; })
|
||||
convenientAttrPath
|
||||
executablePathInStore
|
||||
recUpdateFoldl
|
||||
;
|
||||
|
||||
pkgs = host.pkgs;
|
||||
|
||||
/** Either a list of strings, or a dotted string that will be split. */
|
||||
convenientAttrPath = t.coercedTo t.str (lib.splitString ".") (t.listOf t.str);
|
||||
|
||||
executablePathInStore = mkOptionType {
|
||||
name = "exepath";
|
||||
description = "executable path in the Nix store";
|
||||
descriptionClass = "noun";
|
||||
merge = lib.mergeEqualOption;
|
||||
functor = lib.defaultFunctor "exepath";
|
||||
check = x: if lib.isDerivation x then (
|
||||
x.meta.mainProgram or null != null
|
||||
) else (
|
||||
lib.pathInStore.check x
|
||||
);
|
||||
};
|
||||
in
|
||||
{
|
||||
options = {
|
||||
|
|
@ -74,8 +57,9 @@ in
|
|||
};
|
||||
|
||||
configFile = mkOption {
|
||||
type = t.pathInStore;
|
||||
type = t.nullOr t.pathInStore;
|
||||
internal = true;
|
||||
default = null;
|
||||
};
|
||||
|
||||
unitDropins = mkOption {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue