1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-25 11:19:47 +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 committed by Mikilio
parent 1fd55da2a1
commit 286546ec2f
No known key found for this signature in database
GPG key ID: 5B2F1A890CF33F3F
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
# to avoid merge conflicts.
excludes=(
modules/default.nix
modules/files.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
tests/default.nix
)
exclude_args=()

View file

@ -1,12 +1,9 @@
{ configuration
, pkgs
, lib ? pkgs.lib
{ configuration, pkgs, lib ? pkgs.lib
# Whether to check that each option has a matching declaration.
, check ? true
# Extra arguments passed to specialArgs.
, extraSpecialArgs ? { }
}:
, extraSpecialArgs ? { } }:
with lib;
@ -16,39 +13,33 @@ let
map (x: x.message) (filter (x: !x.assertion) cfg.assertions);
showWarnings = res:
let
f = w: x: builtins.trace "warning: ${w}" x;
in
fold f res res.config.warnings;
let f = w: x: builtins.trace "warning: ${w}" x;
in fold f res res.config.warnings;
extendedLib = import ./lib/stdlib-extended.nix lib;
hmModules =
import ./modules.nix {
hmModules = import ./modules.nix {
inherit check pkgs;
lib = extendedLib;
};
rawModule = extendedLib.evalModules {
modules = [ configuration ] ++ hmModules;
specialArgs = {
modulesPath = builtins.toString ./.;
} // extraSpecialArgs;
specialArgs = { modulesPath = builtins.toString ./.; } // extraSpecialArgs;
};
module = showWarnings (
let
module = showWarnings (let
failed = collectFailed rawModule.config;
failedStr = concatStringsSep "\n" (map (x: "- ${x}") failed);
in
if failed == []
then rawModule
else throw "\nFailed assertions:\n${failedStr}"
);
in if failed == [ ] then
rawModule
else
throw ''
in
Failed assertions:
${failedStr}'');
{
in {
inherit (module) options config;
activationPackage = module.config.home.activationPackage;
@ -57,10 +48,8 @@ in
activation-script = module.config.home.activationPackage;
newsDisplay = rawModule.config.news.display;
newsEntries =
sort (a: b: a.time > b.time) (
filter (a: a.condition) rawModule.config.news.entries
);
newsEntries = sort (a: b: a.time > b.time)
(filter (a: a.condition) rawModule.config.news.entries);
inherit (module._module.args) pkgs;
}

View file

@ -1,9 +1,9 @@
{ homeDirectory, lib, pkgs }:
let
inherit (lib) hasPrefix hm literalExpression mkDefault mkIf mkOption removePrefix types;
in
{
inherit (lib)
hasPrefix hm literalExpression mkDefault mkIf mkOption removePrefix types;
in {
# Constructs a type suitable for a `home.file` like option. The
# target path may be either absolute or relative, in which case it
# is relative the `basePath` argument (which itself must be an
@ -13,8 +13,8 @@ in
# - opt the name of the option, for self-references
# - basePathDesc docbook compatible description of the base path
# - basePath the file base path
fileType = opt: basePathDesc: basePath: types.attrsOf (types.submodule (
{ name, config, ... }: {
fileType = opt: basePathDesc: basePath:
types.attrsOf (types.submodule ({ name, config, ... }: {
options = {
enable = mkOption {
type = types.bool;
@ -27,10 +27,8 @@ in
target = mkOption {
type = types.str;
apply = p:
let
absPath = if hasPrefix "/" p then p else "${basePath}/${p}";
in
removePrefix (homeDirectory + "/") absPath;
let absPath = if hasPrefix "/" p then p else "${basePath}/${p}";
in removePrefix (homeDirectory + "/") absPath;
defaultText = literalExpression "name";
description = ''
Path to target file relative to ${basePathDesc}.
@ -113,14 +111,11 @@ in
config = {
target = mkDefault name;
source = mkIf (config.text != null) (
mkDefault (pkgs.writeTextFile {
source = mkIf (config.text != null) (mkDefault (pkgs.writeTextFile {
inherit (config) text;
executable = config.executable == true; # can be null
name = hm.strings.storeFileName name;
})
);
}));
};
}
));
}));
}

View file

@ -42,14 +42,10 @@ let
};
};
config = {
id = mkDefault (builtins.hashString "sha256" config.message);
};
config = { id = mkDefault (builtins.hashString "sha256" config.message); };
});
in
{
in {
meta.maintainers = [ maintainers.rycee ];
options = {
@ -97,9 +93,8 @@ in
};
config = {
news.json.output = pkgs.writeText "hm-news.json" (builtins.toJSON {
inherit (cfg) display entries;
});
news.json.output = pkgs.writeText "hm-news.json"
(builtins.toJSON { inherit (cfg) display entries; });
# Add news entries in chronological order (i.e., latest time
# 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";
condition = hostPlatform.isLinux && config.services.screen-locker.enable;
condition = hostPlatform.isLinux
&& config.services.screen-locker.enable;
message = ''
'xautolock' is now optional in 'services.screen-locker', and the
'services.screen-locker' options have been reorganized for clarity.

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)`
@ -142,10 +142,7 @@ 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;
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.
@ -230,10 +227,7 @@ 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;
apply = p: if p == null then [ ] else if isString p then [ p ] else p;
description = ''
Specifies files from which the user certificate is read.
'';
@ -305,15 +299,17 @@ let
# 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.forwardAgent != null)
" ForwardAgent ${lib.hm.booleans.yesNo cf.forwardAgent}"
++ optional cf.forwardX11 " ForwardX11 yes"
++ optional cf.forwardX11Trusted " ForwardX11Trusted yes"
++ optional cf.identitiesOnly " IdentitiesOnly yes"
@ -326,21 +322,21 @@ let
" 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.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 {
@ -499,43 +496,41 @@ in
};
config = mkIf cfg.enable {
assertions = [
{
assertion =
let
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;
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;
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));
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
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}";
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)
${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}
@ -552,8 +547,10 @@ in
${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);
};
}

View file

@ -13,8 +13,7 @@ let
modules = import ../modules/modules.nix {
inherit lib pkgs;
check = false;
} ++ [
{
} ++ [{
# Bypass <nixpkgs> reference inside modules/modules.nix to make the test
# suite more pure.
_module.args.pkgsPath = pkgs.path;
@ -35,15 +34,12 @@ let
imports = [ ./asserts.nix ./big-test.nix ./stubs.nix ];
test.enableBig = enableBig;
}
];
}];
isDarwin = pkgs.stdenv.hostPlatform.isDarwin;
isLinux = pkgs.stdenv.hostPlatform.isLinux;
in
import nmt {
in import nmt {
inherit lib pkgs modules;
testedAttrPath = [ "home" "activationPackage" ];
tests = builtins.foldl' (a: b: a // (import b)) { } ([