diff --git a/.github/workflows/cachix.yaml b/.github/workflows/cachix.yaml index e67eb4f..1ecf070 100644 --- a/.github/workflows/cachix.yaml +++ b/.github/workflows/cachix.yaml @@ -4,9 +4,37 @@ on: push: branches: [master] jobs: - Nix-CI: - name: + + # Nix builds + Nix-Build: runs-on: ubuntu-latest + # Build for 3 latest Stackage package sets + strategy: + matrix: + package-set: [lts-20, lts-19, lts-18] + steps: + - uses: actions/checkout@v3 + - uses: cachix/install-nix-action@v17 + with: + extra_nix_config: | + trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= + substituters = https://hydra.iohk.io https://cache.nixos.org/ + - uses: cachix/cachix-action@v10 + with: + name: brechtserckx-openscad + authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' + + # Nix build + - run: make nix-build PACKAGE_SET=${{matrix.package-set}} + + # Cabal build in nix-shell + - run: nix-shell --argstr packageSet ${{matrix.package-set}} --run "make build" + + # Additional package checking using nix + Nix-Check: + runs-on: ubuntu-latest + # Only run after build completed, to re-use caching + needs: Nix-Build steps: - uses: actions/checkout@v3 - uses: cachix/install-nix-action@v17 @@ -18,6 +46,4 @@ jobs: with: name: brechtserckx-openscad authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' - - run: make nix-build - - run: nix-shell --run "echo 'Shell ok'" - run: nix-shell --run "make check" diff --git a/Makefile b/Makefile index 399c72a..c3f4fe0 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,13 @@ SHELL := /usr/bin/env bash +ifdef PACKAGE_SET + NIX_ARGS += --argstr packageSet $(PACKAGE_SET) +endif + +.PHONY: info +info: + echo "NIX_ARGS: '$(NIX_ARGS)'" + .PHONY: clean clean: rm -rf dist-newstyle result result-* bench/out/* @@ -13,12 +21,12 @@ test: cabal test OpenSCAD .PHONY: bench -test: +bench: cabal bench .PHONY: nix-build nix-build: - nix-build --no-out-link default.nix -A OpenSCAD.components + nix-build $(NIX_ARGS) --no-out-link default.nix -A OpenSCAD.components .PHONY: format format: @@ -40,6 +48,14 @@ hlint: ci-cd: act $(ACT_ARGS) -.PHONY: make check +.PHONY: check check: format-check hlint cabal check + +.PHONY: haddock +haddock: + cabal haddock + +.PHONY: doctest +doctest: + doctest diff --git a/OpenSCAD.cabal b/OpenSCAD.cabal index 38089dc..445e758 100644 --- a/OpenSCAD.cabal +++ b/OpenSCAD.cabal @@ -19,7 +19,7 @@ description: functions for rendering an ADT into an OpenSCAD program. category: Graphics -tested-with: GHC ==8.6.5 || ==8.8.4 || ==8.10.7 || ==9.0.2 || ==9.2.2 +tested-with: GHC ==8.10.7 || ==9.0.2 || ==9.2.2 extra-doc-files: README.md library diff --git a/default.nix b/default.nix index 7dedfff..484d39e 100644 --- a/default.nix +++ b/default.nix @@ -1,7 +1,14 @@ +{ packageSet ? null }: let pkgs = import ./nix/pkgs.nix; cleanSource = pkgs.haskell-nix.haskellLib.cleanGit; -in pkgs.haskell-nix.project { +in pkgs.haskell-nix.stackProject { + stackYaml = if isNull packageSet || packageSet == "lts-20" then + "stack.yaml" + else if builtins.elem packageSet [ "lts-19" "lts-18" ] then + "stack-${toString packageSet}.yaml" + else + abort "packageSet must be one of , lts-19 or lts-18"; src = cleanSource { name = "OpenSCAD"; src = ./.; diff --git a/nix/sources.json b/nix/sources.json index 584bd82..7783bb8 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -5,10 +5,10 @@ "homepage": "https://input-output-hk.github.io/haskell.nix", "owner": "input-output-hk", "repo": "haskell.nix", - "rev": "9bc8625f18ed1aa633f5f3a52ee03d1718eaeebe", - "sha256": "0mm4z0wc7vic1185id912lfmrm2vy8ky25qa2ivf8fphi4ls5qb8", + "rev": "a6825537df7c0834a4410f652b6659e07ec5bde3", + "sha256": "1nqm48clz0739l11gzyfacs3mfs4rygiyhdcac9kynjk0mqb0xyn", "type": "tarball", - "url": "https://github.com/input-output-hk/haskell.nix/archive/9bc8625f18ed1aa633f5f3a52ee03d1718eaeebe.tar.gz", + "url": "https://github.com/input-output-hk/haskell.nix/archive/a6825537df7c0834a4410f652b6659e07ec5bde3.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, "niv": { diff --git a/nix/sources.nix b/nix/sources.nix index 1938409..9a01c8a 100644 --- a/nix/sources.nix +++ b/nix/sources.nix @@ -31,8 +31,28 @@ let if spec ? branch then "refs/heads/${spec.branch}" else if spec ? tag then "refs/tags/${spec.tag}" else abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"; + submodules = if spec ? submodules then spec.submodules else false; + submoduleArg = + let + nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; + emptyArgWithWarning = + if submodules == true + then + builtins.trace + ( + "The niv input \"${name}\" uses submodules " + + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " + + "does not support them" + ) + {} + else {}; + in + if nixSupportsSubmodules + then { inherit submodules; } + else emptyArgWithWarning; in - builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; }; + builtins.fetchGit + ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); fetch_local = spec: spec.path; diff --git a/shell.nix b/shell.nix index bbd9261..f8c8d12 100644 --- a/shell.nix +++ b/shell.nix @@ -1,5 +1,6 @@ +args@{ packageSet ? null }: let - project = import ./default.nix; + project = import ./default.nix args; pkgs = import ./nix/pkgs.nix; sources = import ./nix/sources.nix { }; in project.shellFor { @@ -7,7 +8,7 @@ in project.shellFor { withHoogle = true; - tools = { + tools = if isNull packageSet || packageSet == "lts-20" then { cabal = "3.6.2.0"; hlint = "3.5"; ghcid = "0.8.7"; @@ -15,7 +16,16 @@ in project.shellFor { haskell-ci = "0.14.3"; haskell-language-server = "1.9.1.0"; cabal-fmt = "0.1.6"; - }; + } else if packageSet == "lts-19" then { + cabal = "3.4.1.0"; + ghcid = "0.8.7"; + haskell-language-server = "1.9.0.0"; + } else if packageSet == "lts-18" then { + cabal = "3.2.0.0"; + ghcid = "0.8.7"; + haskell-language-server = "1.8.0.0"; + } else + abort "packageSet must be one of , lts-19 or lts-18"; buildInputs = with pkgs; [ nixfmt @@ -23,7 +33,15 @@ in project.shellFor { cmake bash openscad + # not available from haskell.nix? + pkgs.haskellPackages.doctest ]; exactDeps = true; + + shellHook = if isNull packageSet then + "" + else '' + export PACKAGE_SET=${packageSet} + ''; } diff --git a/stack-lts-18.yaml b/stack-lts-18.yaml new file mode 100644 index 0000000..a7a9e29 --- /dev/null +++ b/stack-lts-18.yaml @@ -0,0 +1,5 @@ +flags: {} +packages: +- '.' +extra-deps: [] +resolver: lts-18.28 diff --git a/stack-lts-19.yaml b/stack-lts-19.yaml new file mode 100644 index 0000000..786fa82 --- /dev/null +++ b/stack-lts-19.yaml @@ -0,0 +1,5 @@ +flags: {} +packages: +- '.' +extra-deps: [] +resolver: lts-19.33