Skip to content

Commit d3def95

Browse files
authored
Fix using /nix/store paths in cabal.project (input-output-hk#1978)
* Fix using /nix/store paths in cabal.project This change makes sure paths have a context so they will be included in the derivation inputs for the component derivations. Without this sandbox builds cannot see the input and fail with the error: do not know how to unpack source archive /nix/store/... This PR also fixes an issue if project src has no cabal files and is not the root directory of the repo. * Enable fix * Fix remote eval test * Check that path is in the store * Include `storePaths` project arg * Fix typo * Revert "Include `storePaths` project arg" This reverts commit ed56a88. # Conflicts: # modules/plan.nix # modules/project-common.nix * Fix subdirs * Use __storeDir
1 parent 54b12fe commit d3def95

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

lib/call-cabal-project-to-nix.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,9 @@ let
496496
--exclude '*' \
497497
$tmp/ $out/
498498
499+
# Make sure the subDir' exists even if it did not contain any cabal files
500+
mkdir -p $out${subDir'}
501+
499502
# make sure the path's in the plan.json are relative to $out instead of $tmp
500503
# this is necessary so that plan-to-nix relative path logic can work.
501504
substituteInPlace $tmp${subDir'}/dist-newstyle/cache/plan.json --replace "$tmp" "$out"

modules/package.nix

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,15 @@ in {
301301
type = either path package;
302302
default = pkgs.fetchurl { url = "mirror://hackage/${config.name}.tar.gz"; inherit (config) sha256; };
303303
defaultText = "pkgs.fetchurl { url = \"mirror://hackage/\${config.name}.tar.gz\"; inherit (config) sha256; };";
304+
# Make sure paths have a context so they will be included in the derivation
305+
# inputs for the component derivations. Without this sandbox builds fail
306+
# cannot see the input and fail with the error:
307+
# do not know how to unpack source archive /nix/store/...
308+
apply = v:
309+
let storeDirMatch = __match "(${__storeDir}/[^/]+).*" v;
310+
in if isString v && __getContext v == {} && storeDirMatch != null
311+
then __appendContext v { ${__head storeDirMatch} = { path = true; }; }
312+
else v;
304313
};
305314
package-description-override = mkOption {
306315
type = nullOr str;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{ lib, cabalProject', tool, recurseIntoAttrs, testSrc, compiler-nix-name, evalPackages }:
2+
let
3+
project = cabalProject' {
4+
name = "cabal-project-nix-path";
5+
inherit compiler-nix-name evalPackages;
6+
src = testSrc "cabal-project-nix-path";
7+
cabalProject = ''
8+
packages: ${(tool compiler-nix-name "hello" { inherit evalPackages; }).project.args.src}
9+
'';
10+
};
11+
# The same but with source in a subdir of the store path
12+
projectSubDir = project.appendModule {
13+
cabalProject = lib.mkForce ''
14+
packages: ${evalPackages.runCommand "hello-src" {} "mkdir -p $out && cp -r ${(tool compiler-nix-name "hello" { inherit evalPackages; }).project.args.src} $out/subdir"}/subdir
15+
'';
16+
};
17+
18+
in recurseIntoAttrs {
19+
ifdInputs = {
20+
inherit (project) plan-nix;
21+
};
22+
23+
build = project.hsPkgs.hello.components.exes.hello;
24+
buildSubDir = projectSubDir.hsPkgs.hello.components.exes.hello;
25+
}

test/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ let
216216
ca-derivations = callTest ./ca-derivations { inherit CADerivationsEnabled; };
217217
ca-derivations-include = callTest ./ca-derivations-include { inherit CADerivationsEnabled; };
218218
test-only = callTest ./test-only { inherit util; };
219+
cabal-project-nix-path = callTest ./cabal-project-nix-path {};
219220
unit = unitTests;
220221
};
221222

0 commit comments

Comments
 (0)