Skip to content

Commit

Permalink
Revert lib changes for now
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishmack committed Feb 8, 2022
1 parent 24dd197 commit a80b538
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 91 deletions.
74 changes: 3 additions & 71 deletions lib/cabal-project-parser.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 <<EOF > $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;
}
34 changes: 15 additions & 19 deletions lib/call-cabal-project-to-nix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ let

replaceSourceRepos = projectFile:
let
fetchPackageRepo = fetchgit: repoData:
fetchRepo = fetchgit: repoData:
let
fetched =
if repoData.sha256 != null
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -614,5 +610,5 @@ in {
projectNix = plan-nix;
index-state = index-state-found;
inherit src;
inherit (fixedProject) sourceRepos extra-hackages;
inherit (fixedProject) sourceRepos;
}
2 changes: 1 addition & 1 deletion lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ in {

inherit (import ./cabal-project-parser.nix {
inherit pkgs;
}) parseIndexState parseSourceRepositoryPackages parseRepositories;
}) parseIndexState parseBlock;


cabalToNixpkgsLicense = import ./spdx/cabal.nix pkgs;
Expand Down

0 comments on commit a80b538

Please sign in to comment.