diff --git a/CHANGELOG.md b/CHANGELOG.md index ad469ea..358f342 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased - #210: Add `extraLibraries` to `settings` module. +- #277: Add `otherOverlays` option to add custom Haskell package overlays. - #225: settings: add `removeReferencesTo` - #215: Improved debug logging. - #216: Remove `debug` option (pass `--trace-verbose` to nix instead) @@ -30,8 +31,8 @@ ## 0.3.0 (May 22, 2023) - #134: Add `autoWire` option to control generation of flake outputs - - #138: Add `checks` to `outputs` submodule - - #143: Changed `autoWire` to be an enum type, for granular controlling of which outputs to autowire. + - #138: Add `checks` to `outputs` submodule + - #143: Changed `autoWire` to be an enum type, for granular controlling of which outputs to autowire. - #137: Expose cabal executables as flake apps. Add a corresponding `outputs.apps` option, while the `outputs.localPackages` option is renamed to `outputs.packages` (it now contains package metadata, including packages and its executables). - #151: Use `lib.getBin` to get the bin output - #148: Remove automatic hpack->cabal generation. Use `pre-commit-hooks.nix` instead. diff --git a/flake.nix b/flake.nix index 3f35dc5..5fbef8a 100644 --- a/flake.nix +++ b/flake.nix @@ -64,6 +64,13 @@ inherit nixpkgs flake-parts haskell-flake; }; }; + + test-otherOverlays = { + dir = "test/otherOverlays"; + overrideInputs = { + inherit nixpkgs flake-parts haskell-flake; + }; + }; }; }; } diff --git a/nix/modules/project/default.nix b/nix/modules/project/default.nix index 2f6d42b..028882d 100644 --- a/nix/modules/project/default.nix +++ b/nix/modules/project/default.nix @@ -68,6 +68,17 @@ in default = pkgs.haskellPackages; defaultText = lib.literalExpression "pkgs.haskellPackages"; }; + otherOverlays = lib.mkOption { + type = types.listOf (import ../../types/haskell-overlay-type.nix { inherit lib; }); + description = '' + 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. + ''; + default = [ ]; + }; autoWire = let outputTypes = [ "packages" "checks" "apps" "devShells" ]; diff --git a/nix/modules/project/outputs.nix b/nix/modules/project/outputs.nix index ca33023..4b1e5f2 100644 --- a/nix/modules/project/outputs.nix +++ b/nix/modules/project/outputs.nix @@ -83,10 +83,10 @@ in localPackages = lib.filterAttrs (_: cfg: cfg.local.toCurrentProject) config.packages; - finalOverlay = lib.composeManyExtensions [ + finalOverlay = lib.composeManyExtensions ([ config.packagesOverlay config.settingsOverlay - ]; + ] ++ config.otherOverlays); finalPackages = config.basePackages.extend finalOverlay; diff --git a/test/otherOverlays/flake.nix b/test/otherOverlays/flake.nix new file mode 100644 index 0000000..5b8e194 --- /dev/null +++ b/test/otherOverlays/flake.nix @@ -0,0 +1,32 @@ +{ + # Since there is no flake.lock file (to avoid incongruent haskell-flake + # pinning), we must specify revisions for *all* inputs to ensure + # reproducibility. + inputs = { + nixpkgs = { }; + flake-parts = { }; + haskell-flake = { }; + + haskell-multi-nix.url = "github:srid/haskell-multi-nix/d6ac6ccab559f886d1fc7da8cab44b99cb0c2c3d"; + haskell-multi-nix.inputs.haskell-flake.follows = "haskell-flake"; + haskell-multi-nix.inputs.nixpkgs.follows = "nixpkgs"; + haskell-multi-nix.inputs.flake-parts.follows = "flake-parts"; + }; + outputs = inputs@{ self, nixpkgs, flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = nixpkgs.lib.systems.flakeExposed; + imports = [ + inputs.haskell-flake.flakeModule + ]; + perSystem = { self', pkgs, ... }: { + haskellProjects.default = { + otherOverlays = [ + (self: super: { + foo = super.callCabal2nix "foo" "${inputs.haskell-multi-nix}/foo" { }; + }) + ]; + }; + packages.default = self'.packages.haskell-flake-test; + }; + }; +} diff --git a/test/otherOverlays/haskell-flake-test.cabal b/test/otherOverlays/haskell-flake-test.cabal new file mode 100644 index 0000000..14d5ef6 --- /dev/null +++ b/test/otherOverlays/haskell-flake-test.cabal @@ -0,0 +1,19 @@ +cabal-version: 3.0 +name: haskell-flake-test +version: 0.1.0.0 +license: NONE +author: Joe +maintainer: joe@example.com +build-type: Simple + +common warnings + ghc-options: -Wall + +executable haskell-flake-test + import: warnings + main-is: Main.hs + build-depends: + base, + foo + hs-source-dirs: src + default-language: Haskell2010 diff --git a/test/otherOverlays/src/Main.hs b/test/otherOverlays/src/Main.hs new file mode 100644 index 0000000..f9b44a6 --- /dev/null +++ b/test/otherOverlays/src/Main.hs @@ -0,0 +1,7 @@ +module Main where + +import Foo + +main :: IO () +main = do + fooFunc