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
51
ci.nix
51
ci.nix
|
@ -26,30 +26,39 @@ let
|
||||||
tests //
|
tests //
|
||||||
{
|
{
|
||||||
buildEnv = (import liminix {
|
buildEnv = (import liminix {
|
||||||
inherit nixpkgs borderVmConf;
|
inherit nixpkgs borderVmConf;
|
||||||
device = import (liminix + "/devices/qemu");
|
device = import (liminix + "/devices/qemu");
|
||||||
liminix-config = vanilla;
|
liminix-config = vanilla;
|
||||||
}).buildEnv;
|
}).buildEnv;
|
||||||
doc = pkgs.stdenv.mkDerivation {
|
doc =
|
||||||
name = "liminix-doc";
|
let json =
|
||||||
nativeBuildInputs = with pkgs; [
|
(import liminix {
|
||||||
gnumake sphinx
|
inherit nixpkgs borderVmConf;
|
||||||
fennel luaPackages.lyaml
|
device = import (liminix + "/devices/qemu");
|
||||||
];
|
liminix-config = {...} : {
|
||||||
src = ./doc;
|
imports = [ ./modules/all-modules.nix ];
|
||||||
buildPhase = ''
|
};
|
||||||
cat ${(import ./doc/extract-options.nix).doc} > options.json
|
}).outputs.optionsJson;
|
||||||
cat options.json | fennel --correlate parse-options.fnl > modules-generated.rst
|
in pkgs.stdenv.mkDerivation {
|
||||||
cp ${(import ./doc/hardware.nix)} hardware.rst
|
name = "liminix-doc";
|
||||||
make html
|
nativeBuildInputs = with pkgs; [
|
||||||
'';
|
gnumake sphinx fennel luaPackages.lyaml
|
||||||
installPhase = ''
|
];
|
||||||
mkdir -p $out/nix-support $out/share/doc/
|
src = ./.;
|
||||||
cp modules.rst options.json $out
|
buildPhase = ''
|
||||||
cp -a _build/html $out/share/doc/liminix
|
cat ${json} | fennel --correlate doc/parse-options.fnl > doc/modules-generated.rst
|
||||||
echo "file source-dist \"$out/share/doc/liminix\"" \
|
cp ${(import ./doc/hardware.nix)} doc/hardware.rst
|
||||||
> $out/nix-support/hydra-build-products
|
make -C doc html
|
||||||
'';
|
'';
|
||||||
|
installPhase = ''
|
||||||
|
mkdir -p $out/nix-support $out/share/doc/
|
||||||
|
cd doc
|
||||||
|
cp modules-generated.rst $out
|
||||||
|
ln -s ${json} $out/options.json
|
||||||
|
cp -a _build/html $out/share/doc/liminix
|
||||||
|
echo "file source-dist \"$out/share/doc/liminix\"" \
|
||||||
|
> $out/nix-support/hydra-build-products
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
with-unstable = (import liminix {
|
with-unstable = (import liminix {
|
||||||
nixpkgs = unstable;
|
nixpkgs = unstable;
|
||||||
|
|
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,21 +2,25 @@
|
||||||
|
|
||||||
(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"))]
|
(with-open [f (assert (io.open pathname :r))]
|
||||||
(with-open [f (assert (io.open pathname :r))]
|
(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