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

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:

perSystem.haskellProjectTests

Patch an existing haskellProject to run some checks. This module will create a flake check automatically.

Type: lazy attribute set of (submodule)

Default: { }

Declared by:

perSystem.haskellProjectTests.<name>.expect

Arbitrary expression to evaluate as part of the generated flake check

Type: raw value

Declared by:

perSystem.haskellProjectTests.<name>.extraHaskellProjectConfig

Extra configuration to apply to the patched haskell-flake project.

Type: module

Default: { }

Declared by:

perSystem.haskellProjectTests.<name>.from

Which haskellProjects.?? to patch.

Type: string

Default: "default"

Declared by:

perSystem.haskellProjectTests.<name>.patches

List of patches to apply to the project root.

Each patch can be a path to the diff file, or inline patch string.

Type: list of (path or string)

Declared by:

perSystem.haskellProjects

Haskell projects

Type: lazy attribute set of (submodule)

Declared by:

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:

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:

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: lazy attribute set of raw value

Default: pkgs.haskellPackages

Example: "pkgs.haskell.packages.ghc924"

Declared by:

perSystem.haskellProjects.<name>.defaults.enable

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

Type: boolean

Default: true

Declared by:

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:

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:

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:

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

Default settings for all packages whose derivations are produced by haskell-flake.

For example,

{
  # Inside haskellProjects.<name>
  imports = [
    inputs.moo.haskellFlakeProjectModules.output
  ];
  packages = {
    foo.source = "0.1";
    bar.source = inputs.bar;
  };
  settings = {
    baz.check = false;
  };
}

and

...
build-depends:
    moo
  , foo
  , bar
  , baz
  , qux
...

This will apply the settings to moo, foo, bar, baz. But not to qux.

Type: module

Default:

''
  Nothing is changed by default.
''

Declared by:

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

Default settings for all the packages defined using haskell-flake.

For example,

{
  # Inside haskellProjects.<name>
  imports = [
    inputs.moo.haskellFlakeProjectModules.output
  ];
  packages = {
    foo.source = "0.1";
    bar.source = inputs.bar;
  };
  settings = {
    baz.check = false;
  };
}

and

...
build-depends:
    moo
  , foo
  , bar
  , baz
  , qux
...

This will apply the settings to moo and packages in current project. But not to foo, bar, baz and qux.

Type: module

Default:

''
  Speed up builds by disabling haddock and library profiling. Also ensures
  release-worthiness.
  
  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:

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

Default settings for packages local to the current project.

Type: module

Default: { }

Declared by:

perSystem.haskellProjects.<name>.devShell

Development shell configuration

Type: submodule

Default: { }

Declared by:

perSystem.haskellProjects.<name>.devShell.enable

Whether to enable a development shell for the project.

Type: boolean

Default: true

Declared by:

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:

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) lazy attribute set of (null or package))

Default: null

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

Declared by:

perSystem.haskellProjects.<name>.devShell.hlsCheck

A check to make sure that your IDE will work.

Type: submodule

Default: { }

Declared by:

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:

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

The hlsCheck derivation generated for this project.

Type: package (read only)

Declared by:

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:

perSystem.haskellProjects.<name>.devShell.mkShellArgs

Extra arguments to pass to pkgs.mkShell.

Type: lazy 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:

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:

perSystem.haskellProjects.<name>.otherOverlays

Extra overlays to apply.

Normally, you would only use packages.* and settings.* (which translate to overlays), but you can use this option if you want control over the final overlay.

Type: list of A Haskell overlay function taking ‘self’ and ‘super’ args.

Default: [ ]

Declared by:

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:

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: lazy attribute set of (submodule) (read only)

Declared by:

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

The local package derivation.

Type: package

Declared by:

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: lazy attribute set of (submodule)

Declared by:

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

Metadata information about the app. Standardized in Nix at https://github.com/NixOS/nix/pull/11297.

Note: nix flake check is only aware of the description attribute in meta.

Type: lazy attribute set of raw value

Default: { }

Declared by:

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:

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

A type tag for apps consumers.

Type: value “app” (singular enum)

Default: "app"

Declared by:

perSystem.haskellProjects.<name>.outputs.apps

Flake apps for each Cabal executable in the project.

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

Declared by:

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

Metadata information about the app. Standardized in Nix at https://github.com/NixOS/nix/pull/11297.

Note: nix flake check is only aware of the description attribute in meta.

Type: lazy attribute set of raw value

Default: { }

Declared by:

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:

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

A type tag for apps consumers.

Type: value “app” (singular enum)

Default: "app"

Declared by:

perSystem.haskellProjects.<name>.outputs.checks

The flake checks generated for this project.

Type: lazy attribute set of package (read only)

Declared by:

perSystem.haskellProjects.<name>.outputs.devShell

The development shell derivation generated for this project.

Type: package (read only)

Declared by:

perSystem.haskellProjects.<name>.outputs.finalPackages

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

Type: lazy attribute set of raw value (read only)

Declared by:

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:

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:

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: