From 0f37d0ef055671c82597adf645714a042368ad04 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Wed, 30 Mar 2022 15:12:35 -0400 Subject: [PATCH] Switch to declarative linters Resolves #8 --- flake.lock | 12 ++++++------ flake.nix | 40 +++++++++++++++------------------------- src/Main.hs | 4 ++-- 3 files changed, 23 insertions(+), 33 deletions(-) diff --git a/flake.lock b/flake.lock index c1409d6..9170a8d 100644 --- a/flake.lock +++ b/flake.lock @@ -54,16 +54,16 @@ ] }, "locked": { - "lastModified": 1648246591, - "narHash": "sha256-GDyLjj64sA65MPMlOtzs5DHPK4O5O8u6jMYKiGHgaPU=", - "ref": "master", - "rev": "3a4289e086d48b409c8c6eb51de1d9e405c7f379", - "revCount": 20, + "lastModified": 1648667273, + "narHash": "sha256-eQUb40xDyv0Ye3oMzGz6tcHPF9y9Xhq1QksV9h7uEDk=", + "ref": "spec-type", + "rev": "4648a98d91f754ae0f7a3d035a1aaa871eb1b4fc", + "revCount": 34, "type": "git", "url": "https://gitlab.homotopic.tech/nix/lint-utils.git" }, "original": { - "ref": "master", + "ref": "spec-type", "type": "git", "url": "https://gitlab.homotopic.tech/nix/lint-utils.git" } diff --git a/flake.nix b/flake.nix index d0c5530..1851537 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ lint-utils = { type = "git"; url = "https://gitlab.homotopic.tech/nix/lint-utils.git"; - ref = "master"; + ref = "spec-type"; # https://gitlab.homotopic.tech/nix/lint-utils/-/merge_requests/4 inputs.nixpkgs.follows = "nixpkgs"; }; }; @@ -25,7 +25,6 @@ # Change GHC version here. To get the appropriate value, run: # nix-env -f "" -qaP -A haskell.compiler hp = pkgs.haskellPackages; # pkgs.haskell.packages.ghc921; - haskellFormatter = "fourmoluStandardGhc8107"; # The formatter to use from inputs.lint-utils project = returnShellEnv: hp.developPackage { @@ -53,24 +52,20 @@ ]); }; + lintSpec = { + nixpkgs-fmt = { }; + cabal-fmt = { }; + fourmolu = { + ghcOpts = "-o-XTypeApplications -o-XImportQualifiedPost"; + }; + }; + # Checks the shell script using ShellCheck checkedShellScript = name: text: (pkgs.writeShellApplication { inherit name text; }) + "/bin/${name}"; - # Concat a list of Flake apps to produce a new app that runs all of them - # in sequence. - concatApps = apps: - { - type = "app"; - program = checkedShellScript "concatApps" - (pkgs.lib.strings.concatMapStringsSep - "\n" - (app: app.program) - apps); - }; - in { # Used by `nix build` & `nix run` (prod exe) @@ -80,20 +75,15 @@ # Used by `nix run ...` apps = { - format = concatApps [ - inputs.lint-utils.apps.${system}.${haskellFormatter} - inputs.lint-utils.apps.${system}.cabal-fmt - inputs.lint-utils.apps.${system}.nixpkgs-fmt - ]; + format = inputs.lint-utils.mkApp.${system} lintSpec; }; # Used by `nix flake check` (but see next attribute) - checks = { - format-haskell = inputs.lint-utils.linters.${system}.${haskellFormatter} ./.; - format-cabal = inputs.lint-utils.linters.${system}.cabal-fmt ./.; - format-nix = inputs.lint-utils.linters.${system}.nixpkgs-fmt ./.; - hls = checkedShellScript "hls" "${hp.haskell-language-server}/bin/haskell-language-server"; - }; + checks = + inputs.lint-utils.mkChecks.${system} lintSpec ./. + // { + hls = checkedShellScript "hls" "${hp.haskell-language-server}/bin/haskell-language-server"; + }; # We need this hack because `nix flake check` won't work for Haskell # projects: https://nixos.wiki/wiki/Import_From_Derivation#IFD_and_Haskell diff --git a/src/Main.hs b/src/Main.hs index a853643..540ecf0 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -1,6 +1,6 @@ module Main where -import Main.Utf8 (withUtf8) +import Main.Utf8 qualified as Utf8 {- | Main entry point. @@ -11,5 +11,5 @@ import Main.Utf8 (withUtf8) main :: IO () main = do -- For withUtf8, see https://serokell.io/blog/haskell-with-utf8 - withUtf8 $ do + Utf8.withUtf8 $ do putStrLn "Hello 🌎"