Skip to content

Commit f4c2e41

Browse files
committed
Last parts
1 parent efbd1a1 commit f4c2e41

File tree

11 files changed

+35
-186
lines changed

11 files changed

+35
-186
lines changed

builder/comp-builder.nix

Lines changed: 8 additions & 9 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 ? []
@@ -239,16 +238,16 @@ let
239238
executableToolDepends =
240239
(lib.concatMap (c: if c.isHaskell or false
241240
then builtins.attrValues (c.components.exes or {})
242-
else [c])
241+
else [c])
243242
(builtins.filter (x: !(isNull x))
244-
(map
243+
(map
245244
(p: if builtins.isFunction p
246-
then p { inherit (package.identifier) version; inherit revision; }
245+
then p { inherit (package.identifier) version; }
247246
else p) build-tools))) ++
248247
lib.optional (pkgconfig != []) buildPackages.cabalPkgConfigWrapper;
249248

250249
# Unfortunately, we need to wrap ghc commands for cabal builds to
251-
# work in the nix-shell. See ../doc/removing-with-package-wrapper.md.
250+
# work in the nix-shell. See ../docs/dev/removing-with-package-wrapper.md.
252251
shellWrappers = ghcForComponent {
253252
componentName = fullName;
254253
inherit configFiles enableDWARF;
@@ -298,11 +297,11 @@ let
298297
''
299298
);
300299
}
301-
# patches can (if they like) depend on the version and revision of the package.
300+
# patches can (if they like) depend on the version of the package.
302301
// lib.optionalAttrs (patches != []) {
303302
patches = map (p:
304303
if builtins.isFunction p
305-
then p { inherit (package.identifier) version; inherit revision; }
304+
then p { inherit (package.identifier) version; }
306305
else p
307306
) patches;
308307
}
@@ -316,7 +315,7 @@ let
316315

