mirror of
https://github.com/nix-community/home-manager
synced 2024-11-25 06:00:31 +00:00
Remove some formatting exceptions
This formats a few more file using nixfmt.
This commit is contained in:
parent
6217b73598
commit
f2942f3385
6 changed files with 157 additions and 190 deletions
6
format
6
format
|
@ -26,15 +26,9 @@ done
|
||||||
# The excludes are for files touched by open pull requests and we want
|
# The excludes are for files touched by open pull requests and we want
|
||||||
# to avoid merge conflicts.
|
# to avoid merge conflicts.
|
||||||
excludes=(
|
excludes=(
|
||||||
modules/default.nix
|
|
||||||
modules/files.nix
|
modules/files.nix
|
||||||
modules/home-environment.nix
|
modules/home-environment.nix
|
||||||
modules/lib/default.nix
|
|
||||||
modules/lib/file-type.nix
|
|
||||||
modules/misc/news.nix
|
|
||||||
modules/programs/ssh.nix
|
|
||||||
modules/programs/zsh.nix
|
modules/programs/zsh.nix
|
||||||
tests/default.nix
|
|
||||||
)
|
)
|
||||||
|
|
||||||
exclude_args=()
|
exclude_args=()
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
{ configuration
|
{ configuration, pkgs, lib ? pkgs.lib
|
||||||
, pkgs
|
|
||||||
, lib ? pkgs.lib
|
|
||||||
|
|
||||||
# Whether to check that each option has a matching declaration.
|
# Whether to check that each option has a matching declaration.
|
||||||
, check ? true
|
, check ? true
|
||||||
# Extra arguments passed to specialArgs.
|
# Extra arguments passed to specialArgs.
|
||||||
, extraSpecialArgs ? { }
|
, extraSpecialArgs ? { } }:
|
||||||
}:
|
|
||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
|
@ -16,39 +13,33 @@ let
|
||||||
map (x: x.message) (filter (x: !x.assertion) cfg.assertions);
|
map (x: x.message) (filter (x: !x.assertion) cfg.assertions);
|
||||||
|
|
||||||
showWarnings = res:
|
showWarnings = res:
|
||||||
let
|
let f = w: x: builtins.trace "[1;31mwarning: ${w}[0m" x;
|
||||||
f = w: x: builtins.trace "[1;31mwarning: ${w}[0m" x;
|
in fold f res res.config.warnings;
|
||||||
in
|
|
||||||
fold f res res.config.warnings;
|
|
||||||
|
|
||||||
extendedLib = import ./lib/stdlib-extended.nix lib;
|
extendedLib = import ./lib/stdlib-extended.nix lib;
|
||||||
|
|
||||||
hmModules =
|
hmModules = import ./modules.nix {
|
||||||
import ./modules.nix {
|
inherit check pkgs;
|
||||||
inherit check pkgs;
|
lib = extendedLib;
|
||||||
lib = extendedLib;
|
};
|
||||||
};
|
|
||||||
|
|
||||||
rawModule = extendedLib.evalModules {
|
rawModule = extendedLib.evalModules {
|
||||||
modules = [ configuration ] ++ hmModules;
|
modules = [ configuration ] ++ hmModules;
|
||||||
specialArgs = {
|
specialArgs = { modulesPath = builtins.toString ./.; } // extraSpecialArgs;
|
||||||
modulesPath = builtins.toString ./.;
|
|
||||||
} // extraSpecialArgs;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module = showWarnings (
|
module = showWarnings (let
|
||||||
let
|
failed = collectFailed rawModule.config;
|
||||||
failed = collectFailed rawModule.config;
|
failedStr = concatStringsSep "\n" (map (x: "- ${x}") failed);
|
||||||
failedStr = concatStringsSep "\n" (map (x: "- ${x}") failed);
|
in if failed == [ ] then
|
||||||
in
|
rawModule
|
||||||
if failed == []
|
else
|
||||||
then rawModule
|
throw ''
|
||||||
else throw "\nFailed assertions:\n${failedStr}"
|
|
||||||
);
|
|
||||||
|
|
||||||
in
|
Failed assertions:
|
||||||
|
${failedStr}'');
|
||||||
|
|
||||||
{
|
in {
|
||||||
inherit (module) options config;
|
inherit (module) options config;
|
||||||
|
|
||||||
activationPackage = module.config.home.activationPackage;
|
activationPackage = module.config.home.activationPackage;
|
||||||
|
@ -57,10 +48,8 @@ in
|
||||||
activation-script = module.config.home.activationPackage;
|
activation-script = module.config.home.activationPackage;
|
||||||
|
|
||||||
newsDisplay = rawModule.config.news.display;
|
newsDisplay = rawModule.config.news.display;
|
||||||
newsEntries =
|
newsEntries = sort (a: b: a.time > b.time)
|
||||||
sort (a: b: a.time > b.time) (
|
(filter (a: a.condition) rawModule.config.news.entries);
|
||||||
filter (a: a.condition) rawModule.config.news.entries
|
|
||||||
);
|
|
||||||
|
|
||||||
inherit (module._module.args) pkgs;
|
inherit (module._module.args) pkgs;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
{ homeDirectory, lib, pkgs }:
|
{ homeDirectory, lib, pkgs }:
|
||||||
|
|
||||||
let
|
let
|
||||||
inherit (lib) hasPrefix hm literalExpression mkDefault mkIf mkOption removePrefix types;
|
inherit (lib)
|
||||||
in
|
hasPrefix hm literalExpression mkDefault mkIf mkOption removePrefix types;
|
||||||
{
|
in {
|
||||||
# Constructs a type suitable for a `home.file` like option. The
|
# Constructs a type suitable for a `home.file` like option. The
|
||||||
# target path may be either absolute or relative, in which case it
|
# target path may be either absolute or relative, in which case it
|
||||||
# is relative the `basePath` argument (which itself must be an
|
# is relative the `basePath` argument (which itself must be an
|
||||||
|
@ -13,8 +13,8 @@ in
|
||||||
# - opt the name of the option, for self-references
|
# - opt the name of the option, for self-references
|
||||||
# - basePathDesc docbook compatible description of the base path
|
# - basePathDesc docbook compatible description of the base path
|
||||||
# - basePath the file base path
|
# - basePath the file base path
|
||||||
fileType = opt: basePathDesc: basePath: types.attrsOf (types.submodule (
|
fileType = opt: basePathDesc: basePath:
|
||||||
{ name, config, ... }: {
|
types.attrsOf (types.submodule ({ name, config, ... }: {
|
||||||
options = {
|
options = {
|
||||||
enable = mkOption {
|
enable = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
|
@ -27,10 +27,8 @@ in
|
||||||
target = mkOption {
|
target = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
apply = p:
|
apply = p:
|
||||||
let
|
let absPath = if hasPrefix "/" p then p else "${basePath}/${p}";
|
||||||
absPath = if hasPrefix "/" p then p else "${basePath}/${p}";
|
in removePrefix (homeDirectory + "/") absPath;
|
||||||
in
|
|
||||||
removePrefix (homeDirectory + "/") absPath;
|
|
||||||
defaultText = literalExpression "name";
|
defaultText = literalExpression "name";
|
||||||
description = ''
|
description = ''
|
||||||
Path to target file relative to ${basePathDesc}.
|
Path to target file relative to ${basePathDesc}.
|
||||||
|
@ -113,14 +111,11 @@ in
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
target = mkDefault name;
|
target = mkDefault name;
|
||||||
source = mkIf (config.text != null) (
|
source = mkIf (config.text != null) (mkDefault (pkgs.writeTextFile {
|
||||||
mkDefault (pkgs.writeTextFile {
|
inherit (config) text;
|
||||||
inherit (config) text;
|
executable = config.executable == true; # can be null
|
||||||
executable = config.executable == true; # can be null
|
name = hm.strings.storeFileName name;
|
||||||
name = hm.strings.storeFileName name;
|
}));
|
||||||
})
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
}
|
}));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,14 +42,10 @@ let
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = { id = mkDefault (builtins.hashString "sha256" config.message); };
|
||||||
id = mkDefault (builtins.hashString "sha256" config.message);
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|
||||||
in
|
in {
|
||||||
|
|
||||||
{
|
|
||||||
meta.maintainers = [ maintainers.rycee ];
|
meta.maintainers = [ maintainers.rycee ];
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
|
@ -97,9 +93,8 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
news.json.output = pkgs.writeText "hm-news.json" (builtins.toJSON {
|
news.json.output = pkgs.writeText "hm-news.json"
|
||||||
inherit (cfg) display entries;
|
(builtins.toJSON { inherit (cfg) display entries; });
|
||||||
});
|
|
||||||
|
|
||||||
# Add news entries in chronological order (i.e., latest time
|
# Add news entries in chronological order (i.e., latest time
|
||||||
# should be at the bottom of the list). The time should be
|
# should be at the bottom of the list). The time should be
|
||||||
|
@ -255,7 +250,8 @@ in
|
||||||
|
|
||||||
{
|
{
|
||||||
time = "2021-09-23T17:04:48+00:00";
|
time = "2021-09-23T17:04:48+00:00";
|
||||||
condition = hostPlatform.isLinux && config.services.screen-locker.enable;
|
condition = hostPlatform.isLinux
|
||||||
|
&& config.services.screen-locker.enable;
|
||||||
message = ''
|
message = ''
|
||||||
'xautolock' is now optional in 'services.screen-locker', and the
|
'xautolock' is now optional in 'services.screen-locker', and the
|
||||||
'services.screen-locker' options have been reorganized for clarity.
|
'services.screen-locker' options have been reorganized for clarity.
|
||||||
|
|
|
@ -9,17 +9,17 @@ let
|
||||||
isPath = x: builtins.substring 0 1 (toString x) == "/";
|
isPath = x: builtins.substring 0 1 (toString x) == "/";
|
||||||
|
|
||||||
addressPort = entry:
|
addressPort = entry:
|
||||||
if isPath entry.address
|
if isPath entry.address then
|
||||||
then " ${entry.address}"
|
" ${entry.address}"
|
||||||
else " [${entry.address}]:${toString entry.port}";
|
else
|
||||||
|
" [${entry.address}]:${toString entry.port}";
|
||||||
|
|
||||||
unwords = builtins.concatStringsSep " ";
|
unwords = builtins.concatStringsSep " ";
|
||||||
|
|
||||||
mkSetEnvStr = envStr: unwords
|
mkSetEnvStr = envStr:
|
||||||
(mapAttrsToList
|
unwords (mapAttrsToList
|
||||||
(name: value: ''${name}="${escape [ "\"" "\\" ] (toString value)}"'')
|
(name: value: ''${name}="${escape [ ''"'' "\\" ] (toString value)}"'')
|
||||||
envStr
|
envStr);
|
||||||
);
|
|
||||||
|
|
||||||
bindOptions = {
|
bindOptions = {
|
||||||
address = mkOption {
|
address = mkOption {
|
||||||
|
@ -37,9 +37,7 @@ let
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
dynamicForwardModule = types.submodule {
|
dynamicForwardModule = types.submodule { options = bindOptions; };
|
||||||
options = bindOptions;
|
|
||||||
};
|
|
||||||
|
|
||||||
forwardModule = types.submodule {
|
forwardModule = types.submodule {
|
||||||
options = {
|
options = {
|
||||||
|
@ -83,7 +81,9 @@ let
|
||||||
match = mkOption {
|
match = mkOption {
|
||||||
type = types.nullOr types.str;
|
type = types.nullOr types.str;
|
||||||
default = null;
|
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 = ''
|
description = ''
|
||||||
`Match` block conditions used by this block. See
|
`Match` block conditions used by this block. See
|
||||||
{manpage}`ssh_config(5)`
|
{manpage}`ssh_config(5)`
|
||||||
|
@ -141,11 +141,8 @@ let
|
||||||
|
|
||||||
identityFile = mkOption {
|
identityFile = mkOption {
|
||||||
type = with types; either (listOf str) (nullOr str);
|
type = with types; either (listOf str) (nullOr str);
|
||||||
default = [];
|
default = [ ];
|
||||||
apply = p:
|
apply = p: if p == null then [ ] else if isString p then [ p ] else p;
|
||||||
if p == null then []
|
|
||||||
else if isString p then [p]
|
|
||||||
else p;
|
|
||||||
description = ''
|
description = ''
|
||||||
Specifies files from which the user identity is read.
|
Specifies files from which the user identity is read.
|
||||||
Identities will be tried in the given order.
|
Identities will be tried in the given order.
|
||||||
|
@ -182,7 +179,7 @@ let
|
||||||
|
|
||||||
sendEnv = mkOption {
|
sendEnv = mkOption {
|
||||||
type = types.listOf types.str;
|
type = types.listOf types.str;
|
||||||
default = [];
|
default = [ ];
|
||||||
description = ''
|
description = ''
|
||||||
Environment variables to send from the local host to the
|
Environment variables to send from the local host to the
|
||||||
server.
|
server.
|
||||||
|
@ -191,7 +188,7 @@ let
|
||||||
|
|
||||||
setEnv = mkOption {
|
setEnv = mkOption {
|
||||||
type = with types; attrsOf (oneOf [ str path int float ]);
|
type = with types; attrsOf (oneOf [ str path int float ]);
|
||||||
default = {};
|
default = { };
|
||||||
description = ''
|
description = ''
|
||||||
Environment variables and their value to send to the server.
|
Environment variables and their value to send to the server.
|
||||||
'';
|
'';
|
||||||
|
@ -229,11 +226,8 @@ let
|
||||||
|
|
||||||
certificateFile = mkOption {
|
certificateFile = mkOption {
|
||||||
type = with types; either (listOf str) (nullOr str);
|
type = with types; either (listOf str) (nullOr str);
|
||||||
default = [];
|
default = [ ];
|
||||||
apply = p:
|
apply = p: if p == null then [ ] else if isString p then [ p ] else p;
|
||||||
if p == null then []
|
|
||||||
else if isString p then [p]
|
|
||||||
else p;
|
|
||||||
description = ''
|
description = ''
|
||||||
Specifies files from which the user certificate is read.
|
Specifies files from which the user certificate is read.
|
||||||
'';
|
'';
|
||||||
|
@ -241,7 +235,7 @@ let
|
||||||
|
|
||||||
addressFamily = mkOption {
|
addressFamily = mkOption {
|
||||||
default = null;
|
default = null;
|
||||||
type = types.nullOr (types.enum ["any" "inet" "inet6"]);
|
type = types.nullOr (types.enum [ "any" "inet" "inet6" ]);
|
||||||
description = ''
|
description = ''
|
||||||
Specifies which address family to use when connecting.
|
Specifies which address family to use when connecting.
|
||||||
'';
|
'';
|
||||||
|
@ -249,7 +243,7 @@ let
|
||||||
|
|
||||||
localForwards = mkOption {
|
localForwards = mkOption {
|
||||||
type = types.listOf forwardModule;
|
type = types.listOf forwardModule;
|
||||||
default = [];
|
default = [ ];
|
||||||
example = literalExpression ''
|
example = literalExpression ''
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
|
@ -267,7 +261,7 @@ let
|
||||||
|
|
||||||
remoteForwards = mkOption {
|
remoteForwards = mkOption {
|
||||||
type = types.listOf forwardModule;
|
type = types.listOf forwardModule;
|
||||||
default = [];
|
default = [ ];
|
||||||
example = literalExpression ''
|
example = literalExpression ''
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
|
@ -285,7 +279,7 @@ let
|
||||||
|
|
||||||
dynamicForwards = mkOption {
|
dynamicForwards = mkOption {
|
||||||
type = types.listOf dynamicForwardModule;
|
type = types.listOf dynamicForwardModule;
|
||||||
default = [];
|
default = [ ];
|
||||||
example = literalExpression ''
|
example = literalExpression ''
|
||||||
[ { port = 8080; } ];
|
[ { port = 8080; } ];
|
||||||
'';
|
'';
|
||||||
|
@ -297,50 +291,52 @@ let
|
||||||
|
|
||||||
extraOptions = mkOption {
|
extraOptions = mkOption {
|
||||||
type = types.attrsOf types.str;
|
type = types.attrsOf types.str;
|
||||||
default = {};
|
default = { };
|
||||||
description = "Extra configuration options for the host.";
|
description = "Extra configuration options for the host.";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
# config.host = mkDefault dagName;
|
# config.host = mkDefault dagName;
|
||||||
});
|
});
|
||||||
|
|
||||||
matchBlockStr = key: cf: concatStringsSep "\n" (
|
matchBlockStr = key: cf:
|
||||||
let
|
concatStringsSep "\n" (let
|
||||||
hostOrDagName = if cf.host != null then cf.host else key;
|
hostOrDagName = if cf.host != null then cf.host else key;
|
||||||
matchHead = if cf.match != null
|
matchHead = if cf.match != null then
|
||||||
then "Match ${cf.match}"
|
"Match ${cf.match}"
|
||||||
else "Host ${hostOrDagName}";
|
else
|
||||||
|
"Host ${hostOrDagName}";
|
||||||
in [ "${matchHead}" ]
|
in [ "${matchHead}" ]
|
||||||
++ optional (cf.port != null) " Port ${toString cf.port}"
|
++ optional (cf.port != null) " Port ${toString cf.port}"
|
||||||
++ optional (cf.forwardAgent != null) " ForwardAgent ${lib.hm.booleans.yesNo cf.forwardAgent}"
|
++ optional (cf.forwardAgent != null)
|
||||||
++ optional cf.forwardX11 " ForwardX11 yes"
|
" ForwardAgent ${lib.hm.booleans.yesNo cf.forwardAgent}"
|
||||||
++ optional cf.forwardX11Trusted " ForwardX11Trusted yes"
|
++ optional cf.forwardX11 " ForwardX11 yes"
|
||||||
++ optional cf.identitiesOnly " IdentitiesOnly yes"
|
++ optional cf.forwardX11Trusted " ForwardX11Trusted yes"
|
||||||
++ optional (cf.user != null) " User ${cf.user}"
|
++ optional cf.identitiesOnly " IdentitiesOnly yes"
|
||||||
++ optional (cf.hostname != null) " HostName ${cf.hostname}"
|
++ optional (cf.user != null) " User ${cf.user}"
|
||||||
++ optional (cf.addressFamily != null) " AddressFamily ${cf.addressFamily}"
|
++ optional (cf.hostname != null) " HostName ${cf.hostname}"
|
||||||
++ optional (cf.sendEnv != []) " SendEnv ${unwords cf.sendEnv}"
|
++ optional (cf.addressFamily != null) " AddressFamily ${cf.addressFamily}"
|
||||||
++ optional (cf.setEnv != {}) " SetEnv ${mkSetEnvStr cf.setEnv}"
|
++ optional (cf.sendEnv != [ ]) " SendEnv ${unwords cf.sendEnv}"
|
||||||
|
++ optional (cf.setEnv != { }) " SetEnv ${mkSetEnvStr cf.setEnv}"
|
||||||
++ optional (cf.serverAliveInterval != 0)
|
++ optional (cf.serverAliveInterval != 0)
|
||||||
" ServerAliveInterval ${toString cf.serverAliveInterval}"
|
" ServerAliveInterval ${toString cf.serverAliveInterval}"
|
||||||
++ optional (cf.serverAliveCountMax != 3)
|
++ optional (cf.serverAliveCountMax != 3)
|
||||||
" ServerAliveCountMax ${toString cf.serverAliveCountMax}"
|
" ServerAliveCountMax ${toString cf.serverAliveCountMax}"
|
||||||
++ optional (cf.compression != null) " Compression ${lib.hm.booleans.yesNo cf.compression}"
|
++ optional (cf.compression != null)
|
||||||
++ optional (!cf.checkHostIP) " CheckHostIP no"
|
" Compression ${lib.hm.booleans.yesNo cf.compression}"
|
||||||
++ optional (cf.proxyCommand != null) " ProxyCommand ${cf.proxyCommand}"
|
++ optional (!cf.checkHostIP) " CheckHostIP no"
|
||||||
++ optional (cf.proxyJump != null) " ProxyJump ${cf.proxyJump}"
|
++ optional (cf.proxyCommand != null) " ProxyCommand ${cf.proxyCommand}"
|
||||||
|
++ optional (cf.proxyJump != null) " ProxyJump ${cf.proxyJump}"
|
||||||
++ map (file: " IdentityFile ${file}") cf.identityFile
|
++ map (file: " IdentityFile ${file}") cf.identityFile
|
||||||
++ map (file: " CertificateFile ${file}") cf.certificateFile
|
++ map (file: " CertificateFile ${file}") cf.certificateFile
|
||||||
++ map (f: " LocalForward" + addressPort f.bind + addressPort f.host) cf.localForwards
|
++ map (f: " LocalForward" + addressPort f.bind + addressPort f.host)
|
||||||
++ map (f: " RemoteForward" + addressPort f.bind + addressPort f.host) cf.remoteForwards
|
cf.localForwards
|
||||||
|
++ map (f: " RemoteForward" + addressPort f.bind + addressPort f.host)
|
||||||
|
cf.remoteForwards
|
||||||
++ map (f: " DynamicForward" + addressPort f) cf.dynamicForwards
|
++ 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 ];
|
meta.maintainers = [ maintainers.rycee ];
|
||||||
|
|
||||||
options.programs.ssh = {
|
options.programs.ssh = {
|
||||||
|
@ -349,7 +345,8 @@ in
|
||||||
package = mkPackageOption pkgs "openssh" {
|
package = mkPackageOption pkgs "openssh" {
|
||||||
nullable = true;
|
nullable = true;
|
||||||
default = null;
|
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 {
|
forwardAgent = mkOption {
|
||||||
|
@ -418,7 +415,7 @@ in
|
||||||
|
|
||||||
controlMaster = mkOption {
|
controlMaster = mkOption {
|
||||||
default = "no";
|
default = "no";
|
||||||
type = types.enum ["yes" "no" "ask" "auto" "autoask"];
|
type = types.enum [ "yes" "no" "ask" "auto" "autoask" ];
|
||||||
description = ''
|
description = ''
|
||||||
Configure sharing of multiple sessions over a single network connection.
|
Configure sharing of multiple sessions over a single network connection.
|
||||||
'';
|
'';
|
||||||
|
@ -451,7 +448,7 @@ in
|
||||||
|
|
||||||
extraOptionOverrides = mkOption {
|
extraOptionOverrides = mkOption {
|
||||||
type = types.attrsOf types.str;
|
type = types.attrsOf types.str;
|
||||||
default = {};
|
default = { };
|
||||||
description = ''
|
description = ''
|
||||||
Extra SSH configuration options that take precedence over any
|
Extra SSH configuration options that take precedence over any
|
||||||
host specific configuration.
|
host specific configuration.
|
||||||
|
@ -460,7 +457,7 @@ in
|
||||||
|
|
||||||
includes = mkOption {
|
includes = mkOption {
|
||||||
type = types.listOf types.str;
|
type = types.listOf types.str;
|
||||||
default = [];
|
default = [ ];
|
||||||
description = ''
|
description = ''
|
||||||
File globs of ssh config files that should be included via the
|
File globs of ssh config files that should be included via the
|
||||||
`Include` directive.
|
`Include` directive.
|
||||||
|
@ -473,7 +470,7 @@ in
|
||||||
|
|
||||||
matchBlocks = mkOption {
|
matchBlocks = mkOption {
|
||||||
type = hm.types.dagOf matchBlockModule;
|
type = hm.types.dagOf matchBlockModule;
|
||||||
default = {};
|
default = { };
|
||||||
example = literalExpression ''
|
example = literalExpression ''
|
||||||
{
|
{
|
||||||
"john.example.com" = {
|
"john.example.com" = {
|
||||||
|
@ -499,43 +496,41 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
assertions = [
|
assertions = [{
|
||||||
{
|
assertion = let
|
||||||
assertion =
|
# `builtins.any`/`lib.lists.any` does not return `true` if there are no elements.
|
||||||
let
|
any' = pred: items: if items == [ ] then true else any pred items;
|
||||||
# `builtins.any`/`lib.lists.any` does not return `true` if there are no elements.
|
# Check that if `entry.address` is defined, and is a path, that `entry.port` has not
|
||||||
any' = pred: items: if items == [] then true else any pred items;
|
# been defined.
|
||||||
# Check that if `entry.address` is defined, and is a path, that `entry.port` has not
|
noPathWithPort = entry:
|
||||||
# been defined.
|
entry.address != null && isPath entry.address -> entry.port == null;
|
||||||
noPathWithPort = entry: entry.address != null && isPath entry.address -> entry.port == null;
|
checkDynamic = block: any' noPathWithPort block.dynamicForwards;
|
||||||
checkDynamic = block: any' noPathWithPort block.dynamicForwards;
|
checkBindAndHost = fwd:
|
||||||
checkBindAndHost = fwd: noPathWithPort fwd.bind && noPathWithPort fwd.host;
|
noPathWithPort fwd.bind && noPathWithPort fwd.host;
|
||||||
checkLocal = block: any' checkBindAndHost block.localForwards;
|
checkLocal = block: any' checkBindAndHost block.localForwards;
|
||||||
checkRemote = block: any' checkBindAndHost block.remoteForwards;
|
checkRemote = block: any' checkBindAndHost block.remoteForwards;
|
||||||
checkMatchBlock = block: all (fn: fn block) [ checkLocal checkRemote checkDynamic ];
|
checkMatchBlock = block:
|
||||||
in any' checkMatchBlock (map (block: block.data) (builtins.attrValues cfg.matchBlocks));
|
all (fn: fn block) [ checkLocal checkRemote checkDynamic ];
|
||||||
message = "Forwarded paths cannot have ports.";
|
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.packages = optional (cfg.package != null) cfg.package;
|
||||||
|
|
||||||
home.file.".ssh/config".text =
|
home.file.".ssh/config".text = let
|
||||||
let
|
sortedMatchBlocks = hm.dag.topoSort cfg.matchBlocks;
|
||||||
sortedMatchBlocks = hm.dag.topoSort cfg.matchBlocks;
|
sortedMatchBlocksStr = builtins.toJSON sortedMatchBlocks;
|
||||||
sortedMatchBlocksStr = builtins.toJSON sortedMatchBlocks;
|
matchBlocks = if sortedMatchBlocks ? result then
|
||||||
matchBlocks =
|
sortedMatchBlocks.result
|
||||||
if sortedMatchBlocks ? result
|
else
|
||||||
then sortedMatchBlocks.result
|
abort "Dependency cycle in SSH match blocks: ${sortedMatchBlocksStr}";
|
||||||
else abort "Dependency cycle in SSH match blocks: ${sortedMatchBlocksStr}";
|
in ''
|
||||||
in ''
|
${concatStringsSep "\n"
|
||||||
${concatStringsSep "\n" (
|
((mapAttrsToList (n: v: "${n} ${v}") cfg.extraOptionOverrides)
|
||||||
(mapAttrsToList (n: v: "${n} ${v}") cfg.extraOptionOverrides)
|
|
||||||
++ (optional (cfg.includes != [ ]) ''
|
++ (optional (cfg.includes != [ ]) ''
|
||||||
Include ${concatStringsSep " " cfg.includes}
|
Include ${concatStringsSep " " cfg.includes}
|
||||||
'')
|
'') ++ (map (block: matchBlockStr block.name block.data) matchBlocks))}
|
||||||
++ (map (block: matchBlockStr block.name block.data) matchBlocks)
|
|
||||||
)}
|
|
||||||
|
|
||||||
Host *
|
Host *
|
||||||
ForwardAgent ${lib.hm.booleans.yesNo cfg.forwardAgent}
|
ForwardAgent ${lib.hm.booleans.yesNo cfg.forwardAgent}
|
||||||
|
@ -549,11 +544,13 @@ in
|
||||||
ControlPath ${cfg.controlPath}
|
ControlPath ${cfg.controlPath}
|
||||||
ControlPersist ${cfg.controlPersist}
|
ControlPersist ${cfg.controlPersist}
|
||||||
|
|
||||||
${replaceStrings ["\n"] ["\n "] cfg.extraConfig}
|
${replaceStrings [ "\n" ] [ "\n " ] cfg.extraConfig}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
warnings = mapAttrsToList
|
warnings = mapAttrsToList (n: v: ''
|
||||||
(n: v: "The SSH config match block `programs.ssh.matchBlocks.${n}` sets both of the host and match options.\nThe match option takes precedence.")
|
The SSH config match block `programs.ssh.matchBlocks.${n}` sets both of the host and match options.
|
||||||
(filterAttrs (n: v: v.data.host != null && v.data.match != null) cfg.matchBlocks);
|
The match option takes precedence.'')
|
||||||
|
(filterAttrs (n: v: v.data.host != null && v.data.match != null)
|
||||||
|
cfg.matchBlocks);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{ pkgs ? import <nixpkgs> {}, enableBig ? true }:
|
{ pkgs ? import <nixpkgs> { }, enableBig ? true }:
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
|
@ -13,37 +13,33 @@ let
|
||||||
modules = import ../modules/modules.nix {
|
modules = import ../modules/modules.nix {
|
||||||
inherit lib pkgs;
|
inherit lib pkgs;
|
||||||
check = false;
|
check = false;
|
||||||
} ++ [
|
} ++ [{
|
||||||
{
|
# Bypass <nixpkgs> reference inside modules/modules.nix to make the test
|
||||||
# Bypass <nixpkgs> reference inside modules/modules.nix to make the test
|
# suite more pure.
|
||||||
# suite more pure.
|
_module.args.pkgsPath = pkgs.path;
|
||||||
_module.args.pkgsPath = pkgs.path;
|
|
||||||
|
|
||||||
# Fix impurities. Without these some of the user's environment
|
# Fix impurities. Without these some of the user's environment
|
||||||
# will leak into the tests through `builtins.getEnv`.
|
# will leak into the tests through `builtins.getEnv`.
|
||||||
xdg.enable = true;
|
xdg.enable = true;
|
||||||
home = {
|
home = {
|
||||||
username = "hm-user";
|
username = "hm-user";
|
||||||
homeDirectory = "/home/hm-user";
|
homeDirectory = "/home/hm-user";
|
||||||
stateVersion = lib.mkDefault "18.09";
|
stateVersion = lib.mkDefault "18.09";
|
||||||
};
|
};
|
||||||
|
|
||||||
# Avoid including documentation since this will cause
|
# Avoid including documentation since this will cause
|
||||||
# unnecessary rebuilds of the tests.
|
# unnecessary rebuilds of the tests.
|
||||||
manual.manpages.enable = lib.mkDefault false;
|
manual.manpages.enable = lib.mkDefault false;
|
||||||
|
|
||||||
imports = [ ./asserts.nix ./big-test.nix ./stubs.nix ];
|
imports = [ ./asserts.nix ./big-test.nix ./stubs.nix ];
|
||||||
|
|
||||||
test.enableBig = enableBig;
|
test.enableBig = enableBig;
|
||||||
}
|
}];
|
||||||
];
|
|
||||||
|
|
||||||
isDarwin = pkgs.stdenv.hostPlatform.isDarwin;
|
isDarwin = pkgs.stdenv.hostPlatform.isDarwin;
|
||||||
isLinux = pkgs.stdenv.hostPlatform.isLinux;
|
isLinux = pkgs.stdenv.hostPlatform.isLinux;
|
||||||
|
|
||||||
in
|
in import nmt {
|
||||||
|
|
||||||
import nmt {
|
|
||||||
inherit lib pkgs modules;
|
inherit lib pkgs modules;
|
||||||
testedAttrPath = [ "home" "activationPackage" ];
|
testedAttrPath = [ "home" "activationPackage" ];
|
||||||
tests = builtins.foldl' (a: b: a // (import b)) { } ([
|
tests = builtins.foldl' (a: b: a // (import b)) { } ([
|
||||||
|
@ -180,7 +176,7 @@ import nmt {
|
||||||
./modules/programs/abook
|
./modules/programs/abook
|
||||||
./modules/programs/autorandr
|
./modules/programs/autorandr
|
||||||
./modules/programs/awscli
|
./modules/programs/awscli
|
||||||
./modules/programs/beets # One test relies on services.mpd
|
./modules/programs/beets # One test relies on services.mpd
|
||||||
./modules/programs/bemenu
|
./modules/programs/bemenu
|
||||||
./modules/programs/borgmatic
|
./modules/programs/borgmatic
|
||||||
./modules/programs/boxxy
|
./modules/programs/boxxy
|
||||||
|
|
Loading…
Reference in a new issue