mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 19:46:05 +01:00
treewide: reformat nixfmt-rfc-style
Reformat repository using new nixfmt-rfc-style.
This commit is contained in:
parent
5df48c4255
commit
cba2f9ce95
1051 changed files with 37028 additions and 26594 deletions
|
|
@ -1,66 +1,85 @@
|
|||
{ lib }: rec {
|
||||
{ lib }:
|
||||
rec {
|
||||
mkNushellInline = expr: lib.setType "nushell-inline" { inherit expr; };
|
||||
|
||||
isNushellInline = lib.isType "nushell-inline";
|
||||
|
||||
toNushell = { indent ? "", multiline ? true, asBindings ? false, }@args:
|
||||
toNushell =
|
||||
{
|
||||
indent ? "",
|
||||
multiline ? true,
|
||||
asBindings ? false,
|
||||
}@args:
|
||||
v:
|
||||
let
|
||||
innerIndent = "${indent} ";
|
||||
introSpace = if multiline then ''
|
||||
introSpace =
|
||||
if multiline then
|
||||
''
|
||||
|
||||
${innerIndent}'' else
|
||||
" ";
|
||||
outroSpace = if multiline then ''
|
||||
${innerIndent}''
|
||||
else
|
||||
" ";
|
||||
outroSpace =
|
||||
if multiline then
|
||||
''
|
||||
|
||||
${indent}'' else
|
||||
" ";
|
||||
${indent}''
|
||||
else
|
||||
" ";
|
||||
innerArgs = args // {
|
||||
indent = if asBindings then indent else innerIndent;
|
||||
asBindings = false;
|
||||
};
|
||||
concatItems = lib.concatStringsSep introSpace;
|
||||
|
||||
generatedBindings = assert lib.assertMsg (badVarNames == [ ])
|
||||
"Bad Nushell variable names: ${
|
||||
lib.generators.toPretty { } badVarNames
|
||||
}";
|
||||
lib.concatStrings (lib.mapAttrsToList (key: value: ''
|
||||
${indent}let ${key} = ${toNushell innerArgs value}
|
||||
'') v);
|
||||
generatedBindings =
|
||||
assert lib.assertMsg (badVarNames == [ ])
|
||||
"Bad Nushell variable names: ${lib.generators.toPretty { } badVarNames}";
|
||||
lib.concatStrings (
|
||||
lib.mapAttrsToList (key: value: ''
|
||||
${indent}let ${key} = ${toNushell innerArgs value}
|
||||
'') v
|
||||
);
|
||||
|
||||
isBadVarName = name:
|
||||
isBadVarName =
|
||||
name:
|
||||
# Extracted from https://github.com/nushell/nushell/blob/ebc7b80c23f777f70c5053cca428226b3fe00d30/crates/nu-parser/src/parser.rs#L33
|
||||
# Variables with numeric or even empty names are allowed. The only requisite is not containing any of the following characters
|
||||
let invalidVariableCharacters = ".[({+-*^/=!<>&|";
|
||||
in lib.match "^[$]?[^${lib.escapeRegex invalidVariableCharacters}]+$"
|
||||
name == null;
|
||||
let
|
||||
invalidVariableCharacters = ".[({+-*^/=!<>&|";
|
||||
in
|
||||
lib.match "^[$]?[^${lib.escapeRegex invalidVariableCharacters}]+$" name == null;
|
||||
badVarNames = lib.filter isBadVarName (builtins.attrNames v);
|
||||
in if asBindings then
|
||||
in
|
||||
if asBindings then
|
||||
generatedBindings
|
||||
else if v == null then
|
||||
"null"
|
||||
else if lib.isInt v || lib.isFloat v || lib.isString v || lib.isBool v then
|
||||
lib.strings.toJSON v
|
||||
else if lib.isList v then
|
||||
(if v == [ ] then
|
||||
"[]"
|
||||
else
|
||||
"[${introSpace}${
|
||||
concatItems (map (value: "${toNushell innerArgs value}") v)
|
||||
}${outroSpace}]")
|
||||
(
|
||||
if v == [ ] then
|
||||
"[]"
|
||||
else
|
||||
"[${introSpace}${concatItems (map (value: "${toNushell innerArgs value}") v)}${outroSpace}]"
|
||||
)
|
||||
else if lib.isAttrs v then
|
||||
(if isNushellInline v then
|
||||
"(${v.expr})"
|
||||
else if v == { } then
|
||||
"{}"
|
||||
else if lib.isDerivation v then
|
||||
toString v
|
||||
else
|
||||
"{${introSpace}${
|
||||
concatItems (lib.mapAttrsToList (key: value:
|
||||
"${lib.strings.toJSON key}: ${toNushell innerArgs value}") v)
|
||||
}${outroSpace}}")
|
||||
(
|
||||
if isNushellInline v then
|
||||
"(${v.expr})"
|
||||
else if v == { } then
|
||||
"{}"
|
||||
else if lib.isDerivation v then
|
||||
toString v
|
||||
else
|
||||
"{${introSpace}${
|
||||
concatItems (
|
||||
lib.mapAttrsToList (key: value: "${lib.strings.toJSON key}: ${toNushell innerArgs value}") v
|
||||
)
|
||||
}${outroSpace}}"
|
||||
)
|
||||
else
|
||||
abort "nushell.toNushell: type ${lib.typeOf v} is unsupported";
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue