2024-12-08 09:39:51 +01:00
|
|
|
{ lib, config, ... }:
|
2024-12-13 14:37:43 +01:00
|
|
|
let
|
|
|
|
inherit (lib)
|
|
|
|
mkOption
|
|
|
|
splitString
|
|
|
|
length
|
|
|
|
hasPrefix
|
|
|
|
filter
|
|
|
|
concatStrings
|
|
|
|
concatStringsSep
|
|
|
|
;
|
|
|
|
inherit (lib.types)
|
|
|
|
str
|
|
|
|
listOf
|
|
|
|
enum
|
|
|
|
port
|
|
|
|
;
|
|
|
|
in
|
2024-12-08 09:39:51 +01:00
|
|
|
{
|
|
|
|
options = {
|
|
|
|
system = {
|
|
|
|
host-name = mkOption {
|
2024-12-13 14:37:43 +01:00
|
|
|
type = str;
|
2024-12-08 09:39:51 +01:00
|
|
|
description = "The hostname of the switch.";
|
|
|
|
};
|
|
|
|
root-authentication = {
|
|
|
|
hashedPasswd = mkOption {
|
2024-12-13 14:37:43 +01:00
|
|
|
type = str;
|
2024-12-08 09:39:51 +01:00
|
|
|
description = "Hashed password for root.";
|
|
|
|
};
|
|
|
|
ssh-keys = mkOption {
|
2024-12-13 14:37:43 +01:00
|
|
|
type = listOf str;
|
2024-12-08 09:39:51 +01:00
|
|
|
description = "ssh keys for root user.";
|
|
|
|
default = [ ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
services = {
|
|
|
|
ssh.root-login = mkOption {
|
2024-12-13 14:37:43 +01:00
|
|
|
type = enum [
|
2024-12-08 09:39:51 +01:00
|
|
|
"allow"
|
|
|
|
"deny"
|
|
|
|
"deny-password"
|
|
|
|
];
|
|
|
|
description = "Login policy to use for root.";
|
|
|
|
};
|
|
|
|
netconf.port = mkOption {
|
2024-12-13 14:37:43 +01:00
|
|
|
type = port;
|
2024-12-08 09:39:51 +01:00
|
|
|
description = "Port to use for netconf.";
|
|
|
|
default = 830;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
netconf.xmls.system = mkOption {
|
2024-12-13 14:37:43 +01:00
|
|
|
type = str;
|
2024-12-08 09:39:51 +01:00
|
|
|
visible = false;
|
|
|
|
readOnly = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
config.netconf.xmls.system =
|
|
|
|
let
|
|
|
|
ssh-keys1 = map (splitString " ") config.system.root-authentication.ssh-keys;
|
|
|
|
ssh-keys2 = map (key: if length key < 3 then key ++ [ "foo@bar" ] else key) ssh-keys1;
|
|
|
|
ssh-keys = map (concatStringsSep " ") ssh-keys2;
|
|
|
|
edsca = map (key: "<ssh-edsca><name>${key}</name></ssh-edsca>") (
|
|
|
|
filter (hasPrefix "ssh-edsca ") ssh-keys
|
|
|
|
);
|
|
|
|
rsa = map (key: "<ssh-rsa><name>${key}</name></ssh-rsa>") (filter (hasPrefix "ssh-rsa ") ssh-keys);
|
|
|
|
ed25519 = map (key: "<ssh-ed25519><name>${key}</name></ssh-ed25519>") (
|
|
|
|
filter (hasPrefix "ssh-ed25519 ") ssh-keys
|
|
|
|
);
|
|
|
|
in
|
|
|
|
''
|
|
|
|
<system>
|
|
|
|
<host-name operation="replace">${config.system.host-name}</host-name>
|
|
|
|
<root-authentication operation="replace">
|
|
|
|
<encrypted-password>${config.system.root-authentication.hashedPasswd}</encrypted-password>
|
|
|
|
${concatStrings (edsca ++ rsa ++ ed25519)}
|
|
|
|
</root-authentication>
|
|
|
|
<services operation="replace">
|
|
|
|
<ssh><root-login>${config.system.services.ssh.root-login}</root-login></ssh>
|
|
|
|
<netconf>
|
|
|
|
<ssh><port>${toString config.system.services.netconf.port}</port></ssh>
|
|
|
|
<rfc-compliant/><yang-compliant/>
|
|
|
|
</netconf>
|
|
|
|
</services>
|
|
|
|
</system>
|
|
|
|
'';
|
|
|
|
}
|