refactor(nix): order let bindings
This commit was merged in pull request #103.
This commit is contained in:
@@ -7,32 +7,6 @@
|
||||
# SSH on this machine, in both directions.
|
||||
let
|
||||
cfg = config.modules.network.ssh; # NOLINT(let_order)
|
||||
user = config.user.name;
|
||||
|
||||
inherit (lib)
|
||||
concatLists
|
||||
concatStringsSep
|
||||
elem
|
||||
filter
|
||||
genAttrs
|
||||
hasAttr
|
||||
imap0
|
||||
listToAttrs
|
||||
mapAttrs
|
||||
mapAttrsToList
|
||||
mkIf
|
||||
mkMerge
|
||||
mkOption
|
||||
nameValuePair
|
||||
optional
|
||||
optionalAttrs
|
||||
types
|
||||
unique
|
||||
;
|
||||
|
||||
hostKeySecret = type: "ssh-host-${type}-key";
|
||||
userKeySecret = "ssh-user-ed25519-key";
|
||||
|
||||
targetType = types.submodule (
|
||||
{ name, ... }:
|
||||
{
|
||||
@@ -90,54 +64,18 @@ let
|
||||
}
|
||||
);
|
||||
|
||||
keyWithoutComment = key: concatStringsSep " " (lib.take 2 (lib.splitString " " key));
|
||||
|
||||
targetNamesIn = names: filter (name: hasAttr name cfg.targets) names;
|
||||
|
||||
workstationNames = targetNamesIn cfg.hosts.workstations;
|
||||
serverNames = targetNamesIn cfg.hosts.servers;
|
||||
|
||||
clientKeysFor = names: filter (key: key != null) (map (name: cfg.targets.${name}.clientKey) names);
|
||||
|
||||
currentHost = config.networking.hostName;
|
||||
isServer = elem currentHost cfg.hosts.servers;
|
||||
isWorkstation = elem currentHost cfg.hosts.workstations;
|
||||
|
||||
defaultAuthorizedKeys = lib.flatten (
|
||||
clientKeysFor workstationNames ++ optional isServer (clientKeysFor serverNames)
|
||||
);
|
||||
|
||||
outboundTargetNames =
|
||||
let
|
||||
groupTargets =
|
||||
if isServer then
|
||||
[ "gitea" ] ++ cfg.hosts.servers
|
||||
else if isWorkstation then
|
||||
[ "gitea" ] ++ cfg.hosts.servers ++ cfg.hosts.workstations
|
||||
else
|
||||
[ "gitea" ];
|
||||
in
|
||||
filter (name: name != currentHost) (targetNamesIn groupTargets);
|
||||
clientKeysFor = names: filter (key: key != null) (map (name: cfg.targets.${name}.clientKey) names);
|
||||
|
||||
sshSettingsFor =
|
||||
name:
|
||||
let
|
||||
target = cfg.targets.${name};
|
||||
in
|
||||
{
|
||||
header = "Host ${concatStringsSep " " target.aliases}";
|
||||
HostName = target.hostName;
|
||||
User = target.user;
|
||||
}
|
||||
// optionalAttrs (target.port != 22) { Port = target.port; };
|
||||
workstationNames = targetNamesIn cfg.hosts.workstations;
|
||||
targetNamesIn = names: filter (name: hasAttr name cfg.targets) names;
|
||||
|
||||
knownHostNamesFor =
|
||||
target:
|
||||
let
|
||||
names = unique (target.aliases ++ [ target.hostName ]);
|
||||
withPort = name: if target.port == 22 then name else "[${name}]:${toString target.port}";
|
||||
in
|
||||
map withPort names;
|
||||
isServer = elem currentHost cfg.hosts.servers;
|
||||
currentHost = config.networking.hostName;
|
||||
serverNames = targetNamesIn cfg.hosts.servers;
|
||||
|
||||
knownHosts = listToAttrs (
|
||||
concatLists (
|
||||
@@ -153,6 +91,68 @@ let
|
||||
) cfg.targets
|
||||
)
|
||||
);
|
||||
knownHostNamesFor =
|
||||
target:
|
||||
let
|
||||
withPort = name: if target.port == 22 then name else "[${name}]:${toString target.port}";
|
||||
names = unique (target.aliases ++ [ target.hostName ]);
|
||||
in
|
||||
map withPort names;
|
||||
|
||||
keyWithoutComment = key: concatStringsSep " " (lib.take 2 (lib.splitString " " key));
|
||||
|
||||
sshSettingsFor =
|
||||
name:
|
||||
let
|
||||
target = cfg.targets.${name};
|
||||
in
|
||||
{
|
||||
header = "Host ${concatStringsSep " " target.aliases}";
|
||||
HostName = target.hostName;
|
||||
User = target.user;
|
||||
}
|
||||
// optionalAttrs (target.port != 22) { Port = target.port; };
|
||||
|
||||
outboundTargetNames =
|
||||
let
|
||||
groupTargets =
|
||||
if isServer then
|
||||
[ "gitea" ] ++ cfg.hosts.servers
|
||||
else if isWorkstation then
|
||||
[ "gitea" ] ++ cfg.hosts.servers ++ cfg.hosts.workstations
|
||||
else
|
||||
[ "gitea" ];
|
||||
in
|
||||
filter (name: name != currentHost) (targetNamesIn groupTargets);
|
||||
|
||||
isWorkstation = elem currentHost cfg.hosts.workstations;
|
||||
|
||||
hostKeySecret = type: "ssh-host-${type}-key";
|
||||
user = config.user.name;
|
||||
|
||||
inherit (lib)
|
||||
concatLists
|
||||
concatStringsSep
|
||||
elem
|
||||
filter
|
||||
genAttrs
|
||||
hasAttr
|
||||
imap0
|
||||
listToAttrs
|
||||
mapAttrs
|
||||
mapAttrsToList
|
||||
mkIf
|
||||
mkMerge
|
||||
mkOption
|
||||
nameValuePair
|
||||
optional
|
||||
optionalAttrs
|
||||
types
|
||||
unique
|
||||
;
|
||||
|
||||
userKeySecret = "ssh-user-ed25519-key";
|
||||
|
||||
in
|
||||
{
|
||||
options.modules.network.ssh = {
|
||||
|
||||
Reference in New Issue
Block a user