haskell-flake

haskell-flake scans your flake files for Haskell projects and turns them into packages using the Nixpkgs Haskell infrastructure.

It also provides checks and devShells

Multiple projects can be declared to represent each package set, which is great for GHCJS frontends.

Installation

To use these options, add to your flake inputs:

haskell-flake.url = "github:srid/haskell-flake";

and inside the mkFlake:

imports = [
  inputs.haskell-flake.flakeModule
];

Run nix flake lock and you're set.

Options

flake.haskellFlakeProjectModules

perSystem.haskellProjects

perSystem.haskellProjects.<name>.packages

perSystem.haskellProjects.<name>.autoWire

perSystem.haskellProjects.<name>.basePackages

perSystem.haskellProjects.<name>.defaults.enable

perSystem.haskellProjects.<name>.defaults.packages

perSystem.haskellProjects.<name>.defaults.devShell.tools

perSystem.haskellProjects.<name>.defaults.projectModules.output

perSystem.haskellProjects.<name>.defaults.settings.default

perSystem.haskellProjects.<name>.devShell

perSystem.haskellProjects.<name>.devShell.enable

perSystem.haskellProjects.<name>.devShell.benchmark

perSystem.haskellProjects.<name>.devShell.extraLibraries

perSystem.haskellProjects.<name>.devShell.hlsCheck

perSystem.haskellProjects.<name>.devShell.hlsCheck.enable

perSystem.haskellProjects.<name>.devShell.hlsCheck.drv

perSystem.haskellProjects.<name>.devShell.hoogle

perSystem.haskellProjects.<name>.devShell.mkShellArgs

perSystem.haskellProjects.<name>.devShell.tools

perSystem.haskellProjects.<name>.outputs

perSystem.haskellProjects.<name>.outputs.packages

perSystem.haskellProjects.<name>.outputs.packages.<name>.package

perSystem.haskellProjects.<name>.outputs.packages.<name>.exes

perSystem.haskellProjects.<name>.outputs.packages.<name>.exes.<name>.program

perSystem.haskellProjects.<name>.outputs.packages.<name>.exes.<name>.type

perSystem.haskellProjects.<name>.outputs.apps

perSystem.haskellProjects.<name>.outputs.apps.<name>.program

perSystem.haskellProjects.<name>.outputs.apps.<name>.type

perSystem.haskellProjects.<name>.outputs.checks

perSystem.haskellProjects.<name>.outputs.devShell

perSystem.haskellProjects.<name>.outputs.finalPackages

perSystem.haskellProjects.<name>.projectFlakeName

perSystem.haskellProjects.<name>.projectRoot

perSystem.haskellProjects.<name>.settings

flake.haskellFlakeProjectModules

A lazy attrset of haskellProjects.<name> modules that can be imported in other flakes.

Type: lazy attribute set of module

Default: Package and dependency information for this project exposed for reuse in another flake, when using this project as a Haskell dependency.

The ‘output’ module of the default project is included by default, returning defaults.projectModules.output.

Declared by:

haskell-flake/nix/modules/project-modules.nix

perSystem.haskellProjects

Haskell projects

Type: attribute set of (submodule)

Declared by:

haskell-flake/nix/modules/projects.nix

perSystem.haskellProjects.<name>.packages

Additional packages to add to basePackages.

Local packages are added automatically (see config.defaults.packages):

You can also override the source for existing packages here.

Type: lazy attribute set of module

Default: { }

Declared by:

haskell-flake/nix/modules/project/packages

perSystem.haskellProjects.<name>.autoWire

List of flake output types to autowire.

Using an empty list will disable autowiring entirely, enabling you to manually wire them using config.haskellProjects.<name>.outputs.

Type: list of (one of “packages”, “checks”, “apps”, “devShells”)

Default:

[
  "packages"
  "checks"
  "apps"
  "devShells"
]

Declared by:

haskell-flake/nix/modules/project

perSystem.haskellProjects.<name>.basePackages

Which Haskell package set / compiler to use.

You can effectively select the GHC version here.

To get the appropriate value, run:

nix-env -f "<nixpkgs>" -qaP -A haskell.compiler

And then, use that in pkgs.haskell.packages.ghc<version>

Type: attribute set of raw value

Default: pkgs.haskellPackages

Example: "pkgs.haskell.packages.ghc924"

Declared by:

haskell-flake/nix/modules/project

perSystem.haskellProjects.<name>.defaults.enable

Whether to enable haskell-flake’s default settings for this project.

