working on harmonia
This commit is contained in:
parent
1f466b63d3
commit
8dba8e7ce8
20 changed files with 556 additions and 90 deletions
|
|
@ -4,6 +4,9 @@ let
|
|||
mkOption
|
||||
showOption
|
||||
;
|
||||
inherit (lib.asserts)
|
||||
checkAssertWarn
|
||||
;
|
||||
t = lib.types;
|
||||
|
||||
inherit (import ./lib.nix { inherit lib; })
|
||||
|
|
@ -19,7 +22,6 @@ let
|
|||
opts = options.dynamicism;
|
||||
|
||||
subOpts = lib.mapAttrs (_: metaAttr: metaAttr.configuration.options) options.dynamicism.for.valueMeta.attrs;
|
||||
settingsFormat = pkgs.formats.yaml { };
|
||||
|
||||
finalSettingsFor = { ... }@submod: recUpdateFoldl (optPath:
|
||||
lib.setAttrByPath optPath (lib.getAttrFromPath optPath config)
|
||||
|
|
@ -82,45 +84,62 @@ in
|
|||
#
|
||||
# Generic implementation.
|
||||
#
|
||||
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))
|
||||
];
|
||||
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
|
||||
];
|
||||
environment.systemPackages = [
|
||||
config.dynamicism.for.gotosocial.activate
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
allActivations = lib.mapAttrsToList (name: submod: submod.activate) config.dynamicism.for;
|
||||
allActivationScripts = pkgs.writeShellApplication {
|
||||
name = "dynamicism-activate";
|
||||
runtimeInputs = allActivations;
|
||||
text = nixosAfter.config.dynamicism.for
|
||||
|> lib.mapAttrsToList (name: submod: ''
|
||||
echo "Activating dynamicism for ${name}"
|
||||
${lib.getExe submod.activate}
|
||||
'')
|
||||
|> lib.concatStringsSep "\n";
|
||||
};
|
||||
in allActivationScripts;
|
||||
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;
|
||||
|
||||
config.dynamicism.finalSettings = lib.asserts.checkAssertWarn ourAssertions [ ] (
|
||||
recUpdateFoldlAttrs (name: { ... }@submod: finalSettingsFor submod) config.dynamicism.for
|
||||
);
|
||||
finalSettings = config.dynamicism.for
|
||||
|> recUpdateFoldlAttrs (name: { ... }@submod: finalSettingsFor submod)
|
||||
|> checkAssertWarn ourAssertions [ ];
|
||||
};
|
||||
|
||||
# Implementations.
|
||||
imports = [
|
||||
./gotosocial.nix
|
||||
./harmonia.nix
|
||||
#./tzupdate.nix
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,17 +3,20 @@ let
|
|||
cfg = config.dynamicism.for.gotosocial;
|
||||
|
||||
settingsFormat = pkgs.formats.yaml { };
|
||||
configFile = settingsFormat.generate "gotosocial-override.yml" config.services.gotosocial.settings;
|
||||
in
|
||||
{
|
||||
dynamicism.for.gotosocial = {
|
||||
source-options = [ "services.gotosocial.settings" ];
|
||||
|
||||
configFile = settingsFormat.generate "gotosocial-overrde.yml" config.services.gotosocial.settings;
|
||||
|
||||
unitDropins."gotosocial.service" = pkgs.writeText "gotosocial-override.conf" ''
|
||||
[Service]
|
||||
ExecStart=
|
||||
ExecStart=${lib.getExe' pkgs.gotosocial "gotosocial"} --config-path ${cfg.configFile} start
|
||||
'';
|
||||
unitDropins."gotosocial.service" = pkgs.writeTextFile {
|
||||
name = "gotosocial-override.conf";
|
||||
text = ''
|
||||
[Service]
|
||||
ExecStart=
|
||||
ExecStart=${lib.getExe' pkgs.gotosocial "gotosocial"} --config-path ${configFile} start
|
||||
'';
|
||||
passthru = { inherit configFile; };
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
26
modules/dynamicism/harmonia.nix
Normal file
26
modules/dynamicism/harmonia.nix
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
{ pkgs, lib, config, ... }:
|
||||
let
|
||||
cfg = config.dynamicism.for.harmonia;
|
||||
settingsFormat = pkgs.formats.toml { };
|
||||
|
||||
# FIXME: referring to config.dynamicism.finalSettings.* in here
|
||||
# makes lib.checkAssertWarn in the generic module cause infinite recursion.
|
||||
finalSettings = config.services.harmonia.settings;
|
||||
|
||||
configFile = settingsFormat.generate "harmonia-override.toml" finalSettings;
|
||||
in
|
||||
{
|
||||
dynamicism.for.harmonia = {
|
||||
source-options = [ "services.harmonia.settings" ];
|
||||
|
||||
unitDropins."harmonia.service" = pkgs.writeTextFile {
|
||||
name = "harmonia-override.conf";
|
||||
text = ''
|
||||
[Service]
|
||||
Environment=CONFIG_FILE=${configFile}
|
||||
'';
|
||||
|
||||
passthru = { inherit configFile; };
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -65,7 +65,7 @@ in
|
|||
};
|
||||
|
||||
unitDropins = mkOption {
|
||||
type = t.attrsOf t.pathInStore;
|
||||
type = t.attrsOf t.package;
|
||||
internal = true;
|
||||
};
|
||||
|
||||
|
|
@ -82,7 +82,7 @@ in
|
|||
text = let
|
||||
doEdits = config.unitDropins
|
||||
|> lib.mapAttrsToList (service: dropin: ''
|
||||
cat "${dropin}" | systemctl edit "${service}" --runtime --stdin
|
||||
cat "${dropin}" | systemctl edit "${service}" --runtime --drop=dynix-${dropin.name} --stdin
|
||||
'');
|
||||
doReloads = config.unitDropins
|
||||
|> lib.mapAttrsToList (service: _: ''
|
||||
|
|
|
|||
20
modules/dynamicism/tzupdate.nix
Normal file
20
modules/dynamicism/tzupdate.nix
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{ pkgs, lib, config, ... }: let
|
||||
cfg = config.dynamicism.for.tzupdate;
|
||||
|
||||
|
||||
# FIXME: referring to config.dynamicism.finalSettings.* in here
|
||||
# makes lib.checkAssertWarn in the generic module cause infinite recursion.
|
||||
#finalSettings = config.dynamicism.finalSettings.tzupdate;
|
||||
finalSettings = config.services.tzupdate.timer;
|
||||
in
|
||||
{
|
||||
dynamicism.for.tzupdate = {
|
||||
source-options = [ "services.tzupdate.timer" ];
|
||||
|
||||
unitDropins."tzupdate.timer" = pkgs.writeText "tzupdate-timer-override.conf" ''
|
||||
[Timer]
|
||||
OnCalendar=
|
||||
OnCalendar=${finalSettings.interval}
|
||||
'';
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue