make dynamicism/default.nix a stub for dynamicism.nix
This commit is contained in:
parent
d7a0cbefe5
commit
15641360ca
3 changed files with 147 additions and 144 deletions
|
|
@ -1,145 +1,5 @@
|
||||||
{ 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;
|
|
||||||
|
|
||||||
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
|
|
||||||
{
|
{
|
||||||
#
|
imports = [ ./dynamicism.nix ];
|
||||||
# Interface.
|
|
||||||
#
|
|
||||||
options.dynamicism = {
|
|
||||||
for = mkOption {
|
|
||||||
type = t.attrsOf (t.submoduleWith {
|
|
||||||
modules = [ ./submodule.nix ];
|
|
||||||
shorthandOnlyDefinesConfig = false;
|
|
||||||
specialArgs = { inherit pkgs; };
|
|
||||||
});
|
|
||||||
default = { };
|
|
||||||
};
|
|
||||||
|
|
||||||
finalSettings = mkOption {
|
|
||||||
type = t.attrsOf t.raw;
|
|
||||||
internal = true;
|
|
||||||
readOnly = true;
|
|
||||||
description = ''
|
|
||||||
Attrset of each `source-options` tree to their actual values.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
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 = {
|
|
||||||
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
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
allActivations = config.dynamicism.for
|
|
||||||
|> lib.filterAttrs (name: submod: submod.enable)
|
|
||||||
|> lib.mapAttrsToList (name: submod: submod.activate);
|
|
||||||
allActivationScripts = pkgs.writeShellApplication {
|
|
||||||
name = "dynamicism-activate";
|
|
||||||
runtimeInputs = allActivations;
|
|
||||||
text = nixosAfter.config.dynamicism.for
|
|
||||||
|> lib.filterAttrs (name: submod: submod.enable)
|
|
||||||
|> lib.mapAttrsToList (name: submod: ''
|
|
||||||
echo "Activating dynamicism for ${name}"
|
|
||||||
${lib.getExe submod.activate}
|
|
||||||
'')
|
|
||||||
|> lib.concatStringsSep "\n";
|
|
||||||
};
|
|
||||||
in allActivationScripts;
|
|
||||||
|
|
||||||
finalSettings = config.dynamicism.for
|
|
||||||
|> recUpdateFoldlAttrs (name: { ... }@submod: finalSettingsFor submod)
|
|
||||||
|> checkAssertWarn ourAssertions [ ];
|
|
||||||
};
|
|
||||||
|
|
||||||
# Implementations.
|
|
||||||
imports = [
|
|
||||||
./gotosocial.nix
|
|
||||||
./harmonia.nix
|
|
||||||
#./tzupdate.nix
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
145
modules/dynamicism/dynamicism.nix
Normal file
145
modules/dynamicism/dynamicism.nix
Normal file
|
|
@ -0,0 +1,145 @@
|
||||||
|
{ 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;
|
||||||
|
|
||||||
|
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;
|
||||||
|
specialArgs = { inherit pkgs; };
|
||||||
|
});
|
||||||
|
default = { };
|
||||||
|
};
|
||||||
|
|
||||||
|
finalSettings = mkOption {
|
||||||
|
type = t.attrsOf t.raw;
|
||||||
|
internal = true;
|
||||||
|
readOnly = true;
|
||||||
|
description = ''
|
||||||
|
Attrset of each `source-options` tree to their actual values.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
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 = {
|
||||||
|
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
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
allActivations = config.dynamicism.for
|
||||||
|
|> lib.filterAttrs (name: submod: submod.enable)
|
||||||
|
|> lib.mapAttrsToList (name: submod: submod.activate);
|
||||||
|
allActivationScripts = pkgs.writeShellApplication {
|
||||||
|
name = "dynamicism-activate";
|
||||||
|
runtimeInputs = allActivations;
|
||||||
|
text = nixosAfter.config.dynamicism.for
|
||||||
|
|> lib.filterAttrs (name: submod: submod.enable)
|
||||||
|
|> lib.mapAttrsToList (name: submod: ''
|
||||||
|
echo "Activating dynamicism for ${name}"
|
||||||
|
${lib.getExe submod.activate}
|
||||||
|
'')
|
||||||
|
|> lib.concatStringsSep "\n";
|
||||||
|
};
|
||||||
|
in allActivationScripts;
|
||||||
|
|
||||||
|
finalSettings = config.dynamicism.for
|
||||||
|
|> recUpdateFoldlAttrs (name: { ... }@submod: finalSettingsFor submod)
|
||||||
|
|> checkAssertWarn ourAssertions [ ];
|
||||||
|
};
|
||||||
|
|
||||||
|
# Implementations.
|
||||||
|
imports = [
|
||||||
|
./gotosocial.nix
|
||||||
|
./harmonia.nix
|
||||||
|
#./tzupdate.nix
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
{ pkgs, lib, config, ... }:
|
{ pkgs, lib, config, ... }:
|
||||||
let
|
let
|
||||||
cfg = config.dynamicism.for.gotosocial;
|
|
||||||
|
|
||||||
settingsFormat = pkgs.formats.yaml { };
|
settingsFormat = pkgs.formats.yaml { };
|
||||||
configFile = settingsFormat.generate "gotosocial-override.yml" config.services.gotosocial.settings;
|
configFile = settingsFormat.generate "gotosocial-override.yml" config.services.gotosocial.settings;
|
||||||
in
|
in
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue