feat: init repo
This commit is contained in:
commit
a9556bd812
2 changed files with 83 additions and 0 deletions
3
flake.nix
Normal file
3
flake.nix
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
outputs = inputs: { flakeModules.default = ./module.nix; };
|
||||||
|
}
|
80
module.nix
Normal file
80
module.nix
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
{ lib, ... }:
|
||||||
|
let
|
||||||
|
inherit (lib)
|
||||||
|
mapAttrsToList
|
||||||
|
optional
|
||||||
|
concatStrings
|
||||||
|
flatten
|
||||||
|
mkOption
|
||||||
|
mapAttrs
|
||||||
|
isString
|
||||||
|
replicate
|
||||||
|
flip
|
||||||
|
getAttr
|
||||||
|
concatStringsSep
|
||||||
|
;
|
||||||
|
inherit (lib.types)
|
||||||
|
lazyAttrsOf
|
||||||
|
oneOf
|
||||||
|
submodule
|
||||||
|
str
|
||||||
|
listOf
|
||||||
|
;
|
||||||
|
textType = oneOf [
|
||||||
|
str
|
||||||
|
(submodule {
|
||||||
|
options = {
|
||||||
|
heading = mkOption {
|
||||||
|
type = str;
|
||||||
|
default = "";
|
||||||
|
};
|
||||||
|
description = mkOption {
|
||||||
|
type = str;
|
||||||
|
default = "";
|
||||||
|
};
|
||||||
|
order = mkOption {
|
||||||
|
type = listOf str;
|
||||||
|
default = [ ];
|
||||||
|
};
|
||||||
|
parts = mkOption { type = lazyAttrsOf textType; };
|
||||||
|
};
|
||||||
|
})
|
||||||
|
];
|
||||||
|
mkListFromAttrs =
|
||||||
|
prefix:
|
||||||
|
{ name, value }:
|
||||||
|
let
|
||||||
|
sectionHeading = result: "${concatStrings (replicate prefix "#")} ${result}";
|
||||||
|
in
|
||||||
|
if isString value then
|
||||||
|
[
|
||||||
|
(sectionHeading name)
|
||||||
|
value
|
||||||
|
]
|
||||||
|
else
|
||||||
|
flatten [
|
||||||
|
[
|
||||||
|
(sectionHeading (if value.heading == "" then name else value.heading))
|
||||||
|
]
|
||||||
|
(optional (value.description != "") value.description)
|
||||||
|
(map (mkListFromAttrs (prefix + 1)) (
|
||||||
|
if value.order == [ ] then
|
||||||
|
mapAttrsToList (name: value: { inherit name value; }) value.parts
|
||||||
|
else
|
||||||
|
map (x: {
|
||||||
|
name = x;
|
||||||
|
value = flip getAttr value.parts x;
|
||||||
|
}) value.order
|
||||||
|
))
|
||||||
|
];
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.text = mkOption {
|
||||||
|
default = { };
|
||||||
|
type = lazyAttrsOf textType;
|
||||||
|
apply = mapAttrs (
|
||||||
|
name: value: concatStringsSep "\n" (flatten (mkListFromAttrs 1 { inherit name value; }))
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue