Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a0943687d2a5094a6d92f25a4b6e16a76b5b7
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00

76 lines
2.3 KiB
Nix

{
lib,
writeTextFile,
}:
let
inherit (builtins) typeOf;
in
rec {
# Docs: doc/build-helpers/dev-shell-tools.chapter.md
# Tests: ./tests/default.nix
# This function closely mirrors what this Nix code does:
# https://github.com/NixOS/nix/blob/2.8.0/src/libexpr/primops.cc#L1102
# https://github.com/NixOS/nix/blob/2.8.0/src/libexpr/eval.cc#L1981-L2036
valueToString =
value:
# We can't just use `toString` on all derivation attributes because that
# would not put path literals in the closure. So we explicitly copy
# those into the store here
if typeOf value == "path" then
"${value}"
else if typeOf value == "list" then
toString (map valueToString value)
else
toString value;
# Docs: doc/build-helpers/dev-shell-tools.chapter.md
# Tests: ./tests/default.nix
# https://github.com/NixOS/nix/blob/2.8.0/src/libstore/build/local-derivation-goal.cc#L992-L1004
unstructuredDerivationInputEnv =
{ drvAttrs }:
# FIXME: this should be `normalAttrs // passAsFileAttrs`
lib.mapAttrs'
(
name: value:
let
str = valueToString value;
in
if lib.elem name (drvAttrs.passAsFile or [ ]) then
let
nameHash =
if builtins ? convertHash then
builtins.convertHash {
hash = "sha256:" + builtins.hashString "sha256" name;
toHashFormat = "nix32";
}
else
builtins.hashString "sha256" name;
basename = ".attr-${nameHash}";
in
lib.nameValuePair "${name}Path" "${
writeTextFile {
name = "shell-passAsFile-${name}";
text = str;
destination = "/${basename}";
}
}/${basename}"
else
lib.nameValuePair name str
)
(
removeAttrs drvAttrs [
# TODO: there may be more of these
"args"
]
);
# Docs: doc/build-helpers/dev-shell-tools.chapter.md
# Tests: ./tests/default.nix
derivationOutputEnv =
{ outputList, outputMap }:
# A mapping from output name to the nix store path where they should end up
# https://github.com/NixOS/nix/blob/2.8.0/src/libexpr/primops.cc#L1253
lib.genAttrs outputList (output: builtins.unsafeDiscardStringContext outputMap.${output}.outPath);
}