Type: boolean

Default: true

Declared by:

haskell-flake/nix/modules/project/defaults.nix

perSystem.haskellProjects.<name>.defaults.packages

Local packages scanned from projectRoot

Type: lazy attribute set of module

Default: If you have a cabal.project file (under projectRoot), those packages are automatically discovered. Otherwise, the top-level .cabal file is used to discover the only local package.

haskell-flake currently supports a limited range of syntax for cabal.project. Specifically it requires an explicit list of package directories under the “packages” option.

Declared by:

haskell-flake/nix/modules/project/defaults.nix

perSystem.haskellProjects.<name>.defaults.devShell.tools

Build tools always included in devShell

Type: function that evaluates to a(n) lazy attribute set of (null or package)

Default: <function>

Declared by:

haskell-flake/nix/modules/project/defaults.nix

perSystem.haskellProjects.<name>.defaults.projectModules.output

A haskell-flake project module that exports the packages and settings options to the consuming flake. This enables the use of this flake’s Haskell package as a dependency, re-using its overrides.

Type: module

Default: a generated module

Declared by:

haskell-flake/nix/modules/project/defaults.nix

perSystem.haskellProjects.<name>.defaults.settings.default

Default settings for all packages in packages option.

Type: module

Default:

''
  Speed up builds by disabling haddock and library profiling.

This uses local.toDefinedProject option to determine which packages to override. Thus, it applies to both local packages as well as transitively imported packags that are local to that flake (managed by haskell-flake). The goal being to use the same configuration consistently for all packages using haskell-flake. ''

Declared by:

haskell-flake/nix/modules/project/defaults.nix

perSystem.haskellProjects.<name>.devShell

Development shell configuration

Type: submodule

Default: { }

Declared by:

haskell-flake/nix/modules/project/hls-check.nix, haskell-flake/nix/modules/project/devshell.nix

perSystem.haskellProjects.<name>.devShell.enable

Whether to enable a development shell for the project.

Type: boolean

Default: true

Declared by:

haskell-flake/nix/modules/project/devshell.nix

perSystem.haskellProjects.<name>.devShell.benchmark

Whether to include benchmark dependencies in the development shell. The value of this option will set the corresponding doBenchmark flag in the shellFor derivation.

Type: boolean

Default: false

Declared by:

haskell-flake/nix/modules/project/devshell.nix

perSystem.haskellProjects.<name>.devShell.extraLibraries

Extra Haskell libraries available in the shell’s environment. These can be used in the shell’s runghc and ghci for instance.

The argument is the Haskell package set.

The return type is an attribute set for overridability and syntax, as only the values are used.

Type: null or (function that evaluates to a(n) attribute set of (null or package))

Default: null

Example: hp: { inherit (hp) releaser; }

Declared by:

haskell-flake/nix/modules/project/devshell.nix

perSystem.haskellProjects.<name>.devShell.hlsCheck

A check to make sure that your IDE will work.

Type: submodule

Default: { }

Declared by:

haskell-flake/nix/modules/project/hls-check.nix

perSystem.haskellProjects.<name>.devShell.hlsCheck.enable

Whether to enable a flake check to verify that HLS works.

This is equivalent to nix develop -i -c haskell-language-server.

