nixos/tsm-client: add migration code for freeform settings

To help users migrate from the previous
settings to new freeform settings type,
the commit at hand adds some
`mkRemovedOptionModule` and `mkRenamedOptionModule`.

These modules are not designed to work
inside an attribute set of submodules.
They create values for `assertions` and
`warnings` to inform the user of required changes.
Also, these informational texts do not contain
the full attribute path of the changed options.
To work around these deficiencies,
we define the required options `assertions` and `warnings`
inside the submodule and later add the values collected
inside these options to the corresponding top-level options.
In the course of doing so, we also add the full attribute path
to the informational texts so the user knows these warning
and error messages refer to the `tsmClient.servers` option.

Also, we have to filter out `warnings`, `assertions`, and
the "old" options when rendering the target config file.
This commit is contained in:
Yarny0 2023-08-23 21:29:29 +02:00
parent 98c03bf8c6
commit 20a9a21b24

View file

@ -1,4 +1,5 @@
{ config, lib, pkgs, ... }:
{ config, lib, options, pkgs, ... }: # XXX migration code for freeform settings: `options` can be removed in 2025
let optionsGlobal = options; in
let
@ -95,6 +96,19 @@ let
};
config.commmethod = mkDefault "v6tcpip"; # uses v4 or v6, based on dns lookup result
config.passwordaccess = if config.genPasswd then "generate" else "prompt";
# XXX migration code for freeform settings, these can be removed in 2025:
options.warnings = optionsGlobal.warnings;
options.assertions = optionsGlobal.assertions;
imports = let inherit (lib.modules) mkRemovedOptionModule mkRenamedOptionModule; in [
(mkRemovedOptionModule [ "extraConfig" ] "Please just add options directly to the server attribute set, cf. the description of `programs.tsmClient.servers`.")
(mkRemovedOptionModule [ "text" ] "Please just add options directly to the server attribute set, cf. the description of `programs.tsmClient.servers`.")
(mkRenamedOptionModule [ "name" ] [ "servername" ])
(mkRenamedOptionModule [ "server" ] [ "tcpserveraddress" ])
(mkRenamedOptionModule [ "port" ] [ "tcpport" ])
(mkRenamedOptionModule [ "node" ] [ "nodename" ])
(mkRenamedOptionModule [ "passwdDir" ] [ "passworddir" ])
(mkRenamedOptionModule [ "includeExclude" ] [ "inclexcl" ])
];
};
options.programs.tsmClient = {
@ -209,7 +223,9 @@ let
contain duplicate names
(note that setting names are case insensitive).
'';
}) cfg.servers);
}) cfg.servers)
# XXX migration code for freeform settings, this can be removed in 2025:
++ (enrichMigrationInfos "assertions" (addText: { assertion, message }: { inherit assertion; message = addText message; }));
makeDsmSysLines = key: value:
# Turn a key-value pair from the server options attrset
@ -228,7 +244,12 @@ let
makeDsmSysStanza = {servername, ... }@serverCfg:
let
# drop special values that should not go into server config block
attrs = removeAttrs serverCfg [ "servername" "genPasswd" ];
attrs = removeAttrs serverCfg [ "servername" "genPasswd"
# XXX migration code for freeform settings, these can be removed in 2025:
"assertions" "warnings"
"extraConfig" "text"
"name" "server" "port" "node" "passwdDir" "includeExclude"
];
in
''
servername ${servername}
@ -246,6 +267,13 @@ let
${concatLines (map makeDsmSysStanza (attrValues cfg.servers))}
'';
# XXX migration code for freeform settings, this can be removed in 2025:
enrichMigrationInfos = what: how: concatLists (
mapAttrsToList
(name: serverCfg: map (how (text: "In `programs.tsmClient.servers.${name}`: ${text}")) serverCfg."${what}")
cfg.servers
);
in
{
@ -260,6 +288,8 @@ in
dsmSysApi = dsmSysCli;
};
environment.systemPackages = [ cfg.wrappedPackage ];
# XXX migration code for freeform settings, this can be removed in 2025:
warnings = enrichMigrationInfos "warnings" (addText: addText);
};
meta.maintainers = [ lib.maintainers.yarny ];