Skip to content

Commit

Permalink
Determine if the tag is a ref or a rev (#1665)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
parsonsmatt committed Sep 15, 2022
1 parent 65405aa commit 25b47bf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions lib/cabal-project-parser.nix
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,15 @@ let
# --shar256: 003lm3pm0000hbfmii7xcdd9v20000flxf7gdl2pyxia7p014i8z
# will be trated like a field and returned here
# (used in call-cabal-project-to-nix.nix to create a fixed-output derivation)
extractSourceRepoPackageData = cabalProjectFileName: sha256map: repo: {
extractSourceRepoPackageData = cabalProjectFileName: sha256map: repo:
let
refOrRev =
if builtins.match "[0-9a-f](40)" repo.tag != null
then "rev"
else "ref";
in {
url = repo.location;
ref = repo.tag;
"${refOrRev}" = repo.tag;
sha256 = repo."--sha256" or (
if sha256map != null
then sha256map."${repo.location}"."${repo.tag}"
Expand Down
6 changes: 3 additions & 3 deletions lib/call-cabal-project-to-nix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ let
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}."
else inputMap.${repoData.url})
else if repoData.sha256 != null
then fetchgit { inherit (repoData) url sha256; rev = repoData.ref; }
then fetchgit { inherit (repoData) url sha256; rev = repoData.rev or repoData.ref; }
else
let drv = builtins.fetchGit { inherit (repoData) url ref; };
in __trace "WARNING: No sha256 found for source-repository-package ${repoData.url} ${repoData.ref} download may fail in restricted mode (hydra)"
let drv = builtins.fetchGit { inherit (repoData) url ; rev = repoData.rev or repoData.ref; ref = repoData.ref or null; };
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)"
(__trace "Consider adding `--sha256: ${hashPath drv}` to the ${cabalProjectFileName} file or passing in a sha256map argument"
drv);
in {
Expand Down

0 comments on commit 25b47bf

Please sign in to comment.