haskell-flake icon indicating copy to clipboard operation
haskell-flake copied to clipboard

Detect globally installed GHC and related tools

Open srid opened this issue 2 years ago • 0 comments

The following shellHook will warn if the user accidentally ends up using a non-nix-shell haskell tools (such as that of ghcup). Perhaps haskell-flake can provide this as an opt-in module to import (like #160).

        haskellProjects.default = { config, ... }: {
          devShell = {
            mkShellArgs.shellHook = ''
              function samePath {
                [[ "$1" == "$2" ]] || (
                  echo "\n!!! WARNING: Found $1, but expected $2"
                )
              }
              function inNixStore {
                [[ "$1" == $NIX_STORE/* ]] || (
                  echo "\n!!! WARNING: $1 is not in the Nix store"
                )
              }
              inNixStore "$(which ghc)"
              # samePath "$(which ghc)" "${lib.getExe config.outputs.finalPackages.ghc}"
              samePath "$(which cabal)" "${lib.getExe config.outputs.finalPackages.cabal-install}"
              samePath "$(which haskell-language-server)" "${lib.getExe config.outputs.finalPackages.haskell-language-server}"
            '';
          };
        }

srid avatar Jul 21 '23 18:07 srid