Skip to content

Commit 22ad57c

Browse files
authored
fix the way the isProject package flag is set (#1003)
1 parent 36a85c8 commit 22ad57c

File tree

1 file changed

+35
-22
lines changed

1 file changed

+35
-22
lines changed

lib/import-and-filter-project.nix

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,43 @@ in project // {
2424
packages = pkgs.lib.attrsets.mapAttrs (name: value:
2525
if builtins.isFunction value
2626
then value
27-
else {...}@args:
28-
let oldPkg = import value args;
29-
packageSrc = if !pkgs.lib.strings.hasPrefix (toString projectNix) (toString oldPkg.src.content)
30-
then toString oldPkg.src.content
31-
else let
32-
subDir = pkgs.lib.strings.removePrefix "/" (
33-
pkgs.lib.strings.removePrefix (toString projectNix)
34-
(toString oldPkg.src.content));
35-
srcRepoPrefix = projectSubDir'' + ".source-repository-packages/";
36-
in if pkgs.lib.strings.hasPrefix srcRepoPrefix subDir
37-
then
38-
pkgs.lib.lists.elemAt sourceRepos (
39-
pkgs.lib.strings.toInt (pkgs.lib.strings.removePrefix srcRepoPrefix subDir))
40-
else haskellLib.appendSubDir {
41-
src = srcRoot;
42-
inherit subDir;
43-
includeSiblings = true; # Filtering sibling dirs of the package dir is done in the
44-
# component builder so that relative paths can be used to
45-
# reference project directories not in the package subDir.
46-
};
27+
else {...}@args: with pkgs.lib.strings;
28+
let
29+
oldPkg = import value args;
30+
# When the package src is in the project dir, this is the subDir it is in.
31+
subDir = removePrefix "/" (removePrefix (toString projectNix)
32+
(toString oldPkg.src.content));
33+
srcRepoPrefix = projectSubDir'' + ".source-repository-packages/";
34+
35+
packageInfo =
36+
if !hasPrefix (toString projectNix) (toString oldPkg.src.content)
37+
then {
38+
# Source location does not match project prefix
39+
isProject = false;
40+
packageSrc = toString oldPkg.src.content;
41+
}
42+
else if hasPrefix srcRepoPrefix subDir
43+
then {
44+
# The source is from a source repository
45+
isProject = false;
46+
packageSrc = pkgs.lib.lists.elemAt sourceRepos (
47+
toInt (removePrefix srcRepoPrefix subDir));
48+
}
49+
else {
50+
# Source does match project prefix and it is not from a source repository
51+
isProject = true;
52+
packageSrc = haskellLib.appendSubDir {
53+
src = srcRoot;
54+
inherit subDir;
55+
includeSiblings = true; # Filtering sibling dirs of the package dir is done in the
56+
# component builder so that relative paths can be used to
57+
# reference project directories not in the package subDir.
58+
};
59+
};
4760
in oldPkg // {
48-
src = (pkgs.lib).mkDefault packageSrc;
61+
src = (pkgs.lib).mkDefault packageInfo.packageSrc;
4962
package = oldPkg.package // {
50-
isProject = (pkgs.lib).mkDefault true;
63+
isProject = (pkgs.lib).mkDefault packageInfo.isProject;
5164
};
5265
}) old;
5366
};

0 commit comments

Comments
 (0)