diff --git a/lib/call-cabal-project-to-nix.nix b/lib/call-cabal-project-to-nix.nix index 925c5da186..3268341016 100644 --- a/lib/call-cabal-project-to-nix.nix +++ b/lib/call-cabal-project-to-nix.nix @@ -496,6 +496,9 @@ let --exclude '*' \ $tmp/ $out/ + # Make sure the subDir' exists even if it did not contain any cabal files + mkdir -p $out${subDir'} + # make sure the path's in the plan.json are relative to $out instead of $tmp # this is necessary so that plan-to-nix relative path logic can work. substituteInPlace $tmp${subDir'}/dist-newstyle/cache/plan.json --replace "$tmp" "$out" diff --git a/modules/package.nix b/modules/package.nix index 3a0f7fa818..01820bf5d8 100644 --- a/modules/package.nix +++ b/modules/package.nix @@ -301,6 +301,15 @@ in { type = either path package; default = pkgs.fetchurl { url = "mirror://hackage/${config.name}.tar.gz"; inherit (config) sha256; }; defaultText = "pkgs.fetchurl { url = \"mirror://hackage/\${config.name}.tar.gz\"; inherit (config) sha256; };"; + # Make sure paths have a context so they will be included in the derivation + # inputs for the component derivations. Without this sandbox builds fail + # cannot see the input and fail with the error: + # do not know how to unpack source archive /nix/store/... + apply = v: + let storeDirMatch = __match "(${__storeDir}/[^/]+).*" v; + in if isString v && __getContext v == {} && storeDirMatch != null + then __appendContext v { ${__head storeDirMatch} = { path = true; }; } + else v; }; package-description-override = mkOption { type = nullOr str; diff --git a/test/cabal-project-nix-path/default.nix b/test/cabal-project-nix-path/default.nix new file mode 100644 index 0000000000..deeef9f904 --- /dev/null +++ b/test/cabal-project-nix-path/default.nix @@ -0,0 +1,25 @@ +{ lib, cabalProject', tool, recurseIntoAttrs, testSrc, compiler-nix-name, evalPackages }: +let + project = cabalProject' { + name = "cabal-project-nix-path"; + inherit compiler-nix-name evalPackages; + src = testSrc "cabal-project-nix-path"; + cabalProject = '' + packages: ${(tool compiler-nix-name "hello" { inherit evalPackages; }).project.args.src} + ''; + }; + # The same but with source in a subdir of the store path + projectSubDir = project.appendModule { + cabalProject = lib.mkForce '' + packages: ${evalPackages.runCommand "hello-src" {} "mkdir -p $out && cp -r ${(tool compiler-nix-name "hello" { inherit evalPackages; }).project.args.src} $out/subdir"}/subdir + ''; + }; + +in recurseIntoAttrs { + ifdInputs = { + inherit (project) plan-nix; + }; + + build = project.hsPkgs.hello.components.exes.hello; + buildSubDir = projectSubDir.hsPkgs.hello.components.exes.hello; +} diff --git a/test/default.nix b/test/default.nix index 64a0488352..4cdee4dd3a 100644 --- a/test/default.nix +++ b/test/default.nix @@ -216,6 +216,7 @@ let ca-derivations = callTest ./ca-derivations { inherit CADerivationsEnabled; }; ca-derivations-include = callTest ./ca-derivations-include { inherit CADerivationsEnabled; }; test-only = callTest ./test-only { inherit util; }; + cabal-project-nix-path = callTest ./cabal-project-nix-path {}; unit = unitTests; };