From 5cfb230f15e1a10a74d9625504d7b1347063b497 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar <3998+srid@users.noreply.github.com> Date: Sun, 28 Aug 2022 18:50:08 -0400 Subject: [PATCH] Add a flake check for HLS (#47) Also use check-flake for .#check package. Deal with network access by disabling sandbox, and excluding in garnix. --- .github/workflows/ci.yaml | 9 ++++++--- README.md | 1 + flake.lock | 22 +++++++++++++++++++--- flake.nix | 9 ++++++--- garnix.yaml | 5 ++++- haskell-template.cabal | 6 +++--- 6 files changed, 39 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b06f866..d442f23 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -18,13 +18,16 @@ jobs: - name: Cache Nix dependencies run: | nix develop -j 4 -c echo - - name: Format check + - name: Flake checks run: | - nix develop -j auto -c treefmt --fail-on-change + # Sandbox must be disabled due to HLS, + # https://github.com/haskell/haskell-language-server/issues/3128 + nix --option sandbox false build .#check --no-link -L + # TODO: Remove after https://github.com/srid/haskell-flake/issues/19 - name: Hlint run: | nix develop -j auto -c hlint src - name: Build id: build run: | - nix build -j auto + nix build -j auto -L diff --git a/README.md b/README.md index a49a591..410ef66 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ git add . && git commit -m rename ## Tips - Run `nix flake update` to update all flake inputs. +- Run `nix --option sandbox false build .#check -L` to run the flake checks. - Run `treefmt` in nix shell to autoformat the project. This uses [treefmt](https://github.com/numtide/treefmt), which uses `./treefmt.toml` (where fourmolu and nixpkgs-fmt are specified). - Run `bin/hoogle` to start Hoogle with packages in your cabal file. - Run `bin/test` to run the test suite. diff --git a/flake.lock b/flake.lock index 4e0eaff..13e1468 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,20 @@ { "nodes": { + "check-flake": { + "locked": { + "lastModified": 1661723725, + "narHash": "sha256-zbt1vEDQ5Uxdqz4AlW/xOvoUs9tK4ayg8q4+2EtrMEQ=", + "owner": "srid", + "repo": "check-flake", + "rev": "e48e6b5c86f6fb67f0e565a6862fa8b3e7a53446", + "type": "github" + }, + "original": { + "owner": "srid", + "repo": "check-flake", + "type": "github" + } + }, "flake-parts": { "inputs": { "nixpkgs": [ @@ -22,11 +37,11 @@ }, "haskell-flake": { "locked": { - "lastModified": 1660319056, - "narHash": "sha256-MX6PLEtXVyXXUEk3t1e0c20XRL4m4u9TFET2X0TpTdE=", + "lastModified": 1661726764, + "narHash": "sha256-YzzOoff6m3W4g4B0E8xd3omvOhEVuRu/Rdvnmy2H6Jc=", "owner": "srid", "repo": "haskell-flake", - "rev": "1ca2be3c354ef2a3296cac7e54ae21e1d6ead6d7", + "rev": "3c27b5ba2eafc52f4bed232a8ff74cf0a5a99375", "type": "github" }, "original": { @@ -53,6 +68,7 @@ }, "root": { "inputs": { + "check-flake": "check-flake", "flake-parts": "flake-parts", "haskell-flake": "haskell-flake", "nixpkgs": "nixpkgs", diff --git a/flake.nix b/flake.nix index b18ec50..e5155ee 100644 --- a/flake.nix +++ b/flake.nix @@ -6,14 +6,16 @@ flake-parts.inputs.nixpkgs.follows = "nixpkgs"; haskell-flake.url = "github:srid/haskell-flake"; treefmt-flake.url = "github:srid/treefmt-flake"; + check-flake.url = "github:srid/check-flake"; }; - outputs = { self, nixpkgs, flake-parts, haskell-flake, treefmt-flake, ... }: + outputs = inputs@{ self, nixpkgs, flake-parts, ... }: flake-parts.lib.mkFlake { inherit self; } { systems = nixpkgs.lib.systems.flakeExposed; imports = [ - haskell-flake.flakeModule - treefmt-flake.flakeModule + inputs.haskell-flake.flakeModule + inputs.treefmt-flake.flakeModule + inputs.check-flake.flakeModule ]; perSystem = { self', config, pkgs, ... }: { haskellProjects.default = { @@ -22,6 +24,7 @@ inherit (pkgs) treefmt; } // config.treefmt.formatters; + enableHLSCheck = true; }; treefmt.formatters = { inherit (pkgs) diff --git a/garnix.yaml b/garnix.yaml index d25f3af..0b4456a 100644 --- a/garnix.yaml +++ b/garnix.yaml @@ -6,4 +6,7 @@ builds: - "checks.aarch64-darwin.*" - "devShells.x86_64-linux.default" - "devShells.aarch64-darwin.default" - exclude: [] + exclude: + # https://github.com/srid/haskell-flake/issues/21 + - "checks.*.default-hls" + - "packages.*.check" diff --git a/haskell-template.cabal b/haskell-template.cabal index 5d398ba..ff1ac2a 100644 --- a/haskell-template.cabal +++ b/haskell-template.cabal @@ -93,11 +93,11 @@ common shared hs-source-dirs: src other-modules: Lib + default-language: Haskell2010 executable haskell-template - import: shared - main-is: Main.hs - default-language: Haskell2010 + import: shared + main-is: Main.hs test-suite tests import: shared