Skip to content

Commit 25b47bf

Browse files
authored
Determine if the tag is a ref or a rev (#1665)
* Determine if the tag is a ref or a rev Test the `tag` attribute in the `cabal.project` file. If it looks like a git hash, then assign it to `rev`. Otherwise, assign it to `ref`. * ok * ok * lmao * Address comments * better if not present
1 parent 65405aa commit 25b47bf

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

lib/cabal-project-parser.nix

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,15 @@ let
7474
# --shar256: 003lm3pm0000hbfmii7xcdd9v20000flxf7gdl2pyxia7p014i8z
7575
# will be trated like a field and returned here
7676
# (used in call-cabal-project-to-nix.nix to create a fixed-output derivation)
77-
extractSourceRepoPackageData = cabalProjectFileName: sha256map: repo: {
77+
extractSourceRepoPackageData = cabalProjectFileName: sha256map: repo:
78+
let
79+
refOrRev =
80+
if builtins.match "[0-9a-f](40)" repo.tag != null
81+
then "rev"
82+
else "ref";
83+
in {
7884
url = repo.location;
79-
ref = repo.tag;
85+
"${refOrRev}" = repo.tag;
8086
sha256 = repo."--sha256" or (
8187
if sha256map != null
8288
then sha256map."${repo.location}"."${repo.tag}"

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,10 @@ let
228228
then throw "${inputMap.${repoData.url}.rev} may not match ${repoData.ref} for ${repoData.url} use \"${repoData.url}/${repoData.ref}\" as the inputMap key if ${repoData.ref} is a branch or tag that points to ${inputMap.${repoData.url}.rev}."
229229
else inputMap.${repoData.url})
230230
else if repoData.sha256 != null
231-
then fetchgit { inherit (repoData) url sha256; rev = repoData.ref; }
231+
then fetchgit { inherit (repoData) url sha256; rev = repoData.rev or repoData.ref; }
232232
else
233-
let drv = builtins.fetchGit { inherit (repoData) url ref; };
234-
in __trace "WARNING: No sha256 found for source-repository-package ${repoData.url} ${repoData.ref} download may fail in restricted mode (hydra)"
233+
let drv = builtins.fetchGit { inherit (repoData) url ; rev = repoData.rev or repoData.ref; ref = repoData.ref or null; };
234+
in __trace "WARNING: No sha256 found for source-repository-package ${repoData.url} ref=${repoData.ref or "(unspecified)"} rev=${repoData.rev or "(unspecified)"} download may fail in restricted mode (hydra)"
235235
(__trace "Consider adding `--sha256: ${hashPath drv}` to the ${cabalProjectFileName} file or passing in a sha256map argument"
236236
drv);
237237
in {

0 commit comments

Comments
 (0)