feat: add files module, text helper, and update readme generation
This commit is contained in:
parent
a19ede01a2
commit
295f5daba9
7 changed files with 79 additions and 25 deletions
|
@ -1 +1,4 @@
|
||||||
test README
|
This flake uses the [files flake-parts module](https://flake.parts/options/files.html) to generate documentation.
|
||||||
|
The list of generated files are:
|
||||||
|
|
||||||
|
The option `text.<name> supports either a string or a submodule with attributes order and parts. The parts attribute can either be a string, which will get concatenated in the order laid out in `text.<name>.order`, or can itself have the attributes order and parts, in which case it will be evaluated recursively.
|
|
@ -1,21 +1,20 @@
|
||||||
{ config, ... }:
|
{ config, lib, ... }:
|
||||||
|
let
|
||||||
|
inherit (lib) singleton;
|
||||||
|
in
|
||||||
{
|
{
|
||||||
# text.readme = {
|
text.readme.order = [
|
||||||
#
|
"generated-files"
|
||||||
# };
|
"helpers"
|
||||||
|
];
|
||||||
|
text.readme.parts.helpers.order = [ "text-helper" ];
|
||||||
|
|
||||||
perSystem =
|
perSystem =
|
||||||
{ pkgs, ... }:
|
{ pkgs, ... }:
|
||||||
{
|
{
|
||||||
files.files = [
|
files.files = singleton {
|
||||||
{
|
path_ = "README.md";
|
||||||
path_ = "README.md";
|
drv = pkgs.writeText "README.md" config.text.readme;
|
||||||
drv =
|
};
|
||||||
pkgs.writeText "README.md" # config.text.readme
|
|
||||||
''
|
|
||||||
test README
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
11
modules/flake-parts/files.nix
Normal file
11
modules/flake-parts/files.nix
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
{ inputs, ... }:
|
||||||
|
{
|
||||||
|
imports = [ inputs.files.flakeModules.default ];
|
||||||
|
perSystem = psArgs: {
|
||||||
|
make-shells.default.packages = [ psArgs.config.files.writer.drv ];
|
||||||
|
};
|
||||||
|
text.readme.parts.generated-files = ''
|
||||||
|
This flake uses the [files flake-parts module](https://flake.parts/options/files.html) to generate documentation.
|
||||||
|
The list of generated files are:
|
||||||
|
'';
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
{ inputs, ... }:
|
{ inputs, ... }:
|
||||||
{
|
{
|
||||||
|
#TODO: add to readme
|
||||||
imports = [ inputs.make-shell.flakeModules.default ];
|
imports = [ inputs.make-shell.flakeModules.default ];
|
||||||
}
|
}
|
49
modules/helpers/text.nix
Normal file
49
modules/helpers/text.nix
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
{ lib, ... }:
|
||||||
|
let
|
||||||
|
inherit (lib)
|
||||||
|
mkOption
|
||||||
|
mapAttrs
|
||||||
|
isString
|
||||||
|
pipe
|
||||||
|
flip
|
||||||
|
getAttr
|
||||||
|
concatStringsSep
|
||||||
|
;
|
||||||
|
inherit (lib.types)
|
||||||
|
lazyAttrsOf
|
||||||
|
oneOf
|
||||||
|
submodule
|
||||||
|
str
|
||||||
|
listOf
|
||||||
|
;
|
||||||
|
textType = oneOf [
|
||||||
|
str
|
||||||
|
(submodule {
|
||||||
|
options = {
|
||||||
|
order = mkOption { type = listOf str; };
|
||||||
|
parts = mkOption { type = lazyAttrsOf textType; };
|
||||||
|
};
|
||||||
|
})
|
||||||
|
];
|
||||||
|
recurseAttrs =
|
||||||
|
value:
|
||||||
|
if isString value then
|
||||||
|
value
|
||||||
|
else
|
||||||
|
# TODO: handle order being empty
|
||||||
|
# TODO: add headings for each part with possible option to disable
|
||||||
|
pipe value.order [
|
||||||
|
(map (flip getAttr value.parts))
|
||||||
|
(map recurseAttrs)
|
||||||
|
(concatStringsSep "\n")
|
||||||
|
];
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.text = mkOption {
|
||||||
|
default = { };
|
||||||
|
type = lazyAttrsOf textType;
|
||||||
|
apply = mapAttrs (_: recurseAttrs);
|
||||||
|
};
|
||||||
|
config.text.readme.parts.helpers.parts.text-helper =
|
||||||
|
"The option `text.<name> supports either a string or a submodule with attributes order and parts. The parts attribute can either be a string, which will get concatenated in the order laid out in `text.<name>.order`, or can itself have the attributes order and parts, in which case it will be evaluated recursively.";
|
||||||
|
}
|
|
@ -1,7 +0,0 @@
|
||||||
{ inputs, ... }:
|
|
||||||
{
|
|
||||||
imports = [ inputs.files.flakeModules.default ];
|
|
||||||
perSystem = psArgs: {
|
|
||||||
make-shells.default.packages = [ psArgs.config.files.writer.drv ];
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,5 +1,3 @@
|
||||||
{
|
{
|
||||||
systems = [
|
systems = [ "x86_64-linux" ];
|
||||||
"x86_64-linux"
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue