2019-05-15 18:17:30 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
inherit (builtins) length map;
|
|
|
|
inherit (lib.attrsets) attrNames filterAttrs hasAttr mapAttrs mapAttrsToList optionalAttrs;
|
|
|
|
inherit (lib.modules) mkDefault mkIf;
|
2021-10-03 18:06:03 +02:00
|
|
|
inherit (lib.options) literalExpression mkEnableOption mkOption;
|
2019-05-15 18:17:30 +02:00
|
|
|
inherit (lib.strings) concatStringsSep optionalString toLower;
|
2021-12-05 13:52:06 +01:00
|
|
|
inherit (lib.types) addCheck attrsOf lines nonEmptyStr nullOr package path port str strMatching submodule;
|
2019-05-15 18:17:30 +02:00
|
|
|
|
|
|
|
# Checks if given list of strings contains unique
|
|
|
|
# elements when compared without considering case.
|
|
|
|
# Type: checkIUnique :: [string] -> bool
|
|
|
|
# Example: checkIUnique ["foo" "Foo"] => false
|
|
|
|
checkIUnique = lst:
|
|
|
|
let
|
|
|
|
lenUniq = l: length (lib.lists.unique l);
|
|
|
|
in
|
|
|
|
lenUniq lst == lenUniq (map toLower lst);
|
|
|
|
|
|
|
|
# TSM rejects servername strings longer than 64 chars.
|
|
|
|
servernameType = strMatching ".{1,64}";
|
|
|
|
|
|
|
|
serverOptions = { name, config, ... }: {
|
|
|
|
options.name = mkOption {
|
|
|
|
type = servernameType;
|
|
|
|
example = "mainTsmServer";
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2019-05-15 18:17:30 +02:00
|
|
|
Local name of the IBM TSM server,
|
|
|
|
must be uncapitalized and no longer than 64 chars.
|
|
|
|
The value will be used for the
|
2022-07-28 23:19:15 +02:00
|
|
|
`server`
|
|
|
|
directive in {file}`dsm.sys`.
|
2019-05-15 18:17:30 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
options.server = mkOption {
|
2021-12-05 13:52:06 +01:00
|
|
|
type = nonEmptyStr;
|
2019-05-15 18:17:30 +02:00
|
|
|
example = "tsmserver.company.com";
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2019-05-15 18:17:30 +02:00
|
|
|
Host/domain name or IP address of the IBM TSM server.
|
|
|
|
The value will be used for the
|
2022-07-28 23:19:15 +02:00
|
|
|
`tcpserveraddress`
|
|
|
|
directive in {file}`dsm.sys`.
|
2019-05-15 18:17:30 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
options.port = mkOption {
|
|
|
|
type = addCheck port (p: p<=32767);
|
|
|
|
default = 1500; # official default
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2019-05-15 18:17:30 +02:00
|
|
|
TCP port of the IBM TSM server.
|
|
|
|
The value will be used for the
|
2022-07-28 23:19:15 +02:00
|
|
|
`tcpport`
|
|
|
|
directive in {file}`dsm.sys`.
|
2019-05-15 18:17:30 +02:00
|
|
|
TSM does not support ports above 32767.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
options.node = mkOption {
|
2021-12-05 13:52:06 +01:00
|
|
|
type = nonEmptyStr;
|
2019-05-15 18:17:30 +02:00
|
|
|
example = "MY-TSM-NODE";
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2019-05-15 18:17:30 +02:00
|
|
|
Target node name on the IBM TSM server.
|
|
|
|
The value will be used for the
|
2022-07-28 23:19:15 +02:00
|
|
|
`nodename`
|
|
|
|
directive in {file}`dsm.sys`.
|
2019-05-15 18:17:30 +02:00
|
|
|
'';
|
|
|
|
};
|
2022-08-28 21:18:44 +02:00
|
|
|
options.genPasswd = mkEnableOption (lib.mdDoc ''
|
2019-05-15 18:17:30 +02:00
|
|
|
automatic client password generation.
|
|
|
|
This option influences the
|
2022-08-28 21:18:44 +02:00
|
|
|
`passwordaccess`
|
|
|
|
directive in {file}`dsm.sys`.
|
2019-05-15 18:17:30 +02:00
|
|
|
The password will be stored in the directory
|
2022-08-28 21:18:44 +02:00
|
|
|
given by the option {option}`passwdDir`.
|
|
|
|
*Caution*:
|
2019-05-15 18:17:30 +02:00
|
|
|
If this option is enabled and the server forces
|
|
|
|
to renew the password (e.g. on first connection),
|
|
|
|
a random password will be generated and stored
|
2022-08-28 21:18:44 +02:00
|
|
|
'');
|
2019-05-15 18:17:30 +02:00
|
|
|
options.passwdDir = mkOption {
|
|
|
|
type = path;
|
|
|
|
example = "/home/alice/tsm-password";
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2019-05-15 18:17:30 +02:00
|
|
|
Directory that holds the TSM
|
|
|
|
node's password information.
|
|
|
|
The value will be used for the
|
2022-07-28 23:19:15 +02:00
|
|
|
`passworddir`
|
|
|
|
directive in {file}`dsm.sys`.
|
2019-05-15 18:17:30 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
options.includeExclude = mkOption {
|
|
|
|
type = lines;
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
exclude.dir /nix/store
|
|
|
|
include.encrypt /home/.../*
|
|
|
|
'';
|
2022-08-15 07:16:25 +02:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
`include.*` and
|
|
|
|
`exclude.*` directives to be
|
2019-05-15 18:17:30 +02:00
|
|
|
used when sending files to the IBM TSM server.
|
|
|
|
The lines will be written into a file that the
|
2022-08-15 07:16:25 +02:00
|
|
|
`inclexcl`
|
|
|
|
directive in {file}`dsm.sys` points to.
|
2019-05-15 18:17:30 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
options.extraConfig = mkOption {
|
|
|
|
# TSM option keys are case insensitive;
|
|
|
|
# we have to ensure there are no keys that
|
|
|
|
# differ only by upper and lower case.
|
|
|
|
type = addCheck
|
|
|
|
(attrsOf (nullOr str))
|
|
|
|
(attrs: checkIUnique (attrNames attrs));
|
|
|
|
default = {};
|
|
|
|
example.compression = "yes";
|
|
|
|
example.passwordaccess = null;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2019-05-15 18:17:30 +02:00
|
|
|
Additional key-value pairs for the server stanza.
|
2022-07-28 23:19:15 +02:00
|
|
|
Values must be strings, or `null`
|
2019-05-15 18:17:30 +02:00
|
|
|
for the key not to be used in the stanza
|
|
|
|
(e.g. to overrule values generated by other options).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
options.text = mkOption {
|
|
|
|
type = lines;
|
2021-10-03 18:06:03 +02:00
|
|
|
example = literalExpression
|
2019-05-15 18:17:30 +02:00
|
|
|
''lib.modules.mkAfter "compression no"'';
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2019-05-15 18:17:30 +02:00
|
|
|
Additional text lines for the server stanza.
|
|
|
|
This option can be used if certion configuration keys
|
|
|
|
must be used multiple times or ordered in a certain way
|
2022-07-28 23:19:15 +02:00
|
|
|
as the {option}`extraConfig` option can't
|
2019-05-15 18:17:30 +02:00
|
|
|
control the order of lines in the resulting stanza.
|
2022-07-28 23:19:15 +02:00
|
|
|
Note that the `server`
|
2019-05-15 18:17:30 +02:00
|
|
|
line at the beginning of the stanza is
|
|
|
|
not part of this option's value.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
options.stanza = mkOption {
|
|
|
|
type = str;
|
|
|
|
internal = true;
|
|
|
|
visible = false;
|
2022-08-29 01:38:36 +02:00
|
|
|
description = lib.mdDoc "Server stanza text generated from the options.";
|
2019-05-15 18:17:30 +02:00
|
|
|
};
|
|
|
|
config.name = mkDefault name;
|
|
|
|
# Client system-options file directives are explained here:
|
2021-10-24 10:17:59 +02:00
|
|
|
# https://www.ibm.com/docs/en/spectrum-protect/8.1.13?topic=commands-processing-options
|
2019-05-15 18:17:30 +02:00
|
|
|
config.extraConfig =
|
|
|
|
mapAttrs (lib.trivial.const mkDefault) (
|
|
|
|
{
|
|
|
|
commmethod = "v6tcpip"; # uses v4 or v6, based on dns lookup result
|
|
|
|
tcpserveraddress = config.server;
|
|
|
|
tcpport = builtins.toString config.port;
|
|
|
|
nodename = config.node;
|
|
|
|
passwordaccess = if config.genPasswd then "generate" else "prompt";
|
|
|
|
passworddir = ''"${config.passwdDir}"'';
|
|
|
|
} // optionalAttrs (config.includeExclude!="") {
|
|
|
|
inclexcl = ''"${pkgs.writeText "inclexcl.dsm.sys" config.includeExclude}"'';
|
|
|
|
}
|
|
|
|
);
|
|
|
|
config.text =
|
|
|
|
let
|
|
|
|
attrset = filterAttrs (k: v: v!=null) config.extraConfig;
|
|
|
|
mkLine = k: v: k + optionalString (v!="") " ${v}";
|
|
|
|
lines = mapAttrsToList mkLine attrset;
|
|
|
|
in
|
|
|
|
concatStringsSep "\n" lines;
|
|
|
|
config.stanza = ''
|
|
|
|
server ${config.name}
|
|
|
|
${config.text}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
options.programs.tsmClient = {
|
2022-08-28 21:18:44 +02:00
|
|
|
enable = mkEnableOption (lib.mdDoc ''
|
2019-05-15 18:17:30 +02:00
|
|
|
IBM Spectrum Protect (Tivoli Storage Manager, TSM)
|
|
|
|
client command line applications with a
|
|
|
|
client system-options file "dsm.sys"
|
2022-08-28 21:18:44 +02:00
|
|
|
'');
|
2019-05-15 18:17:30 +02:00
|
|
|
servers = mkOption {
|
2020-08-23 01:28:45 +02:00
|
|
|
type = attrsOf (submodule [ serverOptions ]);
|
2019-05-15 18:17:30 +02:00
|
|
|
default = {};
|
|
|
|
example.mainTsmServer = {
|
|
|
|
server = "tsmserver.company.com";
|
|
|
|
node = "MY-TSM-NODE";
|
|
|
|
extraConfig.compression = "yes";
|
|
|
|
};
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2019-05-15 18:17:30 +02:00
|
|
|
Server definitions ("stanzas")
|
|
|
|
for the client system-options file.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
defaultServername = mkOption {
|
|
|
|
type = nullOr servernameType;
|
|
|
|
default = null;
|
|
|
|
example = "mainTsmServer";
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2019-05-15 18:17:30 +02:00
|
|
|
If multiple server stanzas are declared with
|
2022-07-28 23:19:15 +02:00
|
|
|
{option}`programs.tsmClient.servers`,
|
2019-05-15 18:17:30 +02:00
|
|
|
this option may be used to name a default
|
|
|
|
server stanza that IBM TSM uses in the absence of
|
2022-07-28 23:19:15 +02:00
|
|
|
a user-defined {file}`dsm.opt` file.
|
2019-05-15 18:17:30 +02:00
|
|
|
This option translates to a
|
2022-07-28 23:19:15 +02:00
|
|
|
`defaultserver` configuration line.
|
2019-05-15 18:17:30 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
dsmSysText = mkOption {
|
|
|
|
type = lines;
|
|
|
|
readOnly = true;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2019-05-15 18:17:30 +02:00
|
|
|
This configuration key contains the effective text
|
|
|
|
of the client system-options file "dsm.sys".
|
|
|
|
It should not be changed, but may be
|
|
|
|
used to feed the configuration into other
|
|
|
|
TSM-depending packages used on the system.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
package = mkOption {
|
|
|
|
type = package;
|
|
|
|
default = pkgs.tsm-client;
|
2021-10-03 18:06:03 +02:00
|
|
|
defaultText = literalExpression "pkgs.tsm-client";
|
|
|
|
example = literalExpression "pkgs.tsm-client-withGui";
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2019-05-15 18:17:30 +02:00
|
|
|
The TSM client derivation to be
|
|
|
|
added to the system environment.
|
2022-07-28 23:19:15 +02:00
|
|
|
It will called with `.override`
|
2019-05-15 18:17:30 +02:00
|
|
|
to add paths to the client system-options file.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
wrappedPackage = mkOption {
|
|
|
|
type = package;
|
|
|
|
readOnly = true;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2019-05-15 18:17:30 +02:00
|
|
|
The TSM client derivation, wrapped with the path
|
|
|
|
to the client system-options file "dsm.sys".
|
|
|
|
This option is to provide the effective derivation
|
|
|
|
for other modules that want to call TSM executables.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
cfg = config.programs.tsmClient;
|
|
|
|
|
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = checkIUnique (mapAttrsToList (k: v: v.name) cfg.servers);
|
|
|
|
message = ''
|
|
|
|
TSM servernames contain duplicate name
|
|
|
|
(note that case doesn't matter!)
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion = (cfg.defaultServername!=null)->(hasAttr cfg.defaultServername cfg.servers);
|
|
|
|
message = "TSM defaultServername not found in list of servers";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
dsmSysText = ''
|
|
|
|
**** IBM Spectrum Protect (Tivoli Storage Manager)
|
|
|
|
**** client system-options file "dsm.sys".
|
|
|
|
**** Do not edit!
|
|
|
|
**** This file is generated by NixOS configuration.
|
|
|
|
|
|
|
|
${optionalString (cfg.defaultServername!=null) "defaultserver ${cfg.defaultServername}"}
|
|
|
|
|
|
|
|
${concatStringsSep "\n" (mapAttrsToList (k: v: v.stanza) cfg.servers)}
|
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
inherit options;
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
inherit assertions;
|
|
|
|
programs.tsmClient.dsmSysText = dsmSysText;
|
|
|
|
programs.tsmClient.wrappedPackage = cfg.package.override rec {
|
|
|
|
dsmSysCli = pkgs.writeText "dsm.sys" cfg.dsmSysText;
|
|
|
|
dsmSysApi = dsmSysCli;
|
|
|
|
};
|
|
|
|
environment.systemPackages = [ cfg.wrappedPackage ];
|
|
|
|
};
|
|
|
|
|
|
|
|
meta.maintainers = [ lib.maintainers.yarny ];
|
|
|
|
|
|
|
|
}
|