Skip to content

Commit 51c1da6

Browse files
Try #1775:
2 parents 6c86f52 + 9b369a2 commit 51c1da6

File tree

25 files changed

+423
-285
lines changed

25 files changed

+423
-285
lines changed

builder/comp-builder.nix

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ let self =
88
, setup
99
, src
1010
, flags
11-
, revision
1211
, cabalFile
1312
, cabal-generator
1413
, patches ? []
@@ -246,12 +245,12 @@ let
246245
&& x.identifier.name or "" != "hsc2hs")
247246
(map
248247
(p: if builtins.isFunction p
249-
then p { inherit (package.identifier) version; inherit revision; }
248+
then p { inherit (package.identifier) version; }
250249
else p) build-tools))) ++
251250
lib.optional (pkgconfig != []) buildPackages.cabalPkgConfigWrapper;
252251

253252
# Unfortunately, we need to wrap ghc commands for cabal builds to
254-
# work in the nix-shell. See ../doc/removing-with-package-wrapper.md.
253+
# work in the nix-shell. See ../docs/dev/removing-with-package-wrapper.md.
255254
shellWrappers = ghcForComponent {
256255
componentName = fullName;
257256
inherit configFiles enableDWARF;
@@ -301,11 +300,11 @@ let
301300
''
302301
);
303302
}
304-
# patches can (if they like) depend on the version and revision of the package.
303+
# patches can (if they like) depend on the version of the package.
305304
// lib.optionalAttrs (patches != []) {
306305
patches = map (p:
307306
if builtins.isFunction p
308-
then p { inherit (package.identifier) version; inherit revision; }
307+
then p { inherit (package.identifier) version; }
309308
else p
310309
) patches;
311310
}
@@ -319,7 +318,7 @@ let
319318

320319
haddock = haddockBuilder {
321320
inherit componentId component package flags commonConfigureFlags
322-
commonAttrs revision doHaddock
321+
commonAttrs doHaddock
323322
doHoogle hyperlinkSource quickjump setupHaddockFlags
324323
needsProfiling configFiles preHaddock postHaddock pkgconfig;
325324

builder/haddock-builder.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
, component
55
, package
66
, flags
7-
, revision
87
, commonAttrs
98
, preHaddock
109
, postHaddock

builder/hspkg-builder.nix

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ config:
99
, name
1010
, sha256
1111
, src
12-
, revision
13-
, revisionSha256
12+
, cabalFile
1413
, patches
1514

1615
, shellHook
@@ -48,12 +47,6 @@ let
4847
# repository.
4948
inputMap.${__head baseUrlMatch} + "/package/${__elemAt baseUrlMatch 1}"
5049
else pkg.src;
51-
cabalFile = if revision == null || revision == 0 || bundledSrc != null then null else
52-
fetchurl {
53-
name = "${name}-${toString revision}.cabal";
54-
url = "https://hackage.haskell.org/package/${name}/revision/${toString revision}.cabal";
55-
sha256 = revisionSha256;
56-
};
5750

5851
defaultSetupSrc = if stdenv.hostPlatform.isGhcjs then ./Setup.ghcjs.hs else ./Setup.hs;
5952

@@ -134,12 +127,12 @@ let
134127
extraSrcFiles = components.setup.extraSrcFiles ++ [ "Setup.hs" "Setup.lhs" ];
135128
pkgconfig = if components ? library then components.library.pkgconfig or [] else [];
136129
};
137-
inherit package name src flags revision patches defaultSetupSrc;
130+
inherit package name src flags patches defaultSetupSrc;
138131
inherit (pkg) preUnpack postUnpack;
139132
};
140133

141134
buildComp = allComponent: componentId: component: comp-builder {
142-
inherit allComponent componentId component package name src flags setup cabalFile cabal-generator patches revision
135+
inherit allComponent componentId component package name src flags setup cabalFile cabal-generator patches
143136
shellHook
144137
;
145138
};

lib/cabal-project-parser.nix

