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

authored by jade and committed by GitHub e514f073 6af71350

+30 -3
+2 -3
lib/filesystem.nix
··· 385 385 recurseIntoAttrs 386 386 removeSuffix 387 387 ; 388 - inherit (lib.path) append; 389 388 390 389 # Generate an attrset corresponding to a given directory. 391 390 # This function is outside `packagesFromDirectoryRecursive`'s lambda expression, ··· 396 395 name: type: 397 396 # for each directory entry 398 397 let 399 - path = append directory name; 398 + path = directory + "/${name}"; 400 399 in 401 400 if type == "directory" then 402 401 { ··· 429 428 directory, 430 429 }@args: 431 430 let 432 - defaultPath = append directory "package.nix"; 431 + defaultPath = directory + "/package.nix"; 433 432 in 434 433 if pathExists defaultPath then 435 434 # if `${directory}/package.nix` exists, call it directly
+28
lib/tests/misc.nix
··· 4158 4158 }; 4159 4159 }; 4160 4160 4161 + # Make sure that passing a string for the `directory` works. 4162 + # 4163 + # See: https://github.com/NixOS/nixpkgs/pull/361424#discussion_r1934813568 4164 + # See: https://github.com/NixOS/nix/issues/9428 4165 + testPackagesFromDirectoryRecursiveStringDirectory = { 4166 + expr = packagesFromDirectoryRecursive { 4167 + callPackage = path: overrides: import path overrides; 4168 + # Do NOT remove the `builtins.toString` call here!!! 4169 + directory = builtins.toString ./packages-from-directory/plain; 4170 + }; 4171 + expected = { 4172 + a = "a"; 4173 + b = "b"; 4174 + # Note: Other files/directories in `./test-data/c/` are ignored and can be 4175 + # used by `package.nix`. 4176 + c = "c"; 4177 + my-namespace = { 4178 + d = "d"; 4179 + e = "e"; 4180 + f = "f"; 4181 + my-sub-namespace = { 4182 + g = "g"; 4183 + h = "h"; 4184 + }; 4185 + }; 4186 + }; 4187 + }; 4188 + 4161 4189 # Check that `packagesFromDirectoryRecursive` can process a directory with a 4162 4190 # top-level `package.nix` file into a single package. 4163 4191 testPackagesFromDirectoryRecursiveTopLevelPackageNix = {