diff --git a/machines/kat-son/configuration.nix b/machines/kat-son/configuration.nix index ddaba31..d472767 100644 --- a/machines/kat-son/configuration.nix +++ b/machines/kat-son/configuration.nix @@ -1,5 +1,6 @@ { lib, + pkgs, ... }: { @@ -11,6 +12,7 @@ imports = [ ./hardware-configuration.nix ./disks.nix + ./doc ]; boot = { @@ -74,6 +76,45 @@ }; }; }; + extranix = { + enable = true; + modules."netconf" = let + netconf = pkgs.fetchgit { + url = "https://git.dgnum.eu/DGNum/Netconf-Module.git"; + rev = "8f58ee21fe9c0ad22e3f16e58c3837c1c97eb5e8"; + outputHash = "sha256-OXKSFEOjeeRFVbVodJSkhuT+r7+p6QPUzjbw2vs6Xao="; + name = "netconf"; + }; + in { + paths = [ "${netconf.outPath}/junos" "${netconf.outPath}/dgn-module.nix" ]; + base = netconf.outPath; + url = "https://git.dgnum.eu/DGNum/Netconf-Module/src/branch/master/"; + }; + static-data = ./static-data; + host = "son.katvayor.net"; + settings = { + baseUrl = "https://dgnum.eu/"; + title = "DGNum netconf module documentation"; + languageCode = "en-us"; + params = { + release_current_stable = "netconf"; + logo = "images/dgnum.png"; + footer_credits_line = '' + Powered by catvayor | + Based on Home Manager Option Search + ''; + footer_copyright_line = '' + Made by catvayor for the DGNum. + ''; + main_menu = [ + { + name = '' Source''; + url = "https://git.dgnum.eu/DGNum/Netconf-Module/"; + } + ]; + }; + }; + }; }; system.stateVersion = "23.11"; diff --git a/machines/kat-son/doc/0001-fix-pretty-no-defaults.patch b/machines/kat-son/doc/0001-fix-pretty-no-defaults.patch new file mode 100644 index 0000000..605fadb --- /dev/null +++ b/machines/kat-son/doc/0001-fix-pretty-no-defaults.patch @@ -0,0 +1,25 @@ +From f050ca4374c8c4d9d4fa85e46a1dedaaaedec791 Mon Sep 17 00:00:00 2001 +From: catvayor +Date: Wed, 11 Dec 2024 15:34:42 +0100 +Subject: [PATCH] fix: pretty no defaults + +--- + static/js/script.js | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/static/js/script.js b/static/js/script.js +index 56b633b..04234d7 100644 +--- a/static/js/script.js ++++ b/static/js/script.js +@@ -293,7 +293,7 @@ var expandOption = function(el){ + var elDesc = "
Description
" + parseDescription(currentSet[el].description) + "
"; + var elType = "
Type
" + currentSet[el].type + "
"; + //var elNote = ( currentSet[el].note == "" ? "": "
Note
" + currentSet[el].note + "
"); +- var elDefault = "
Default
" + currentSet[el].default + "
"; ++ var elDefault = ( currentSet[el].default == "" ? "" : "
Default
" + currentSet[el].default + "
"); + var elExample = ( currentSet[el].example == "" ? "" : "
Example
" + currentSet[el].example + "
"); + + //var declared_by_str = currentSet[el].declarations[0].name; +-- +2.47.0 + diff --git a/machines/kat-son/doc/default.nix b/machines/kat-son/doc/default.nix new file mode 100644 index 0000000..c510d80 --- /dev/null +++ b/machines/kat-son/doc/default.nix @@ -0,0 +1,125 @@ +{ + lib, + config, + pkgs, + ... +}: +let + inherit (lib) + mkOption + mkEnableOption + mkIf + types + importJSON + filterAttrs + mapAttrs' + mapAttrsToList + removePrefix + pathIsDirectory + hasSuffix + ; + inherit (lib.strings) + sanitizeDerivationName + ; + yaml = pkgs.formats.yaml { }; + json = pkgs.formats.json { }; + cfg = config.services.extranix; + + module-eval = + module: + let + eval = lib.evalModules { modules = module.paths; }; + opts-doc = pkgs.nixosOptionsDoc { inherit (eval) options; }; + val = importJSON "${opts-doc.optionsJSON}/share/doc/nixos/options.json"; + filtered-opts = filterAttrs (name: _: name != "_module.args") val; + result = json.generate "options-extranix.json" { + last_update = "-/-"; + options = mapAttrsToList (title: val: { + inherit title; + inherit (val) + type + readOnly + description + loc + ; + example = val.example.text or ""; + default = val.default.text or ""; + declarations = map ( + decl: + let + baseString1 = toString module.base; + baseString = baseString1 + (if hasSuffix "/" baseString1 then "" else "/"); + innerPath1 = if pathIsDirectory decl then decl + "/default.nix" else decl; + innerPath = removePrefix baseString innerPath1; + in + { + name = "<${innerPath}>"; + url = "${module.url}${if hasSuffix "/" module.url then "" else "/"}${innerPath}"; + } + ) val.declarations; + }) filtered-opts; + }; + in + result; + + options-files = mapAttrs' (name: value: { + name = sanitizeDerivationName name; + value = module-eval value; + }) cfg.modules; + + webroot = pkgs.callPackage ./webroot.nix { + inherit options-files; + inherit (cfg) static-data; + settings = yaml.generate "config.yaml" cfg.settings; + hugo-theme-extranix-options-search = pkgs.callPackage ./hugo-theme-extranix-options-search.nix { }; + }; +in +{ + options.services.extranix = { + enable = mkEnableOption "extranix documentation"; + modules = mkOption { + type = + let + module-mod.options = { + paths = mkOption { + type = types.listOf types.path; + }; + base = mkOption { + type = types.path; + }; + url = mkOption { + type = types.str; + }; + }; + in + types.attrsOf (types.submodule module-mod); + }; + settings = mkOption { + type = yaml.type; + }; + static-data = mkOption { + type = types.path; + }; + host = mkOption { + type = types.str; + }; + }; + config = mkIf cfg.enable { + services = { + extranix = { + settings = { + markup.goldmark.renderer.unsafe = true; + theme = "extranix-options-search"; + params.releases = mapAttrsToList (name: _: { + inherit name; + value = sanitizeDerivationName name; + }) cfg.modules; + }; + }; + nginx = { + enable = true; + virtualHosts.${cfg.host}.locations."/".alias = "${webroot}/"; + }; + }; + }; +} diff --git a/machines/kat-son/doc/hugo-theme-extranix-options-search.nix b/machines/kat-son/doc/hugo-theme-extranix-options-search.nix new file mode 100644 index 0000000..cfcbba6 --- /dev/null +++ b/machines/kat-son/doc/hugo-theme-extranix-options-search.nix @@ -0,0 +1,31 @@ +{ + fetchFromGitHub, + stdenv, + lib, +}: +stdenv.mkDerivation { + name = "hugo-theme-extranix-options-search"; + + src = fetchFromGitHub { + owner = "mipmip"; + repo = "hugo-theme-extranix-options-search"; + rev = "1b5cdc63b3127ab81aed2736b0dea7ed09b7ec72"; + hash = "sha256-oowopWC9JdZIex548S0W91MIPSDCaJ3isuNLfesjT9U="; + }; + + patches = [ + ./0001-fix-pretty-no-defaults.patch + ]; + + installPhase = '' + mkdir $out + cp -r * $out + ''; + + meta = { + description = "Theme which implements a nix modules options search machine."; + homepage = "https://github.com/mipmip/hugo-theme-extranix-options-search"; + license = lib.licenses.asl20; + maintainers = [ ]; + }; +} diff --git a/machines/kat-son/doc/webroot.nix b/machines/kat-son/doc/webroot.nix new file mode 100644 index 0000000..a930983 --- /dev/null +++ b/machines/kat-son/doc/webroot.nix @@ -0,0 +1,22 @@ +{ + hugo, + hugo-theme-extranix-options-search, + options-files, + settings, + static-data, + lib, + runCommand, +}: +runCommand "nix-doc-webroot" { } +'' + mkdir themes + ln -s ${hugo-theme-extranix-options-search} themes/extranix-options-search + cp -rs ${static-data} static + chmod -R u+w static + mkdir static/data + ${lib.concatStringsSep "\n" ( + lib.mapAttrsToList (name: file: "ln -s ${file} static/data/options-${name}.json") options-files + )} + ln -s ${settings} config.yaml + ${lib.getExe hugo} --noBuildLock -d $out +'' diff --git a/machines/kat-son/static-data/images/dgnum.png b/machines/kat-son/static-data/images/dgnum.png new file mode 100644 index 0000000..e2a56a6 Binary files /dev/null and b/machines/kat-son/static-data/images/dgnum.png differ diff --git a/machines/kat-son/static-data/images/forgejo.png b/machines/kat-son/static-data/images/forgejo.png new file mode 100644 index 0000000..2cb009c Binary files /dev/null and b/machines/kat-son/static-data/images/forgejo.png differ