Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft for overlays using flake.nix outputs.flakeModule #222155

Closed
wants to merge 9 commits into from
2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,7 @@
nixosModules = {
notDetected = ./nixos/modules/installer/scan/not-detected.nix;
};

flakeModules.default = ./pkgs/top-level/flakeModule.nix;
};
}
86 changes: 86 additions & 0 deletions pkgs/top-level/flakeModule.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{ lib, config, ... }:
let
inherit (lib) mkOption types;

nixpkgsOverlayType = types.mkOptionType {
name = "nixpkgsOverlay";
description = "A nixpkgs overlay function";
descriptionClass = "noun";
check = lib.isFunction;
merge = _loc: defs:
let
logWarning =
# TODO: do not warn when lib.mkOrder/mkBefore/mkAfter are used unambiguously
if builtins.length defs > 1
then builtins.trace "WARNING[nixpkgs.flakeModule]: Multiple overlays are applied in arbitrary order." null
else null;
overlays =
map (x: x.value)
# TODO: lib.warnIf to replace the seq + if
(builtins.seq
logWarning
defs);
in
lib.composeManyExtensions overlays;
};

mkPkgsFromArgsType = types.mkOptionType {
name = "mkPkgsFromArgs";
description = "A function that returns `pkgs` from a set of arguments";
descriptionClass = "noun";
check = lib.isFunction;
};

pkgsType = types.mkOptionType {
name = "nixpkgs";
description = "An evaluation of Nixpkgs; the top level attribute set of packages";
check = builtins.isAttrs;
};

nixpkgsSubmodule = with types; submodule {
options = {
overlays = mkOption {
type = listOf nixpkgsOverlayType;
description = "Nixpkgs overlays";
default = [ ];
};

mkPkgsFromArgs = mkOption {
type = mkPkgsFromArgsType;
description = "Returns `pkgs` from `system";
internal = true;
default = args:
import ./. ({
localSystem = { system = builtins.currentSystem; };
} // args);
};

allPkgsPerSystem = mkOption {
type = types.lazyAttrsOf types.unspecified;
description = "Attribute set of `pkgs` named by `system`";
internal = true;
default =
let
mkPkgsFromSystem = system: config.nixpkgs.mkPkgsFromArgs { inherit system; };
in
lib.genAttrs lib.systems.flakeExposed config.nixpkgs.mkPkgsFromSystem;
};

# TODO: develop or eliminate
pkgs = mkOption {
internal = true;
type = pkgsType;
};
};
};

in
{
options = {
nixpkgs = lib.mkOption {
type = nixpkgsSubmodule;
description = "Configuration of nixpkgs";
default = { };
};
};
}