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";
languageCode = "en-us";
params = {
release_current_stable = "infra-DGNum";
release_current_stable = "DGNum-Infrastructure";
logo = "images/dgnum.png";
footer_credits_line = ''
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)
attrNames
concatMapStringsSep
concatStringsSep
escapeXML
filter
getExe
hasPrefix
@ -20,6 +22,7 @@ let
importJSON
mapAttrs'
mapAttrsToList
mkDefault
mkEnableOption
mkIf
mkOption
@ -100,13 +103,13 @@ let
type
readOnly
loc
description
;
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 "";
default = val.default.text or "";
description = escapeXML val.description;
example = escapeXML (val.example.text or "");
default = escapeXML (val.default.text or "");
declarations = map path-translation val.declarations;
}) filtered-opts;
};
@ -238,13 +241,14 @@ in
};
config = mkIf cfg.enable {
services = {
extranix = {
settings = {
theme = "extranix-options-search";
params.releases = mapAttrsToList (name: _: {
extranix.settings = {
theme = "extranix-options-search";
params = {
releases = mapAttrsToList (name: _: {
inherit name;
value = sanitizeDerivationName name;
}) cfg.modules;
release_current_stable = mkDefault (head (attrNames options-files));
};
};
nginx = {
@ -252,5 +256,21 @@ in
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)}
'';
}
];
};
}