1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-23 02:39:40 +01:00

Remove some formatting exceptions

This formats a few more file using nixfmt.
This commit is contained in:
Robert Helgesson 2024-01-13 00:57:02 +01:00
parent 6217b73598
commit f2942f3385
No known key found for this signature in database
GPG key ID: 96E745BD17AA17ED
6 changed files with 157 additions and 190 deletions

View file

@ -9,17 +9,17 @@ let
isPath = x: builtins.substring 0 1 (toString x) == "/";
addressPort = entry:
if isPath entry.address
then " ${entry.address}"
else " [${entry.address}]:${toString entry.port}";
if isPath entry.address then
" ${entry.address}"
else
" [${entry.address}]:${toString entry.port}";
unwords = builtins.concatStringsSep " ";
mkSetEnvStr = envStr: unwords
(mapAttrsToList
(name: value: ''${name}="${escape [ "\"" "\\" ] (toString value)}"'')
envStr
);
mkSetEnvStr = envStr:
unwords (mapAttrsToList
(name: value: ''${name}="${escape [ ''"'' "\\" ] (toString value)}"'')
envStr);
bindOptions = {
address = mkOption {
@ -37,9 +37,7 @@ let
};
};
dynamicForwardModule = types.submodule {
options = bindOptions;
};
dynamicForwardModule = types.submodule { options = bindOptions; };
forwardModule = types.submodule {
options = {
@ -83,7 +81,9 @@ let
match = mkOption {
type = types.nullOr types.str;
default = null;
example = "host <hostname> canonical\nhost <hostname> exec \"ping -c1 -q 192.168.17.1\"";
example = ''
host <hostname> canonical
host <hostname> exec "ping -c1 -q 192.168.17.1"'';
description = ''
`Match` block conditions used by this block. See
{manpage}`ssh_config(5)`
@ -141,11 +141,8 @@ let
identityFile = mkOption {
type = with types; either (listOf str) (nullOr str);
default = [];
apply = p:
if p == null then []
else if isString p then [p]
else p;
default = [ ];
apply = p: if p == null then [ ] else if isString p then [ p ] else p;
description = ''
Specifies files from which the user identity is read.
Identities will be tried in the given order.
@ -182,7 +179,7 @@ let
sendEnv = mkOption {
type = types.listOf types.str;
default = [];
default = [ ];
description = ''
Environment variables to send from the local host to the
server.
@ -191,7 +188,7 @@ let
setEnv = mkOption {
type = with types; attrsOf (oneOf [ str path int float ]);
default = {};
default = { };
description = ''
Environment variables and their value to send to the server.
'';
@ -229,11 +226,8 @@ let
certificateFile = mkOption {
type = with types; either (listOf str) (nullOr str);
default = [];
apply = p:
if p == null then []
else if isString p then [p]
else p;
default = [ ];
apply = p: if p == null then [ ] else if isString p then [ p ] else p;
description = ''
Specifies files from which the user certificate is read.
'';
@ -241,7 +235,7 @@ let
addressFamily = mkOption {
default = null;
type = types.nullOr (types.enum ["any" "inet" "inet6"]);
type = types.nullOr (types.enum [ "any" "inet" "inet6" ]);
description = ''
Specifies which address family to use when connecting.
'';
@ -249,7 +243,7 @@ let
localForwards = mkOption {
type = types.listOf forwardModule;
default = [];
default = [ ];
example = literalExpression ''
[
{
@ -267,7 +261,7 @@ let
remoteForwards = mkOption {
type = types.listOf forwardModule;
default = [];
default = [ ];
example = literalExpression ''
[
{
@ -285,7 +279,7 @@ let
dynamicForwards = mkOption {
type = types.listOf dynamicForwardModule;
default = [];
default = [ ];
example = literalExpression ''
[ { port = 8080; } ];
'';
@ -297,50 +291,52 @@ let
extraOptions = mkOption {
type = types.attrsOf types.str;
default = {};
default = { };
description = "Extra configuration options for the host.";
};
};
# config.host = mkDefault dagName;
# config.host = mkDefault dagName;
});
matchBlockStr = key: cf: concatStringsSep "\n" (
let
matchBlockStr = key: cf:
concatStringsSep "\n" (let
hostOrDagName = if cf.host != null then cf.host else key;
matchHead = if cf.match != null
then "Match ${cf.match}"
else "Host ${hostOrDagName}";
matchHead = if cf.match != null then
"Match ${cf.match}"
else
"Host ${hostOrDagName}";
in [ "${matchHead}" ]
++ optional (cf.port != null) " Port ${toString cf.port}"
++ optional (cf.forwardAgent != null) " ForwardAgent ${lib.hm.booleans.yesNo cf.forwardAgent}"
++ optional cf.forwardX11 " ForwardX11 yes"
++ optional cf.forwardX11Trusted " ForwardX11Trusted yes"
++ optional cf.identitiesOnly " IdentitiesOnly yes"
++ optional (cf.user != null) " User ${cf.user}"
++ optional (cf.hostname != null) " HostName ${cf.hostname}"
++ optional (cf.addressFamily != null) " AddressFamily ${cf.addressFamily}"
++ optional (cf.sendEnv != []) " SendEnv ${unwords cf.sendEnv}"
++ optional (cf.setEnv != {}) " SetEnv ${mkSetEnvStr cf.setEnv}"
++ optional (cf.port != null) " Port ${toString cf.port}"
++ optional (cf.forwardAgent != null)
" ForwardAgent ${lib.hm.booleans.yesNo cf.forwardAgent}"
++ optional cf.forwardX11 " ForwardX11 yes"
++ optional cf.forwardX11Trusted " ForwardX11Trusted yes"
++ optional cf.identitiesOnly " IdentitiesOnly yes"
++ optional (cf.user != null) " User ${cf.user}"
++ optional (cf.hostname != null) " HostName ${cf.hostname}"
++ optional (cf.addressFamily != null) " AddressFamily ${cf.addressFamily}"
++ optional (cf.sendEnv != [ ]) " SendEnv ${unwords cf.sendEnv}"
++ optional (cf.setEnv != { }) " SetEnv ${mkSetEnvStr cf.setEnv}"
++ optional (cf.serverAliveInterval != 0)
" ServerAliveInterval ${toString cf.serverAliveInterval}"
" ServerAliveInterval ${toString cf.serverAliveInterval}"
++ optional (cf.serverAliveCountMax != 3)
" ServerAliveCountMax ${toString cf.serverAliveCountMax}"
++ optional (cf.compression != null) " Compression ${lib.hm.booleans.yesNo cf.compression}"
++ optional (!cf.checkHostIP) " CheckHostIP no"
++ optional (cf.proxyCommand != null) " ProxyCommand ${cf.proxyCommand}"
++ optional (cf.proxyJump != null) " ProxyJump ${cf.proxyJump}"
" ServerAliveCountMax ${toString cf.serverAliveCountMax}"
++ optional (cf.compression != null)
" Compression ${lib.hm.booleans.yesNo cf.compression}"
++ optional (!cf.checkHostIP) " CheckHostIP no"
++ optional (cf.proxyCommand != null) " ProxyCommand ${cf.proxyCommand}"
++ optional (cf.proxyJump != null) " ProxyJump ${cf.proxyJump}"
++ map (file: " IdentityFile ${file}") cf.identityFile
++ map (file: " CertificateFile ${file}") cf.certificateFile
++ map (f: " LocalForward" + addressPort f.bind + addressPort f.host) cf.localForwards
++ map (f: " RemoteForward" + addressPort f.bind + addressPort f.host) cf.remoteForwards
++ map (f: " LocalForward" + addressPort f.bind + addressPort f.host)
cf.localForwards
++ map (f: " RemoteForward" + addressPort f.bind + addressPort f.host)
cf.remoteForwards
++ map (f: " DynamicForward" + addressPort f) cf.dynamicForwards
++ mapAttrsToList (n: v: " ${n} ${v}") cf.extraOptions
);
++ mapAttrsToList (n: v: " ${n} ${v}") cf.extraOptions);
in
{
in {
meta.maintainers = [ maintainers.rycee ];
options.programs.ssh = {
@ -349,7 +345,8 @@ in
package = mkPackageOption pkgs "openssh" {
nullable = true;
default = null;
extraDescription = "By default, the client provided by your system is used.";
extraDescription =
"By default, the client provided by your system is used.";
};
forwardAgent = mkOption {
@ -418,7 +415,7 @@ in
controlMaster = mkOption {
default = "no";
type = types.enum ["yes" "no" "ask" "auto" "autoask"];
type = types.enum [ "yes" "no" "ask" "auto" "autoask" ];
description = ''
Configure sharing of multiple sessions over a single network connection.
'';
@ -451,7 +448,7 @@ in
extraOptionOverrides = mkOption {
type = types.attrsOf types.str;
default = {};
default = { };
description = ''
Extra SSH configuration options that take precedence over any
host specific configuration.
@ -460,7 +457,7 @@ in
includes = mkOption {
type = types.listOf types.str;
default = [];
default = [ ];
description = ''
File globs of ssh config files that should be included via the
`Include` directive.
@ -473,7 +470,7 @@ in
matchBlocks = mkOption {
type = hm.types.dagOf matchBlockModule;
default = {};
default = { };
example = literalExpression ''
{
"john.example.com" = {
@ -499,43 +496,41 @@ in
};
config = mkIf cfg.enable {
assertions = [
{
assertion =
let
# `builtins.any`/`lib.lists.any` does not return `true` if there are no elements.
any' = pred: items: if items == [] then true else any pred items;
# Check that if `entry.address` is defined, and is a path, that `entry.port` has not
# been defined.
noPathWithPort = entry: entry.address != null && isPath entry.address -> entry.port == null;
checkDynamic = block: any' noPathWithPort block.dynamicForwards;
checkBindAndHost = fwd: noPathWithPort fwd.bind && noPathWithPort fwd.host;
checkLocal = block: any' checkBindAndHost block.localForwards;
checkRemote = block: any' checkBindAndHost block.remoteForwards;
checkMatchBlock = block: all (fn: fn block) [ checkLocal checkRemote checkDynamic ];
in any' checkMatchBlock (map (block: block.data) (builtins.attrValues cfg.matchBlocks));
message = "Forwarded paths cannot have ports.";
}
];
assertions = [{
assertion = let
# `builtins.any`/`lib.lists.any` does not return `true` if there are no elements.
any' = pred: items: if items == [ ] then true else any pred items;
# Check that if `entry.address` is defined, and is a path, that `entry.port` has not
# been defined.
noPathWithPort = entry:
entry.address != null && isPath entry.address -> entry.port == null;
checkDynamic = block: any' noPathWithPort block.dynamicForwards;
checkBindAndHost = fwd:
noPathWithPort fwd.bind && noPathWithPort fwd.host;
checkLocal = block: any' checkBindAndHost block.localForwards;
checkRemote = block: any' checkBindAndHost block.remoteForwards;
checkMatchBlock = block:
all (fn: fn block) [ checkLocal checkRemote checkDynamic ];
in any' checkMatchBlock
(map (block: block.data) (builtins.attrValues cfg.matchBlocks));
message = "Forwarded paths cannot have ports.";
}];
home.packages = optional (cfg.package != null) cfg.package;
home.file.".ssh/config".text =
let
sortedMatchBlocks = hm.dag.topoSort cfg.matchBlocks;
sortedMatchBlocksStr = builtins.toJSON sortedMatchBlocks;
matchBlocks =
if sortedMatchBlocks ? result
then sortedMatchBlocks.result
else abort "Dependency cycle in SSH match blocks: ${sortedMatchBlocksStr}";
in ''
${concatStringsSep "\n" (
(mapAttrsToList (n: v: "${n} ${v}") cfg.extraOptionOverrides)
home.file.".ssh/config".text = let
sortedMatchBlocks = hm.dag.topoSort cfg.matchBlocks;
sortedMatchBlocksStr = builtins.toJSON sortedMatchBlocks;
matchBlocks = if sortedMatchBlocks ? result then
sortedMatchBlocks.result
else
abort "Dependency cycle in SSH match blocks: ${sortedMatchBlocksStr}";
in ''
${concatStringsSep "\n"
((mapAttrsToList (n: v: "${n} ${v}") cfg.extraOptionOverrides)
++ (optional (cfg.includes != [ ]) ''
Include ${concatStringsSep " " cfg.includes}
'')
++ (map (block: matchBlockStr block.name block.data) matchBlocks)
)}
'') ++ (map (block: matchBlockStr block.name block.data) matchBlocks))}
Host *
ForwardAgent ${lib.hm.booleans.yesNo cfg.forwardAgent}
@ -549,11 +544,13 @@ in
ControlPath ${cfg.controlPath}
ControlPersist ${cfg.controlPersist}
${replaceStrings ["\n"] ["\n "] cfg.extraConfig}
${replaceStrings [ "\n" ] [ "\n " ] cfg.extraConfig}
'';
warnings = mapAttrsToList
(n: v: "The SSH config match block `programs.ssh.matchBlocks.${n}` sets both of the host and match options.\nThe match option takes precedence.")
(filterAttrs (n: v: v.data.host != null && v.data.match != null) cfg.matchBlocks);
warnings = mapAttrsToList (n: v: ''
The SSH config match block `programs.ssh.matchBlocks.${n}` sets both of the host and match options.
The match option takes precedence.'')
(filterAttrs (n: v: v.data.host != null && v.data.match != null)
cfg.matchBlocks);
};
}