diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b89221be..8331bf46 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -5,15 +5,25 @@ on: - master pull_request: jobs: - checks: + nix: runs-on: self-hosted + strategy: + matrix: + # TODO: Add Linux, after enabling test flake check to work without internet access. + # https://github.com/srid/haskell-flake/issues/241 + system: [aarch64-darwin] steps: - uses: actions/checkout@v4 - - name: Build Nix - id: build-nix - run: | - nixci - - name: Run test - id: test - run: | - nix run nixpkgs#bash runtest.sh + - run: nixci --build-systems "github:nix-systems/${{ matrix.system }}" + # Remove this job after doing the TODO above. + linux-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: DeterminateSystems/nix-installer-action@main + - run: bash ./runtest.sh + docs-linkcheck: + runs-on: self-hosted + steps: + - uses: actions/checkout@v4 + - run: bash ./doc/test.sh diff --git a/doc/test.sh b/doc/test.sh index ddf575b4..bf65a368 100644 --- a/doc/test.sh +++ b/doc/test.sh @@ -1,5 +1,6 @@ -source ../test/common.sh +SYSTEM=$(nix eval --impure --expr builtins.currentSystem) +HERE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -nix build ${OVERRIDE_HASKELL_FLAKE} \ +nix build --override-input haskell-flake ${HERE}/.. \ --option log-lines 1000 --show-trace \ "github:hercules-ci/flake.parts-website#checks.${SYSTEM}.linkcheck" \ No newline at end of file diff --git a/flake.nix b/flake.nix index 307d81c3..c47363cb 100644 --- a/flake.nix +++ b/flake.nix @@ -13,10 +13,15 @@ }; # https://github.com/srid/nixci - nixci.default = let overrideInputs = { "haskell-flake" = ./.; }; in { - dev = { inherit overrideInputs; dir = "dev"; }; - doc.dir = "doc"; - example = { inherit overrideInputs; dir = "example"; }; - }; + nixci.default = + let + overrideInputs = { "haskell-flake" = ./.; }; + in + { + dev = { inherit overrideInputs; dir = "dev"; }; + test = { inherit overrideInputs; dir = "test"; }; + doc = { dir = "doc"; }; + example = { inherit overrideInputs; dir = "example"; }; + }; }; } diff --git a/runtest.sh b/runtest.sh index 0ab39ffd..399b87ea 100755 --- a/runtest.sh +++ b/runtest.sh @@ -13,7 +13,8 @@ TESTS=( ./test/simple ./test/with-subdir ./test/project-module - ./doc + # We run this separately, because it's a bit slow. + # ./doc ) for testDir in "${TESTS[@]}" diff --git a/test/common.sh b/test/common.sh index a9c4b39a..0617f2fc 100644 --- a/test/common.sh +++ b/test/common.sh @@ -5,7 +5,9 @@ function logHeader { echo -e "\n||| $@" } -SYSTEM=$(nix show-config | grep 'system =' | nix run nixpkgs#gawk '{print $3}') +nix --version + +SYSTEM=$(nix show-config | grep 'system =' | awk '{print $3}') DIR_OF_COMMON_SH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" HASKELL_FLAKE=${DIR_OF_COMMON_SH}/.. @@ -24,12 +26,6 @@ if [ "$(printf '%s\n' "$requiredver" "$currentver" | sort -V | head -n1)" = "$re then echo else - echo "!!!! Your Nix version is old ($currentver). Using newer Nix from github:nixos/nix/2.14.1" - # We use newer Nix for: - # - https://github.com/NixOS/nix/issues/7263 - # - https://github.com/NixOS/nix/issues/7026 - nix build --no-link github:nixos/nix/2.14.1 - export PATH=$(nix eval --raw github:nixos/nix/2.14.1#default.outPath)/bin:$PATH + echo "!!!! Your Nix version is old ($currentver)." + exit 2 fi - -nix --version \ No newline at end of file diff --git a/test/flake.nix b/test/flake.nix new file mode 100644 index 00000000..5eeda4f8 --- /dev/null +++ b/test/flake.nix @@ -0,0 +1,38 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + flake-parts.url = "github:hercules-ci/flake-parts"; + haskell-flake = { }; # Overriden by nixci (see top-level flake.nix) + }; + outputs = inputs: + inputs.flake-parts.lib.mkFlake { inherit inputs; } { + systems = inputs.nixpkgs.lib.systems.flakeExposed; + perSystem = { pkgs, ... }: { + checks.tests = pkgs.runCommandNoCC "tests" + { + nativeBuildInputs = with pkgs; [ + coreutils + bash + nix + cacert + git + which + gawk + ]; + } '' + export HOME=$(mktemp -d) + cd $HOME + mkdir -p .config/nix + echo 'experimental-features = nix-command flakes' > .config/nix/nix.conf + cp -r ${inputs.haskell-flake} ./haskell-flake + chmod -R u+rw haskell-flake + cd haskell-flake + git config --global user.email "nix@localhost" + git config --global user.name "nix" + git init && git add . && git commit -m "Initial commit" + bash ./runtest.sh + touch $out + ''; + }; + }; +}