mirror of
https://github.com/nix-community/home-manager
synced 2024-11-05 02:39:45 +01:00
36a53d9f26
This process was automated by [my fork of `nix-doc-munge`]. All conversions were automatically checked to produce the same DocBook result when converted back, modulo minor typographical/formatting differences on the acceptable-to-desirable spectrum. To reproduce this commit, run: $ NIX_PATH=nixpkgs=flake:nixpkgs/e7e69199f0372364a6106a1e735f68604f4c5a25 \ nix shell nixpkgs#coreutils \ -c find . -name '*.nix' \ -exec nix run -- github:emilazy/nix-doc-munge/98dadf1f77351c2ba5dcb709a2a171d655f15099 \ {} + $ ./format [my fork of `nix-doc-munge`]: https://github.com/emilazy/nix-doc-munge/tree/home-manager
110 lines
3.6 KiB
Nix
110 lines
3.6 KiB
Nix
{ lib, gvariant ? import ./gvariant.nix { inherit lib; } }:
|
|
|
|
let
|
|
inherit (lib)
|
|
all concatMap foldl' getFiles getValues head isFunction literalExpression
|
|
mergeAttrs mergeDefaultOption mergeOneOption mergeOptions mkOption
|
|
mkOptionType showFiles showOption types;
|
|
|
|
typesDag = import ./types-dag.nix { inherit lib; };
|
|
|
|
# Needed since the type is called gvariant and its merge attribute
|
|
# must refer back to the type.
|
|
gvar = gvariant;
|
|
|
|
in rec {
|
|
|
|
inherit (typesDag) dagOf;
|
|
|
|
selectorFunction = mkOptionType {
|
|
name = "selectorFunction";
|
|
description = "Function that takes an attribute set and returns a list"
|
|
+ " containing a selection of the values of the input set";
|
|
check = isFunction;
|
|
merge = _loc: defs: as: concatMap (select: select as) (getValues defs);
|
|
};
|
|
|
|
overlayFunction = mkOptionType {
|
|
name = "overlayFunction";
|
|
description = "An overlay function, takes self and super and returns"
|
|
+ " an attribute set overriding the desired attributes.";
|
|
check = isFunction;
|
|
merge = _loc: defs: self: super:
|
|
foldl' (res: def: mergeAttrs res (def.value self super)) { } defs;
|
|
};
|
|
|
|
fontType = types.submodule {
|
|
options = {
|
|
package = mkOption {
|
|
type = types.nullOr types.package;
|
|
default = null;
|
|
example = literalExpression "pkgs.dejavu_fonts";
|
|
description = lib.mdDoc ''
|
|
Package providing the font. This package will be installed
|
|
to your profile. If `null` then the font
|
|
is assumed to already be available in your profile.
|
|
'';
|
|
};
|
|
|
|
name = mkOption {
|
|
type = types.str;
|
|
example = "DejaVu Sans";
|
|
description = lib.mdDoc ''
|
|
The family name of the font within the package.
|
|
'';
|
|
};
|
|
|
|
size = mkOption {
|
|
type = types.nullOr types.number;
|
|
default = null;
|
|
example = "8";
|
|
description = lib.mdDoc ''
|
|
The size of the font.
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
|
|
gvariant = mkOptionType rec {
|
|
name = "gvariant";
|
|
description = "GVariant value";
|
|
check = v: gvar.mkValue v != null;
|
|
merge = loc: defs:
|
|
let
|
|
vdefs = map (d:
|
|
d // {
|
|
value =
|
|
if gvar.isGVariant d.value then d.value else gvar.mkValue d.value;
|
|
}) defs;
|
|
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;
|
|
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
|
|
gvar.mkValue ((types.listOf gvariant).merge loc
|
|
(map (d: d // { value = d.value.value; }) vdefs)) // {
|
|
type = sharedDefType;
|
|
}
|
|
else if gvar.isTuple sharedDefType && allChecked then
|
|
mergeOneOption loc defs
|
|
else if gvar.isMaybe sharedDefType && allChecked then
|
|
mergeOneOption loc defs
|
|
else if gvar.isDictionaryEntry sharedDefType && allChecked then
|
|
mergeOneOption loc defs
|
|
else if gvar.type.variant == sharedDefType && allChecked then
|
|
mergeOneOption loc defs
|
|
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;
|
|
};
|
|
|
|
}
|