Skip to content

Commit

Permalink
Expose finalPackages
Browse files Browse the repository at this point in the history
  • Loading branch information
roberth committed Feb 8, 2023
1 parent bdde8bb commit ea95618
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 31 deletions.
50 changes: 49 additions & 1 deletion flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,27 @@ in
};
};
};
projectSubmodule = types.submodule (args@{ name, config, lib, ... }: {
projectSubmodule = types.submodule (args@{ name, config, lib, ... }:
let
localPackagesOverlay = self: _:
let
fromSdist = self.buildFromCabalSdist or (builtins.trace "Your version of Nixpkgs does not support hs.buildFromCabalSdist yet." (pkg: pkg));
filterSrc = name: src: lib.cleanSourceWith { inherit src name; filter = path: type: true; };
in
lib.mapAttrs
(name: value:
let
# callCabal2nix does not need a filtered source. It will
# only pick out the cabal and/or hpack file.
pkgProto = self.callCabal2nix name value.root { };
pkgFiltered = pkgs.haskell.lib.overrideSrc pkgProto {
src = filterSrc name value.root;
};
in
fromSdist pkgFiltered)
config.packages;
in
{
options = {
haskellPackages = mkOption {
type = types.attrsOf raw;
Expand Down Expand Up @@ -133,6 +153,34 @@ in
This is an internal option, not meant to be set by the user.
'';
};

# Derived options

finalPackages = mkOption {
type = types.attrsOf raw;
readOnly = true;
default = config.haskellPackages.extend config.finalOverlay;
defaultText = lib.literalMD "internal definition.";
description = ''
The final package set, based `haskellPackages` plus
the additions and overrides specified in this other options.
'';
};
finalOverlay = mkOption {
type = types.raw;
readOnly = true;
internal = true;
default = lib.composeManyExtensions [
# The order here matters.
#
# User's overrides (cfg.overrides) is applied **last** so
# as to give them maximum control over the final package
# set used.
localPackagesOverlay
(pkgs.haskell.lib.packageSourceOverrides config.source-overrides)
config.overrides
];
};
};
config = import ./haskell-project.nix (args // { inherit self pkgs; });
});
Expand Down
31 changes: 1 addition & 30 deletions haskell-project.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,7 @@ in
let
projectKey = name;

localPackagesOverlay = self: _:
let
fromSdist = self.buildFromCabalSdist or (builtins.trace "Your version of Nixpkgs does not support hs.buildFromCabalSdist yet." (pkg: pkg));
filterSrc = name: src: lib.cleanSourceWith { inherit src name; filter = path: type: true; };
in
lib.mapAttrs
(name: value:
let
# callCabal2nix does not need a filtered source. It will
# only pick out the cabal and/or hpack file.
pkgProto = self.callCabal2nix name value.root { };
pkgFiltered = pkgs.haskell.lib.overrideSrc pkgProto {
src = filterSrc name value.root;
};
in
fromSdist pkgFiltered)
config.packages;
finalOverlay =
lib.composeManyExtensions
[
# The order here matters.
#
# User's overrides (cfg.overrides) is applied **last** so
# as to give them maximum control over the final package
# set used.
localPackagesOverlay
(pkgs.haskell.lib.packageSourceOverrides config.source-overrides)
config.overrides
];
finalPackages = config.haskellPackages.extend finalOverlay;
finalPackages = config.finalPackages;

defaultBuildTools = hp: with hp; {
inherit
Expand Down

0 comments on commit ea95618

Please sign in to comment.