diff --git a/flake-module.nix b/flake-module.nix index 5b1ad8ee..904e5e98 100644 --- a/flake-module.nix +++ b/flake-module.nix @@ -110,6 +110,26 @@ in }; }; }; + topLevelPackages = mkOption { + type = types.submodule { + options = { + enableMultiPkgs = mkBoolOption { + description = "Whether or not to use multiple top-level package dirs"; + default = false; + }; + + dirs = mkOption { + type = types.listOf types.str; + description = '' + Subdirs containing a separate Cabal package + + Define as nonempty only if enableMultiPkgs is set to `true` + ''; + default = [ ]; + }; + }; + }; + }; }; }); }; @@ -151,6 +171,23 @@ in (pkgs.lib.composeExtensions (pkgs.haskell.lib.packageSourceOverrides cfg.source-overrides) cfg.overrides); + hp = hp.extend + ( + let + enableMultiPkgs = cfg.topLevelPackages.enableMultiPkgs; + dirs = cfg.topLevelPackages.dirs; + in + if enableMultiPkgs then + (self: _: + listToAttrs (map + (dir: { + name = dir; + value = self.callCabal2nix dir ./${dir} { }; + }) + dirs) + ) + else (_: _: { }) + ); defaultBuildTools = hp: with hp; { inherit cabal-install @@ -161,7 +198,16 @@ in buildTools = lib.attrValues (defaultBuildTools hp // cfg.buildTools hp); package = cfg.modifier (hp.callCabal2nixWithOptions cfg.name cfg.root "" { }); devShell = with pkgs.haskell.lib; - (addBuildTools package buildTools).envFunc { withHoogle = true; }; + (addBuildTools package buildTools).envFunc ( + { + withHoogle = true; + } // ( + if cfg.topLevelPackages.enableMultiPkgs then { + packages = pkgs: map (pkg: pkgs.${pkg}) cfg.topLevelPackages.dirs; + buildInputs = [ hp.ghcid ]; + } else { } + ) + ); devShellCheck = name: command: runCommandInSimulatedShell devShell cfg.root "${projectKey}-${name}-check" { } command; in