2022-01-13 18:21:32 +01:00
|
|
|
{ lib, gvariant ? import ./gvariant.nix { inherit lib; } }:
|
2018-12-29 21:21:11 +01:00
|
|
|
|
2020-01-14 23:41:59 +01:00
|
|
|
let
|
2021-10-27 13:58:56 +02:00
|
|
|
inherit (lib)
|
|
|
|
all concatMap foldl' getFiles getValues head isFunction literalExpression
|
|
|
|
mergeAttrs mergeDefaultOption mergeOneOption mergeOptions mkOption
|
|
|
|
mkOptionType showFiles showOption types;
|
2020-01-14 23:41:59 +01:00
|
|
|
|
2022-01-13 18:21:32 +01:00
|
|
|
typesDag = import ./types-dag.nix { inherit lib; };
|
2020-01-14 23:41:59 +01:00
|
|
|
|
2020-03-09 23:25:23 +01:00
|
|
|
# Needed since the type is called gvariant and its merge attribute
|
|
|
|
# must refer back to the type.
|
|
|
|
gvar = gvariant;
|
|
|
|
|
2020-04-06 12:51:11 +02:00
|
|
|
in rec {
|
2018-12-29 21:21:11 +01:00
|
|
|
|
2023-06-04 09:49:30 +02:00
|
|
|
inherit (typesDag) dagOf;
|
2020-01-14 23:41:59 +01:00
|
|
|
|
2018-12-29 21:21:11 +01:00
|
|
|
selectorFunction = mkOptionType {
|
|
|
|
name = "selectorFunction";
|
2020-04-06 12:51:11 +02:00
|
|
|
description = "Function that takes an attribute set and returns a list"
|
2018-12-29 21:21:11 +01:00
|
|
|
+ " containing a selection of the values of the input set";
|
|
|
|
check = isFunction;
|
2020-04-06 12:51:11 +02:00
|
|
|
merge = _loc: defs: as: concatMap (select: select as) (getValues defs);
|
2018-12-29 21:21:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
overlayFunction = mkOptionType {
|
|
|
|
name = "overlayFunction";
|
2020-04-06 12:51:11 +02:00
|
|
|
description = "An overlay function, takes self and super and returns"
|
2018-12-29 21:21:11 +01:00
|
|
|
+ " an attribute set overriding the desired attributes.";
|
|
|
|
check = isFunction;
|
2020-04-06 12:51:11 +02:00
|
|
|
merge = _loc: defs: self: super:
|
|
|
|
foldl' (res: def: mergeAttrs res (def.value self super)) { } defs;
|
2018-12-29 21:21:11 +01:00
|
|
|
};
|
|
|
|
|
2020-02-23 11:11:12 +01:00
|
|
|
fontType = types.submodule {
|
|
|
|
options = {
|
|
|
|
package = mkOption {
|
|
|
|
type = types.nullOr types.package;
|
|
|
|
default = null;
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression "pkgs.dejavu_fonts";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2020-02-23 11:11:12 +01:00
|
|
|
Package providing the font. This package will be installed
|
2023-07-01 01:30:13 +02:00
|
|
|
to your profile. If `null` then the font
|
2020-02-23 11:11:12 +01:00
|
|
|
is assumed to already be available in your profile.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
2021-04-07 16:18:09 +02:00
|
|
|
example = "DejaVu Sans";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-04-07 16:18:09 +02:00
|
|
|
The family name of the font within the package.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
size = mkOption {
|
2022-11-30 21:46:17 +01:00
|
|
|
type = types.nullOr types.number;
|
2021-04-07 16:18:09 +02:00
|
|
|
default = null;
|
|
|
|
example = "8";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-04-07 16:18:09 +02:00
|
|
|
The size of the font.
|
2020-02-23 11:11:12 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-03-09 23:25:23 +01:00
|
|
|
gvariant = mkOptionType rec {
|
|
|
|
name = "gvariant";
|
|
|
|
description = "GVariant value";
|
|
|
|
check = v: gvar.mkValue v != null;
|
|
|
|
merge = loc: defs:
|
|
|
|
let
|
2021-08-13 01:50:09 +02:00
|
|
|
vdefs = map (d:
|
|
|
|
d // {
|
|
|
|
value =
|
|
|
|
if gvar.isGVariant d.value then d.value else gvar.mkValue d.value;
|
|
|
|
}) defs;
|
2020-03-09 23:25:23 +01:00
|
|
|
vals = map (d: d.value) vdefs;
|
|
|
|
defTypes = map (x: x.type) vals;
|
|
|
|
sameOrNull = x: y: if x == y then y else null;
|
|
|
|
# A bit naive to just check the first entry…
|
|
|
|
sharedDefType = foldl' sameOrNull (head defTypes) defTypes;
|
|
|
|
allChecked = all (x: check x) vals;
|
2020-04-06 12:51:11 +02:00
|
|
|
in if sharedDefType == null then
|
|
|
|
throw ("Cannot merge definitions of `${showOption loc}' with"
|
|
|
|
+ " mismatched GVariant types given in"
|
|
|
|
+ " ${showFiles (getFiles defs)}.")
|
|
|
|
else if gvar.isArray sharedDefType && allChecked then
|
2021-08-13 01:50:09 +02:00
|
|
|
gvar.mkValue ((types.listOf gvariant).merge loc
|
|
|
|
(map (d: d // { value = d.value.value; }) vdefs)) // {
|
|
|
|
type = sharedDefType;
|
|
|
|
}
|
2020-04-06 12:51:11 +02:00
|
|
|
else if gvar.isTuple sharedDefType && allChecked then
|
|
|
|
mergeOneOption loc defs
|
2020-07-24 16:31:56 +02:00
|
|
|
else if gvar.isMaybe sharedDefType && allChecked then
|
|
|
|
mergeOneOption loc defs
|
2022-09-11 04:28:38 +02:00
|
|
|
else if gvar.isDictionaryEntry sharedDefType && allChecked then
|
|
|
|
mergeOneOption loc defs
|
|
|
|
else if gvar.type.variant == sharedDefType && allChecked then
|
|
|
|
mergeOneOption loc defs
|
2020-04-06 12:51:11 +02:00
|
|
|
else if gvar.type.string == sharedDefType && allChecked then
|
|
|
|
types.str.merge loc defs
|
|
|
|
else if gvar.type.double == sharedDefType && allChecked then
|
|
|
|
types.float.merge loc defs
|
|
|
|
else
|
|
|
|
mergeDefaultOption loc defs;
|
2020-03-09 23:25:23 +01:00
|
|
|
};
|
|
|
|
|
2018-12-29 21:21:11 +01:00
|
|
|
}
|