Lines changed: 1 addition & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -121,99 +121,6 @@ let
121121
initialText
122122
++ (builtins.map (x: x.otherText) repoBlocks));
123123
};
124-
125-
# Parse and replace repository
126-
# This works in a similar way to the `source-repository-package` but we are
127-
# able to simply replace the `repository` blocks with local `file:/nix/store` ones.
128-
# This works because `cabal configure` does not include any of the `/nix/sore/`
129-
# paths in the `plan.json` (so materialized plan-nix will still work as expeced).
130-
# See tests/unit.nix for examples of input and output.
131-
parseRepositoryBlock = evalPackages: cabalProjectFileName: sha256map: inputMap: cabal-install: nix-tools: block:
132-
let
133-
lines = pkgs.lib.splitString "\n" block;
134-
# The first line will contain the repository name.
135-
x = span (pkgs.lib.strings.hasPrefix " ") (__tail lines);
136-
attrs = parseBlockLines x.fst;
137-
sha256 = attrs."--sha256" or (
138-
if sha256map != null
139-
then sha256map."${attrs.url}"
140-
else null);
141-
in rec {
142-
# This is `some-name` from the `repository some-name` line in the `cabal.project` file.
143-
name = __head lines;
144-
# The $HOME/.cabal/packages/${name} after running `cabal v2-update` to download the repository
145-
repoContents = if inputMap ? ${attrs.url}
146-
# If there is an input use it to make `file:` url and create a suitable `.cabal/packages/${name}` directory
147-
then evalPackages.runCommand name ({
148-
nativeBuildInputs = [ cabal-install ] ++ evalPackages.haskell-nix.cabal-issue-8352-workaround;
149-
preferLocalBuild = true;
150-
}) ''
151-
HOME=$(mktemp -d)
152-
mkdir -p $HOME/.cabal/packages/${name}
153-
cat <<EOF > $HOME/.cabal/config
154-
repository ${name}
155-
url: file:${inputMap.${attrs.url}}
156-
${pkgs.lib.optionalString (attrs ? secure) "secure: ${attrs.secure}"}
157-
${pkgs.lib.optionalString (attrs ? root-keys) "root-keys: ${attrs.root-keys}"}
158-
${pkgs.lib.optionalString (attrs ? key-threshold) "key-threshold: ${attrs.key-threshold}"}
159-
EOF
160-
161-
cabal v2-update ${name}
162-
cp -r $HOME/.cabal/packages/${name} $out
163-
''
164-
else evalPackages.runCommand name ({
165-
nativeBuildInputs = [ cabal-install evalPackages.curl nix-tools ] ++ evalPackages.haskell-nix.cabal-issue-8352-workaround;
166-
LOCALE_ARCHIVE = pkgs.lib.optionalString (evalPackages.stdenv.buildPlatform.libc == "glibc") "${evalPackages.glibcLocales}/lib/locale/locale-archive";
167-
LANG = "en_US.UTF-8";
168-
preferLocalBuild = true;
169-
} // pkgs.lib.optionalAttrs (sha256 != null) {
170-
outputHashMode = "recursive";
171-
outputHashAlgo = "sha256";
172-
outputHash = sha256;
173-
}) ''
174-
HOME=$(mktemp -d)
175-
mkdir -p $HOME/.cabal/packages/${name}
176-
cat <<EOF > $HOME/.cabal/config
177-
repository ${name}
178-
url: ${attrs.url}
179-
${pkgs.lib.optionalString (attrs ? secure) "secure: ${attrs.secure}"}
180-
${pkgs.lib.optionalString (attrs ? root-keys) "root-keys: ${attrs.root-keys}"}
181-
${pkgs.lib.optionalString (attrs ? key-threshold) "key-threshold: ${attrs.key-threshold}"}
182-
EOF
183-
184-
export SSL_CERT_FILE=${evalPackages.cacert}/etc/ssl/certs/ca-bundle.crt
185-
cabal v2-update ${name}
186-
cp -r $HOME/.cabal/packages/${name} $out
187-
'';
188-
# Output of hackage-to-nix
189-
hackage = import (
190-
evalPackages.runCommand ("hackage-to-nix-" + name) {
191-
nativeBuildInputs = [ cabal-install evalPackages.curl nix-tools ];
192-
LOCALE_ARCHIVE = pkgs.lib.optionalString (evalPackages.stdenv.buildPlatform.libc == "glibc") "${evalPackages.glibcLocales}/lib/locale/locale-archive";
193-
LANG = "en_US.UTF-8";
194-
preferLocalBuild = true;
195-
} ''
196-
mkdir -p $out
197-
hackage-to-nix $out ${repoContents}/01-index.tar ${attrs.url}
198-
'');
199-
# Directory to `lndir` when constructing a suitable $HOME/.cabal dir
200-
repo = {
201-
${name} = repoContents;
202-
};
203-
};
204-
205-
parseRepositories = evalPackages: cabalProjectFileName: sha256map: inputMap: cabal-install: nix-tools: projectFile:
206-
let
207-
# This will leave the name of repository in the first line of each block
208-
blocks = pkgs.lib.splitString "\nrepository " ("\n" + projectFile);
209-
repoBlocks = builtins.map (parseRepositoryBlock evalPackages cabalProjectFileName sha256map inputMap cabal-install nix-tools) (pkgs.lib.lists.drop 1 blocks);
210-
in {
211-
extra-hackages = pkgs.lib.lists.map (block: block.hackage) repoBlocks;
212-
repos = pkgs.lib.lists.foldl' (x: block: x // block.repo) {} repoBlocks;
213-
};
214-
215124
in {
216-
inherit parseIndexState parseSourceRepositoryPackages parseRepositories
217-
# These are only exposed for tests
218-
parseSourceRepositoryPackageBlock parseRepositoryBlock;
125+
inherit parseIndexState parseSourceRepositoryPackages;
219126
}

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