Note that, HLS will try to access the network through Cabal (see https://github.com/haskell/haskell-language-server/issues/3128), therefore sandboxing must be disabled when evaluating this check.

Type: boolean

Default: false

Declared by:

haskell-flake/nix/modules/project/hls-check.nix

perSystem.haskellProjects.<name>.devShell.hlsCheck.drv

The hlsCheck derivation generated for this project.

Type: package (read only)

Declared by:

haskell-flake/nix/modules/project/hls-check.nix

perSystem.haskellProjects.<name>.devShell.hoogle

Whether to include Hoogle in the development shell. The value of this option will set the corresponding withHoogle flag in the shellFor derivation.

Type: boolean

Default: true

Declared by:

haskell-flake/nix/modules/project/devshell.nix

perSystem.haskellProjects.<name>.devShell.mkShellArgs

Extra arguments to pass to pkgs.mkShell.

Type: attribute set of raw value

Default: { }

Example:

''
  {
    shellHook = \'\'
      # Re-generate .cabal files so HLS will work (per hie.yaml)
      ''${pkgs.findutils}/bin/find -name package.yaml -exec hpack {} \;
    \'\';
  };
''

Declared by:

haskell-flake/nix/modules/project/devshell.nix

perSystem.haskellProjects.<name>.devShell.tools

Build tools for developing the Haskell project.

These tools are merged with the haskell-flake defaults defined in the defaults.devShell.tools option. Set the value to null to remove that default tool.

Type: function that evaluates to a(n) lazy attribute set of (null or package)

Default: <function>

Declared by:

haskell-flake/nix/modules/project/devshell.nix

perSystem.haskellProjects.<name>.outputs

The flake outputs generated for this project.

This is an internal option, not meant to be set by the user.

Type: submodule

Declared by:

haskell-flake/nix/modules/project/hls-check.nix, haskell-flake/nix/modules/project/outputs.nix, haskell-flake/nix/modules/project/devshell.nix

perSystem.haskellProjects.<name>.outputs.packages

Package information for all local packages. Contains the following keys:

  • package: The Haskell package derivation

  • exes: Attrset of executables found in the .cabal file

Type: attribute set of (submodule) (read only)

Declared by:

haskell-flake/nix/modules/project/outputs.nix

perSystem.haskellProjects.<name>.outputs.packages.<name>.package

The local package derivation.

Type: package

Declared by:

haskell-flake/nix/modules/project/outputs.nix

perSystem.haskellProjects.<name>.outputs.packages.<name>.exes

Attrset of executables from .cabal file.

If the associated Haskell project has a separate bin output (cf. enableSeparateBinOutput), then this exe will refer only to the bin output.

NOTE: Evaluating up to this option will involve IFD.

Type: attribute set of (submodule)

Declared by:

haskell-flake/nix/modules/project/outputs.nix

perSystem.haskellProjects.<name>.outputs.packages.<name>.exes.<name>.program

A path to an executable or a derivation with meta.mainProgram.

Type: string or package convertible to it

Declared by:

haskell-flake/nix/modules/project/outputs.nix

perSystem.haskellProjects.<name>.outputs.packages.<name>.exes.<name>.type

A type tag for apps consumers.

Type: value “app” (singular enum)

Default: "app"

Declared by:

haskell-flake/nix/modules/project/outputs.nix

perSystem.haskellProjects.<name>.outputs.apps

Flake apps for each Cabal executable in the project.

Type: attribute set of (submodule) (read only)

Declared by:

haskell-flake/nix/modules/project/outputs.nix

perSystem.haskellProjects.<name>.outputs.apps.<name>.program

A path to an executable or a derivation with meta.mainProgram.

Type: string or package convertible to it

Declared by:

haskell-flake/nix/modules/project/outputs.nix

perSystem.haskellProjects.<name>.outputs.apps.<name>.type

A type tag for apps consumers.

Type: value “app” (singular enum)

Default: "app"

Declared by:

haskell-flake/nix/modules/project/outputs.nix

perSystem.haskellProjects.<name>.outputs.checks

The flake checks generated for this project.

Type: lazy attribute set of package (read only)

Declared by:

haskell-flake/nix/modules/project/hls-check.nix

perSystem.haskellProjects.<name>.outputs.devShell

The development shell derivation generated for this project.

Type: package (read only)

Declared by:

haskell-flake/nix/modules/project/devshell.nix

perSystem.haskellProjects.<name>.outputs.finalPackages

The final Haskell package set including local packages and any overrides, on top of basePackages.

Type: attribute set of raw value (read only)

Declared by:

haskell-flake/nix/modules/project/outputs.nix

perSystem.haskellProjects.<name>.projectFlakeName

A descriptive name for the flake in which this project resides.

If unspecified, the Nix store path’s basename will be used.

Type: null or string

Default: null

Declared by:

haskell-flake/nix/modules/project

perSystem.haskellProjects.<name>.projectRoot

Path to the root of the project directory.

Chaning this affects certain functionality, like where to look for the ‘cabal.project’ file.

Type: path

Default: "Top-level directory of the flake"

Declared by:

haskell-flake/nix/modules/project

perSystem.haskellProjects.<name>.settings

Overrides for packages in basePackages and packages.

Attr values are submodules that take the following arguments:

  • name: Package name

  • package: The reference to the package in packages option if it exists, null otherwise.

  • self/super: The ‘self’ and ‘super’ (aka. ‘final’ and ‘prev’) used in the Haskell overlay.

  • pkgs: Nixpkgs instance of the module user (import’er).

Default settings are defined in project.config.defaults.settings which can be overriden.

Type: lazy attribute set of module

Default: { }

Declared by:

haskell-flake/nix/modules/project/settings