Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add haskellFlakeProjectModules option #79

Merged
merged 7 commits into from
Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
- ??: `flake.haskellFlakeProjectModules.<name>` 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
5 changes: 5 additions & 0 deletions flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ let
raw;
in
{
imports = [
./project-module.nix
];
options = {
perSystem = mkPerSystemOption
({ config, self', inputs', pkgs, system, ... }:
Expand Down Expand Up @@ -237,6 +240,7 @@ in
}
];
};

in
{
options.haskellProjects = mkOption {
Expand Down Expand Up @@ -264,5 +268,6 @@ in
config.haskellProjects;
};
});

};
}
20 changes: 20 additions & 0 deletions project-module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{ config, lib, flake-parts-lib, ... }:
let
inherit (lib)
mkOption
types
;
inherit (flake-parts-lib)
mkTransposedPerSystemModule
;
in
mkTransposedPerSystemModule {
name = "haskellFlakeProjectModules";
option = mkOption {
type = types.lazyAttrsOf types.deferredModule;
default = { };
description = ''
'';
};
file = ./project-module.nix;
}
33 changes: 15 additions & 18 deletions test/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,23 @@
inputs.check-flake.flakeModule
];
perSystem = { self', pkgs, ... }: {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think using the local pkgs is the right thing to do. It should come from the environment where it's imported, so all we can really need to do is flake.haskellFlakeProjectModules.foo = { pkgs, ... }: { overrides = f pkgs; };.

If a flake does need to reference packages it defines, it can do so with getSystem and the like.

haskellFlakeProjectModules.default = {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roberth I must say I'm not happy with this flake-parts module now providing two (not one) top-level options -- haskellProjects and, now, haskellFlakeProjectModules.

A single top-level would make sense. Like:

{ 
  haskellFlake = {
    projectModules = { .. };
    projects.default = { .. };
  };
}

It also makes the option name obvious enough to indicate that it comes from inputs.haskell-flake rather than any other inputs (the same cannot be strictly said for haskellProjects naming). A similar naming is adopted by other modules like https://github.com/Platonic-Systems/mission-control

wdyt?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OTOH, the current way of naming it outputs.haskellFlakeProjectModules.${system}.default appears to follow the unspoken convention of using flat attributes à la nixosModules, darwinModules, etc.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need options in two separate locations anyway. See previous comment https://github.com/srid/haskell-flake/pull/79/files#r1103655549

flat attributes à la nixosModules,

Flat attributes is probably the way to go. I've made an exception for flakeModule, which I'm not eager to remove until the imports UX is improved. Not sure exactly what can be achieved in that area yet. My previous attempt found too much resistance, so I'll have to find something creative... Anyway, until then, I'd say flat is good.

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;
};
};
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
# module system merges them in such order. cf. the WARNING in option
Expand Down