feat(son): experimental auto-extranix
This commit is contained in:
parent
9b3c851d4a
commit
b56afb2ca7
7 changed files with 244 additions and 0 deletions
|
@ -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 <a href="https://github.com/mipmip/home-manager-option-search">Home Manager Option Search</a>
|
||||
'';
|
||||
footer_copyright_line = ''
|
||||
Made by catvayor for the <a href="https://dgnum.eu">DGNum</a>.
|
||||
'';
|
||||
main_menu = [
|
||||
{
|
||||
name = ''<img src="images/forgejo.png" style="display:inline-block; height:2.5em; transform:translate(0, -0.7em)" /> Source'';
|
||||
url = "https://git.dgnum.eu/DGNum/Netconf-Module/";
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
system.stateVersion = "23.11";
|
||||
|
|
25
machines/kat-son/doc/0001-fix-pretty-no-defaults.patch
Normal file
25
machines/kat-son/doc/0001-fix-pretty-no-defaults.patch
Normal file
|
@ -0,0 +1,25 @@
|
|||
From f050ca4374c8c4d9d4fa85e46a1dedaaaedec791 Mon Sep 17 00:00:00 2001
|
||||
From: catvayor <catvayor@katvayor.net>
|
||||
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 = "<h5 style='margin:1em 0 0 0'>Description</h5><div>" + parseDescription(currentSet[el].description) + "</div>";
|
||||
var elType = "<h5 style='margin:1em 0 0 0'>Type</h5><div>" + currentSet[el].type + "</div>";
|
||||
//var elNote = ( currentSet[el].note == "" ? "": "<h5 style='margin:1em 0 0 0'>Note</h5><div>" + currentSet[el].note + "</div>");
|
||||
- var elDefault = "<h5 style='margin:1em 0 0 0'>Default</h5><div><pre style='margin-top:0.5em'>" + currentSet[el].default + "</pre></div>";
|
||||
+ var elDefault = ( currentSet[el].default == "" ? "" : "<h5 style='margin:1em 0 0 0'>Default</h5><div><pre style='margin-top:0.5em'>" + currentSet[el].default + "</pre></div>");
|
||||
var elExample = ( currentSet[el].example == "" ? "" : "<h5 style='margin:1em 0 0 0'>Example</h5><div><pre style='margin-top:0.5em'>" + currentSet[el].example + "</pre></div>");
|
||||
|
||||
//var declared_by_str = currentSet[el].declarations[0].name;
|
||||
--
|
||||
2.47.0
|
||||
|
125
machines/kat-son/doc/default.nix
Normal file
125
machines/kat-son/doc/default.nix
Normal file
|
@ -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}/";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
31
machines/kat-son/doc/hugo-theme-extranix-options-search.nix
Normal file
31
machines/kat-son/doc/hugo-theme-extranix-options-search.nix
Normal file
|
@ -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 = [ ];
|
||||
};
|
||||
}
|
22
machines/kat-son/doc/webroot.nix
Normal file
22
machines/kat-son/doc/webroot.nix
Normal file
|
@ -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
|
||||
''
|
BIN
machines/kat-son/static-data/images/dgnum.png
Normal file
BIN
machines/kat-son/static-data/images/dgnum.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
BIN
machines/kat-son/static-data/images/forgejo.png
Normal file
BIN
machines/kat-son/static-data/images/forgejo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.8 KiB |
Loading…
Reference in a new issue