release: forbid use of lib.fileset in Nixpkgs (#369694)

This commit is contained in:
Silvan Mosberger 2025-01-01 06:51:48 +01:00 committed by GitHub
commit 82d084b914
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
87 changed files with 115 additions and 160 deletions

View File

@ -94,10 +94,7 @@
stdenvNoCC.mkDerivation { stdenvNoCC.mkDerivation {
name = "nixpkgs-lib-docs"; name = "nixpkgs-lib-docs";
src = lib.fileset.toSource { src = ../../lib;
root = ../..;
fileset = ../../lib;
};
nativeBuildInputs = [ nativeBuildInputs = [
nixdoc nixdoc
@ -105,6 +102,8 @@ stdenvNoCC.mkDerivation {
]; ];
installPhase = '' installPhase = ''
cd ..
export NIX_STATE_DIR=$(mktemp -d) export NIX_STATE_DIR=$(mktemp -d)
nix-instantiate --eval --strict --json ${./lib-function-locations.nix} \ nix-instantiate --eval --strict --json ${./lib-function-locations.nix} \
--arg nixpkgsPath "./." \ --arg nixpkgsPath "./." \

View File

@ -25,16 +25,22 @@ stdenvNoCC.mkDerivation (
nativeBuildInputs = [ nixos-render-docs ]; nativeBuildInputs = [ nixos-render-docs ];
src = lib.fileset.toSource { src = lib.cleanSourceWith {
root = ../.; src = ../.;
fileset = lib.fileset.unions [ filter =
(lib.fileset.fileFilter (file: file.hasExt "md" || file.hasExt "md.in") ../.) path: type:
../style.css type == "directory"
../anchor-use.js || lib.hasSuffix ".md" path
../anchor.min.js || lib.hasSuffix ".md.in" path
../manpage-urls.json || lib.elem path (
../redirects.json map toString [
]; ../style.css
../anchor-use.js
../anchor.min.js
../manpage-urls.json
../redirects.json
]
);
}; };
postPatch = '' postPatch = ''

View File

@ -14,22 +14,12 @@
extraPythonPackages ? (_: [ ]), extraPythonPackages ? (_: [ ]),
nixosTests, nixosTests,
}: }:
let
fs = lib.fileset;
in
python3Packages.buildPythonApplication { python3Packages.buildPythonApplication {
pname = "nixos-test-driver"; pname = "nixos-test-driver";
version = "1.1"; version = "1.1";
pyproject = true; pyproject = true;
src = fs.toSource { src = ./src;
root = ./.;
fileset = fs.unions [
./pyproject.toml
./test_driver
./extract-docstrings.py
];
};
build-system = with python3Packages; [ build-system = with python3Packages; [
setuptools setuptools

View File

@ -11,6 +11,6 @@ in
runCommand "nixos-test-driver-docstrings" env '' runCommand "nixos-test-driver-docstrings" env ''
mkdir $out mkdir $out
python3 ${./extract-docstrings.py} ${./test_driver/machine.py} \ python3 ${./src/extract-docstrings.py} ${./src/test_driver/machine.py} \
> $out/machine-methods.md > $out/machine-methods.md
'' ''

View File

@ -2,6 +2,7 @@
{ {
lib, lib,
stdenv, stdenv,
runCommand,
shellcheck, shellcheck,
}: }:
@ -10,7 +11,7 @@
# Tests: ./tests.nix # Tests: ./tests.nix
{ src }: { src }:
let let
inherit (lib) fileset pathType isPath; inherit (lib) pathType isPath;
in in
stdenv.mkDerivation { stdenv.mkDerivation {
name = "run-shellcheck"; name = "run-shellcheck";
@ -18,10 +19,10 @@ stdenv.mkDerivation {
if if
isPath src && pathType src == "regular" # note that for strings this would have been IFD, which we prefer to avoid isPath src && pathType src == "regular" # note that for strings this would have been IFD, which we prefer to avoid
then then
fileset.toSource { runCommand "testers-shellcheck-src" { } ''
root = dirOf src; mkdir $out
fileset = src; cp ${src} $out
} ''
else else
src; src;
nativeBuildInputs = [ shellcheck ]; nativeBuildInputs = [ shellcheck ];

View File

@ -6,9 +6,6 @@
testers, testers,
runCommand, runCommand,
}: }:
let
inherit (lib) fileset;
in
lib.recurseIntoAttrs { lib.recurseIntoAttrs {
example-dir = example-dir =
@ -16,12 +13,7 @@ lib.recurseIntoAttrs {
{ {
failure = testers.testBuildFailure ( failure = testers.testBuildFailure (
testers.shellcheck { testers.shellcheck {
src = fileset.toSource { src = ./src;
root = ./.;
fileset = fileset.unions [
./example.sh
];
};
} }
); );
} }
@ -37,7 +29,7 @@ lib.recurseIntoAttrs {
{ {
failure = testers.testBuildFailure ( failure = testers.testBuildFailure (
testers.shellcheck { testers.shellcheck {
src = ./example.sh; src = ./src/example.sh;
} }
); );
} }

View File

@ -1,25 +1,19 @@
{ {
callPackage, callPackage,
lib, nix-gitignore,
python3Packages, python3Packages,
}: }:
let let
inherit (lib) fileset;
helpers = callPackage ./helpers.nix { }; helpers = callPackage ./helpers.nix { };
pythonPackages = python3Packages; pythonPackages = python3Packages;
in in
pythonPackages.buildPythonApplication { pythonPackages.buildPythonApplication {
version = "0.1.0"; version = "0.1.0";
pname = "flatten-references-graph"; pname = "flatten-references-graph";
src = fileset.toSource { # Note: this uses only ./src/.gitignore
root = ./src; src = nix-gitignore.gitignoreSource [ ] ./src;
fileset = fileset.unions [
./src/.flake8
./src/flatten_references_graph
./src/setup.py
];
};
propagatedBuildInputs = with pythonPackages; [ propagatedBuildInputs = with pythonPackages; [
igraph igraph

View File

@ -14,6 +14,6 @@ Suggested additional ``buildInputs``
To update this package To update this package
====================== ======================
#. Bump the ``./package.json`` version pin #. Bump the ``./manifests/package.json`` version pin
#. Run ``nix-shell -p nodejs --command "npm i --package-lock-only"`` #. Run ``(cd manifests && nix-shell -p nodejs --command "npm i --package-lock-only")``
#. Update ``npmDeps.hash`` in the ``package.nix`` #. Update ``npmDeps.hash`` in the ``package.nix``

View File

@ -8,7 +8,7 @@
let let
inherit (lib) fileset; inherit (lib) fileset;
packageLock = builtins.fromJSON (builtins.readFile ./package-lock.json); packageLock = builtins.fromJSON (builtins.readFile ./manifests/package-lock.json);
pname = "purescm"; pname = "purescm";
version = packageLock.packages."node_modules/${pname}".version; version = packageLock.packages."node_modules/${pname}".version;
@ -16,24 +16,11 @@ let
package = buildNpmPackage { package = buildNpmPackage {
inherit pname version; inherit pname version;
src = fileset.toSource { src = ./manifests;
root = ./.;
fileset = fileset.unions [
./package.json
./package-lock.json
./.gitignore
];
};
dontNpmBuild = true; dontNpmBuild = true;
npmDeps = fetchNpmDeps { npmDeps = fetchNpmDeps {
src = fileset.toSource { src = ./manifests;
root = ./.;
fileset = fileset.unions [
./package-lock.json
./package.json
];
};
hash = "sha256-ljeFcLvIET77Q0OR6O5Ok1fGnaxaKaoywpcy2aHq/6o="; hash = "sha256-ljeFcLvIET77Q0OR6O5Ok1fGnaxaKaoywpcy2aHq/6o=";
}; };

View File

@ -6,13 +6,7 @@ buildNpmPackage {
pname = "shopify"; pname = "shopify";
version = version; version = version;
src = lib.fileset.toSource { src = ./manifests;
root = ./.;
fileset = with lib.fileset; unions [
./package.json
./package-lock.json
];
};
npmDepsHash = "sha256-QhbOKOs/0GEOeySG4uROzgtD4o7C+6tS/TAaPcmC3xk="; npmDepsHash = "sha256-QhbOKOs/0GEOeySG4uROzgtD4o7C+6tS/TAaPcmC3xk=";
dontNpmBuild = true; dontNpmBuild = true;

View File

@ -18,6 +18,8 @@ if [[ "$UPDATE_NIX_OLD_VERSION" == "$version" ]]; then
exit 0 exit 0
fi fi
pushd manifests
# Update the package.json # Update the package.json
sed -i "s|$UPDATE_NIX_OLD_VERSION|$version|g" package.json sed -i "s|$UPDATE_NIX_OLD_VERSION|$version|g" package.json
@ -25,6 +27,9 @@ sed -i "s|$UPDATE_NIX_OLD_VERSION|$version|g" package.json
rm -f package-lock.json rm -f package-lock.json
npm i --package-lock-only npm i --package-lock-only
npm_hash=$(prefetch-npm-deps package-lock.json) npm_hash=$(prefetch-npm-deps package-lock.json)
popd
sed -i "s|npmDepsHash = \".*\";|npmDepsHash = \"$npm_hash\";|" package.nix sed -i "s|npmDepsHash = \".*\";|npmDepsHash = \"$npm_hash\";|" package.nix
popd popd

View File

@ -18,19 +18,12 @@ let
libcublas libcublas
; ;
inherit (lib) getDev getLib getOutput; inherit (lib) getDev getLib getOutput;
fs = lib.fileset;
in in
backendStdenv.mkDerivation { backendStdenv.mkDerivation {
pname = "saxpy"; pname = "saxpy";
version = "unstable-2023-07-11"; version = "unstable-2023-07-11";
src = fs.toSource { src = ./src;
root = ./.;
fileset = fs.unions [
./CMakeLists.txt
./saxpy.cu
];
};
__structuredAttrs = true; __structuredAttrs = true;
strictDeps = true; strictDeps = true;

View File

@ -6,22 +6,12 @@
waitress, waitress,
}: }:
let
fs = lib.fileset;
in
buildPythonPackage { buildPythonPackage {
pname = "waitress-django"; pname = "waitress-django";
version = "1.0.0"; version = "1.0.0";
pyproject = true; pyproject = true;
src = fs.toSource { src = ./src;
root = ./.;
fileset = fs.unions [
./setup.py
./src
];
};
build-system = [ setuptools ]; build-system = [ setuptools ];

View File

@ -7,6 +7,5 @@ setup( name = "waitress-django"
, description = "A waitress WSGI server serving django" , description = "A waitress WSGI server serving django"
, author = "Bas van Dijk" , author = "Bas van Dijk"
, author_email = "v.dijk.bas@gmail.com" , author_email = "v.dijk.bas@gmail.com"
, package_dir = {"" : "src"} , scripts = ["waitress-serve-django"]
, scripts = ["src/waitress-serve-django"]
) )

View File

@ -398,15 +398,7 @@ in rec {
}); });
yarn2nix = mkYarnPackage { yarn2nix = mkYarnPackage {
src = lib.fileset.toSource { src = ./yarn2nix;
root = ./.;
fileset = lib.fileset.unions [
./bin
./lib
./package.json
./yarn.lock
];
};
# yarn2nix is the only package that requires the yarnNix option. # yarn2nix is the only package that requires the yarnNix option.
# All the other projects can auto-generate that file. # All the other projects can auto-generate that file.
@ -415,7 +407,7 @@ in rec {
# Using the filter above and importing package.json from the filtered # Using the filter above and importing package.json from the filtered
# source results in an error in restricted mode. To circumvent this, # source results in an error in restricted mode. To circumvent this,
# we import package.json from the unfiltered source # we import package.json from the unfiltered source
packageJSON = ./package.json; packageJSON = ./yarn2nix/package.json;
yarnFlags = defaultYarnFlags ++ [ "--ignore-scripts" "--production=true" ]; yarnFlags = defaultYarnFlags ++ [ "--ignore-scripts" "--production=true" ];
@ -446,7 +438,7 @@ in rec {
mkdir -p $out/lib mkdir -p $out/lib
mkdir -p $out/bin mkdir -p $out/bin
cp ${./lib/urlToName.js} $out/lib/urlToName.js cp ${./yarn2nix/lib/urlToName.js} $out/lib/urlToName.js
cp ${./internal/fixup_yarn_lock.js} $out/bin/fixup_yarn_lock cp ${./internal/fixup_yarn_lock.js} $out/bin/fixup_yarn_lock
patchShebangs $out patchShebangs $out

View File

@ -6,18 +6,7 @@
}: }:
let let
src = lib.fileset.toSource { localRaw = haskellPackages.callPackage ./generated.nix { };
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 in
lib.recurseIntoAttrs rec { lib.recurseIntoAttrs rec {
@ -28,7 +17,6 @@ lib.recurseIntoAttrs rec {
localFromCabalSdist = haskellPackages.buildFromCabalSdist localRaw; localFromCabalSdist = haskellPackages.buildFromCabalSdist localRaw;
# NOTE: ./local refers to the "./." path in `./local/generated.nix`.
# This test makes sure that localHasNoDirectReference can actually fail if # This test makes sure that localHasNoDirectReference can actually fail if
# it doesn't do anything. If this test fails, either the test setup was broken, # it doesn't do anything. If this test fails, either the test setup was broken,
# or Haskell packaging has changed the way `src` is treated in such a way that # or Haskell packaging has changed the way `src` is treated in such a way that
@ -39,7 +27,7 @@ lib.recurseIntoAttrs rec {
drvPath = builtins.unsafeDiscardOutputDependency localRaw.drvPath; drvPath = builtins.unsafeDiscardOutputDependency localRaw.drvPath;
} }
'' ''
grep ${src} $drvPath >/dev/null grep ${localRaw.src} $drvPath >/dev/null
touch $out touch $out
''; '';
@ -49,7 +37,7 @@ lib.recurseIntoAttrs rec {
drvPath = builtins.unsafeDiscardOutputDependency localFromCabalSdist.drvPath; drvPath = builtins.unsafeDiscardOutputDependency localFromCabalSdist.drvPath;
} }
'' ''
grep -v ${src} $drvPath >/dev/null grep -v ${localRaw.src} $drvPath >/dev/null
touch $out touch $out
''; '';
} }

View File

@ -1,4 +1,4 @@
# nix run ../../../../..#cabal2nix -- ./. # nix run ../../../../..#cabal2nix -- ./local
{ {
mkDerivation, mkDerivation,
base, base,
@ -7,10 +7,11 @@
mkDerivation { mkDerivation {
pname = "local"; pname = "local";
version = "0.1.0.0"; version = "0.1.0.0";
src = ./.; # also referred to as ./local in the test; these are the same path constants src = ./local;
isLibrary = false; isLibrary = false;
isExecutable = true; isExecutable = true;
executableHaskellDepends = [ base ]; executableHaskellDepends = [ base ];
description = "Nixpkgs test case"; description = "Nixpkgs test case";
license = lib.licenses.mit; license = lib.licenses.mit;
mainProgram = "local";
} }

View File

@ -1,7 +1,7 @@
{ pkgs, haskellPackages }: { pkgs, haskellPackages }:
let let
# This can be regenerated by running `cabal2nix .` in the current directory. # This can be regenerated by running `cabal2nix ./src` in the current directory.
pkgDef = pkgDef =
{ {
mkDerivation, mkDerivation,
@ -11,19 +11,11 @@ let
mkDerivation { mkDerivation {
pname = "haskell-setBuildTarget"; pname = "haskell-setBuildTarget";
version = "0.1.0.0"; version = "0.1.0.0";
src = lib.fileset.toSource { src = ./src;
root = ./.;
fileset = lib.fileset.unions [
./haskell-setBuildTarget.cabal
./Bar.hs
./Foo.hs
./Setup.hs
];
};
isLibrary = false; isLibrary = false;
isExecutable = true; isExecutable = true;
executableHaskellDepends = [ base ]; executableHaskellDepends = [ base ];
license = lib.licenses.bsd3; license = "unknown";
}; };
drv = haskellPackages.callPackage pkgDef { }; drv = haskellPackages.callPackage pkgDef { };

View File

@ -20,16 +20,7 @@ let
runCommand "make-binary-wrapper-test-${testname}" env '' runCommand "make-binary-wrapper-test-${testname}" env ''
mkdir -p tmp/foo # for the chdir test mkdir -p tmp/foo # for the chdir test
source=${ source=${./${testname}}
lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
(./. + "/${testname}.cmdline")
(./. + "/${testname}.c")
(lib.fileset.maybeMissing (./. + "/${testname}.env"))
];
}
}
params=$(<"$source/${testname}.cmdline") params=$(<"$source/${testname}.cmdline")
eval "makeCWrapper /send/me/flags $params" > wrapper.c eval "makeCWrapper /send/me/flags $params" > wrapper.c

View File

@ -5667,7 +5667,7 @@ with pkgs;
yarn-berry = callPackage ../development/tools/yarn-berry { }; yarn-berry = callPackage ../development/tools/yarn-berry { };
yarn2nix-moretea = callPackage ../development/tools/yarn2nix-moretea/yarn2nix { pkgs = pkgs.__splicedPackages; }; yarn2nix-moretea = callPackage ../development/tools/yarn2nix-moretea { pkgs = pkgs.__splicedPackages; };
inherit (yarn2nix-moretea) inherit (yarn2nix-moretea)
yarn2nix yarn2nix

View File

@ -27,6 +27,10 @@
, # Allow a configuration attribute set to be passed in as an argument. , # Allow a configuration attribute set to be passed in as an argument.
config ? {} config ? {}
, # Temporary hack to let Nixpkgs forbid internal use of `lib.fileset`
# until <https://github.com/NixOS/nix/issues/11503> is fixed.
__allowFileset ? true
, # List of overlays layers used to extend Nixpkgs. , # List of overlays layers used to extend Nixpkgs.
overlays ? [] overlays ? []
@ -47,7 +51,24 @@ let # Rename the function arguments
crossSystem0 = crossSystem; crossSystem0 = crossSystem;
in let in let
lib = import ../../lib; pristineLib = import ../../lib;
lib =
if __allowFileset then
pristineLib
else
pristineLib.extend (_: _: {
fileset = abort ''
The use of `lib.fileset` is currently forbidden in Nixpkgs due to the
upstream Nix bug <https://github.com/NixOS/nix/issues/11503>. This
causes difficulttodebug errors when combined with chroot stores,
such as in the NixOS installer.
For packages that require source to be vendored inside Nixpkgs,
please use a subdirectory of the package instead.
'';
});
inherit (lib) throwIfNot; inherit (lib) throwIfNot;

View File

@ -17,7 +17,10 @@
, # Strip most of attributes when evaluating to spare memory usage , # Strip most of attributes when evaluating to spare memory usage
scrubJobs ? true scrubJobs ? true
, # Attributes passed to nixpkgs. Don't build packages marked as unfree. , # Attributes passed to nixpkgs. Don't build packages marked as unfree.
nixpkgsArgs ? { config = { allowUnfree = false; inHydra = true; }; } nixpkgsArgs ? {
config = { allowUnfree = false; inHydra = true; };
__allowFileset = false;
}
}: }:
let let

View File

@ -43,6 +43,8 @@ in
"${variant}Support" = true; "${variant}Support" = true;
inHydra = true; inHydra = true;
}; };
__allowFileset = false;
}, },
... ...
}@args: }@args:

View File

@ -3,7 +3,10 @@
, packageSet ? (import ../..) , packageSet ? (import ../..)
, scrubJobs ? true , scrubJobs ? true
, # Attributes passed to nixpkgs. Don't build packages marked as unfree. , # Attributes passed to nixpkgs. Don't build packages marked as unfree.
nixpkgsArgs ? { config = { allowUnfree = false; inHydra = true; }; } nixpkgsArgs ? {
config = { allowUnfree = false; inHydra = true; };
__allowFileset = false;
}
}: }:
let let

View File

@ -57,6 +57,8 @@ let
inHydra = true; inHydra = true;
}; };
__allowFileset = false;
}; };
}; };
recurseIntoAttrs = attrs: attrs // { recurseForDerivations = true; }; recurseIntoAttrs = attrs: attrs // { recurseForDerivations = true; };

View File

@ -15,6 +15,8 @@
allowUnfree = false; allowUnfree = false;
inHydra = true; inHydra = true;
}; };
__allowFileset = false;
}, },
}: }:

