Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/call-cabal-project-to-nix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 9 additions & 0 deletions modules/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions test/cabal-project-nix-path/default.nix
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions test/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down