Skip to content
Snippets Groups Projects
Forked from Glasgow Haskell Compiler / ghc.nix
68 commits behind, 1 commit ahead of the upstream repository.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
flake.nix 3.20 KiB
{
  description = "ghc.nix - the ghc devShell";
  nixConfig = {
    bash-prompt = "\\[\\e[34;1m\\]ghc.nix ~ \\[\\e[0m\\]";
    extra-substituters = [ "https://ghc-nix.cachix.org" ];
    extra-trusted-public-keys = [ "ghc-nix.cachix.org-1:wI8l3tirheIpjRnr2OZh6YXXNdK2fVQeOI4SVz/X8nA=" ];
  };

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";
    flake-compat = {
      url = "github:edolstra/flake-compat";
      flake = false;
    };

    all-cabal-hashes = {
      url = "github:commercialhaskell/all-cabal-hashes/hackage";
      flake = false;
    };

    pre-commit-hooks = {
      url = "github:cachix/pre-commit-hooks.nix";
      inputs.nixpkgs.follows = "nixpkgs";
      inputs.nixpkgs-stable.follows = "nixpkgs";
      inputs.flake-compat.follows = "flake-compat";
    };

    ghc-wasm-meta.url = "gitlab:ghc/ghc-wasm-meta?host=gitlab.haskell.org";
  };

  outputs = { nixpkgs, all-cabal-hashes, pre-commit-hooks, ghc-wasm-meta, ... }: with nixpkgs.lib; let
    supportedSystems =
      # allow nix flake show and nix flake check when passing --impure
      if builtins.hasAttr "currentSystem" builtins
      then [ builtins.currentSystem ]
      else nixpkgs.lib.systems.flakeExposed;
    perSystem = genAttrs supportedSystems;

    lib = { inherit supportedSystems perSystem; };

    defaultSettings = system: {
      inherit nixpkgs system;
      all-cabal-hashes = all-cabal-hashes.outPath;
      inherit (ghc-wasm-meta.outputs.packages."${system}") wasi-sdk wasmtime;
    };

    pre-commit-check = system: pre-commit-hooks.lib.${system}.run {
      src = ./.;
      hooks = {
        nixpkgs-fmt.enable = true;
        statix.enable = true;
        deadnix.enable = true;
        typos.enable = true;
      };
    };

    # NOTE: change this according to the settings allowed in the ./ghc.nix file and described
    # in the `README.md`
    userSettings = {
      withHadrianDeps = true;
      withIde = true;
    };
  in
  rec {
    devShells = perSystem (system: rec {
      default = ghc-nix;
      ghc-nix = import ./ghc.nix (defaultSettings system // userSettings);
      wasm-cross = import ./ghc.nix (defaultSettings system // userSettings // { withWasm = true; });
      # Backward compat synonym
      wasi-cross = wasm-cross;