317316
haddock = haddockBuilder {
318317
inherit componentId component package flags commonConfigureFlags
319-
commonAttrs revision doHaddock
318+
commonAttrs doHaddock
320319
doHoogle hyperlinkSource quickjump setupHaddockFlags
321320
needsProfiling configFiles preHaddock postHaddock pkgconfig;
322321

@@ -328,7 +327,7 @@ let
328327
outputHashMode = "recursive";
329328
outputHashAlgo = "sha256";
330329
};
331-
330+
332331
drv = stdenv.mkDerivation (commonAttrs // contentAddressedAttrs // {
333332
pname = nameOnly;
334333
inherit (package.identifier) version;

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: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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
'' +
@@ -522,7 +517,7 @@ let
522517
"freeze" # The `cabal.project.freeze` file created by `cabal v2-freeze`
523518
];
524519
} ''
525-
set -x
520+
set -e
526521
527522
tmp=$(mktemp -d)
528523
cd $tmp
@@ -578,19 +573,17 @@ let
578573
EOF
579574
cat $CABAL_DIR/config
580575
576+
echo "Installing fake curl"
581577
PATH=${
582578
fakeCurl ({
583579
"http://hackage.haskell.org" = hackageRepo { index-state = cached-index-state; sha256 = index-sha256-found; };
584580
} // inputMap)
585-
}/bin:$PATH \
586-
cabal update -v \
581+
}/bin:$PATH
582+
583+
cabal update \
587584
-w ${ghc.targetPrefix}ghc \
588-
--with-ghc-pkg=${ghc.targetPrefix}ghc-pkg \
585+
--with-ghc-pkg=${ghc.targetPrefix}ghc-pkg
589586
590-
# Using `cabal v2-freeze` will configure the project (since
591-
# it is not configured yet), taking the existing `cabal.project.freeze`
592-
# file into account. Then it "writes out a freeze file which
593-
# records all of the versions and flags that are picked" (from cabal docs).
594587
echo "Using index-state ${index-state-found}"
595588
596589
make-install-plan ${
@@ -661,5 +654,5 @@ in {
661654
projectNix = plan-nix;
662655
index-state = index-state-found;
663656
inherit src;
664-
inherit (fixedProject) sourceRepos extra-hackages;
657+
inherit (fixedProject) sourceRepos;
665658
}

modules/configuration-nix.nix

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
{ pkgs, config, ... }:
77
let
8-
fromUntil = from: until: patch: { version, revision }:
8+
fromUntil = from: until: patch: { version }:
99
if builtins.compareVersions version from >= 0
1010
&& builtins.compareVersions version until < 0
1111
then patch
1212
else null;
13-
from = v: patch: { version, revision }:
13+
from = v: patch: { version }:
1414
if builtins.compareVersions version v >= 0
1515
then patch
1616
else null;
@@ -91,16 +91,16 @@ in {
9191

9292
packages.discount.components.library.libs = pkgs.lib.mkForce [ pkgs.discount ];
9393

94-
packages.llvm-hs.components.library.build-tools = pkgs.lib.mkForce [
94+
packages.llvm-hs.components.library.build-tools = pkgs.lib.mkForce [
9595
(fromUntil "5.0.0" "6" pkgs.llvmPackages_5.llvm)
9696
(fromUntil "6.0.0" "7" pkgs.llvmPackages_6.llvm)
9797
(fromUntil "7.0.0" "8" pkgs.llvmPackages_7.llvm)
9898
(fromUntil "8.0.0" "9" pkgs.llvmPackages_8.llvm)
9999
(fromUntil "9.0.0" "12" pkgs.llvmPackages_9.llvm)
100100
(fromUntil "12.0.0" "15" pkgs.llvmPackages_12.llvm)
101-
# NOTE: we currently don't have a llvm versoin > 12 that has a tag
102-
# in nixpkgs, so we probably can't build `llvm-hs > 12`, there
103-
# is however a head version of llvm in nixpkgs, which we might
101+
# NOTE: we currently don't have a llvm versoin > 12 that has a tag
102+
# in nixpkgs, so we probably can't build `llvm-hs > 12`, there
103+
# is however a head version of llvm in nixpkgs, which we might
104104
# be able to use if that case were to occur
105105
];
106106

modules/hackage-project.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ in {
3232
'';
3333
cabalProjectLocal = lib.mkOverride 1100 null;
3434
cabalProjectFreeze = lib.mkOverride 1100 null;
35-
src =
36-
let
35+
src =
36+
let
3737
tarball = config.evalPackages.fetchurl {
3838
url = "mirror://hackage/${name}-${version}.tar.gz";
3939
inherit (pkgs.haskell-nix.hackage.${name}.${version}) sha256; };

modules/package.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ in {
129129
flags = mkOption {
130130
type = attrsOf bool;
131131
};
132+
cabalFile = mkOption {
133+
type = nullOr path;
134+
};
132135
package = {
133136
specVersion = mkOption {
134137
type = str;

modules/plan.nix

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ let
253253
'';
254254
};
255255
planned = mkOption {
256-
description = "Set to true by `plan-to-nix` for any component that was included in the `plan.json` file.";
256+
description = "Set to true by `plan-to-nix` for any component that was included in the `plan.json` file.";
257257
# This is here so that (rather than in componentOptions) so it can be set project wide for stack projects
258258
type = bool;
259259
default = def.planned or false;
@@ -316,7 +316,9 @@ in {
316316
then (abort "${name} has no revision!")
317317
else revision (modArgs // { hsPkgs = hsPkgs // (mapAttrs (l: _: hsPkgs.${name}.components.sublibs.${l}) (m.components.sublibs or {})); });
318318
in
319-
m // { flags = lib.mapAttrs (_: lib.mkDefault) (m.flags // revArgs.flags or {}); }
319+
m // { flags = lib.mapAttrs (_: lib.mkDefault) (m.flags // revArgs.flags or {});
320+
cabalFile = revArgs.cabalFile or null;
321+
}
320322
) (lib.filterAttrs (n: v: v == null || v.revision != null ) module.packages);
321323
};
322324
}

nix-tools/plan2nix/Plan2Nix.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ plan2nix args Plan { packages, extras, components, compilerVersion, compilerPack
139139
[revBinding pkg mkNull]
140140
bind pkg (Just Package { packageFlags, packageHasDescriptionOverride = True }) =
141141
bindPath (VarName pkg :| ["revision"]) (mkSym "import" @@ mkPath False ("." </> "cabal-files" </> T.unpack pkg <.> "nix"))
142-
: bindPath (VarName pkg :| ["cabalFile"]) (mkSym "builtins" @. "readFile" @@ mkPath False ("." </> "cabal-files" </> T.unpack pkg <.> "cabal"))
142+
: bindPath (VarName pkg :| ["cabalFile"]) (mkPath False ("." </> "cabal-files" </> T.unpack pkg <.> "cabal"))
143143
: flagBindings
144144

145145
where

0 commit comments

Comments
 (0)