1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-23 03:29:45 +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

6
format
View file

@ -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=()

View file

@ -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 "warning: ${w}" x;
f = w: x: builtins.trace "warning: ${w}" 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 in if failed == [ ] then
if failed == [] rawModule
then rawModule else
else throw "\nFailed assertions:\n${failedStr}" throw ''
);
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;
} }

View file

@ -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;
}) }));
);
}; };
} }));
));
} }

View file

@ -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.

View file

@ -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)`
@ -142,10 +142,7 @@ 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.
@ -230,10 +227,7 @@ 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.
''; '';
@ -305,15 +299,17 @@ let
# 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)
" ForwardAgent ${lib.hm.booleans.yesNo cf.forwardAgent}"
++ optional cf.forwardX11 " ForwardX11 yes" ++ optional cf.forwardX11 " ForwardX11 yes"
++ optional cf.forwardX11Trusted " ForwardX11Trusted yes" ++ optional cf.forwardX11Trusted " ForwardX11Trusted yes"
++ optional cf.identitiesOnly " IdentitiesOnly yes" ++ optional cf.identitiesOnly " IdentitiesOnly yes"
@ -326,21 +322,21 @@ let
" 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)
" Compression ${lib.hm.booleans.yesNo cf.compression}"
++ optional (!cf.checkHostIP) " CheckHostIP no" ++ optional (!cf.checkHostIP) " CheckHostIP no"
++ optional (cf.proxyCommand != null) " ProxyCommand ${cf.proxyCommand}" ++ optional (cf.proxyCommand != null) " ProxyCommand ${cf.proxyCommand}"
++ optional (cf.proxyJump != null) " ProxyJump ${cf.proxyJump}" ++ 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 {
@ -499,43 +496,41 @@ in
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
assertions = [ assertions = [{
{ assertion = let
assertion =
let
# `builtins.any`/`lib.lists.any` does not return `true` if there are no elements. # `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; 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 # Check that if `entry.address` is defined, and is a path, that `entry.port` has not
# been defined. # been defined.
noPathWithPort = entry: 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: noPathWithPort fwd.bind && noPathWithPort fwd.host; checkBindAndHost = fwd:
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 ];
in any' checkMatchBlock
(map (block: block.data) (builtins.attrValues cfg.matchBlocks));
message = "Forwarded paths cannot have ports."; 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 = matchBlocks = if sortedMatchBlocks ? result then
if sortedMatchBlocks ? result sortedMatchBlocks.result
then sortedMatchBlocks.result else
else abort "Dependency cycle in SSH match blocks: ${sortedMatchBlocksStr}"; 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}
@ -552,8 +547,10 @@ in
${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);
}; };
} }

View file

@ -13,8 +13,7 @@ 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;
@ -35,15 +34,12 @@ let
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)) { } ([