Skip to content

Commit 2ddda49

Browse files
authored
Merge pull request #2075 from tweag/cg/use_run_nix_shell
chore: use `tweag/run-nix-shell`
2 parents 0fe84eb + 2dc85b7 commit 2ddda49

File tree

3 files changed

+132
-11
lines changed

3 files changed

+132
-11
lines changed

.github/workflows/workflow.yaml

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ jobs:
6161
- ghc: 9.6.2
6262
bzlmod: true
6363
runs-on: ${{ matrix.os }}
64+
env:
65+
NIX_SHELL_ARGS: --arg docTools false --argstr ghcVersion ${{ matrix.ghc }}
6466
steps:
6567
- uses: actions/checkout@v4
6668
- uses: ./.github/actions/free_disk_space_on_linux
@@ -98,29 +100,35 @@ jobs:
98100
cp .bazelrc.local rules_haskell_nix
99101
cp .bazelrc.local rules_haskell_tests
100102
- name: Check Bazel version
101-
run: |
102-
nix-shell --arg docTools false --argstr ghcVersion ${{ matrix.ghc }} --pure --run .ci/check-bazel-version
103+
uses: tweag/run-nix-shell@v0
104+
with:
105+
options: ${{ env.NIX_SHELL_ARGS }}
106+
run: .ci/check-bazel-version
103107
- name: Build & test - rules_haskell
104108
if: matrix.module == 'rules_haskell'
105-
run: |
106-
nix-shell --arg docTools false --argstr ghcVersion ${{ matrix.ghc }} --pure --run '
109+
uses: tweag/run-nix-shell@v0
110+
with:
111+
options: ${{ env.NIX_SHELL_ARGS }}
112+
run: |
107113
set -euo pipefail
108114
bazel test //...
109115
bazel build //docs:api_html
110116
bazel build //docs:guide_html
111-
'
112117
- name: Build & test - rules_haskell_nix
113118
if: matrix.module == 'rules_haskell_nix'
114-
run: |
115-
nix-shell --arg docTools false --argstr ghcVersion ${{ matrix.ghc }} --pure --run '
119+
uses: tweag/run-nix-shell@v0
120+
with:
121+
options: ${{ env.NIX_SHELL_ARGS }}
122+
run: |
116123
set -euo pipefail
117124
cd rules_haskell_nix
118125
bazel test //...
119-
'
120126
- name: Build & test - rules_haskell_tests
121127
if: matrix.module == 'rules_haskell_tests'
122-
run: |
123-
nix-shell --arg docTools false --argstr ghcVersion ${{ matrix.ghc }} --pure --run '
128+
uses: tweag/run-nix-shell@v0
129+
with:
130+
options: ${{ env.NIX_SHELL_ARGS }}
131+
run: |
124132
set -euo pipefail
125133
cd rules_haskell_tests
126134
# XXX run start script `--with-bzlmod=true` when supported
@@ -130,7 +138,6 @@ jobs:
130138
bazel build //tests:run-tests
131139
./bazel-ci-bin/tests/run-tests
132140
bazel coverage //...
133-
'
134141
135142
test-bindist:
136143
name: Build & Test - bindist

