nixpkgs/pkgs/top-level/nixpkgs-basic-release-checks.nix
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 b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00

106 lines
3.3 KiB
Nix

{
supportedSystems,
nixpkgs,
pkgs,
}:
pkgs.runCommand "nixpkgs-release-checks"
{
src = nixpkgs;
buildInputs = [ pkgs.nix ];
requiredSystemFeatures = [ "big-parallel" ]; # 1 thread but ~10G RAM; see #227945
}
''
set -o pipefail
export NIX_STORE_DIR=$TMPDIR/store
export NIX_STATE_DIR=$TMPDIR/state
export NIX_PATH=nixpkgs=$TMPDIR/barf.nix
opts=()
nix-store --init
echo 'abort "Illegal use of <nixpkgs> in Nixpkgs."' > $TMPDIR/barf.nix
# Make sure that Nixpkgs does not use <nixpkgs>.
badFiles=$(find $src/pkgs -type f -name '*.nix' -print | xargs grep -l '^[^#]*<nixpkgs/' || true)
if [[ -n $badFiles ]]; then
echo "Nixpkgs is not allowed to use <nixpkgs> to refer to itself."
echo "The offending files: $badFiles"
exit 1
fi
# Make sure that no paths collide on case-preserving or case-insensitive filesysytems.
conflictingPaths=$(find $src | awk '{ print $1 " " tolower($1) }' | sort -k2 | uniq -D -f 1 | cut -d ' ' -f 1)
if [[ -n $conflictingPaths ]]; then
echo "Files in nixpkgs must not vary only by case"
echo "The offending paths: $conflictingPaths"
exit 1
fi
src2=$TMPDIR/foo
cp -rd $src $src2
# Check that all-packages.nix evaluates on a number of platforms without any warnings.
for platform in ${pkgs.lib.concatStringsSep " " supportedSystems}; do
echo "checking Nixpkgs on $platform"
# To get a call trace; see https://nixos.org/manual/nixpkgs/stable/#function-library-lib.trivial.warn
# Relies on impure eval
export NIX_ABORT_ON_WARN=true
# Suppress GC warnings
export GC_LARGE_ALLOC_WARN_INTERVAL=100000
set +e
(
set -x
nix-env -f $src \
--show-trace --argstr system "$platform" \
--arg config '{ allowAliases = false; }' \
--option experimental-features 'no-url-literals' \
-qa --drv-path --system-filter \* --system \
"''${opts[@]}" 2> eval-warnings.log > packages1
)
rc=$?
set -e
if [ "$rc" != "0" ]; then
cat eval-warnings.log
exit $rc
fi
s1=$(sha1sum packages1 | cut -c1-40)
nix-env -f $src2 \
--show-trace --argstr system "$platform" \
--arg config '{ allowAliases = false; }' \
--option experimental-features 'no-url-literals' \
-qa --drv-path --system-filter \* --system \
"''${opts[@]}" > packages2
s2=$(sha1sum packages2 | cut -c1-40)
if [[ $s1 != $s2 ]]; then
echo "Nixpkgs evaluation depends on Nixpkgs path"
diff packages1 packages2
exit 1
fi
# Catch any trace calls not caught by NIX_ABORT_ON_WARN (lib.warn)
if [ -s eval-warnings.log ]; then
echo "Nixpkgs on $platform evaluated with warnings, aborting"
echo "Warnings logged:"
cat eval-warnings.log
exit 1
fi
nix-env -f $src \
--show-trace --argstr system "$platform" \
--arg config '{ allowAliases = false; }' \
--option experimental-features 'no-url-literals' \
-qa --drv-path --system-filter \* --system --meta --xml \
"''${opts[@]}" > /dev/null
done
touch $out
''