From d3099822fb42ca4f905dc0c7ed456539cfc4b088 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 24 Feb 2024 07:36:15 -0500 Subject: [PATCH 01/16] rm check-flake --- test/simple/flake.nix | 3 --- test/simple/test.sh | 4 +--- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/test/simple/flake.nix b/test/simple/flake.nix index 5d337666..140a031e 100644 --- a/test/simple/flake.nix +++ b/test/simple/flake.nix @@ -7,8 +7,6 @@ flake-parts = { }; haskell-flake = { }; - check-flake.url = "github:srid/check-flake/48a17393ed4fcd523399d6602c283775b5127295"; - haskell-multi-nix.url = "github:srid/haskell-multi-nix/7aed736571714ec12105ec110358998d70d59e34"; haskell-multi-nix.flake = false; }; @@ -17,7 +15,6 @@ systems = nixpkgs.lib.systems.flakeExposed; imports = [ inputs.haskell-flake.flakeModule - inputs.check-flake.flakeModule ]; flake.haskellFlakeProjectModules.default = { pkgs, lib, ... }: { packages = { diff --git a/test/simple/test.sh b/test/simple/test.sh index 5ff9a596..68e9d2cb 100755 --- a/test/simple/test.sh +++ b/test/simple/test.sh @@ -22,6 +22,4 @@ nix run ${OVERRIDE_ALL} .#app1 # Test non-devshell features: # Checks logHeader "Testing nix flake checks" -nix --option sandbox false build \ - --no-link --print-out-paths \ - ${OVERRIDE_ALL} -L .#check +nix flake check ${OVERRIDE_ALL} From dac5d373ae34c5b93cedb99f737062805d90c282 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 24 Feb 2024 07:43:26 -0500 Subject: [PATCH 02/16] reintroduce sandbox --- test/simple/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/simple/test.sh b/test/simple/test.sh index 68e9d2cb..1f98ff62 100755 --- a/test/simple/test.sh +++ b/test/simple/test.sh @@ -22,4 +22,4 @@ nix run ${OVERRIDE_ALL} .#app1 # Test non-devshell features: # Checks logHeader "Testing nix flake checks" -nix flake check ${OVERRIDE_ALL} +nix --option sandbox false flake check ${OVERRIDE_ALL} From 03563ccf0e851e16bf612ba7be4b3d0efdd72d32 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 24 Feb 2024 07:50:21 -0500 Subject: [PATCH 03/16] test/simple: add a flake check, with nixci config --- flake.nix | 9 +++++++++ test/simple/flake.nix | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/flake.nix b/flake.nix index f7d64c38..a4fdd5dd 100644 --- a/flake.nix +++ b/flake.nix @@ -35,6 +35,15 @@ overrideInputs."haskell-parsers" = ./nix/haskell-parsers; }; + test-simple = { + dir = "test/simple"; + overrideInputs = { + "haskell-flake" = ./.; + "flake-parts" = "github:hercules-ci/flake-parts/7c7a8bce3dffe71203dcd4276504d1cb49dfe05f"; + "nixpkgs" = "github:nixos/nixpkgs/bb31220cca6d044baa6dc2715b07497a2a7c4bc7"; + }; + }; + # Legacy shell script test test = { dir = "test"; diff --git a/test/simple/flake.nix b/test/simple/flake.nix index 140a031e..17f4a745 100644 --- a/test/simple/flake.nix +++ b/test/simple/flake.nix @@ -71,6 +71,23 @@ # An explicit app to test `nix run .#test` (*without* falling back to # using self.packages.test) apps.app1 = self'.apps.haskell-flake-test; + + # Our test + checks.test = + pkgs.runCommandNoCC "simple-test" + { + nativeBuildInputs = with pkgs; [ + nix + ]; + } + '' + echo "Testing test/simple ..." + + # Run the app + ${self'.apps.app1.program} + + touch $out + ''; }; }; } From 4562145a380b3a2597e859cfa8da7ae983510b06 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 24 Feb 2024 07:55:00 -0500 Subject: [PATCH 04/16] ci: see if sandbox=false helps --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 815862ee..9316be0f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,7 +12,7 @@ jobs: system: [aarch64-darwin, aarch64-linux] steps: - uses: actions/checkout@v4 - - run: nixci --build-systems "github:nix-systems/${{ matrix.system }}" + - run: nixci --build-systems "github:nix-systems/${{ matrix.system }}" -- --option sandbox false # TODO: Remove this job after https://github.com/srid/haskell-flake/issues/241 linux-test: runs-on: ubuntu-latest From 9c32bbc535e27d3ffc57b18d57444e1ee584da5d Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 24 Feb 2024 07:56:45 -0500 Subject: [PATCH 05/16] Revert "ci: see if sandbox=false helps" This reverts commit 4562145a380b3a2597e859cfa8da7ae983510b06. --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9316be0f..815862ee 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,7 +12,7 @@ jobs: system: [aarch64-darwin, aarch64-linux] steps: - uses: actions/checkout@v4 - - run: nixci --build-systems "github:nix-systems/${{ matrix.system }}" -- --option sandbox false + - run: nixci --build-systems "github:nix-systems/${{ matrix.system }}" # TODO: Remove this job after https://github.com/srid/haskell-flake/issues/241 linux-test: runs-on: ubuntu-latest From 6e62d6d90406155eda31767acc3e918326819ba3 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 24 Feb 2024 07:57:34 -0500 Subject: [PATCH 06/16] let's not bother to check HLS that's not the domain of haskell-flake --- test/simple/flake.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/test/simple/flake.nix b/test/simple/flake.nix index 17f4a745..e72e3c37 100644 --- a/test/simple/flake.nix +++ b/test/simple/flake.nix @@ -35,7 +35,6 @@ # Setting to null should remove this tool from defaults. ghcid = null; }; - hlsCheck.enable = true; }; }; perSystem = { self', pkgs, lib, ... }: { From 253718b04b8017827475a9f131689ee992323070 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 24 Feb 2024 07:58:53 -0500 Subject: [PATCH 07/16] no need for sandbox here --- test/simple/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/simple/test.sh b/test/simple/test.sh index 1f98ff62..68e9d2cb 100755 --- a/test/simple/test.sh +++ b/test/simple/test.sh @@ -22,4 +22,4 @@ nix run ${OVERRIDE_ALL} .#app1 # Test non-devshell features: # Checks logHeader "Testing nix flake checks" -nix --option sandbox false flake check ${OVERRIDE_ALL} +nix flake check ${OVERRIDE_ALL} From 6317f46655244c6f3eba89c9dc7a3de029d55567 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 24 Feb 2024 07:59:21 -0500 Subject: [PATCH 08/16] we no longer care to test HLS --- test/simple/test-in-devshell.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/simple/test-in-devshell.sh b/test/simple/test-in-devshell.sh index 460add35..c5faa437 100755 --- a/test/simple/test-in-devshell.sh +++ b/test/simple/test-in-devshell.sh @@ -8,9 +8,6 @@ set -xe -# Test haskell devshell (via HLS check) -haskell-language-server - # Setting buildTools.ghcid to null should disable that default buildTool which ghcid && exit 2 || echo From f2ee895e0aa262ea627f62024e2a0919c868a412 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 24 Feb 2024 08:02:17 -0500 Subject: [PATCH 09/16] simple: executable should work --- test/simple/flake.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/simple/flake.nix b/test/simple/flake.nix index e72e3c37..cfefe1f7 100644 --- a/test/simple/flake.nix +++ b/test/simple/flake.nix @@ -82,8 +82,8 @@ '' echo "Testing test/simple ..." - # Run the app - ${self'.apps.app1.program} + # Run the cabal executable as flake app + ${self'.apps.app1.program} | grep fooFunc touch $out ''; From fe80fb20c21b958a740983fa261c3f622b179e1e Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 24 Feb 2024 08:05:23 -0500 Subject: [PATCH 10/16] SYSTEM det --- test/common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/common.sh b/test/common.sh index 0617f2fc..1f4ee732 100644 --- a/test/common.sh +++ b/test/common.sh @@ -7,7 +7,7 @@ function logHeader { nix --version -SYSTEM=$(nix show-config | grep 'system =' | awk '{print $3}') +SYSTEM=$(nix eval --impure --expr builtins.currentSystem) DIR_OF_COMMON_SH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" HASKELL_FLAKE=${DIR_OF_COMMON_SH}/.. From d08dfb50eef96582f69ab0069a1315ca28ca4e5a Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 24 Feb 2024 08:09:36 -0500 Subject: [PATCH 11/16] rm --- test/simple/test.sh | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/test/simple/test.sh b/test/simple/test.sh index 68e9d2cb..528ada51 100755 --- a/test/simple/test.sh +++ b/test/simple/test.sh @@ -1,12 +1,11 @@ +# TODO: This is being moved to a flake check. +# Currently doing only what's not being done in the flake check (via nixci). + source ../common.sh set -euxo pipefail rm -f result result-bin -# First, build the flake -logHeader "Testing nix build" -nix build ${OVERRIDE_ALL} - # Test defaults.settings module behaviour, viz: haddock nix build ${OVERRIDE_ALL} .#default^doc && { echo "ERROR: dontHaddock (from defaults.settings) not in effect" @@ -16,10 +15,3 @@ nix build ${OVERRIDE_ALL} .#default^doc && { # Run the devshell test script in a nix develop shell. logHeader "Testing nix devshell" nix develop ${OVERRIDE_ALL} -c ./test-in-devshell.sh -# Run the cabal executable as flake app -logHeader "Testing nix flake app (cabal exe)" -nix run ${OVERRIDE_ALL} .#app1 -# Test non-devshell features: -# Checks -logHeader "Testing nix flake checks" -nix flake check ${OVERRIDE_ALL} From 123a3765899315c50577b319d5d8f5234b5f2341 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 24 Feb 2024 08:09:55 -0500 Subject: [PATCH 12/16] can we query devShell? --- test/simple/flake.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/simple/flake.nix b/test/simple/flake.nix index cfefe1f7..ce392743 100644 --- a/test/simple/flake.nix +++ b/test/simple/flake.nix @@ -85,6 +85,9 @@ # Run the cabal executable as flake app ${self'.apps.app1.program} | grep fooFunc + cat ${self'.devShells.default} | grep ghcid + cat ${self'.devShells.default} | grep adfsd + touch $out ''; }; From a9d7ba199a872c06794804b86ec51a47b7867b35 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 24 Feb 2024 08:20:12 -0500 Subject: [PATCH 13/16] make it work --- test/simple/flake.nix | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/test/simple/flake.nix b/test/simple/flake.nix index ce392743..514506a0 100644 --- a/test/simple/flake.nix +++ b/test/simple/flake.nix @@ -78,15 +78,25 @@ nativeBuildInputs = with pkgs; [ nix ]; + DEVSHELL_ENV = self'.devShells.default; } '' + set -x echo "Testing test/simple ..." # Run the cabal executable as flake app ${self'.apps.app1.program} | grep fooFunc - cat ${self'.devShells.default} | grep ghcid - cat ${self'.devShells.default} | grep adfsd + # Setting buildTools.ghcid to null should disable that default + # buildTool (ghcid) + grep ghcid $DEVSHELL_ENV && \ + (echo "ghcid should not be in devshell"; exit 2) + + # Adding a buildTool (fzf, here) should put it in devshell. + grep fzf $DEVSHELL_ENV || \ + (echo "fzf should be in devshell"; exit 2) + + echo $DEVSHELL_ENV touch $out ''; From 366b466dfd127c3abc5b85f9ff9260250c557907 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 24 Feb 2024 08:24:19 -0500 Subject: [PATCH 14/16] port test-in-devshell.sh entirely --- test/simple/flake.nix | 23 +++++++++++++++++------ test/simple/test-in-devshell.sh | 26 -------------------------- test/simple/test.sh | 4 ---- 3 files changed, 17 insertions(+), 36 deletions(-) delete mode 100755 test/simple/test-in-devshell.sh diff --git a/test/simple/flake.nix b/test/simple/flake.nix index 514506a0..963d1127 100644 --- a/test/simple/flake.nix +++ b/test/simple/flake.nix @@ -76,11 +76,11 @@ pkgs.runCommandNoCC "simple-test" { nativeBuildInputs = with pkgs; [ - nix - ]; - DEVSHELL_ENV = self'.devShells.default; + which + ] ++ self'.devShells.default.nativeBuildInputs; } '' + ( set -x echo "Testing test/simple ..." @@ -89,16 +89,27 @@ # Setting buildTools.ghcid to null should disable that default # buildTool (ghcid) - grep ghcid $DEVSHELL_ENV && \ + which ghcid && \ (echo "ghcid should not be in devshell"; exit 2) # Adding a buildTool (fzf, here) should put it in devshell. - grep fzf $DEVSHELL_ENV || \ + which fzf || \ (echo "fzf should be in devshell"; exit 2) - echo $DEVSHELL_ENV + # mkShellArgs works + ${self'.devShells.default.shellHook} + if [[ "$FOO" == "bar" ]]; then + echo "$FOO" + else + echo "FOO is not bar" + exit 2 + fi + + # extraLibraries works + runghc ${./script} | grep -F 'TOML-flavored boolean: Bool True' touch $out + ) ''; }; }; diff --git a/test/simple/test-in-devshell.sh b/test/simple/test-in-devshell.sh deleted file mode 100755 index c5faa437..00000000 --- a/test/simple/test-in-devshell.sh +++ /dev/null @@ -1,26 +0,0 @@ -# This script is run in a `nix develop` shell by Github Actions. -# -# You can also run it locally using: -# -# nix develop --override-input haskell-flake ../ -c ./test-in-devshell.sh -# -# Or, just run `runtest.sh` from project root. - -set -xe - -# Setting buildTools.ghcid to null should disable that default buildTool -which ghcid && exit 2 || echo - -# Adding a buildTool (fzf, here) should put it in devshell. -which fzf - -# mkShellArgs works -if [[ "$FOO" == "bar" ]]; then - echo "$FOO" -else - echo "FOO is not bar" - exit 2 -fi - -# extraLibraries works -runghc ./script | grep -F 'TOML-flavored boolean: Bool True' diff --git a/test/simple/test.sh b/test/simple/test.sh index 528ada51..0e789211 100755 --- a/test/simple/test.sh +++ b/test/simple/test.sh @@ -11,7 +11,3 @@ nix build ${OVERRIDE_ALL} .#default^doc && { echo "ERROR: dontHaddock (from defaults.settings) not in effect" exit 1 } - -# Run the devshell test script in a nix develop shell. -logHeader "Testing nix devshell" -nix develop ${OVERRIDE_ALL} -c ./test-in-devshell.sh From 5934b327b4263d337655ca9a1242054201c59bc9 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 24 Feb 2024 08:35:20 -0500 Subject: [PATCH 15/16] test/simple ported over --- runtest.sh | 2 +- test/simple/flake.nix | 5 +++++ test/simple/test.sh | 13 ------------- 3 files changed, 6 insertions(+), 14 deletions(-) delete mode 100755 test/simple/test.sh diff --git a/runtest.sh b/runtest.sh index 42680a3b..0d4501b1 100755 --- a/runtest.sh +++ b/runtest.sh @@ -10,7 +10,7 @@ nix --version # TODO: Supplant these scripts with Nix. See https://github.com/srid/haskell-flake/issues/241 TESTS=( ./example - ./test/simple + # TODO: Move these to flake check, just like ./test/simple ./test/with-subdir ./test/project-module # We run this separately, because it's a bit slow. diff --git a/test/simple/flake.nix b/test/simple/flake.nix index 963d1127..5d81e557 100644 --- a/test/simple/flake.nix +++ b/test/simple/flake.nix @@ -78,6 +78,11 @@ nativeBuildInputs = with pkgs; [ which ] ++ self'.devShells.default.nativeBuildInputs; + + # Test defaults.settings module behaviour, viz: haddock + NO_HADDOCK = + lib.assertMsg (!lib.hasAttr "doc" self'.packages.default) + "doc output should not be present"; } '' ( diff --git a/test/simple/test.sh b/test/simple/test.sh deleted file mode 100755 index 0e789211..00000000 --- a/test/simple/test.sh +++ /dev/null @@ -1,13 +0,0 @@ -# TODO: This is being moved to a flake check. -# Currently doing only what's not being done in the flake check (via nixci). - -source ../common.sh -set -euxo pipefail - -rm -f result result-bin - -# Test defaults.settings module behaviour, viz: haddock -nix build ${OVERRIDE_ALL} .#default^doc && { - echo "ERROR: dontHaddock (from defaults.settings) not in effect" - exit 1 -} From 35995aabec6a2054252b4bf5a5fdaff04ac225f1 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sat, 24 Feb 2024 08:39:02 -0500 Subject: [PATCH 16/16] port test/project-module --- flake.nix | 9 +++++++++ runtest.sh | 3 +-- test/project-module/test.sh | 9 --------- 3 files changed, 10 insertions(+), 11 deletions(-) delete mode 100755 test/project-module/test.sh diff --git a/flake.nix b/flake.nix index a4fdd5dd..eb807273 100644 --- a/flake.nix +++ b/flake.nix @@ -44,6 +44,15 @@ }; }; + test-project-module = { + dir = "test/project-module"; + overrideInputs = { + "haskell-flake" = ./.; + "flake-parts" = "github:hercules-ci/flake-parts/7c7a8bce3dffe71203dcd4276504d1cb49dfe05f"; + "nixpkgs" = "github:nixos/nixpkgs/bb31220cca6d044baa6dc2715b07497a2a7c4bc7"; + }; + }; + # Legacy shell script test test = { dir = "test"; diff --git a/runtest.sh b/runtest.sh index 0d4501b1..ff7352bd 100755 --- a/runtest.sh +++ b/runtest.sh @@ -10,9 +10,8 @@ nix --version # TODO: Supplant these scripts with Nix. See https://github.com/srid/haskell-flake/issues/241 TESTS=( ./example - # TODO: Move these to flake check, just like ./test/simple + # TODO: Move these to flake check, just like ./test/{simple, project-module} ./test/with-subdir - ./test/project-module # We run this separately, because it's a bit slow. # ./doc ) diff --git a/test/project-module/test.sh b/test/project-module/test.sh deleted file mode 100755 index 383725fa..00000000 --- a/test/project-module/test.sh +++ /dev/null @@ -1,9 +0,0 @@ -source ../common.sh -set -euxo pipefail - -# First, build the flake -logHeader "Testing nix build" -nix build ${OVERRIDE_ALL} - -logHeader "Testing nix devshell" -nix develop ${OVERRIDE_ALL} -c echo