Skip to content

Commit

Permalink
Add haskellFlakeProjectModules option (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
srid authored Feb 11, 2023
1 parent 4585d42 commit 5d1f6d9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- #64: Remove hlintCheck (use [treefmt-nix](https://github.com/numtide/treefmt-nix#flake-parts) instead)
- #52: Expose the final package set as `finalPackages`. Rename `haskellPackages`, accordingly, to `basePackages`. Overlays are applied on top of `basePackage` -- using `source-overrides`, `overrides`, `packages` in that order -- to produce `finalPackages`.
- #68: You can now use `imports` inside of `haskellProjects.<name>` to modularize your Haskell project configuration.
- #79: `flake.haskellFlakeProjectModules.<name>` option can be used to set and expose your Haskell project modules to other flakes.
- #67: `overrides` will be combined using `composeManyExtensions`, however their order is arbitrary. This is an experimental feature, and a warning will be logged.

## 0.1.0
Expand Down
17 changes: 14 additions & 3 deletions flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,20 @@ in
};
in
{
options.haskellProjects = mkOption {
description = "Haskell projects";
type = types.attrsOf projectSubmodule;
options = {
haskellProjects = mkOption {
description = "Haskell projects";
type = types.attrsOf projectSubmodule;
};

haskellFlakeProjectModules = mkOption {
type = types.lazyAttrsOf types.deferredModule;
default = { };
description = ''
An attrset of `haskellProjects.<name>` modules that can be imported in
other flakes.
'';
};
};

config =
Expand Down
35 changes: 16 additions & 19 deletions test/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,26 @@
inputs.haskell-flake.flakeModule
inputs.check-flake.flakeModule
];
flake.haskellFlakeProjectModules.default = { pkgs, ... }: {
overrides = self: super: {
# This is purposefully incorrect (pointing to ./.) because we
# expect it to be overriden in perSystem below.
foo = self.callCabal2nix "foo" ./. { };
};
devShell = {
tools = hp: {
# Setting to null should remove this tool from defaults.
ghcid = null;
};
hlsCheck.enable = true;
};
};
perSystem = { self', pkgs, ... }: {
haskellProjects.default = {
# Multiple modules should be merged correctly.
imports =
let
defaults = {
overrides = self: super: {
# This is purposefully incorrect (pointing to ./.) because we
# expect it to be overriden below.
foo = self.callCabal2nix "foo" ./. { };
};
devShell = {
tools = hp: {
# Setting to null should remove this tool from defaults.
ghcid = null;
};
hlsCheck.enable = true;
};
};
in
[ defaults ];
imports = [ self.haskellFlakeProjectModules.default ];
overrides = self: super: {
# This overrides the overlay above (in `defaults`), because the
# This overrides the overlay above (in `flake.*`), because the
# module system merges them in such order. cf. the WARNING in option
# docs.
foo = self.callCabal2nix "foo" (inputs.haskell-multi-nix + /foo) { };
Expand Down

0 comments on commit 5d1f6d9

Please sign in to comment.