Lines changed: 71 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ in
7070
}@args:
7171

7272
let
73-
inherit (evalPackages.haskell-nix) materialize dotCabal;
73+
inherit (evalPackages.haskell-nix) materialize mkLocalHackageRepo;
7474

7575
# These defaults are hear rather than in modules/cabal-project.nix to make them
7676
# lazy enough to avoid infinite recursion issues.
@@ -261,10 +261,6 @@ let
261261
sourceRepoPackageResult = pkgs.haskell-nix.haskellLib.parseSourceRepositoryPackages
262262
cabalProjectFileName sha256map source-repo-override projectFile;
263263

264-
# Parse the `repository` blocks
265-
repoResult = pkgs.haskell-nix.haskellLib.parseRepositories
266-
evalPackages cabalProjectFileName sha256map inputMap cabal-install nix-tools sourceRepoPackageResult.otherText;
267-
268264
# we need the repository content twice:
269265
# * at eval time (below to build the fixed project file)
270266
# Here we want to use evalPackages.fetchgit, so one can calculate
@@ -278,7 +274,6 @@ let
278274
sourceReposBuild = builtins.map (x: (fetchPackageRepo pkgs.fetchgit x).fetched) sourceRepoPackageResult.sourceRepos;
279275
in {
280276
sourceRepos = sourceReposBuild;
281-
inherit (repoResult) repos extra-hackages;
282277
makeFixedProjectFile = ''
283278
cp -f ${evalPackages.writeText "cabal.project" sourceRepoPackageResult.otherText} ./cabal.project
284279
'' +
@@ -456,6 +451,44 @@ let
456451
'';
457452
};
458453

