···11-# Functions for copying sources to the Nix store.11+# Functions for querying information about the filesystem22+# without copying any files to the Nix store.23{ lib }:3455+# Tested in lib/tests/filesystem.sh46let77+ inherit (builtins)88+ readDir99+ pathExists1010+ ;1111+512 inherit (lib.strings)613 hasPrefix1414+ ;1515+1616+ inherit (lib.filesystem)1717+ pathType718 ;819in9201021{2222+2323+ /*2424+ The type of a path. The path needs to exist and be accessible.2525+ The result is either "directory" for a directory, "regular" for a regular file, "symlink" for a symlink, or "unknown" for anything else.2626+2727+ Type:2828+ pathType :: Path -> String2929+3030+ Example:3131+ pathType /.3232+ => "directory"3333+3434+ pathType /some/file.nix3535+ => "regular"3636+ */3737+ pathType =3838+ builtins.readFileType or3939+ # Nix <2.14 compatibility shim4040+ (path:4141+ if ! pathExists path4242+ # Fail irrecoverably to mimic the historic behavior of this function and4343+ # the new builtins.readFileType4444+ then abort "lib.filesystem.pathType: Path ${toString path} does not exist."4545+ # The filesystem root is the only path where `dirOf / == /` and4646+ # `baseNameOf /` is not valid. We can detect this and directly return4747+ # "directory", since we know the filesystem root can't be anything else.4848+ else if dirOf path == path4949+ then "directory"5050+ else (readDir (dirOf path)).${baseNameOf path}5151+ );5252+5353+ /*5454+ Whether a path exists and is a directory.5555+5656+ Type:5757+ pathIsDirectory :: Path -> Bool5858+5959+ Example:6060+ pathIsDirectory /.6161+ => true6262+6363+ pathIsDirectory /this/does/not/exist6464+ => false6565+6666+ pathIsDirectory /some/file.nix6767+ => false6868+ */6969+ pathIsDirectory = path:7070+ pathExists path && pathType path == "directory";7171+7272+ /*7373+ Whether a path exists and is a regular file, meaning not a symlink or any other special file type.7474+7575+ Type:7676+ pathIsRegularFile :: Path -> Bool7777+7878+ Example:7979+ pathIsRegularFile /.8080+ => false8181+8282+ pathIsRegularFile /this/does/not/exist8383+ => false8484+8585+ pathIsRegularFile /some/file.nix8686+ => true8787+ */8888+ pathIsRegularFile = path:8989+ pathExists path && pathType path == "regular";9090+1191 /*1292 A map of all haskell packages defined in the given path,1393 identified by having a cabal file with the same name as the
+18-19
lib/sources.nix
···1818 pathExists1919 readFile2020 ;2121-2222- /*2323- Returns the type of a path: regular (for file), symlink, or directory.2424- */2525- pathType = path: getAttr (baseNameOf path) (readDir (dirOf path));2626-2727- /*2828- Returns true if the path exists and is a directory, false otherwise.2929- */3030- pathIsDirectory = path: if pathExists path then (pathType path) == "directory" else false;3131-3232- /*3333- Returns true if the path exists and is a regular file, false otherwise.3434- */3535- pathIsRegularFile = path: if pathExists path then (pathType path) == "regular" else false;2121+ inherit (lib.filesystem)2222+ pathType2323+ pathIsDirectory2424+ pathIsRegularFile2525+ ;36263727 /*3828 A basic filter for `cleanSourceWith` that removes···261271 };262272263273in {264264- inherit265265- pathType266266- pathIsDirectory267267- pathIsRegularFile268274275275+ pathType = lib.warnIf (lib.isInOldestRelease 2305)276276+ "lib.sources.pathType has been moved to lib.filesystem.pathType."277277+ lib.filesystem.pathType;278278+279279+ pathIsDirectory = lib.warnIf (lib.isInOldestRelease 2305)280280+ "lib.sources.pathIsDirectory has been moved to lib.filesystem.pathIsDirectory."281281+ lib.filesystem.pathIsDirectory;282282+283283+ pathIsRegularFile = lib.warnIf (lib.isInOldestRelease 2305)284284+ "lib.sources.pathIsRegularFile has been moved to lib.filesystem.pathIsRegularFile."285285+ lib.filesystem.pathIsRegularFile;286286+287287+ inherit269288 pathIsGitRepo270289 commitIdFromGitRepo271290
+92
lib/tests/filesystem.sh
···11+#!/usr/bin/env bash22+33+# Tests lib/filesystem.nix44+# Run:55+# [nixpkgs]$ lib/tests/filesystem.sh66+# or:77+# [nixpkgs]$ nix-build lib/tests/release.nix88+99+set -euo pipefail1010+shopt -s inherit_errexit1111+1212+# Use1313+# || die1414+die() {1515+ echo >&2 "test case failed: " "$@"1616+ exit 11717+}1818+1919+if test -n "${TEST_LIB:-}"; then2020+ NIX_PATH=nixpkgs="$(dirname "$TEST_LIB")"2121+else2222+ NIX_PATH=nixpkgs="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.."; pwd)"2323+fi2424+export NIX_PATH2525+2626+work="$(mktemp -d)"2727+clean_up() {2828+ rm -rf "$work"2929+}3030+trap clean_up EXIT3131+cd "$work"3232+3333+mkdir directory3434+touch regular3535+ln -s target symlink3636+mkfifo fifo3737+3838+checkPathType() {3939+ local path=$14040+ local expectedPathType=$24141+ local actualPathType=$(nix-instantiate --eval --strict --json 2>&1 \4242+ -E '{ path }: let lib = import <nixpkgs/lib>; in lib.filesystem.pathType path' \4343+ --argstr path "$path")4444+ if [[ "$actualPathType" != "$expectedPathType" ]]; then4545+ die "lib.filesystem.pathType \"$path\" == $actualPathType, but $expectedPathType was expected"4646+ fi4747+}4848+4949+checkPathType "/" '"directory"'5050+checkPathType "$PWD/directory" '"directory"'5151+checkPathType "$PWD/regular" '"regular"'5252+checkPathType "$PWD/symlink" '"symlink"'5353+checkPathType "$PWD/fifo" '"unknown"'5454+checkPathType "$PWD/non-existent" "error: evaluation aborted with the following error message: 'lib.filesystem.pathType: Path $PWD/non-existent does not exist.'"5555+5656+checkPathIsDirectory() {5757+ local path=$15858+ local expectedIsDirectory=$25959+ local actualIsDirectory=$(nix-instantiate --eval --strict --json 2>&1 \6060+ -E '{ path }: let lib = import <nixpkgs/lib>; in lib.filesystem.pathIsDirectory path' \6161+ --argstr path "$path")6262+ if [[ "$actualIsDirectory" != "$expectedIsDirectory" ]]; then6363+ die "lib.filesystem.pathIsDirectory \"$path\" == $actualIsDirectory, but $expectedIsDirectory was expected"6464+ fi6565+}6666+6767+checkPathIsDirectory "/" "true"6868+checkPathIsDirectory "$PWD/directory" "true"6969+checkPathIsDirectory "$PWD/regular" "false"7070+checkPathIsDirectory "$PWD/symlink" "false"7171+checkPathIsDirectory "$PWD/fifo" "false"7272+checkPathIsDirectory "$PWD/non-existent" "false"7373+7474+checkPathIsRegularFile() {7575+ local path=$17676+ local expectedIsRegularFile=$27777+ local actualIsRegularFile=$(nix-instantiate --eval --strict --json 2>&1 \7878+ -E '{ path }: let lib = import <nixpkgs/lib>; in lib.filesystem.pathIsRegularFile path' \7979+ --argstr path "$path")8080+ if [[ "$actualIsRegularFile" != "$expectedIsRegularFile" ]]; then8181+ die "lib.filesystem.pathIsRegularFile \"$path\" == $actualIsRegularFile, but $expectedIsRegularFile was expected"8282+ fi8383+}8484+8585+checkPathIsRegularFile "/" "false"8686+checkPathIsRegularFile "$PWD/directory" "false"8787+checkPathIsRegularFile "$PWD/regular" "true"8888+checkPathIsRegularFile "$PWD/symlink" "false"8989+checkPathIsRegularFile "$PWD/fifo" "false"9090+checkPathIsRegularFile "$PWD/non-existent" "false"9191+9292+echo >&2 tests ok
···2233## Highlights {#sec-release-23.11-highlights}4455+- Create the first release note entry in this section!66+57## New Services {#sec-release-23.11-new-services}88+99+- Create the first release note entry in this section!610711<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->812913## Backward Incompatibilities {#sec-release-23.11-incompatibilities}10141515+- Create the first release note entry in this section!1616+1117## Other Notable Changes {#sec-release-23.11-notable-changes}12181919+- Create the first release note entry in this section!
···22, attrs33, beautifulsoup444, buildPythonPackage55+, click66+, datasets57, dill68, dm-tree79, fetchFromGitHub···1614, jinja21715, langdetect1816, lib1717+, lxml1918, matplotlib2019, mwparserfromhell2120, networkx···2724, pillow2825, promise2926, protobuf2727+, psutil3028, pycocotools3129, pydub3230, pytest-xdist···6965 numpy7066 promise7167 protobuf6868+ psutil7269 requests7370 six7471 tensorflow-metadata···8479 nativeCheckInputs = [8580 apache-beam8681 beautifulsoup48282+ click8383+ datasets8784 ffmpeg8885 imagemagick8986 jax9087 jaxlib9188 jinja29289 langdetect9090+ lxml9391 matplotlib9492 mwparserfromhell9593 networkx···117109 "tensorflow_datasets/core/dataset_info_test.py"118110 "tensorflow_datasets/core/features/features_test.py"119111 "tensorflow_datasets/core/github_api/github_path_test.py"112112+ "tensorflow_datasets/core/registered_test.py"120113 "tensorflow_datasets/core/utils/gcs_utils_test.py"114114+ "tensorflow_datasets/import_without_tf_test.py"121115 "tensorflow_datasets/scripts/cli/build_test.py"122116123117 # Requires `pretty_midi` which is not packaged in `nixpkgs`.124124- "tensorflow_datasets/audio/groove_test.py"118118+ "tensorflow_datasets/audio/groove.py"119119+ "tensorflow_datasets/datasets/groove/groove_dataset_builder_test.py"125120126121 # Requires `crepe` which is not packaged in `nixpkgs`.127127- "tensorflow_datasets/audio/nsynth_test.py"122122+ "tensorflow_datasets/audio/nsynth.py"123123+ "tensorflow_datasets/datasets/nsynth/nsynth_dataset_builder_test.py"124124+125125+ # Requires `conllu` which is not packaged in `nixpkgs`.126126+ "tensorflow_datasets/core/dataset_builders/conll/conllu_dataset_builder_test.py"127127+ "tensorflow_datasets/datasets/universal_dependencies/universal_dependencies_dataset_builder_test.py"128128+ "tensorflow_datasets/datasets/xtreme_pos/xtreme_pos_dataset_builder_test.py"128129129130 # Requires `gcld3` and `pretty_midi` which are not packaged in `nixpkgs`.130131 "tensorflow_datasets/core/lazy_imports_lib_test.py"131132132133 # Requires `tensorflow_io` which is not packaged in `nixpkgs`.134134+ "tensorflow_datasets/core/features/audio_feature_test.py"133135 "tensorflow_datasets/image/lsun_test.py"134136135137 # Requires `envlogger` which is not packaged in `nixpkgs`.···150132 # deep in TF AutoGraph. Doesn't reproduce in Docker with Ubuntu 22.04 => might be related151133 # to the differences in some of the dependencies?152134 "tensorflow_datasets/rl_unplugged/rlu_atari/rlu_atari_test.py"135135+136136+ # Fails with `ValueError: setting an array element with a sequence`137137+ "tensorflow_datasets/core/dataset_utils_test.py"138138+ "tensorflow_datasets/core/features/sequence_feature_test.py"153139154140 # Requires `tensorflow_docs` which is not packaged in `nixpkgs` and the test is for documentation anyway.155141 "tensorflow_datasets/scripts/documentation/build_api_docs_test.py"