diff --git a/lib/cabal-project-parser.nix b/lib/cabal-project-parser.nix index 64a232cf41..e54119bb3e 100644 --- a/lib/cabal-project-parser.nix +++ b/lib/cabal-project-parser.nix @@ -74,7 +74,7 @@ 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: lookupSha256: repo: { + extractRepoData = cabalProjectFileName: lookupSha256: repo: { url = repo.location; ref = repo.tag; sha256 = repo."--sha256" or (lookupSha256 repo); @@ -95,78 +95,10 @@ let otherText = "\nsource-repository-package\n" + block; } else { - sourceRepo = extractSourceRepoPackageData cabalProjectFileName lookupSha256 attrs; + sourceRepo = extractRepoData cabalProjectFileName lookupSha256 attrs; otherText = pkgs.lib.strings.concatStringsSep "\n" x.snd; }; - parseSourceRepositoryPackages = cabalProjectFileName: lookupSha256: source-repo-override: projectFile: - let - blocks = pkgs.lib.splitString "\nsource-repository-package\n" ("\n" + projectFile); - initialText = pkgs.lib.lists.take 1 blocks; - repoBlocks = builtins.map (parseBlock cabalProjectFileName lookupSha256) (pkgs.lib.lists.drop 1 blocks); - overrideSourceRepo = sourceRepo: (source-repo-override.${sourceRepo.url} or (pkgs.lib.id)) sourceRepo; - in { - sourceRepos = pkgs.lib.lists.map (block: overrideSourceRepo block.sourceRepo) repoBlocks; - otherText = pkgs.lib.strings.concatStringsSep "\n" ( - initialText - ++ (builtins.map (x: x.otherText) repoBlocks)); - }; - - # Parse a repository - parseRepositoryBlock = cabalProjectFileName: lookupSha256: cabal-install: nix-tools: block: - let - lines = pkgs.lib.splitString "\n" block; - x = span (pkgs.lib.strings.hasPrefix " ") (__tail lines); - attrs = parseBlockLines x.fst; - in rec { - name = __head lines; - repo = attrs; - home = - pkgs.evalPackages.runCommandLocal name { nativeBuildInputs = [ cabal-install pkgs.evalPackages.curl nix-tools ]; } '' - mkdir -p $out/.cabal - cat < $out/.cabal/config - repository ${name} - url: ${attrs.url} - ${pkgs.lib.optionalString (attrs ? secure) "secure: ${attrs.secure}"} - ${pkgs.lib.optionalString (attrs ? root-keys) "root-keys: ${attrs.root-keys}"} - ${pkgs.lib.optionalString (attrs ? key-threshold) "key-threshold: ${attrs.key-threshold}"} - EOF - - export SSL_CERT_FILE=${pkgs.evalPackages.cacert}/etc/ssl/certs/ca-bundle.crt - mkdir -p $out/.cabal/packages/${name} - HOME=$out cabal new-update ${name} - ''; - hackage = import ((x: __trace (toString x) x) ( - pkgs.evalPackages.runCommandLocal name { nativeBuildInputs = [ cabal-install pkgs.evalPackages.curl nix-tools ]; } '' - mkdir -p $out - hackage-to-nix $out ${home}/.cabal/packages/${name}/01-index.tar ${attrs.url} - '')); - tarball = { - inherit name; - index = home + "/.cabal/packages/${name}/01-index.tar.gz"; - }; - otherText = '' - repository ${name} - url: file:${home + "/.cabal/packages/${name}"} - secure: True - root-keys: - key-threshold: 0 - '' + pkgs.lib.strings.concatStringsSep "\n" x.snd; - }; - - parseRepositories = cabalProjectFileName: lookupSha256: cabal-install: nix-tools: projectFile: - let - blocks = pkgs.lib.splitString "\nrepository " ("\n" + projectFile); - initialText = pkgs.lib.lists.take 1 blocks; - repoBlocks = builtins.map (parseRepositoryBlock cabalProjectFileName lookupSha256 cabal-install nix-tools) (pkgs.lib.lists.drop 1 blocks); - in { - extra-hackages = pkgs.lib.lists.map (block: block.hackage) repoBlocks; - tarballs = pkgs.lib.lists.map (block: block.tarball) repoBlocks; - otherText = pkgs.lib.strings.concatStringsSep "\n" ( - initialText - ++ (builtins.map (x: x.otherText) repoBlocks)); - }; - in { - inherit parseIndexState parseSourceRepositoryPackages parseRepositories; + inherit parseIndexState parseBlockLines parseBlock; } diff --git a/lib/call-cabal-project-to-nix.nix b/lib/call-cabal-project-to-nix.nix index e266d2f93f..cb42f7370d 100644 --- a/lib/call-cabal-project-to-nix.nix +++ b/lib/call-cabal-project-to-nix.nix @@ -192,7 +192,7 @@ let replaceSourceRepos = projectFile: let - fetchPackageRepo = fetchgit: repoData: + fetchRepo = fetchgit: repoData: let fetched = if repoData.sha256 != null @@ -221,13 +221,14 @@ let tag = "minimal"; }; - # Parse the `source-repository-package` blocks - sourceRepoPackageResult = pkgs.haskell-nix.haskellLib.parseSourceRepositoryPackages - cabalProjectFileName lookupSha256 source-repo-override projectFile; - - # Parse the `repository` blocks - repoResult = pkgs.haskell-nix.haskellLib.parseRepositories - cabalProjectFileName lookupSha256 cabal-install nix-tools sourceRepoPackageResult.otherText; + blocks = pkgs.lib.splitString "\nsource-repository-package\n" ("\n" + projectFile); + initialText = pkgs.lib.lists.take 1 blocks; + repoBlocks = builtins.map (pkgs.haskell-nix.haskellLib.parseBlock cabalProjectFileName lookupSha256) (pkgs.lib.lists.drop 1 blocks); + overrideSourceRepo = sourceRepo: (source-repo-override.${sourceRepo.url} or (pkgs.lib.id)) sourceRepo; + sourceRepoData = pkgs.lib.lists.map (x: overrideSourceRepo x.sourceRepo) repoBlocks; + otherText = pkgs.evalPackages.writeText "cabal.project" (pkgs.lib.strings.concatStringsSep "\n" ( + initialText + ++ (builtins.map (x: x.otherText) repoBlocks))); # we need the repository content twice: # * at eval time (below to build the fixed project file) @@ -238,13 +239,12 @@ let # on the target system would use, so that the derivation is unaffected # and, say, a linux release build job can identify the derivation # as built by a darwin builder, and fetch it from a cache - sourceReposEval = builtins.map (fetchPackageRepo pkgs.evalPackages.fetchgit) sourceRepoPackageResult.sourceRepos; - sourceReposBuild = builtins.map (x: (fetchPackageRepo pkgs.fetchgit x).fetched) sourceRepoPackageResult.sourceRepos; + sourceReposEval = builtins.map (fetchRepo pkgs.evalPackages.fetchgit) sourceRepoData; + sourceReposBuild = builtins.map (x: (fetchRepo pkgs.fetchgit x).fetched) sourceRepoData; in { sourceRepos = sourceReposBuild; - inherit (repoResult) tarballs extra-hackages; makeFixedProjectFile = '' - cp -f ${pkgs.evalPackages.writeText "cabal.project" repoResult.otherText} ./cabal.project + cp -f ${otherText} ./cabal.project '' + pkgs.lib.optionalString (builtins.length sourceReposEval != 0) ('' chmod +w -R ./cabal.project @@ -279,7 +279,7 @@ let fixedProject = if rawCabalProject == null - then { sourceRepos = []; tarballs = []; extra-hackages = []; makeFixedProjectFile = ""; replaceLocations = ""; } + then { sourceRepos = []; makeFixedProjectFile = ""; replaceLocations = ""; } else replaceSourceRepos rawCabalProject; # The use of the actual GHC can cause significant problems: @@ -524,11 +524,7 @@ let # some packages that will be excluded by `index-state-found` # which is used by cabal (cached-index-state >= index-state-found). dotCabal { - inherit cabal-install nix-tools; - extra-hackage-tarballs = - if __length extra-hackage-tarballs != 0 - then extra-hackage-tarballs - else fixedProject.tarballs; + inherit cabal-install nix-tools extra-hackage-tarballs; index-state = cached-index-state; sha256 = index-sha256-found; } @@ -614,5 +610,5 @@ in { projectNix = plan-nix; index-state = index-state-found; inherit src; - inherit (fixedProject) sourceRepos extra-hackages; + inherit (fixedProject) sourceRepos; } diff --git a/lib/default.nix b/lib/default.nix index c3ebff4d0d..2bb6a67509 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -275,7 +275,7 @@ in { inherit (import ./cabal-project-parser.nix { inherit pkgs; - }) parseIndexState parseSourceRepositoryPackages parseRepositories; + }) parseIndexState parseBlock; cabalToNixpkgsLicense = import ./spdx/cabal.nix pkgs;