aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/populate/lib
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/populate/lib')
-rw-r--r--pkgs/populate/lib/default.nix12
-rw-r--r--pkgs/populate/lib/types/populate.nix16
2 files changed, 23 insertions, 5 deletions
diff --git a/pkgs/populate/lib/default.nix b/pkgs/populate/lib/default.nix
index e9155c5..4ccc609 100644
--- a/pkgs/populate/lib/default.nix
+++ b/pkgs/populate/lib/default.nix
@@ -20,7 +20,8 @@ in rec {
# The sources, a list of attribute sets of sources by name, or one, with
# shorthands expanded and defaults filled in, and without settings that
- # are null, as populate reads them, e.g. with builtins.toJSON.
+ # are null, as populate reads them, e.g. with builtins.toJSON. Sources
+ # whose type is set to null are left out.
evalSource = let
eval = source: lib.evalModules {
modules = lib.singleton {
@@ -42,7 +43,14 @@ in rec {
string = x;
};
in
- source: sanitize (eval source).config.source;
+ source: sanitize
+ (lib.filterAttrs (_: source: source.type != null)
+ (eval source).config.source);
+
+ # The settings of a source type if cond holds, else null, which leaves
+ # the source out unless another type is set, e.g.
+ # nixpkgs.file = optionalSource local { path = ...; };
+ optionalSource = cond: settings: if cond then settings else null;
# Inputs a source draws from other sources, as list of attribute sets like
# { path = [ "stockholm" "nixpkgs" ]; source = "nixpkgs"; }.
diff --git a/pkgs/populate/lib/types/populate.nix b/pkgs/populate/lib/types/populate.nix
index e5de33f..6605f61 100644
--- a/pkgs/populate/lib/types/populate.nix
+++ b/pkgs/populate/lib/types/populate.nix
@@ -1,19 +1,29 @@
{ lib }: rec {
- source = lib.types.submodule ({ config, name, ... }: {
+ # A source, of the one type that isn't null. A source whose types are
+ # all null, at least one of them set to null rather than left unset, has
+ # the type null: evalSource leaves it out.
+ source = lib.types.submodule ({ config, name, options, ... }: {
options = {
type = let
known-types = lib.attrNames source-types;
type-candidates = lib.filter (k: config.${k} != null) known-types;
+ # Set to null, e.g. by optionalSource, rather than left unset, which
+ # leaves them at their default's priority.
+ nulled = lib.filter
+ (k: options.${k}.highestPrio < (lib.mkOptionDefault null).priority)
+ known-types;
in lib.mkOption {
default =
if lib.length type-candidates == 1 then
lib.head type-candidates
else if type-candidates != [] then
throw "populate: source ${name} has more than one type: ${lib.concatStringsSep ", " type-candidates}"
+ else if nulled != [] then
+ null
else
- throw "populate: source ${name} has no type; set one of ${lib.concatStringsSep ", " known-types}";
- type = lib.types.enum known-types;
+ throw "populate: source ${name} has no type; set one of ${lib.concatStringsSep ", " known-types}, or set one to null to leave the source out";
+ type = lib.types.nullOr (lib.types.enum known-types);
};
derivation = lib.mkOption {
apply = x: