fix(extranix): ensure default entry exists and escape html #204

Merged
thubrecht merged 1 commit from extranix-fix into main 2025-01-04 13:30:52 +01:00
2 changed files with 29 additions and 9 deletions

View file

@ -92,7 +92,7 @@ in
title = "DGNum module documentation"; title = "DGNum module documentation";
languageCode = "en-us"; languageCode = "en-us";
params = { params = {
release_current_stable = "infra-DGNum"; release_current_stable = "DGNum-Infrastructure";
logo = "images/dgnum.png"; logo = "images/dgnum.png";
footer_credits_line = '' footer_credits_line = ''
Based on <a href="https://github.com/mipmip/home-manager-option-search">Home Manager Option Search</a> Based on <a href="https://github.com/mipmip/home-manager-option-search">Home Manager Option Search</a>

View file

@ -12,6 +12,8 @@ let
inherit (lib) inherit (lib)
attrNames attrNames
concatMapStringsSep concatMapStringsSep
concatStringsSep
escapeXML
filter filter
getExe getExe
hasPrefix hasPrefix
@ -20,6 +22,7 @@ let
importJSON importJSON
mapAttrs' mapAttrs'
mapAttrsToList mapAttrsToList
mkDefault
mkEnableOption mkEnableOption
mkIf mkIf
mkOption mkOption
@ -100,13 +103,13 @@ let
type type
readOnly readOnly
loc loc
description
; ;
descriptionHTML = pkgs.runCommand "option-${title}.html" { } '' descriptionHTML = pkgs.runCommand "option-${title}.html" { } ''
${getExe pkgs.pandoc} -f markdown ${pkgs.writeText "option-${title}.md" val.description} > $out ${getExe pkgs.pandoc} -f markdown-raw_html ${pkgs.writeText "option-${title}.md" val.description} > $out
''; '';
example = val.example.text or ""; description = escapeXML val.description;
default = val.default.text or ""; example = escapeXML (val.example.text or "");
default = escapeXML (val.default.text or "");
declarations = map path-translation val.declarations; declarations = map path-translation val.declarations;
}) filtered-opts; }) filtered-opts;
}; };
@ -238,13 +241,14 @@ in
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
services = { services = {
extranix = { extranix.settings = {
settings = { theme = "extranix-options-search";
theme = "extranix-options-search"; params = {
params.releases = mapAttrsToList (name: _: { releases = mapAttrsToList (name: _: {
inherit name; inherit name;
value = sanitizeDerivationName name; value = sanitizeDerivationName name;
}) cfg.modules; }) cfg.modules;
release_current_stable = mkDefault (head (attrNames options-files));
}; };
}; };
nginx = { nginx = {
@ -252,5 +256,21 @@ in
virtualHosts.${cfg.host}.locations."/".alias = "${webroot}/"; virtualHosts.${cfg.host}.locations."/".alias = "${webroot}/";
}; };
}; };
assertions = [
{
assertion = cfg.modules != { };
message = ''
`services.extranix` can't be enabled without any modules to document.
'';
}
{
assertion = options-files ? ${cfg.settings.params.release_current_stable};
message = ''
`services.extranix.settings.params.release_current_stable` should be the
`sanitizeDerivationName` of a key of `services.extranix.modules`, here one of:
+ ${concatStringsSep "\n + " (attrNames options-files)}
'';
}
];
}; };
} }