View File

@ -19,6 +19,8 @@
allowUnfree = false; allowUnfree = false;
inHydra = true; inHydra = true;
}; };
__allowFileset = false;
}, },
}: }:

View File

@ -37,6 +37,8 @@
cudaSupport = true; cudaSupport = true;
inHydra = true; inHydra = true;
}; };
__allowFileset = false;
}, },
# We only build the full package set on infrequently releasing channels. # We only build the full package set on infrequently releasing channels.
full ? false, full ? false,

View File

@ -28,16 +28,20 @@
# Strip most of attributes when evaluating to spare memory usage # Strip most of attributes when evaluating to spare memory usage
, scrubJobs ? true , scrubJobs ? true
# Attributes passed to nixpkgs. Don't build packages marked as unfree. # Attributes passed to nixpkgs. Don't build packages marked as unfree.
, nixpkgsArgs ? { config = { , nixpkgsArgs ? {
allowUnfree = false; config = {
inHydra = true; allowUnfree = false;
# Exceptional unsafe packages that we still build and distribute, inHydra = true;
# so users choosing to allow don't have to rebuild them every time. # Exceptional unsafe packages that we still build and distribute,
permittedInsecurePackages = [ # so users choosing to allow don't have to rebuild them every time.
"olm-3.2.16" # see PR #347899 permittedInsecurePackages = [
"kanidm_1_3-1.3.3" "olm-3.2.16" # see PR #347899
]; "kanidm_1_3-1.3.3"
}; } ];
};
__allowFileset = false;
}
# This flag, if set to true, will inhibit the use of `mapTestOn` # This flag, if set to true, will inhibit the use of `mapTestOn`
# and `release-lib.packagePlatforms`. Generally, it causes the # and `release-lib.packagePlatforms`. Generally, it causes the