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 https://github.com/infinisil/treewide-nixpkgs-reformat-script/archive/a08b3a4d199c6124ac5b36a889d9099b4383463f.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
This commit is contained in:
Silvan Mosberger
2024-12-10 20:26:33 +01:00
parent b32a094368
commit 4f0dadbf38
21293 changed files with 701276 additions and 428232 deletions
@@ -1,28 +1,34 @@
{ test, lib, ...}:
{ test, lib, ... }:
{
equal = expected: actual:
equal =
expected: actual:
if actual == expected then
(test.passed "= ${toString expected}") else
(test.passed "= ${toString expected}")
else
(test.failed (
"expected '${toString expected}'(${builtins.typeOf expected})"
+ " != "+
"actual '${toString actual}'(${builtins.typeOf actual})"
"expected '${toString expected}'(${builtins.typeOf expected})"
+ " != "
+ "actual '${toString actual}'(${builtins.typeOf actual})"
));
beASet = actual:
beASet =
actual:
if builtins.isAttrs actual then
(test.passed "is a set") else
(test.passed "is a set")
else
(test.failed "is not a set, was ${builtins.typeOf actual}: ${toString actual}");
haveKeys = expected: actual:
if builtins.all
(ex: builtins.any (ac: ex == ac) (builtins.attrNames actual))
expected then
(test.passed "has expected keys") else
haveKeys =
expected: actual:
if builtins.all (ex: builtins.any (ac: ex == ac) (builtins.attrNames actual)) expected then
(test.passed "has expected keys")
else
(test.failed "keys differ: expected: [${lib.concatStringsSep ";" expected}] actual: [${lib.concatStringsSep ";" (builtins.attrNames actual)}]");
havePrefix = expected: actual:
havePrefix =
expected: actual:
if lib.hasPrefix expected actual then
(test.passed "has prefix '${expected}'") else
(test.passed "has prefix '${expected}'")
else
(test.failed "prefix '${expected}' not found in '${actual}'");
}
@@ -1,11 +1,17 @@
/*
Run with:
nix-build -E 'with import <nixpkgs> { }; callPackage ./test.nix {}' --show-trace; and cat result
Run with:
nix-build -E 'with import <nixpkgs> { }; callPackage ./test.nix {}' --show-trace; and cat result
Confusingly, the ideal result ends with something like:
error: build of /nix/store/3245f3dcl2wxjs4rci7n069zjlz8qg85-test-results.tap.drv failed
Confusingly, the ideal result ends with something like:
error: build of /nix/store/3245f3dcl2wxjs4rci7n069zjlz8qg85-test-results.tap.drv failed
*/
{ writeText, lib, callPackage, testFiles, ruby }@defs:
{
writeText,
lib,
callPackage,
testFiles,
ruby,
}@defs:
let
testTools = rec {
test = import ./testing.nix;
@@ -17,4 +23,4 @@ let
results = builtins.concatLists (map (file: callPackage file testTools) testFiles);
in
writeText "test-results.tap" (tap.output results)
writeText "test-results.tap" (tap.output results)
+44 -18
View File
@@ -1,15 +1,41 @@
{ stdenv, lib, ruby, callPackage, ... }:
{
stdenv,
lib,
ruby,
callPackage,
...
}:
let
mkDerivation = {name, ...}@argSet:
derivation {
inherit name;
text = (builtins.toJSON (lib.filterAttrs ( n: v: builtins.any (x: x == n) ["name" "system"]) argSet));
builder = stdenv.shell;
args = [ "-c" "echo $(<$textPath) > $out"];
system = stdenv.hostPlatform.system;
passAsFile = ["text"];
};
fetchurl = {url?"", urls ? [],...}: "fetchurl:${if urls == [] then url else builtins.head urls}";
mkDerivation =
{ name, ... }@argSet:
derivation {
inherit name;
text = (
builtins.toJSON (
lib.filterAttrs (
n: v:
builtins.any (x: x == n) [
"name"
"system"
]
) argSet
)
);
builder = stdenv.shell;
args = [
"-c"
"echo $(<$textPath) > $out"
];
system = stdenv.hostPlatform.system;
passAsFile = [ "text" ];
};
fetchurl =
{
url ? "",
urls ? [ ],
...
}:
"fetchurl:${if urls == [ ] then url else builtins.head urls}";
stdenv' = stdenv // {
inherit mkDerivation;
@@ -20,11 +46,11 @@ let
stubbed = true;
};
in
{
{
ruby = ruby';
buildRubyGem = callPackage ../gem {
inherit fetchurl;
ruby = ruby';
buildRubyGem = callPackage ../gem {
inherit fetchurl;
ruby = ruby';
};
stdenv = stdenv';
}
};
stdenv = stdenv';
}
@@ -1,21 +1,29 @@
with builtins;
let
withIndexes = list: genList (idx: (elemAt list idx) // {index = idx;}) (length list);
withIndexes = list: genList (idx: (elemAt list idx) // { index = idx; }) (length list);
testLine = report: "${okStr report} ${toString (report.index + 1)} ${report.description}" + testDirective report + testYaml report;
testLine =
report:
"${okStr report} ${toString (report.index + 1)} ${report.description}"
+ testDirective report
+ testYaml report;
# These are part of the TAP spec, not yet implemented.
#c.f. https://github.com/NixOS/nixpkgs/issues/27071
testDirective = report: "";
testYaml = report: "";
okStr = { result, ...}: if result == "pass" then "ok" else "not ok";
okStr = { result, ... }: if result == "pass" then "ok" else "not ok";
in
{
output = reports: ''
{
output =
reports:
''
TAP version 13
1..${toString (length reports)}'' + (foldl' (l: r: l + "\n" + r) "" (map testLine (withIndexes reports))) + ''
1..${toString (length reports)}''
+ (foldl' (l: r: l + "\n" + r) "" (map testLine (withIndexes reports)))
+ ''
# Finished at ${toString currentTime}
'';
}
'';
}
@@ -1,27 +1,27 @@
with builtins;
let
/*
underTest = {
x = {
a = 1;
b = "2";
underTest = {
x = {
a = 1;
b = "2";
};
};
};
tests = [
(root: false)
{
x = [
(set: true)
{
a = (a: a > 1);
b = (b: b == "3");
}
];
}
];
tests = [
(root: false)
{
x = [
(set: true)
{
a = (a: a > 1);
b = (b: b == "3");
}
];
}
];
results = run "Examples" underTest tests;
results = run "Examples" underTest tests;
*/
passed = desc: {
@@ -39,24 +39,35 @@ let
description = "${name}: ${res.description}";
};
run = name: under: tests: if isList tests then
(concatLists (map (run name under) tests))
else if isAttrs tests then
(concatLists (map (
subName: run (name + "." + subName) (if hasAttr subName under then getAttr subName under else "<MISSING!>") (getAttr subName tests)
) (attrNames tests)))
else if isFunction tests then
let
res = tests under;
in
run =
name: under: tests:
if isList tests then
(concatLists (map (run name under) tests))
else if isAttrs tests then
(concatLists (
map (
subName:
run (name + "." + subName) (if hasAttr subName under then getAttr subName under else "<MISSING!>") (
getAttr subName tests
)
) (attrNames tests)
))
else if isFunction tests then
let
res = tests under;
in
if isBool res then
[
(prefixName name (if tests under then passed "passed" else failed "failed"))
]
else
[ (prefixName name res) ]
else [
failed (name ": not a function, list or set")
];
else
[
failed
(name ": not a function, list or set")
];
in
{ inherit run passed failed; }
{
inherit run passed failed;
}