forked from Fediversity/fediversity.eu
move custom type into custom lib
This commit is contained in:
parent
c9abe13377
commit
ea0319c60e
|
@ -8,7 +8,11 @@
|
|||
, lib ? import "${sources.nixpkgs}/lib"
|
||||
}:
|
||||
let
|
||||
lib' = final: prev: import ./lib.nix { lib = final; };
|
||||
lib' = final: prev:
|
||||
let
|
||||
new = import ./lib.nix { lib = final; };
|
||||
in
|
||||
new // { types = prev.recursiveUpdate prev.types new.types; };
|
||||
lib'' = lib.extend lib';
|
||||
in
|
||||
{
|
||||
|
|
44
lib.nix
44
lib.nix
|
@ -37,4 +37,48 @@ rec {
|
|||
|
||||
indent = prefix: s:
|
||||
join "\n" (map (x: if x == "" then x else "${prefix}${x}") (splitLines s));
|
||||
|
||||
types = rec {
|
||||
collection = elemType:
|
||||
let
|
||||
unparenthesize = class: class == "noun";
|
||||
desc = type:
|
||||
types.optionDescriptionPhrase unparenthesize type;
|
||||
desc' = type:
|
||||
let
|
||||
typeDesc = lib.types.optionDescriptionPhrase unparenthesize type;
|
||||
in
|
||||
if type.descriptionClass == "noun"
|
||||
then
|
||||
typeDesc + "s"
|
||||
else
|
||||
"many instances of ${typeDesc}";
|
||||
in
|
||||
lib.types.mkOptionType {
|
||||
name = "collection";
|
||||
description = "separately specified ${desc elemType} for a collection of ${desc' elemType}";
|
||||
merge = loc: defs:
|
||||
map
|
||||
(def:
|
||||
let
|
||||
merged = lib.mergeDefinitions
|
||||
(loc ++ [ "[definition ${toString def.file}]" ])
|
||||
elemType
|
||||
[{ inherit (def) file; value = def.value; }];
|
||||
in
|
||||
if merged ? mergedValue then merged.mergedValue else merged.value
|
||||
)
|
||||
defs;
|
||||
check = elemType.check;
|
||||
getSubOptions = elemType.getSubOptions;
|
||||
getSubModules = elemType.getSubModules;
|
||||
substSubModules = m: collection (elemType.substSubModules m);
|
||||
functor = (lib.defaultFunctor "collection") // {
|
||||
type = collection;
|
||||
wrapped = elemType;
|
||||
payload = { };
|
||||
};
|
||||
nestedTypes.elemType = elemType;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ let
|
|||
types
|
||||
;
|
||||
cfg = config;
|
||||
types' = import ./types.nix { inherit lib; } // {
|
||||
types' = {
|
||||
article = { config, collectionName, ... }: {
|
||||
imports = [ types'.page ];
|
||||
options = {
|
||||
|
@ -115,7 +115,7 @@ in
|
|||
};
|
||||
entry = mkOption {
|
||||
description = "An entry in the collection";
|
||||
type = types'.collection (types.submodule ({
|
||||
type = types.collection (types.submodule ({
|
||||
_module.args.collection = config.entry;
|
||||
_module.args.collectionName = name;
|
||||
imports = [ config.type ];
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
{ lib, ... }:
|
||||
let
|
||||
inherit (lib) types;
|
||||
in
|
||||
rec {
|
||||
collection = elemType:
|
||||
let
|
||||
unparenthesize = class: class == "noun";
|
||||
desc = type:
|
||||
types.optionDescriptionPhrase unparenthesize type;
|
||||
desc' = type:
|
||||
let
|
||||
typeDesc = types.optionDescriptionPhrase unparenthesize type;
|
||||
in
|
||||
if type.descriptionClass == "noun"
|
||||
then
|
||||
typeDesc + "s"
|
||||
else
|
||||
"many instances of ${typeDesc}";
|
||||
in
|
||||
types.mkOptionType {
|
||||
name = "collection";
|
||||
description = "separately specified ${desc elemType} for a collection of ${desc' elemType}";
|
||||
merge = loc: defs:
|
||||
map
|
||||
(def:
|
||||
let
|
||||
merged = lib.mergeDefinitions
|
||||
(loc ++ [ "[definition ${toString def.file}]" ])
|
||||
elemType
|
||||
[{ inherit (def) file; value = def.value; }];
|
||||
in
|
||||
if merged ? mergedValue then merged.mergedValue else merged.value
|
||||
)
|
||||
defs;
|
||||
check = elemType.check;
|
||||
getSubOptions = elemType.getSubOptions;
|
||||
getSubModules = elemType.getSubModules;
|
||||
substSubModules = m: collection (elemType.substSubModules m);
|
||||
functor = (lib.defaultFunctor "collection") // {
|
||||
type = collection;
|
||||
wrapped = elemType;
|
||||
payload = { };
|
||||
};
|
||||
nestedTypes.elemType = elemType;
|
||||
};
|
||||
}
|
Reference in a new issue