From f28ab51b54ef2518345594a6baf45b9e25378912 Mon Sep 17 00:00:00 2001 From: Alexander Vieth Date: Wed, 24 Aug 2022 21:57:52 -0400 Subject: haskell.lib.makePackageSet: all-cabal-hashes can be a directory (#188203) * all-cabal-hahses can be a directory Motivating problem: we want to use the flake.lock for all-cabal-hashes as a github repository as our revision pin, and then import that to pass as all-cabal-hashes. To do that we need it to accept a directory rather than a tarball. * all-cabal-hashes: add some comments --- pkgs/development/haskell-modules/make-package-set.nix | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'pkgs/development/haskell-modules/make-package-set.nix') diff --git a/pkgs/development/haskell-modules/make-package-set.nix b/pkgs/development/haskell-modules/make-package-set.nix index 9d35d198825f8..9bbfe44192862 100644 --- a/pkgs/development/haskell-modules/make-package-set.nix +++ b/pkgs/development/haskell-modules/make-package-set.nix @@ -21,6 +21,9 @@ , haskellLib , # hashes for downloading Hackage packages + # This is either a directory or a .tar.gz containing the cabal files and + # hashes of Hackage as exemplified by this repository: + # https://github.com/commercialhaskell/all-cabal-hashes/tree/hackage all-cabal-hashes , # compiler to use @@ -136,10 +139,20 @@ let cabal2nix --compiler=${self.ghc.haskellCompilerName} --system=${hostPlatform.config} ${sha256Arg} "${src}" ${extraCabal2nixOptions} > "$out/default.nix" ''; + # Given a package name and version, e.g. name = "async", version = "2.2.4", + # gives its cabal file and hashes (JSON file) as discovered from the + # all-cabal-hashes value. If that's a directory, it will copy the relevant + # files to $out; if it's a tarball, it will extract and move them to $out. all-cabal-hashes-component = name: version: buildPackages.runCommand "all-cabal-hashes-component-${name}-${version}" {} '' - tar --wildcards -xzvf ${all-cabal-hashes} \*/${name}/${version}/${name}.{json,cabal} mkdir -p $out - mv */${name}/${version}/${name}.{json,cabal} $out + if [ -d ${all-cabal-hashes} ] + then + cp ${all-cabal-hashes}/${name}/${version}/${name}.json $out + cp ${all-cabal-hashes}/${name}/${version}/${name}.cabal $out + else + tar --wildcards -xzvf ${all-cabal-hashes} \*/${name}/${version}/${name}.{json,cabal} + mv */${name}/${version}/${name}.{json,cabal} $out + fi ''; hackage2nix = name: version: let component = all-cabal-hashes-component name version; in self.haskellSrc2nix { -- cgit 1.4.1