Unverified Commit e514f073 authored by jade's avatar jade Committed by GitHub
Browse files

lib.packagesFromDirectoryRecursive: Allow non-"path" `directory` (#406885)

parents 6af71350 4a81a5e5
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -385,7 +385,6 @@ in
        recurseIntoAttrs
        removeSuffix
        ;
      inherit (lib.path) append;

      # Generate an attrset corresponding to a given directory.
      # This function is outside `packagesFromDirectoryRecursive`'s lambda expression,
@@ -396,7 +395,7 @@ in
          name: type:
          # for each directory entry
          let
            path = append directory name;
            path = directory + "/${name}";
          in
          if type == "directory" then
            {
@@ -429,7 +428,7 @@ in
      directory,
    }@args:
    let
      defaultPath = append directory "package.nix";
      defaultPath = directory + "/package.nix";
    in
    if pathExists defaultPath then
      # if `${directory}/package.nix` exists, call it directly
+28 −0
Original line number Diff line number Diff line
@@ -4158,6 +4158,34 @@ runTests {
    };
  };

  # Make sure that passing a string for the `directory` works.
  #
  # See: https://github.com/NixOS/nixpkgs/pull/361424#discussion_r1934813568
  # See: https://github.com/NixOS/nix/issues/9428
  testPackagesFromDirectoryRecursiveStringDirectory = {
    expr = packagesFromDirectoryRecursive {
      callPackage = path: overrides: import path overrides;
      # Do NOT remove the `builtins.toString` call here!!!
      directory = builtins.toString ./packages-from-directory/plain;
    };
    expected = {
      a = "a";
      b = "b";
      # Note: Other files/directories in `./test-data/c/` are ignored and can be
      # used by `package.nix`.
      c = "c";
      my-namespace = {
        d = "d";
        e = "e";
        f = "f";
        my-sub-namespace = {
          g = "g";
          h = "h";
        };
      };
    };
  };

  # Check that `packagesFromDirectoryRecursive` can process a directory with a
  # top-level `package.nix` file into a single package.
  testPackagesFromDirectoryRecursiveTopLevelPackageNix = {