From 0705c7ab2d4a9252d553f72e1611a8f49d60996c Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Tue, 29 Jan 2019 20:38:22 +0700 Subject: [PATCH] WIP NixOS-style docs See https://github.com/hercules-ci/arion/issues/10 --- doc/default.nix | 8 ++++ doc/manual/default.nix | 66 +++++++++++++++++++++++++++++++ nix/overlay.nix | 1 + src/nix/docker-compose-module.nix | 27 +++---------- src/nix/eval-service.nix | 24 +++++++++++ src/nix/service.nix | 11 ++++++ tests/default.nix | 1 + 7 files changed, 116 insertions(+), 22 deletions(-) create mode 100644 doc/default.nix create mode 100644 doc/manual/default.nix create mode 100644 src/nix/eval-service.nix diff --git a/doc/default.nix b/doc/default.nix new file mode 100644 index 0000000..aedd7ff --- /dev/null +++ b/doc/default.nix @@ -0,0 +1,8 @@ +{ pkgs ? import ../nix {} }: +let + inherit (pkgs) recurseIntoAttrs callPackage; +in + +recurseIntoAttrs { + manual = callPackage ./manual {}; +} diff --git a/doc/manual/default.nix b/doc/manual/default.nix new file mode 100644 index 0000000..7352a62 --- /dev/null +++ b/doc/manual/default.nix @@ -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 + ''; +} diff --git a/nix/overlay.nix b/nix/overlay.nix index 7386daa..13ad5dc 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -1,4 +1,5 @@ self: super: { arion = super.callPackage ../arion.nix {}; tests = super.callPackage ../tests {}; + doc = super.callPackage ../doc {}; } diff --git a/src/nix/docker-compose-module.nix b/src/nix/docker-compose-module.nix index 159ff26..f0c1d29 100644 --- a/src/nix/docker-compose-module.nix +++ b/src/nix/docker-compose-module.nix @@ -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 = { diff --git a/src/nix/eval-service.nix b/src/nix/eval-service.nix new file mode 100644 index 0000000..4c855d1 --- /dev/null +++ b/src/nix/eval-service.nix @@ -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 diff --git a/src/nix/service.nix b/src/nix/service.nix index 927126b..beb9262 100644 --- a/src/nix/service.nix +++ b/src/nix/service.nix @@ -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 = ""; }; }; diff --git a/tests/default.nix b/tests/default.nix index 27bbac2..ffa7a94 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -5,4 +5,5 @@ in recurseIntoAttrs { test = nixosTest ./arion-test; + preEval = pkgs.callPackage ./arion-test/preeval.nix {}; }