454+
fakeCurl = inputMap:
455+
let inputMapFile = evalPackages.writeTextFile {
456+
name = "fakeCurlInputMap";
457+
text = ''
458+
${builtins.concatStringsSep "\n" (pkgs.lib.mapAttrsToList f inputMap)}
459+
'';
460+
};
461+
f = name: index: "${name}\tfile://${index}";
462+
in
463+
evalPackages.writeShellApplication {
464+
name = "curl";
465+
text = ''
466+
declare -a ARGS
467+
ARGS=("''${@}")
468+
while read -r uri path; do
469+
ARGS=("''${ARGS[@]/$uri/$path}")
470+
done <${inputMapFile}
471+
${pkgs.curl}/bin/curl "''${ARGS[@]}" >/dev/null
472+
echo 200
473+
'';
474+
};
475+
476+
hackageRepo = { index-state, sha256 }:
477+
assert sha256 != null;
478+
let at = builtins.replaceStrings [ ":" ] [ "" ] index-state;
479+
in mkLocalHackageRepo {
480+
name = "hackage.haskell.org";
481+
index = pkgs.fetchurl {
482+
name = "01-index.tar.gz-at-${at}";
483+
url = "https://hackage.haskell.org/01-index.tar.gz";
484+
downloadToTemp = true;
485+
postFetch =
486+
"${nix-tools}/bin/truncate-index -o $out -i $downloadedFile -s ${index-state}";
487+
outputHashAlgo = "sha256";
488+
outputHash = sha256;
489+
};
490+
};
491+
459492
plan-nix = materialize ({
460493
inherit materialized;
461494
sha256 = plan-sha256;
@@ -484,6 +517,8 @@ let
484517
"freeze" # The `cabal.project.freeze` file created by `cabal v2-freeze`
485518
];
486519
} ''
520+
set -e
521+
487522
tmp=$(mktemp -d)
488523
cd $tmp
489524
# if cleanedSource is empty, this means it's a new
@@ -527,23 +562,31 @@ let
527562
export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
528563
export GIT_SSL_CAINFO=${cacert}/etc/ssl/certs/ca-bundle.crt
529564
530-
# Using `cabal v2-freeze` will configure the project (since
531-
# it is not configured yet), taking the existing `cabal.project.freeze`
532-
# file into account. Then it "writes out a freeze file which
533-
# records all of the versions and flags that are picked" (from cabal docs).
565+
export CABAL_DIR=$(mktemp -d)
566+
567+
cat >$CABAL_DIR/config <<EOF
568+
repository hackage.haskell.org
569+
url: http://hackage.haskell.org/
570+
secure: True
571+
root-keys: aaa
572+
key-threshold: 0
573+
EOF
574+
cat $CABAL_DIR/config
575+
576+
echo "Installing fake curl"
577+
PATH=${
578+
fakeCurl ({
579+
"http://hackage.haskell.org" = hackageRepo { index-state = cached-index-state; sha256 = index-sha256-found; };
580+
} // inputMap)
581+
}/bin:$PATH
582+
583+
cabal update \
584+
-w ${ghc.targetPrefix}ghc \
585+
--with-ghc-pkg=${ghc.targetPrefix}ghc-pkg
586+
534587
echo "Using index-state ${index-state-found}"
535-
HOME=${
536-
# This creates `.cabal` directory that is as it would have
537-
# been at the time `cached-index-state`. We may include
538-
# some packages that will be excluded by `index-state-found`
539-
# which is used by cabal (cached-index-state >= index-state-found).
540-
dotCabal {
541-
inherit cabal-install nix-tools extra-hackage-tarballs;
542-
extra-hackage-repos = fixedProject.repos;
543-
index-state = cached-index-state;
544-
sha256 = index-sha256-found;
545-
}
546-
} cabal v2-freeze ${
588+
589+
make-install-plan ${
547590
# Setting the desired `index-state` here in case it is not
548591
# in the cabal.project file. This will further restrict the
549592
# packages used by the solver (cached-index-state >= index-state-found).
@@ -596,6 +639,11 @@ let
596639
# as they should not be in the output hash (they may change slightly
597640
# without affecting the nix).
598641
find $out \( -type f -or -type l \) ! -name '*.nix' -delete
642+
643+
# Make the revised cabal files available (after the delete step avove)
644+
echo "Moving cabal files from $tmp${subDir'}/dist-newstyle/cabal-files to $out${subDir'}/cabal-files"
645+
mv $tmp${subDir'}/dist-newstyle/cabal-files $out${subDir'}/cabal-files
646+
599647
# Remove empty dirs
600648
find $out -type d -empty -delete
601649
@@ -606,5 +654,5 @@ in {
606654
projectNix = plan-nix;
607655
index-state = index-state-found;
608656
inherit src;
609-
inherit (fixedProject) sourceRepos extra-hackages;
657+
inherit (fixedProject) sourceRepos;
610658
}

materialized/ghc8107/nix-tools/.plan.nix/nix-tools.nix

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)