Skip to content

Commit 0f1ccb9

Browse files
committed
pin-depends: support proper version constraints
Fixes #13
1 parent d8d6d90 commit 0f1ccb9

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/opam.nix

+10-8
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,16 @@ in rec {
211211
filterOpamRepo = packages: repo:
212212
linkFarm "opam-repo" ([ (namePathPair "repo" "${repo}/repo") ] ++ attrValues
213213
(mapAttrs (name: version:
214-
if isNull version then
215-
namePathPair "packages/${name}/${name}.dev"
216-
"${repo}/packages/${name}/${
217-
head (attrNames (readDir "${repo}/packages/${name}"))
218-
}"
214+
let
215+
defaultPath = "${repo}/packages/${name}/${
216+
head (attrNames (readDir "${repo}/packages/${name}"))
217+
}";
218+
in if isNull version then
219+
namePathPair "packages/${name}/${name}.dev" defaultPath
219220
else
220221
namePathPair "packages/${name}/${name}.${version}"
221-
"${repo}/packages/${name}/${name}.${version}") packages))
222+
(let path = "${repo}/packages/${name}/${name}.${version}";
223+
in if builtins.pathExists path then path else defaultPath)) packages))
222224
// optionalAttrs (repo ? passthru) {
223225
passthru = let
224226
pickRelevantVersions = from:
@@ -227,7 +229,7 @@ in rec {
227229
if isNull version then
228230
head (attrValues from.${name})
229231
else
230-
from.${name}.${version};
232+
from.${name}.${version} or head (attrValues from.${name});
231233
}) packages;
232234
in repo.passthru // mapAttrs (_: pickRelevantVersions) {
233235
inherit (repo.passthru) sourceMap pkgdefs;
@@ -404,7 +406,7 @@ in rec {
404406
// {
405407
inherit url;
406408
};
407-
repo = filterOpamRepo { ${name} = null; } (makeOpamRepo path);
409+
repo = filterOpamRepo { ${name} = version; } (makeOpamRepo path);
408410
in if !hasRev && !isImpure then
409411
lib.warn
410412
"pin-depends without an explicit sha1 is not supported in pure evaluation mode; try with --impure"

0 commit comments

Comments
 (0)