{ description = "haskell-template's description"; inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; flake-utils.url = "github:numtide/flake-utils/v1.0.0"; flake-utils.inputs.nixpkgs.follows = "nixpkgs"; flake-compat.url = "github:edolstra/flake-compat"; flake-compat.flake = false; flake-compat.inputs.nixpkgs.follows = "nixpkgs"; }; # Consider this to be a function producing Flake outputs for the given system # and inputs; viz.: # # mkOutputsFrom :: Set Inputs -> System -> Set Outputs # mkOutputsFrom inputs system = { ... } # # We use eachDefaultSystem to allow other architectures. # cf. https://github.com/NixOS/nix/issues/3843#issuecomment-661720562 outputs = inputs: inputs.flake-utils.lib.eachDefaultSystem (system: let name = "haskell-template"; # Because: https://zimbatm.com/notes/1000-instances-of-nixpkgs pkgs = inputs.nixpkgs.legacyPackages.${system}; inherit (pkgs.lib.lists) optionals; # Specify GHC version here. To get the appropriate value, run: # nix-env -f "" -qaP -A haskell.compiler hp = pkgs.haskellPackages; # Eg: pkgs.haskell.packages.ghc921; # Specify your build/dev dependencies here. shellDeps = with hp; [ cabal-fmt cabal-install ghcid haskell-language-server fourmolu hlint pkgs.nixpkgs-fmt pkgs.treefmt ]; project = { returnShellEnv ? false , withHoogle ? false }: hp.developPackage { inherit returnShellEnv withHoogle name; root = ./.; overrides = self: super: with pkgs.haskell.lib; { # Use callCabal2nix to override Haskell dependencies here # cf. https://tek.brick.do/K3VXJd8mEKO7 # Example: # > NanoID = self.callCabal2nix "NanoID" inputs.NanoID { }; # Assumes that you have the 'NanoID' flake input defined. }; modifier = drv: pkgs.haskell.lib.overrideCabal drv (oa: { # All the Cabal-specific overrides go here. # For examples on what is possible, see: # https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/haskell-modules/lib/compose.nix buildTools = (oa.buildTools or [ ]) ++ optionals returnShellEnv shellDeps; }); }; in { # Used by `nix build ...` packages = { default = project { }; }; # Used by `nix run ...` apps = { default = { type = "app"; program = "${inputs.self.packages.${system}.default}/bin/${name}"; }; }; # Used by `nix develop ...` devShells = { default = project { returnShellEnv = true; withHoogle = true; }; }; # For compatability with older Nix (eg in CI) devShell = inputs.self.devShells.${system}.default; defaultPackage = inputs.self.packages.${system}.default; defaultApp = inputs.self.apps.${system}.default; } ); }