WIP NixOS-style docs
See https://github.com/hercules-ci/arion/issues/10
This commit is contained in:
parent
cb25b976ff
commit
0705c7ab2d
7 changed files with 116 additions and 22 deletions
8
doc/default.nix
Normal file
8
doc/default.nix
Normal file
|
@ -0,0 +1,8 @@
|
|||
{ pkgs ? import ../nix {} }:
|
||||
let
|
||||
inherit (pkgs) recurseIntoAttrs callPackage;
|
||||
in
|
||||
|
||||
recurseIntoAttrs {
|
||||
manual = callPackage ./manual {};
|
||||
}
|
66
doc/manual/default.nix
Normal file
66
doc/manual/default.nix
Normal file
|
@ -0,0 +1,66 @@
|
|||
{ pkgs ? import ../../nix {} }:
|
||||
let
|
||||
inherit (pkgs) recurseIntoAttrs callPackage runCommand lib;
|
||||
|
||||
nixosManualPath = s: "${pkgs.path}/nixos/doc/manual/${s}";
|
||||
revision = "0.0-fixme"; # FIXME
|
||||
|
||||
# NixOS module system options in JSON format.
|
||||
options = { moduleType, description, optionsList }: recurseIntoAttrs rec {
|
||||
optionsXML = builtins.toFile "options.xml" (builtins.toXML optionsList);
|
||||
|
||||
optionsDocBook = runCommand "options-db.xml" {} ''
|
||||
optionsXML=${optionsXML}
|
||||
if grep /nixpkgs/nixos/modules $optionsXML; then
|
||||
echo "The manual appears to depend on the location of Nixpkgs, which is bad"
|
||||
echo "since this prevents sharing via the NixOS channel. This is typically"
|
||||
echo "caused by an option default that refers to a relative path (see above"
|
||||
echo "for hints about the offending path)."
|
||||
exit 1
|
||||
fi
|
||||
${pkgs.buildPackages.libxslt.bin}/bin/xsltproc \
|
||||
--stringparam revision '${revision}' \
|
||||
-o intermediate.xml ${nixosManualPath "options-to-docbook.xsl"} $optionsXML
|
||||
${pkgs.buildPackages.libxslt.bin}/bin/xsltproc \
|
||||
-o "$out" ${nixosManualPath "postprocess-option-descriptions.xsl"} intermediate.xml
|
||||
'';
|
||||
|
||||
optionsJSON = runCommand "${moduleType}-options-json" {
|
||||
meta.description = description;
|
||||
} ''
|
||||
# Export list of options in different format.
|
||||
dst=$out/share/doc/arion
|
||||
mkdir -p $dst
|
||||
|
||||
cp ${builtins.toFile "options-${moduleType}.json" (builtins.unsafeDiscardStringContext (builtins.toJSON
|
||||
(builtins.listToAttrs (map (o: { name = o.name; value = removeAttrs o ["name" "visible" "internal"]; }) optionsList))))
|
||||
} $dst/options-${moduleType}.json
|
||||
|
||||
mkdir -p $out/nix-support
|
||||
echo "file json $dst/options-${moduleType}.json" >> $out/nix-support/hydra-build-products
|
||||
'';
|
||||
|
||||
|
||||
};
|
||||
|
||||
in
|
||||
|
||||
recurseIntoAttrs rec {
|
||||
compositionOptions = options {
|
||||
moduleType = "composition";
|
||||
description = "List of Arion composition-level options in JSON format";
|
||||
optionsList = let composition = import ../../src/nix/eval-composition.nix { inherit pkgs; };
|
||||
in lib.optionAttrSetToDocList composition.options;
|
||||
};
|
||||
serviceOptions = options {
|
||||
moduleType = "service";
|
||||
description = "List of Arion service-level options in JSON format";
|
||||
optionsList = let composition = pkgs.callPackage ../../src/nix/eval-service.nix {} { modules = []; uid = -1; };
|
||||
in lib.optionAttrSetToDocList composition.options;
|
||||
};
|
||||
generatedDocBook = runCommand "generated-docbook" {} ''
|
||||
mkdir $out
|
||||
ln -s ${compositionOptions.optionsDocBook} $out/options-composition.xml
|
||||
ln -s ${serviceOptions.optionsDocBook} $out/options-service.xml
|
||||
'';
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
self: super: {
|
||||
arion = super.callPackage ../arion.nix {};
|
||||
tests = super.callPackage ../tests {};
|
||||
doc = super.callPackage ../doc {};
|
||||
}
|
||||
|
|
|
@ -12,44 +12,27 @@
|
|||
{ pkgs, uid, lib, config, ... }:
|
||||
|
||||
let
|
||||
evalService = name: modules:
|
||||
let
|
||||
composite = lib.evalModules {
|
||||
check = true;
|
||||
modules = builtinModules ++ modules;
|
||||
};
|
||||
|
||||
builtinModules = [
|
||||
argsModule
|
||||
./service.nix
|
||||
./service-host-store.nix
|
||||
];
|
||||
|
||||
argsModule = {
|
||||
_file = ./docker-compose-module.nix;
|
||||
key = ./docker-compose-module.nix;
|
||||
config._module.args.pkgs = lib.mkForce pkgs;
|
||||
config._module.args.uid = uid;
|
||||
};
|
||||
|
||||
in
|
||||
composite.config.build.service;
|
||||
evalService = name: modules: (pkgs.callPackage ./eval-service.nix {} { inherit modules uid; }).config.build.service;
|
||||
|
||||
in
|
||||
{
|
||||
options = {
|
||||
build.dockerComposeYaml = lib.mkOption {
|
||||
type = lib.types.package;
|
||||
description = "";
|
||||
};
|
||||
build.dockerComposeYamlText = lib.mkOption {
|
||||
type = lib.types.string;
|
||||
description = "";
|
||||
};
|
||||
docker-compose.raw = lib.mkOption {
|
||||
type = lib.types.attrs;
|
||||
description = "";
|
||||
};
|
||||
docker-compose.services = lib.mkOption {
|
||||
default = {};
|
||||
type = with lib.types; attrsOf (coercedTo unspecified (a: [a]) (listOf unspecified));
|
||||
description = "";
|
||||
};
|
||||
};
|
||||
config = {
|
||||
|
|
24
src/nix/eval-service.nix
Normal file
24
src/nix/eval-service.nix
Normal file
|
@ -0,0 +1,24 @@
|
|||
{ lib, pkgs, ... }:
|
||||
|
||||
{ modules, uid }:
|
||||
let
|
||||
composite = lib.evalModules {
|
||||
check = true;
|
||||
modules = builtinModules ++ modules;
|
||||
};
|
||||
|
||||
builtinModules = [
|
||||
argsModule
|
||||
./service.nix
|
||||
./service-host-store.nix
|
||||
];
|
||||
|
||||
argsModule = {
|
||||
_file = ./docker-compose-module.nix;
|
||||
key = ./docker-compose-module.nix;
|
||||
config._module.args.pkgs = lib.mkForce pkgs;
|
||||
config._module.args.uid = uid;
|
||||
};
|
||||
|
||||
in
|
||||
composite
|
|
@ -15,37 +15,46 @@ in
|
|||
service.volumes = mkOption {
|
||||
type = listOf types.unspecified;
|
||||
default = [];
|
||||
description = "";
|
||||
};
|
||||
service.build.context = mkOption {
|
||||
type = nullOr string;
|
||||
default = null;
|
||||
description = "";
|
||||
};
|
||||
service.environment = mkOption {
|
||||
type = attrsOf (either string int);
|
||||
default = {};
|
||||
description = "";
|
||||
};
|
||||
service.image = mkOption {
|
||||
type = string;
|
||||
description = "";
|
||||
};
|
||||
service.command = mkOption {
|
||||
type = nullOr types.unspecified;
|
||||
default = null;
|
||||
description = "";
|
||||
};
|
||||
service.depends_on = mkOption {
|
||||
type = listOf string;
|
||||
default = [];
|
||||
description = "";
|
||||
};
|
||||
service.working_dir = mkOption {
|
||||
type = nullOr string;
|
||||
default = null;
|
||||
description = "";
|
||||
};
|
||||
service.entrypoint = mkOption {
|
||||
type = nullOr string;
|
||||
default = null;
|
||||
description = "";
|
||||
};
|
||||
service.restart = mkOption {
|
||||
type = nullOr string;
|
||||
default = null;
|
||||
description = "";
|
||||
};
|
||||
service.ports = mkOption {
|
||||
type = listOf types.unspecified;
|
||||
|
@ -58,10 +67,12 @@ in
|
|||
service.expose = mkOption {
|
||||
type = listOf string;
|
||||
default = [];
|
||||
description = "";
|
||||
};
|
||||
|
||||
build.service = mkOption {
|
||||
type = attrsOf types.unspecified;
|
||||
description = "";
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -5,4 +5,5 @@ in
|
|||
|
||||
recurseIntoAttrs {
|
||||
test = nixosTest ./arion-test;
|
||||
preEval = pkgs.callPackage ./arion-test/preeval.nix {};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue