move nixlang impls to their own directory tree
This commit is contained in:
parent
a06790a2af
commit
fe8d00b2c2
9 changed files with 136 additions and 75 deletions
21
modules/dynamic-overrides.nix
Normal file
21
modules/dynamic-overrides.nix
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# Managed by dynix.
|
||||
{ lib, ... }:
|
||||
|
||||
lib.mkMerge [
|
||||
{
|
||||
services.gotosocial = {
|
||||
enable = true;
|
||||
setupPostgresqlDB = true;
|
||||
settings = {
|
||||
application-name = "example!";
|
||||
host = "yuki.local";
|
||||
};
|
||||
};
|
||||
}
|
||||
{
|
||||
services.gotosocial.settings.application-name = lib.mkOverride 99 "removed herobrine";
|
||||
}
|
||||
{
|
||||
services.gotosocial.settings.application-name = lib.mkOverride 98 "reädded herobrine";
|
||||
}
|
||||
]
|
||||
73
modules/dynamicism/default.nix
Normal file
73
modules/dynamicism/default.nix
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
{ pkgs, lib, config, options, ... }:
|
||||
let
|
||||
inherit (lib.modules)
|
||||
mkIf
|
||||
;
|
||||
inherit (lib.options)
|
||||
mkOption
|
||||
mkEnableOption
|
||||
literalExpression
|
||||
showOption
|
||||
;
|
||||
t = lib.types;
|
||||
cfg = config.dynamicism;
|
||||
|
||||
settingsFormat = pkgs.formats.yaml { };
|
||||
|
||||
assertionFor = submodName: unitName: let
|
||||
optName = [ "dynamicism" "for" submodName "systemd-services-updated" ];
|
||||
in {
|
||||
assertion = config.systemd.units.${unitName}.enable or false;
|
||||
message = "'${showOption optName}' specified non-existentant unit '${unitName}'";
|
||||
};
|
||||
|
||||
assertionsFor =
|
||||
submodName:
|
||||
submod:
|
||||
lib.map (assertionFor submodName) submod.systemd-services-updated;
|
||||
|
||||
finalSettingsFor = { ... }@submod: lib.foldl (acc: optPath: let
|
||||
next =
|
||||
assert lib.isList optPath;
|
||||
lib.setAttrByPath optPath (lib.getAttrFromPath optPath config);
|
||||
in lib.recursiveUpdate acc next) { } submod.source-options;
|
||||
in
|
||||
{
|
||||
options.dynamicism = {
|
||||
for = mkOption {
|
||||
type = t.attrsOf (t.submoduleWith {
|
||||
modules = [ ./submodule.nix ];
|
||||
shorthandOnlyDefinesConfig = false;
|
||||
});
|
||||
default = { };
|
||||
};
|
||||
|
||||
finalSettings = mkOption {
|
||||
type = t.attrsOf t.raw;
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
description = ''
|
||||
Attrset of each `source-options` tree to their actual values.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config.assertions = lib.foldlAttrs (acc: name: submod: let
|
||||
next = lib.optionals submod.enable (assertionsFor name submod);
|
||||
in acc ++ next) [ ] cfg.for;
|
||||
|
||||
config.dynamicism.for = {
|
||||
gotosocial = {
|
||||
source-options = [
|
||||
"services.gotosocial.settings"
|
||||
];
|
||||
systemd-services-updated = [
|
||||
"gotosocial.service"
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
config.dynamicism.finalSettings = lib.foldlAttrs (acc: name: { ... }@submod: let
|
||||
next = finalSettingsFor submod;
|
||||
in lib.recursiveUpdate acc next) { } config.dynamicism.for;
|
||||
}
|
||||
47
modules/dynamicism/submodule.nix
Normal file
47
modules/dynamicism/submodule.nix
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
{
|
||||
name,
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
let
|
||||
inherit (lib.modules)
|
||||
mkIf
|
||||
;
|
||||
inherit (lib.options)
|
||||
mkOption
|
||||
mkEnableOption
|
||||
literalExpression
|
||||
;
|
||||
t = lib.types;
|
||||
|
||||
/** Either a list of strings, or a dotted string that will be split. */
|
||||
convenientAttrPath = t.coercedTo t.str (lib.splitString ".") (t.listOf t.str);
|
||||
in
|
||||
{
|
||||
options = {
|
||||
enable = mkEnableOption "Enable dynamicism for '${name}'";
|
||||
|
||||
source-options = mkOption {
|
||||
type = t.listOf convenientAttrPath;
|
||||
description = "A list of attrpaths of the NixOS option the dynamicism for '${name}' uses";
|
||||
example = literalExpression ''
|
||||
[ [ "services" "gotosocial" "settings" ] "services.nginx.settings" ]
|
||||
'';
|
||||
};
|
||||
|
||||
systemd-services-updated = mkOption {
|
||||
type = t.listOf t.str;
|
||||
description = ''
|
||||
A list of systemd unit names (including the suffix, e.g. `.service`) that need to be updated.
|
||||
'';
|
||||
example = literalExpression ''
|
||||
"gotosocial.service"
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf config.enable {
|
||||
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue