1
0
Fork 0
mirror of https://github.com/hercules-ci/flake-parts.git synced 2024-12-14 11:47:31 +00:00
flake-parts/extras/easyOverlay.nix

66 lines
2.1 KiB
Nix
Raw Normal View History

2023-05-29 17:52:03 +00:00
toplevel@{ lib, flake-parts-lib, getSystemIgnoreWarning, ... }:
2022-12-01 16:40:48 +00:00
let
inherit (flake-parts-lib)
mkPerSystemOption;
inherit (lib)
mkOption
types;
in
{
options = {
perSystem = mkPerSystemOption ({ config, extendModules, pkgs, ... }: {
_file = ./easyOverlay.nix;
options = {
extendModules = mkOption {
type = types.raw;
default = extendModules;
internal = true;
};
overlayAttrs = mkOption {
type = types.lazyAttrsOf types.raw;
default = { };
description = ''
Attributes to add to `overlays.default`.
The `overlays.default` overlay will re-evaluate `perSystem` with
the "prev" (or "super") overlay argument value as the `pkgs` module
argument. The `easyOverlay` module also adds the `final` module
argument, for the result of applying the overlay.
When not in an overlay, `final` defaults to `pkgs` plus the generated
overlay. This requires Nixpkgs to be re-evaluated, which is more
expensive than setting `pkgs` to a Nixpkgs that already includes
the necessary overlays that are required for the flake itself.
See [Overlays](../overlays.html).
'';
};
};
config = {
2023-05-29 17:52:03 +00:00
_module.args.final = lib.mkDefault (pkgs.extend toplevel.config.flake.overlays.default);
2022-12-01 16:40:48 +00:00
};
});
};
config = {
flake.overlays.default = final: prev:
let
system =
prev.stdenv.hostPlatform.system or (
prev.system or (
throw "Could not determine the `hostPlatform` of Nixpkgs. Was this overlay loaded as a Nixpkgs overlay, or was it loaded into something else?"
)
);
perSys = (getSystemIgnoreWarning system).extendModules {
2022-12-01 16:40:48 +00:00
modules = [
{
_file = "flake-parts#flakeModules.easyOverlay/overlay-overrides";
_module.args.pkgs = lib.mkForce prev;
_module.args.final = lib.mkForce final;
}
];
};
in
perSys.config.overlayAttrs;
};
}