on iko/ghcjs-patch-master help sign in
flake: export internal functions for more flexibility (#1017)

As of d014079 (#953), haskell.nix internals (such as unapplied ./overlays, sources, etc) are not exported in flake.nix. This makes it harder to override things when using haskell.nix as a flake. The use-case I have in mind is to pin haskell.nix itself to prevent unnecessary GHC rebuilds/redownloads and update only hackage&stackage. This could be done with a following overlay: (haskell-nix.overlays { sourcesOverride = haskell-nix.sources // { inherit hackage stackage; }; }).combined-eval-on-build However, this is not the case as of the aforementioned commit. Now, to do this one has to import ./nix/sources.json, reimplementing what's already done in haskell.nix, and also import ./overlays. With this commit, previous snippet turns into the following: (haskell-nix.internal.overlaysOverrideable { sourcesOverride = haskell-nix.internal.sources // { inherit hackage stackage; }; }).combined-eval-on-build `nix flake check` will now warn us of "unknown flake output 'internal'", but I think it is fine (e.g. nixpkgs has an unknown flake output as well)

commitfd44431a92781898002fe1940dbf52b18d9c8ccd authorAlexander Bantyev <balsoft@balsoft.ru> dateMon 22 Feb 2021, 09:11 (6 years ago) parentbab2eae
1 file changed+24−17
flake.nix+24−17
flake.nix+24−17
@@ -1,27 +1,34 @@
11{
22 description = "Alternative Haskell Infrastructure for Nixpkgs";
33
4− outputs = { self }: let
5− config = import ./config.nix;
6− # We can't import ./nix/sources.nix directly, because that uses nixpkgs to fetch by default,
7− # and importing nixpkgs without specifying localSystem doesn't work on flakes.
8− sources = let
9− sourcesInfo =
10− builtins.fromJSON (builtins.readFile ./nix/sources.json);
11− fetch = sourceInfo:
12− builtins.fetchTarball { inherit (sourceInfo) url sha256; };
13− in builtins.mapAttrs (_: fetch) sourcesInfo;
4+ outputs = { self }:
5+ {
146
15− nixpkgsArgs = {
16− inherit config;
17− overlays = [ self.overlay ];
7+ internal = rec {
8+ config = import ./config.nix;
9+ # We can't import ./nix/sources.nix directly, because that uses nixpkgs to fetch by default,
10+ # and importing nixpkgs without specifying localSystem doesn't work on flakes.
11+ sources = let
12+ sourcesInfo =
13+ builtins.fromJSON (builtins.readFile ./nix/sources.json);
14+ fetch = sourceInfo:
15+ builtins.fetchTarball { inherit (sourceInfo) url sha256; };
16+ in builtins.mapAttrs (_: fetch) sourcesInfo;
17+
18+ nixpkgsArgs = {
19+ inherit config;
20+ overlays = [ self.overlay ];
21+ };
22+
23+ overlaysOverrideable = import ./overlays;
1824 };
19− in {
25+
2026 # Using the eval-on-build version here as the plan is that
2127 # `builtins.currentSystem` will not be supported in flakes.
2228 # https://github.com/NixOS/rfcs/pull/49/files#diff-a5a138ca225433534de8d260f225fe31R429
2329 overlay = self.overlays.combined-eval-on-build;
24− overlays = import ./overlays { sourcesOverride = sources; };
30+ overlays = self.internal.overlaysOverrideable { sourcesOverride = self.sources; };
31+
2532 legacyPackages = let
2633 genAttrs = lst: f:
2734 builtins.listToAttrs (map (name: {
@@ -29,7 +36,7 @@
2936 value = f name;
3037 }) lst);
3138 in genAttrs [ "x86_64-linux" "x86_64-darwin" ] (system:
32− import sources.nixpkgs
33− (nixpkgsArgs // { localSystem = { inherit system; }; }));
39+ import self.internal.sources.nixpkgs
40+ (self.internal.nixpkgsArgs // { localSystem = { inherit system; }; }));
3441 };
3542}