rules_haskell_nix/shell.nix

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{ pkgs ? import ./nixpkgs { }, docTools ? true, ghcVersion ? "9.2.8" }:
2+
3+
with pkgs;
4+
mkShell {
5+
# XXX: hack for macosX, this flags disable bazel usage of xcode
6+
# Note: this is set even for linux so any regression introduced by this flag
7+
# will be catched earlier
8+
# See: https://github.com/bazelbuild/bazel/issues/4231
9+
BAZEL_USE_CPP_ONLY_TOOLCHAIN = 1;
10+
TMPDIR = "/tmp";
11+
12+
GHC_VERSION = ghcVersion;
13+
14+
# Set UTF-8 local so that run-tests can parse GHC's unicode output.
15+
LANG = "C.UTF-8";
16+
17+
buildInputs = [
18+
go
19+
nix
20+
which
21+
perl
22+
python3
23+
jdk11
24+
# For stack_install.
25+
stack
26+
# Needed for ghcide which expects ghc in PATH.
27+
haskell.packages."ghc${ builtins.replaceStrings [ "." ] [ "" ] ghcVersion }".ghc
28+
# Needed for @com_github_golang_protobuf, itself needed by buildifier.
29+
git
30+
# Needed to get correct locale for tests with encoding
31+
glibcLocales
32+
# to avoid CA certificate failures on macOS CI
33+
cacert
34+
# Needed for debug/linking_utils
35+
binutils
36+
# check the start script for problems
37+
shellcheck
38+
file
39+
] ++ lib.optionals docTools [ graphviz python39Packages.sphinx zip unzip ];
40+
41+
packages = [ bazel_6 ];
42+
43+
shellHook = ''
44+
# Add nix config flags to .bazelrc.local.
45+
#
46+
BAZELRC_LOCAL=".bazelrc.local"
47+
if [ ! -e "$BAZELRC_LOCAL" ]
48+
then
49+
echo "[!] It looks like you are using a Nix-based system."
50+
echo "In order to build this project, you need to add the two"
51+
echo "following host_platform entries to your .bazelrc.local file:"
52+
echo
53+
echo "build --host_platform=@rules_nixpkgs_core//platforms:host"
54+
echo "run --host_platform=@rules_nixpkgs_core//platforms:host"
55+
fi
56+
'';
57+
}

rules_haskell_tests/shell.nix

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{ pkgs ? import ./nixpkgs { }, docTools ? true, ghcVersion ? "9.2.8" }:
2+
3+
with pkgs;
4+
mkShell {
5+
# XXX: hack for macosX, this flags disable bazel usage of xcode
6+
# Note: this is set even for linux so any regression introduced by this flag
7+
# will be catched earlier
8+
# See: https://github.com/bazelbuild/bazel/issues/4231
9+
BAZEL_USE_CPP_ONLY_TOOLCHAIN = 1;
10+
TMPDIR = "/tmp";
11+
12+
GHC_VERSION = ghcVersion;
13+
14+
# Set UTF-8 local so that run-tests can parse GHC's unicode output.
15+
LANG = "C.UTF-8";
16+
17+
buildInputs = [
18+
go
19+
nix
20+
which
21+
perl
22+
python3
23+
jdk11
24+
# For stack_install.
25+
stack
26+
# Needed for ghcide which expects ghc in PATH.
27+
haskell.packages."ghc${ builtins.replaceStrings [ "." ] [ "" ] ghcVersion }".ghc
28+
# Needed for @com_github_golang_protobuf, itself needed by buildifier.
29+
git
30+
# Needed to get correct locale for tests with encoding
31+
glibcLocales
32+
# to avoid CA certificate failures on macOS CI
33+
cacert
34+
# Needed for debug/linking_utils
35+
binutils
36+
# check the start script for problems
37+
shellcheck
38+
file
39+
] ++ lib.optionals docTools [ graphviz python39Packages.sphinx zip unzip ];
40+
41+
packages = [ bazel_6 ];
42+
43+
shellHook = ''
44+
# Add nix config flags to .bazelrc.local.
45+
#
46+
BAZELRC_LOCAL=".bazelrc.local"
47+
if [ ! -e "$BAZELRC_LOCAL" ]
48+
then
49+
echo "[!] It looks like you are using a Nix-based system."
50+
echo "In order to build this project, you need to add the two"
51+
echo "following host_platform entries to your .bazelrc.local file:"
52+
echo
53+
echo "build --host_platform=@rules_nixpkgs_core//platforms:host"
54+
echo "run --host_platform=@rules_nixpkgs_core//platforms:host"
55+
fi
56+
'';
57+
}

0 commit comments

Comments
 (0)