From 65e7143039402ddf9f1be37d31f1e0172b4f4f74 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Fri, 12 Jul 2024 03:50:54 +0200 Subject: [PATCH 1/6] nix-info: Format files with nixfmt This is a rare case of a Nix file actually ending up in the build result. We reformat this now, causing a rebuild, so that we won't cause a rebuild in the treewide reformatting PR. --- pkgs/tools/nix/info/multiuser.nix | 21 ++++++++++----------- pkgs/tools/nix/info/relaxedsandbox.nix | 5 +++-- pkgs/tools/nix/info/sandbox.nix | 17 ++++++++--------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/pkgs/tools/nix/info/multiuser.nix b/pkgs/tools/nix/info/multiuser.nix index 827d529876733f2..bfb110c67557f09 100644 --- a/pkgs/tools/nix/info/multiuser.nix +++ b/pkgs/tools/nix/info/multiuser.nix @@ -1,12 +1,11 @@ let - pkgs = import {}; -in pkgs.runCommand "diagnostics-multiuser" - { } - '' - set -x - # no cache: ${toString builtins.currentTime} - # For reproducibility, nix always uses nixbld group: - # https://github.com/NixOS/nix/blob/1dd29d7aebae706f3e90a18bbfae727f2ed03c70/src/libstore/build.cc#L1896-L1908 - test "$(groups)" == "nixbld" - touch $out - '' + pkgs = import { }; +in +pkgs.runCommand "diagnostics-multiuser" { } '' + set -x + # no cache: ${toString builtins.currentTime} + # For reproducibility, nix always uses nixbld group: + # https://github.com/NixOS/nix/blob/1dd29d7aebae706f3e90a18bbfae727f2ed03c70/src/libstore/build.cc#L1896-L1908 + test "$(groups)" == "nixbld" + touch $out +'' diff --git a/pkgs/tools/nix/info/relaxedsandbox.nix b/pkgs/tools/nix/info/relaxedsandbox.nix index 625a6ecc39e07b5..9d5d1ce7d0fac24 100644 --- a/pkgs/tools/nix/info/relaxedsandbox.nix +++ b/pkgs/tools/nix/info/relaxedsandbox.nix @@ -1,6 +1,7 @@ let - pkgs = import {}; -in pkgs.runCommand "diagnostics-sandbox" + pkgs = import { }; +in +pkgs.runCommand "diagnostics-sandbox" { __noChroot = true; } diff --git a/pkgs/tools/nix/info/sandbox.nix b/pkgs/tools/nix/info/sandbox.nix index fa4288c2f9442b1..f7237f5ecc8f83b 100644 --- a/pkgs/tools/nix/info/sandbox.nix +++ b/pkgs/tools/nix/info/sandbox.nix @@ -1,10 +1,9 @@ let - pkgs = import {}; -in pkgs.runCommand "diagnostics-sandbox" - { } - '' - set -x - # no cache: ${toString builtins.currentTime} - test -d "$(dirname "$out")/../var/nix" - touch $out - '' + pkgs = import { }; +in +pkgs.runCommand "diagnostics-sandbox" { } '' + set -x + # no cache: ${toString builtins.currentTime} + test -d "$(dirname "$out")/../var/nix" + touch $out +'' From 323012ced25175532e2aa979f1cd6243f7a8ae92 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Fri, 12 Jul 2024 04:14:07 +0200 Subject: [PATCH 2/6] vimPluginsUpdater: Format files with nixfmt This is a rare case of a Nix file actually ending up in the build result. We reformat this now, causing a rebuild, so that we won't cause a rebuild in the treewide reformatting PR. --- .../editors/vim/plugins/get-plugins.nix | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/pkgs/applications/editors/vim/plugins/get-plugins.nix b/pkgs/applications/editors/vim/plugins/get-plugins.nix index 06ed71f379240fe..6c587a94821f445 100644 --- a/pkgs/applications/editors/vim/plugins/get-plugins.nix +++ b/pkgs/applications/editors/vim/plugins/get-plugins.nix @@ -1,19 +1,28 @@ -with import {}; +with import { }; let - inherit (vimUtils.override {inherit vim;}) buildVimPlugin; + inherit (vimUtils.override { inherit vim; }) buildVimPlugin; inherit (neovimUtils) buildNeovimPlugin; generated = callPackage { inherit buildNeovimPlugin buildVimPlugin; - } {} {}; - hasChecksum = value: - lib.isAttrs value && lib.hasAttrByPath ["src" "outputHash"] value; - getChecksum = name: value: - if hasChecksum value then { - submodules = value.src.fetchSubmodules or false; - sha256 = value.src.outputHash; - rev = value.src.rev; - } else null; + } { } { }; + hasChecksum = + value: + lib.isAttrs value + && lib.hasAttrByPath [ + "src" + "outputHash" + ] value; + getChecksum = + name: value: + if hasChecksum value then + { + submodules = value.src.fetchSubmodules or false; + sha256 = value.src.outputHash; + rev = value.src.rev; + } + else + null; checksums = lib.mapAttrs getChecksum generated; in - lib.filterAttrs (n: v: v != null) checksums +lib.filterAttrs (n: v: v != null) checksums From ea17c502d29f8d24958f41b4217aafd1a413a28a Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Fri, 12 Jul 2024 03:51:31 +0200 Subject: [PATCH 3/6] tests.trivial-builders: Prevent rebuilds when Nix files change There's no need to use a Nix file in the path here. By using a different file we won't cause rebuilds when we change the Nix file, in particular also when the Nix file is reformatted. --- pkgs/build-support/trivial-builders/test/references/apath.txt | 1 + .../trivial-builders/test/references/samples.nix | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 pkgs/build-support/trivial-builders/test/references/apath.txt diff --git a/pkgs/build-support/trivial-builders/test/references/apath.txt b/pkgs/build-support/trivial-builders/test/references/apath.txt new file mode 100644 index 000000000000000..1258b0506057cef --- /dev/null +++ b/pkgs/build-support/trivial-builders/test/references/apath.txt @@ -0,0 +1 @@ +Just some text diff --git a/pkgs/build-support/trivial-builders/test/references/samples.nix b/pkgs/build-support/trivial-builders/test/references/samples.nix index 3afb970c08aebab..5bafdcd8e7d072b 100644 --- a/pkgs/build-support/trivial-builders/test/references/samples.nix +++ b/pkgs/build-support/trivial-builders/test/references/samples.nix @@ -18,8 +18,8 @@ norefsDup = writeText "hi" "hello"; helloRef = writeText "hi" "hello ${hello}"; helloRefDup = writeText "hi" "hello ${hello}"; - path = ./samples.nix; - pathLike.outPath = ./samples.nix; + path = ./apath.txt; + pathLike.outPath = ./apath.txt; helloFigletRef = writeText "hi" "hello ${hello} ${figlet}"; selfRef = runCommand "self-ref-1" { } "echo $out >$out"; selfRef2 = runCommand "self-ref-2" { } ''echo "${figlet}, $out" >$out''; From 7cb66fd5791ac95863fa9e13c419af5b25984e90 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Fri, 12 Jul 2024 04:10:29 +0200 Subject: [PATCH 4/6] tests.makeBinaryWrapper: Prevent rebuilds when Nix files change The source included way more files than it really needed. This commit limits it to exactly those it needs. This also makes sure that no rebuild is necessary when any Nix file changes, in particular useful when we reformat the Nix files. --- pkgs/test/make-binary-wrapper/default.nix | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pkgs/test/make-binary-wrapper/default.nix b/pkgs/test/make-binary-wrapper/default.nix index 4c6fffd100a726f..0d699900cf6d16b 100644 --- a/pkgs/test/make-binary-wrapper/default.nix +++ b/pkgs/test/make-binary-wrapper/default.nix @@ -15,16 +15,25 @@ let makeGoldenTest = testname: runCommand "make-binary-wrapper-test-${testname}" env '' mkdir -p tmp/foo # for the chdir test - params=$(<"${./.}/${testname}.cmdline") + source=${lib.fileset.toSource { + root = ./.; + fileset = lib.fileset.unions [ + (./. + "/${testname}.cmdline") + (./. + "/${testname}.c") + (lib.fileset.maybeMissing (./. + "/${testname}.env")) + ]; + }} + + params=$(<"$source/${testname}.cmdline") eval "makeCWrapper /send/me/flags $params" > wrapper.c - diff wrapper.c "${./.}/${testname}.c" + diff wrapper.c "$source/${testname}.c" - if [ -f "${./.}/${testname}.env" ]; then + if [ -f "$source/${testname}.env" ]; then eval "makeWrapper ${envCheck} wrapped $params" env -i ./wrapped > env.txt sed "s#SUBST_ARGV0#${envCheck}#;s#SUBST_CWD#$PWD#" \ - "${./.}/${testname}.env" > golden-env.txt + "$source/${testname}.env" > golden-env.txt if ! diff env.txt golden-env.txt; then echo "env/argv should be:" cat golden-env.txt From e6d45588ad829d825156d30b5b9c5642e45b37f9 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Fri, 12 Jul 2024 20:41:18 +0200 Subject: [PATCH 5/6] tests.haskell.cabalSdist: Prevent rebuilds when Nix files change The generated file sets its own directory as the source, including the generated file itself, which causes rebuilds when that file is reformatted. We can avoid this by overriding the source with a filtered version and using that throughout the tests. See https://github.com/NixOS/nixpkgs/pull/320572 for more context --- pkgs/test/haskell/cabalSdist/default.nix | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/pkgs/test/haskell/cabalSdist/default.nix b/pkgs/test/haskell/cabalSdist/default.nix index c0a9d406a503934..4432e95ab56ecb7 100644 --- a/pkgs/test/haskell/cabalSdist/default.nix +++ b/pkgs/test/haskell/cabalSdist/default.nix @@ -1,7 +1,18 @@ -{ lib, haskellPackages, runCommand }: +{ lib, haskell, haskellPackages, runCommand }: let - localRaw = haskellPackages.callPackage ./local/generated.nix {}; + src = lib.fileset.toSource { + root = ./local; + fileset = lib.fileset.unions [ + ./local/app + ./local/CHANGELOG.md + ./local/local.cabal + ]; + }; + # This prevents the source from depending on the formatting of the ./local/generated.nix file + localRaw = haskell.lib.compose.overrideSrc { + inherit src; + } (haskellPackages.callPackage ./local/generated.nix {}); in lib.recurseIntoAttrs rec { @@ -20,14 +31,14 @@ lib.recurseIntoAttrs rec { assumptionLocalHasDirectReference = runCommand "localHasDirectReference" { drvPath = builtins.unsafeDiscardOutputDependency localRaw.drvPath; } '' - grep ${./local} $drvPath >/dev/null + grep ${src} $drvPath >/dev/null touch $out ''; localHasNoDirectReference = runCommand "localHasNoDirectReference" { drvPath = builtins.unsafeDiscardOutputDependency localFromCabalSdist.drvPath; } '' - grep -v ${./local} $drvPath >/dev/null + grep -v ${src} $drvPath >/dev/null touch $out ''; } From 8f425c25adc365ccddab932cae96cdbed96c115b Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Fri, 12 Jul 2024 03:20:47 +0200 Subject: [PATCH 6/6] lib/tests: Format a file with nixfmt And fix locations to not break the test. This is a rare case where another change is required after formatting. We do this in a separate commit so that we don't need to do it in the treewide reformatting PR. --- lib/tests/modules.sh | 18 ++++++------- lib/tests/modules/declaration-positions.nix | 30 +++++++++++++-------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index 3a23766a17f5366..3301a3d987ee88a 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -542,21 +542,21 @@ checkConfigOutput '^"pear\\npear"$' config.twice.raw ./merge-module-with-key.nix # Declaration positions # Line should be present for direct options -checkConfigOutput '^10$' options.imported.line10.declarationPositions.0.line ./declaration-positions.nix -checkConfigOutput '/declaration-positions.nix"$' options.imported.line10.declarationPositions.0.file ./declaration-positions.nix +checkConfigOutput '^14$' options.imported.line14.declarationPositions.0.line ./declaration-positions.nix +checkConfigOutput '/declaration-positions.nix"$' options.imported.line14.declarationPositions.0.file ./declaration-positions.nix # Generated options may not have line numbers but they will at least get the # right file -checkConfigOutput '/declaration-positions.nix"$' options.generated.line18.declarationPositions.0.file ./declaration-positions.nix -checkConfigOutput '^null$' options.generated.line18.declarationPositions.0.line ./declaration-positions.nix +checkConfigOutput '/declaration-positions.nix"$' options.generated.line22.declarationPositions.0.file ./declaration-positions.nix +checkConfigOutput '^null$' options.generated.line22.declarationPositions.0.line ./declaration-positions.nix # Submodules don't break it -checkConfigOutput '^39$' config.submoduleLine34.submodDeclLine39.0.line ./declaration-positions.nix -checkConfigOutput '/declaration-positions.nix"$' config.submoduleLine34.submodDeclLine39.0.file ./declaration-positions.nix +checkConfigOutput '^45$' config.submoduleLine38.submodDeclLine45.0.line ./declaration-positions.nix +checkConfigOutput '/declaration-positions.nix"$' config.submoduleLine38.submodDeclLine45.0.file ./declaration-positions.nix # New options under freeform submodules get collected into the parent submodule # (consistent with .declarations behaviour, but weird; notably appears in system.build) -checkConfigOutput '^34|23$' options.submoduleLine34.declarationPositions.0.line ./declaration-positions.nix -checkConfigOutput '^34|23$' options.submoduleLine34.declarationPositions.1.line ./declaration-positions.nix +checkConfigOutput '^38|27$' options.submoduleLine38.declarationPositions.0.line ./declaration-positions.nix +checkConfigOutput '^38|27$' options.submoduleLine38.declarationPositions.1.line ./declaration-positions.nix # nested options work -checkConfigOutput '^30$' options.nested.nestedLine30.declarationPositions.0.line ./declaration-positions.nix +checkConfigOutput '^34$' options.nested.nestedLine34.declarationPositions.0.line ./declaration-positions.nix cat <