Skip to content

Commit be8337e

Browse files
authored
Support conditional source-repository-packages (input-output-hk#2171)
* Support conditional source-repository-packages Updates the way haskell.nix handles source-repository-package blocks so that this can work: ``` if !os(ghcjs) source-repository-package type: git location: https://github.com/hamishmack/hs-libsodium.git tag: c094f210f3bd34d97204451ea57855a5d17e2086 --sha256: sha256-6iCKvdLdjwg2jcoWMEj3qcFTvKe3P4BYxgKeXY3QwRM= ``` * Use actions/checkout@v4 * Update patch bounds * Remove __trace
1 parent 9ee04ea commit be8337e

File tree

7 files changed

+86
-76
lines changed

7 files changed

+86
-76
lines changed

.github/workflows/lints.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
deadnix:
2424
runs-on: [self-hosted, linux]
2525
steps:
26-
- uses: actions/checkout@v3
26+
- uses: actions/checkout@v4
2727
- run: |
2828
nix run github:astro/deadnix -- --edit --no-lambda-pattern-names --exclude materialized
2929
TMPFILE=$(mktemp)

.github/workflows/pipeline.yml

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,126 +21,126 @@ jobs:
2121
nix-build:
2222
runs-on: [self-hosted, linux]
2323
steps:
24-
- uses: actions/checkout@v3
24+
- uses: actions/checkout@v4
2525
- name: "Run tests with ghc8107: Running the nix-build tests..."
2626
run: "./test/tests.sh ghc8107 nix-build"
2727

2828
unit-tests:
2929
runs-on: [self-hosted, linux]
3030
steps:
31-
- uses: actions/checkout@v3
31+
- uses: actions/checkout@v4
3232
- name: "Run tests with ghc8107: Running the unit tests..."
3333
run: "./test/tests.sh ghc8107 unit-tests"
3434

3535
runghc:
3636
runs-on: [self-hosted, linux]
3737
steps:
38-
- uses: actions/checkout@v3
38+
- uses: actions/checkout@v4
3939
- name: "Run tests with ghc8107: Checking that a nix-shell works for runghc..."
4040
run: "./test/tests.sh ghc8107 runghc"
4141

4242
cabal:
4343
runs-on: [self-hosted, linux]
4444
steps:
45-
- uses: actions/checkout@v3
45+
- uses: actions/checkout@v4
4646
- name: "Run tests with ghc8107: Checking that a nix-shell works for cabal..."
4747
run: "./test/tests.sh ghc8107 cabal"
4848

4949
cabal-doExactConfig:
5050
runs-on: [self-hosted, linux]
5151
steps:
52-
- uses: actions/checkout@v3
52+
- uses: actions/checkout@v4
5353
- name: "Run tests with ghc8107: Checking that a nix-shell works for cabal (doExactConfig component)..."
5454
run: "./test/tests.sh ghc8107 cabal-doExactConfig"
5555

5656
tests-benchmarks:
5757
runs-on: [self-hosted, linux]
5858
steps:
59-
- uses: actions/checkout@v3
59+
- uses: actions/checkout@v4
6060
- name: "Run tests with ghc8107: Checking that a nix-shell works for a project with test-suite build-tools and benchmarks..."
6161
run: "./test/tests.sh ghc8107 tests-benchmarks"
6262

6363
multi-target:
6464
runs-on: [self-hosted, linux]
6565
steps:
66-
- uses: actions/checkout@v3
66+
- uses: actions/checkout@v4
6767
- name: "Run tests with ghc8107: Checking that a nix-shell works for a multi-target project..."
6868
run: "./test/tests.sh ghc8107 multi-target"
6969

7070
shellFor-single-package:
7171
runs-on: [self-hosted, linux]
7272
steps:
73-
- uses: actions/checkout@v3
73+
- uses: actions/checkout@v4
7474
- name: "Run tests with ghc8107: Checking shellFor works for a cabal project, multiple packages..."
7575
run: "./test/tests.sh ghc8107 shellFor-single-package"
7676

7777
shellFor-multiple-package:
7878
runs-on: [self-hosted, linux]
7979
steps:
80-
- uses: actions/checkout@v3
80+
- uses: actions/checkout@v4
8181
- name: "Run tests with ghc8107: Checking shellFor works for a cabal project, single package...y"
8282
run: "./test/tests.sh ghc8107 shellFor-multiple-package"
8383

8484
shellFor-hoogle:
8585
runs-on: [self-hosted, linux]
8686
steps:
87-
- uses: actions/checkout@v3
87+
- uses: actions/checkout@v4
8888
- name: "Run tests with ghc8107: Checking shellFor works for a cabal project, single package..."
8989
run: "./test/tests.sh ghc8107 shellFor-hoogle"
9090

9191
shellFor-not-depends:
9292
runs-on: [self-hosted, linux]
9393
steps:
94-
- uses: actions/checkout@v3
94+
- uses: actions/checkout@v4
9595
- name: "Run tests with ghc8107: Checking shellFor does not depend on given packages...y"
9696
run: "./test/tests.sh ghc8107 shellFor-not-depends"
9797

9898
maintainer-scripts:
9999
runs-on: [self-hosted, linux]
100100
steps:
101-
- uses: actions/checkout@v3
101+
- uses: actions/checkout@v4
102102
- name: "Run tests with ghc8107: Checking the maintainer scripts...y"
103103
run: "./test/tests.sh ghc8107 maintainer-scripts"
104104

105105
plan-extra-hackages:
106106
runs-on: [self-hosted, linux]
107107
steps:
108-
- uses: actions/checkout@v3
108+
- uses: actions/checkout@v4
109109
- name: "Run tests with ghc8107: Checking that plan construction works with extra Hackages..."
110110
run: "./test/tests.sh ghc8107 plan-extra-hackages"
111111

112112
build-extra-hackages:
113113
runs-on: [self-hosted, linux]
114114
steps:
115-
- uses: actions/checkout@v3
115+
- uses: actions/checkout@v4
116116
- name: "Run tests with ghc8107: Checking that package with extra Hackages can be build..."
117117
run: "./test/tests.sh ghc8107 build-extra-hackages"
118118

119119
hix:
120120
runs-on: [self-hosted, linux]
121121
steps:
122-
- uses: actions/checkout@v3
122+
- uses: actions/checkout@v4
123123
- name: "Run tests with ghc8107: End-2-end test of hix project initialization and flakes development shell ..."
124124
run: "./test/tests.sh ghc8107 hix"
125125

126126
# template:
127127
# runs-on: [self-hosted, linux]
128128
# steps:
129-
# - uses: actions/checkout@v3
129+
# - uses: actions/checkout@v4
130130
# - name: "Run tests with ghc8107: End-2-end test of hix project initialization and flakes development shell ..."
131131
# run: "./test/tests.sh ghc8107 template"
132132

133133
docs:
134134
runs-on: [self-hosted, linux]
135135
steps:
136-
- uses: actions/checkout@v3
136+
- uses: actions/checkout@v4
137137
- name: "Test examples in documentation ..."
138138
run: "./test/tests.sh ghc8107 docs"
139139

140140
hydra-ifdLevel-0-and-1:
141141
runs-on: [self-hosted, linux]
142142
steps:
143-
- uses: actions/checkout@v3
143+
- uses: actions/checkout@v4
144144
- name: "Check that jobset will evaluate in Hydra at ifdLevel 0 and 1"
145145
run: |
146146
nix-build build.nix -A maintainer-scripts.check-hydra -o check-hydra.sh
@@ -150,7 +150,7 @@ jobs:
150150
hydra-ifdLevel-2:
151151
runs-on: [self-hosted, linux]
152152
steps:
153-
- uses: actions/checkout@v3
153+
- uses: actions/checkout@v4
154154
- name: "Check that jobset will evaluate in Hydra at ifdLevel 2"
155155
run: |
156156
nix-build build.nix -A maintainer-scripts.check-hydra -o check-hydra.sh
@@ -159,7 +159,7 @@ jobs:
159159
hydra-ifdLevel-3-and-ghc-8-10:
160160
runs-on: [self-hosted, linux]
161161
steps:
162-
- uses: actions/checkout@v3
162+
- uses: actions/checkout@v4
163163
- name: "Check that jobset will evaluate in Hydra at ifdLevel 3 and ghc 8.10"
164164
run: |
165165
nix-build build.nix -A maintainer-scripts.check-hydra -o check-hydra.sh
@@ -168,7 +168,7 @@ jobs:
168168
hydra-ifdLevel-3-and-ghc-9-2:
169169
runs-on: [self-hosted, linux]
170170
steps:
171-
- uses: actions/checkout@v3
171+
- uses: actions/checkout@v4
172172
- name: "Check that jobset will evaluate in Hydra at ifdLevel 3 and ghc 9.2"
173173
run: |
174174
nix-build build.nix -A maintainer-scripts.check-hydra -o check-hydra.sh
@@ -177,7 +177,7 @@ jobs:
177177
hydra-ifdLevel-3-and-not-ghc-8-10-or-9-2:
178178
runs-on: [self-hosted, linux]
179179
steps:
180-
- uses: actions/checkout@v3
180+
- uses: actions/checkout@v4
181181
- name: "Check that jobset will evaluate in Hydra at ifdLevel 3 and not (ghc 8.10 or ghc 9.2)"
182182
run: |
183183
nix-build build.nix -A maintainer-scripts.check-hydra -o check-hydra.sh
@@ -186,7 +186,7 @@ jobs:
186186
closure-size:
187187
runs-on: [self-hosted, linux]
188188
steps:
189-
- uses: actions/checkout@v3
189+
- uses: actions/checkout@v4
190190
- name: "Check closure size with ghc8107"
191191
run: |
192192
nix-build build.nix -A maintainer-scripts.check-closure-size --argstr compiler-nix-name ghc8107 -o check-closure-size.sh
@@ -196,7 +196,7 @@ jobs:
196196
update-docs:
197197
runs-on: [self-hosted, linux]
198198
steps:
199-
- uses: actions/checkout@v3
199+
- uses: actions/checkout@v4
200200
- name: "Update docs"
201201
run: |
202202
nix-build build.nix -A maintainer-scripts.update-docs -o update-docs.sh
@@ -205,7 +205,7 @@ jobs:
205205
check-materialization-concurrency:
206206
runs-on: [self-hosted, linux]
207207
steps:
208-
- uses: actions/checkout@v3
208+
- uses: actions/checkout@v4
209209
- name: "Make sure materialize function does not limit concurrency"
210210
run: |
211211
nix-build build.nix -A maintainer-scripts.check-materialization-concurrency -o check-materialization-concurrency.sh
@@ -214,7 +214,7 @@ jobs:
214214
check-path-support:
215215
runs-on: [self-hosted, linux]
216216
steps:
217-
- uses: actions/checkout@v3
217+
- uses: actions/checkout@v4
218218
- name: "Make sure non store paths like can be used as src"
219219
run: |
220220
nix-build build.nix -A maintainer-scripts.check-path-support --argstr compiler-nix-name ghc8107 -o check-path-support.sh
@@ -223,26 +223,26 @@ jobs:
223223
haskell-nix-roots-do-not-require-IFDs:
224224
runs-on: [self-hosted, linux]
225225
steps:
226-
- uses: actions/checkout@v3
226+
- uses: actions/checkout@v4
227227
- name: "Check that the haskell.nix roots do not require IFDs"
228228
run: nix build .#roots.x86_64-linux --accept-flake-config --option allow-import-from-derivation false
229229

230230
hydra-without-remote-builders:
231231
runs-on: [self-hosted, linux]
232232
steps:
233-
- uses: actions/checkout@v3
233+
- uses: actions/checkout@v4
234234
- name: "Check that evaluation of hydra jobs works without using remote builders"
235235
run: nix path-info --derivation .#requiredJobs.x86_64-darwin.required-unstable-ghc8107-native --show-trace --builders ''
236236

237237
hix-cabal:
238238
runs-on: [self-hosted, linux]
239239
steps:
240-
- uses: actions/checkout@v3
240+
- uses: actions/checkout@v4
241241
- name: "Check hix -- run github:haskell/cabal/3.10#cabal-install:exe:cabal -- --version"
242242
run: "HIX_DIR=$(mktemp -d) nix run .#hix --accept-flake-config -- run github:haskell/cabal/3.10#cabal-install:exe:cabal --accept-flake-config --override-input haskellNix . -- --version"
243243

244244
nix-tools:
245245
runs-on: [self-hosted, linux]
246246
steps:
247-
- uses: actions/checkout@v3
247+
- uses: actions/checkout@v4
248248
- run: nix build ./nix-tools#checks.x86_64-linux.truncate-index --accept-flake-config

.github/workflows/updates.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
update-pins:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v4
1313
- uses: cachix/install-nix-action@v15
1414
with:
1515
nix_path: nixpkgs=channel:nixos-unstable

lib/cabal-project-parser.nix

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,32 +94,32 @@ let
9494

9595
# Parse a source-repository-package and return data of `type: git` repositories
9696
# See tests/unit.nix for examples of input and output.
97-
parseSourceRepositoryPackageBlock = cabalProjectFileName: sha256map: block:
97+
parseSourceRepositoryPackageBlock = cabalProjectFileName: sha256map: source-repo-override: indentation: block:
9898
let
99-
x = span (pkgs.lib.strings.hasPrefix " ") (pkgs.lib.splitString "\n" block);
99+
x = span (pkgs.lib.strings.hasPrefix (indentation + " ")) (pkgs.lib.splitString "\n" block);
100100
attrs = parseBlockLines x.fst;
101+
overrideSourceRepo = sourceRepo: (source-repo-override.${sourceRepo.url} or (pkgs.lib.id)) sourceRepo;
101102
in
102103
if attrs."type" or "" != "git"
103104
then {
104-
sourceRepo = [];
105-
otherText = "\nsource-repository-package\n" + block;
105+
followingText = "\n" + indentation + "source-repository-package\n" + block;
106106
}
107107
else {
108-
sourceRepo = extractSourceRepoPackageData cabalProjectFileName sha256map attrs;
109-
otherText = pkgs.lib.strings.concatStringsSep "\n" x.snd;
108+
inherit indentation;
109+
sourceRepo = overrideSourceRepo (extractSourceRepoPackageData cabalProjectFileName sha256map attrs);
110+
followingText = pkgs.lib.strings.concatStringsSep "\n" x.snd;
110111
};
111112

112113
parseSourceRepositoryPackages = cabalProjectFileName: sha256map: source-repo-override: projectFile:
113114
let
114-
blocks = pkgs.lib.splitString "\nsource-repository-package\n" ("\n" + projectFile);
115-
initialText = pkgs.lib.lists.take 1 blocks;
116-
repoBlocks = builtins.map (parseSourceRepositoryPackageBlock cabalProjectFileName sha256map) (pkgs.lib.lists.drop 1 blocks);
117-
overrideSourceRepo = sourceRepo: (source-repo-override.${sourceRepo.url} or (pkgs.lib.id)) sourceRepo;
115+
splitResult = builtins.split "\n( *)source-repository-package\n" ("\n" + projectFile);
116+
# Construct a list of strings with just the indentation amounts for each map
117+
indentations = builtins.concatLists (builtins.filter builtins.isList splitResult);
118+
blocks = builtins.filter builtins.isString (pkgs.lib.lists.drop 1 splitResult);
118119
in {
119-
sourceRepos = pkgs.lib.lists.map (block: overrideSourceRepo block.sourceRepo) repoBlocks;
120-
otherText = pkgs.lib.strings.concatStringsSep "\n" (
121-
initialText
122-
++ (builtins.map (x: x.otherText) repoBlocks));
120+
initialText = builtins.head splitResult;
121+
sourceRepos = pkgs.lib.zipListsWith (parseSourceRepositoryPackageBlock cabalProjectFileName sha256map source-repo-override)
122+
indentations blocks;
123123
};
124124

125125
# Parse and replace repository

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

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,23 @@ let
230230
sourceRepoPackageResult = pkgs.haskell-nix.haskellLib.parseSourceRepositoryPackages
231231
cabalProjectFileName sha256map source-repo-override projectFile;
232232

233-
# Parse the `repository` blocks
234-
repoResult = pkgs.haskell-nix.haskellLib.parseRepositories
235-
evalPackages cabalProjectFileName sha256map inputMap cabal-install nix-tools sourceRepoPackageResult.otherText;
233+
sourceRepoFixedProjectFile =
234+
sourceRepoPackageResult.initialText +
235+
pkgs.lib.strings.concatMapStrings (block:
236+
if block ? sourceRepo
237+
then
238+
let
239+
f = fetchPackageRepo evalPackages.fetchgit block.sourceRepo;
240+
in ''
241+
242+
${block.indentation}source-repository-package
243+
${block.indentation} type: git
244+
${block.indentation} location: file://${f.location}
245+
${block.indentation} subdir: ${builtins.concatStringsSep " " f.subdirs}
246+
${block.indentation} tag: ${f.tag}
247+
'' + block.followingText
248+
else block.followingText
249+
) sourceRepoPackageResult.sourceRepos;
236250

237251
# we need the repository content twice:
238252
# * at eval time (below to build the fixed project file)
@@ -243,28 +257,19 @@ let
243257
# on the target system would use, so that the derivation is unaffected
244258
# and, say, a linux release build job can identify the derivation
245259
# as built by a darwin builder, and fetch it from a cache
246-
sourceReposEval = builtins.map (fetchPackageRepo evalPackages.fetchgit) sourceRepoPackageResult.sourceRepos;
247-
sourceReposBuild = builtins.map (x: (fetchPackageRepo pkgs.fetchgit x).fetched) sourceRepoPackageResult.sourceRepos;
260+
sourceReposEval = builtins.map (x: (fetchPackageRepo evalPackages.fetchgit x.sourceRepo)) sourceRepoPackageResult.sourceRepos;
261+
sourceReposBuild = builtins.map (x: (fetchPackageRepo pkgs.fetchgit x.sourceRepo).fetched) sourceRepoPackageResult.sourceRepos;
262+
263+
# Parse the `repository` blocks
264+
repoResult = pkgs.haskell-nix.haskellLib.parseRepositories
265+
evalPackages cabalProjectFileName sha256map inputMap cabal-install nix-tools sourceRepoFixedProjectFile;
248266
in {
249267
sourceRepos = sourceReposBuild;
250268
inherit (repoResult) repos extra-hackages;
251269
makeFixedProjectFile = ''
252-
cp -f ${evalPackages.writeText "cabal.project" sourceRepoPackageResult.otherText} ./cabal.project
253-
'' +
254-
pkgs.lib.optionalString (builtins.length sourceReposEval != 0) (''
270+
cp -f ${evalPackages.writeText "cabal.project" sourceRepoFixedProjectFile} ./cabal.project
255271
chmod +w -R ./cabal.project
256-
# The newline here is important in case cabal.project does not have one at the end
257-
echo >> ./cabal.project
258-
'' +
259-
# Add replacement `source-repository-package` blocks pointing to the minimal git repos
260-
( pkgs.lib.strings.concatMapStrings (f: ''
261-
echo "source-repository-package" >> ./cabal.project
262-
echo " type: git" >> ./cabal.project
263-
echo " location: file://${f.location}" >> ./cabal.project
264-
echo " subdir: ${builtins.concatStringsSep " " f.subdirs}" >> ./cabal.project
265-
echo " tag: ${f.tag}" >> ./cabal.project
266-
'') sourceReposEval
267-
));
272+
'';
268273
# This will be used to replace refernces to the minimal git repos with just the index
269274
# of the repo. The index will be used in lib/import-and-filter-project.nix to
270275
# lookup the correct repository in `sourceReposBuild`. This avoids having

modules/configuration-nix.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ in {
4444
(fromUntil "3.2.0.0" "3.5" ../overlays/patches/Cabal/Cabal-3.0.0.0-no-final-checks.diff)
4545
(fromUntil "3.6.0.0" "3.11" ../overlays/patches/Cabal/Cabal-3.6.0.0-drop-pkg-db-check.diff)
4646
(fromUntil "3.6.0.0" "3.11" ../overlays/patches/Cabal/Cabal-3.6.0.0-no-final-checks.diff)
47-
(fromUntil "3.10" "3.11" ../overlays/patches/Cabal/9220.patch)
47+
(fromUntil "3.10" "3.10.3" ../overlays/patches/Cabal/9220.patch)
4848
];
4949

5050
# These two patches are:

0 commit comments

Comments
 (0)