forked from DGNum/liminix
export evaluation from default.nix and use it for docs
This commit is contained in:
parent
23b3a2baef
commit
7d5c7b9b44
5 changed files with 104 additions and 69 deletions
27
ci.nix
27
ci.nix
|
@ -30,22 +30,31 @@ let
|
||||||
device = import (liminix + "/devices/qemu");
|
device = import (liminix + "/devices/qemu");
|
||||||
liminix-config = vanilla;
|
liminix-config = vanilla;
|
||||||
}).buildEnv;
|
}).buildEnv;
|
||||||
doc = pkgs.stdenv.mkDerivation {
|
doc =
|
||||||
|
let json =
|
||||||
|
(import liminix {
|
||||||
|
inherit nixpkgs borderVmConf;
|
||||||
|
device = import (liminix + "/devices/qemu");
|
||||||
|
liminix-config = {...} : {
|
||||||
|
imports = [ ./modules/all-modules.nix ];
|
||||||
|
};
|
||||||
|
}).outputs.optionsJson;
|
||||||
|
in pkgs.stdenv.mkDerivation {
|
||||||
name = "liminix-doc";
|
name = "liminix-doc";
|
||||||
nativeBuildInputs = with pkgs; [
|
nativeBuildInputs = with pkgs; [
|
||||||
gnumake sphinx
|
gnumake sphinx fennel luaPackages.lyaml
|
||||||
fennel luaPackages.lyaml
|
|
||||||
];
|
];
|
||||||
src = ./doc;
|
src = ./.;
|
||||||
buildPhase = ''
|
buildPhase = ''
|
||||||
cat ${(import ./doc/extract-options.nix).doc} > options.json
|
cat ${json} | fennel --correlate doc/parse-options.fnl > doc/modules-generated.rst
|
||||||
cat options.json | fennel --correlate parse-options.fnl > modules-generated.rst
|
cp ${(import ./doc/hardware.nix)} doc/hardware.rst
|
||||||
cp ${(import ./doc/hardware.nix)} hardware.rst
|
make -C doc html
|
||||||
make html
|
|
||||||
'';
|
'';
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
mkdir -p $out/nix-support $out/share/doc/
|
mkdir -p $out/nix-support $out/share/doc/
|
||||||
cp modules.rst options.json $out
|
cd doc
|
||||||
|
cp modules-generated.rst $out
|
||||||
|
ln -s ${json} $out/options.json
|
||||||
cp -a _build/html $out/share/doc/liminix
|
cp -a _build/html $out/share/doc/liminix
|
||||||
echo "file source-dist \"$out/share/doc/liminix\"" \
|
echo "file source-dist \"$out/share/doc/liminix\"" \
|
||||||
> $out/nix-support/hydra-build-products
|
> $out/nix-support/hydra-build-products
|
||||||
|
|
11
default.nix
11
default.nix
|
@ -17,7 +17,7 @@ let
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
config = (pkgs.lib.evalModules {
|
eval = pkgs.lib.evalModules {
|
||||||
modules = [
|
modules = [
|
||||||
{ _module.args = { inherit pkgs; inherit (pkgs) lim; }; }
|
{ _module.args = { inherit pkgs; inherit (pkgs) lim; }; }
|
||||||
./modules/hardware.nix
|
./modules/hardware.nix
|
||||||
|
@ -30,7 +30,8 @@ let
|
||||||
./modules/users.nix
|
./modules/users.nix
|
||||||
./modules/outputs.nix
|
./modules/outputs.nix
|
||||||
];
|
];
|
||||||
}).config;
|
};
|
||||||
|
config = eval.config;
|
||||||
|
|
||||||
borderVm = ((import <nixpkgs/nixos/lib/eval-config.nix>) {
|
borderVm = ((import <nixpkgs/nixos/lib/eval-config.nix>) {
|
||||||
system = builtins.currentSystem;
|
system = builtins.currentSystem;
|
||||||
|
@ -43,6 +44,12 @@ let
|
||||||
in {
|
in {
|
||||||
outputs = config.system.outputs // {
|
outputs = config.system.outputs // {
|
||||||
default = config.system.outputs.${config.hardware.defaultOutput};
|
default = config.system.outputs.${config.hardware.defaultOutput};
|
||||||
|
optionsJson =
|
||||||
|
let o = import ./doc/extract-options.nix {
|
||||||
|
inherit pkgs eval;
|
||||||
|
lib = pkgs.lib;
|
||||||
|
};
|
||||||
|
in pkgs.writeText "options.json" (builtins.toJSON o);
|
||||||
};
|
};
|
||||||
|
|
||||||
# this is just here as a convenience, so that we can get a
|
# this is just here as a convenience, so that we can get a
|
||||||
|
|
|
@ -1,31 +1,10 @@
|
||||||
|
{ eval, lib, pkgs }:
|
||||||
let
|
let
|
||||||
overlay = import ../overlay.nix;
|
|
||||||
pkgs = import <nixpkgs> ( {
|
|
||||||
overlays = [overlay];
|
|
||||||
config = {
|
|
||||||
allowUnsupportedSystem = true; # mipsel
|
|
||||||
permittedInsecurePackages = [
|
|
||||||
"python-2.7.18.6" # kernel backports needs python <3
|
|
||||||
];
|
|
||||||
};
|
|
||||||
});
|
|
||||||
inherit (pkgs) lib;
|
|
||||||
inherit (lib) types;
|
inherit (lib) types;
|
||||||
modulenames =
|
|
||||||
builtins.attrNames
|
|
||||||
(lib.filterAttrsRecursive
|
|
||||||
(n: t:
|
|
||||||
(n != "arch") &&
|
|
||||||
((t=="directory") ||
|
|
||||||
((t=="regular") && ((builtins.match ".*\\.nix$" n) != null))))
|
|
||||||
(builtins.readDir ../modules));
|
|
||||||
modulefiles = builtins.map (n: builtins.toPath "${../modules}/${n}") modulenames;
|
|
||||||
eval = (lib.evalModules {
|
|
||||||
modules = [
|
|
||||||
{ _module.args = { inherit pkgs; lib = pkgs.lib; }; }
|
|
||||||
] ++ modulefiles;
|
|
||||||
});
|
|
||||||
conf = eval.config;
|
conf = eval.config;
|
||||||
|
rootDir = builtins.toPath ./..;
|
||||||
|
stripAnyPrefixes = lib.flip (lib.fold lib.removePrefix)
|
||||||
|
["${rootDir}/"];
|
||||||
optToDoc = name: opt : {
|
optToDoc = name: opt : {
|
||||||
inherit name;
|
inherit name;
|
||||||
description = opt.description or null;
|
description = opt.description or null;
|
||||||
|
@ -42,16 +21,12 @@ let
|
||||||
then
|
then
|
||||||
let sd = lib.attrByPath item.loc ["not found"] conf;
|
let sd = lib.attrByPath item.loc ["not found"] conf;
|
||||||
in item // {
|
in item // {
|
||||||
|
declarations = map stripAnyPrefixes item.declarations;
|
||||||
parameters =
|
parameters =
|
||||||
let x = lib.mapAttrsToList optToDoc sd.parameters; in x;
|
let x = lib.mapAttrsToList optToDoc sd.parameters; in x;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
item;
|
item // { declarations = map stripAnyPrefixes item.declarations; };
|
||||||
o = builtins.map spliceServiceDefn
|
in
|
||||||
(pkgs.lib.optionAttrSetToDocList eval.options);
|
builtins.map spliceServiceDefn
|
||||||
in {
|
(pkgs.lib.optionAttrSetToDocList eval.options)
|
||||||
doc = pkgs.writeText "options.yaml" ''
|
|
||||||
# ${./..}
|
|
||||||
${builtins.toJSON o}
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,13 +2,17 @@
|
||||||
|
|
||||||
(local { : view } (require :fennel))
|
(local { : view } (require :fennel))
|
||||||
|
|
||||||
|
(fn basename [str ext]
|
||||||
|
(-> str
|
||||||
|
(string.gsub "(.*/)(.*)" "%2")
|
||||||
|
(string.gsub (.. ext "$") "")))
|
||||||
|
|
||||||
(fn headline [name]
|
(fn headline [name]
|
||||||
(let [(_ _ basename) (string.find name ".*/([^/].*).nix")
|
(let [title (assert (basename name ".nix"))
|
||||||
len (basename:len)]
|
len (title:len)]
|
||||||
(.. basename "\n" (string.rep "=" len))))
|
(.. title "\n" (string.rep "=" len))))
|
||||||
|
|
||||||
(fn read-preamble [pathname]
|
(fn read-preamble [pathname]
|
||||||
(if (= (pathname:sub 1 1) "/")
|
|
||||||
(let [pathname (if (string.match pathname ".nix$")
|
(let [pathname (if (string.match pathname ".nix$")
|
||||||
pathname
|
pathname
|
||||||
(.. pathname "/default.nix"))]
|
(.. pathname "/default.nix"))]
|
||||||
|
@ -16,7 +20,7 @@
|
||||||
(accumulate [lines nil
|
(accumulate [lines nil
|
||||||
l (f:lines)
|
l (f:lines)
|
||||||
:until (not (= (string.sub l 1 2) "##"))]
|
:until (not (= (string.sub l 1 2) "##"))]
|
||||||
(.. (or lines "") (string.gsub l "^## *" "") "\n"))))))
|
(.. (or lines "") (string.gsub l "^## *" "") "\n")))))
|
||||||
|
|
||||||
(fn relative-pathname [pathname]
|
(fn relative-pathname [pathname]
|
||||||
(let [pathname
|
(let [pathname
|
||||||
|
|
40
modules/all-modules.nix
Normal file
40
modules/all-modules.nix
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
# Import all of the modules, used in the documentation generator. Not
|
||||||
|
# currently expected to work in an actual configuration, but it would
|
||||||
|
# be nice if it did.
|
||||||
|
|
||||||
|
{
|
||||||
|
imports = [
|
||||||
|
./base.nix
|
||||||
|
./bridge
|
||||||
|
./busybox.nix
|
||||||
|
./dhcp6c
|
||||||
|
./dnsmasq
|
||||||
|
./ext4fs.nix
|
||||||
|
./firewall
|
||||||
|
./flashimage.nix
|
||||||
|
./hardware.nix
|
||||||
|
./hostapd
|
||||||
|
./hostname.nix
|
||||||
|
./initramfs.nix
|
||||||
|
./jffs2.nix
|
||||||
|
./kernel.nix
|
||||||
|
./kexecboot.nix
|
||||||
|
./mount
|
||||||
|
./network
|
||||||
|
./ntp
|
||||||
|
./outputs.nix
|
||||||
|
./outputs/vmroot.nix
|
||||||
|
./ppp
|
||||||
|
./ramdisk.nix
|
||||||
|
./squashfs.nix
|
||||||
|
./ssh
|
||||||
|
./standard.nix
|
||||||
|
./tftpboot.nix
|
||||||
|
./ubifs.nix
|
||||||
|
./ubimage.nix
|
||||||
|
./users.nix
|
||||||
|
./vlan
|
||||||
|
./watchdog
|
||||||
|
./wlan.nix
|
||||||
|
];
|
||||||
|
}
|
Loading…
Reference in a new issue