Use proper submodule for services
This commit is contained in:
parent
8d3e68c167
commit
83a9d4668f
11 changed files with 40 additions and 83 deletions
1
doc/manual/.gitignore
vendored
1
doc/manual/.gitignore
vendored
|
@ -1,3 +1,2 @@
|
||||||
manual.html
|
manual.html
|
||||||
options-composition.xml
|
options-composition.xml
|
||||||
options-service.xml
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ docbookxsl = http://docbook.sourceforge.net/release/xsl/current
|
||||||
|
|
||||||
all: manual.html
|
all: manual.html
|
||||||
|
|
||||||
manual.html: manual.xml options-composition.xml options-service.xml
|
manual.html: manual.xml options-composition.xml
|
||||||
$(xsltproc) --xinclude --stringparam profile.condition manual \
|
$(xsltproc) --xinclude --stringparam profile.condition manual \
|
||||||
$(docbookxsl)/profiling/profile.xsl manual.xml | \
|
$(docbookxsl)/profiling/profile.xsl manual.xml | \
|
||||||
$(xsltproc) --output manual.html $(docbookxsl)/xhtml/docbook.xsl -
|
$(xsltproc) --output manual.html $(docbookxsl)/xhtml/docbook.xsl -
|
||||||
|
@ -27,8 +27,8 @@ manual.html: manual.xml options-composition.xml options-service.xml
|
||||||
asciidoctor --backend docbook45 --doctype article $<
|
asciidoctor --backend docbook45 --doctype article $<
|
||||||
sed -e 's/<!DOCTYPE.*//' -e 's/<?asciidoc-[a-z]*?>//' -i $@
|
sed -e 's/<!DOCTYPE.*//' -e 's/<?asciidoc-[a-z]*?>//' -i $@
|
||||||
|
|
||||||
options-composition.xml options-service.xml:
|
options-composition.xml:
|
||||||
echo "options-composition.xml and options-service.xml should be written by the derivation. Are you running in 'nix-shell -A manual'?"; exit 1; fi
|
echo "options-composition.xml should be written by the derivation. Are you running in 'nix-shell -A manual'?"; exit 1; fi
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
mkdir -p $(docdir)
|
mkdir -p $(docdir)
|
||||||
|
|
|
@ -58,26 +58,9 @@ let
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
serviceOptions = options {
|
|
||||||
moduleType = "service";
|
|
||||||
description = "List of Arion service-level options in JSON format";
|
|
||||||
optionsExpr = let
|
|
||||||
src = ../../src/nix;
|
|
||||||
in ''
|
|
||||||
let pkgs = import ${pkgs.path} {};
|
|
||||||
fixPaths = opt: opt // {
|
|
||||||
declarations = map (d: "src/nix" + (lib.strings.removePrefix (toString ${src}) (toString d))) opt.declarations;
|
|
||||||
};
|
|
||||||
inherit (pkgs) lib;
|
|
||||||
composition = pkgs.callPackage ${src}/eval-service.nix {} { modules = []; host = {}; name = abort "The manual's service options section must not depend on the service name."; composition = abort "The manual's service options must not depend on the composition."; };
|
|
||||||
in map fixPaths (lib.filter (opt: opt.visible && !opt.internal) (lib.optionAttrSetToDocList composition.options))
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
generatedDocBook = runCommand "generated-docbook" {} ''
|
generatedDocBook = runCommand "generated-docbook" {} ''
|
||||||
mkdir $out
|
mkdir $out
|
||||||
ln -s ${compositionOptions.optionsDocBook} $out/options-composition.xml
|
ln -s ${compositionOptions.optionsDocBook} $out/options-composition.xml
|
||||||
ln -s ${serviceOptions.optionsDocBook} $out/options-service.xml
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
manual = stdenv.mkDerivation {
|
manual = stdenv.mkDerivation {
|
||||||
|
@ -105,11 +88,6 @@ let
|
||||||
'';
|
'';
|
||||||
prePatch = ''
|
prePatch = ''
|
||||||
cp ${generatedDocBook}/* .
|
cp ${generatedDocBook}/* .
|
||||||
substituteInPlace options-service.xml \
|
|
||||||
--replace 'xml:id="appendix-configuration-options"' 'xml:id="appendix-service-options"' \
|
|
||||||
--replace '<title>Configuration Options</title>' '<title>Service Options</title>' \
|
|
||||||
--replace 'xml:id="configuration-variable-list"' 'xml:id="service-variable-list"' \
|
|
||||||
;
|
|
||||||
substituteInPlace options-composition.xml \
|
substituteInPlace options-composition.xml \
|
||||||
--replace 'xml:id="appendix-configuration-options"' 'xml:id="appendix-composition-options"' \
|
--replace 'xml:id="appendix-configuration-options"' 'xml:id="appendix-composition-options"' \
|
||||||
--replace '<title>Configuration Options</title>' '<title>Composition Options</title>' \
|
--replace '<title>Configuration Options</title>' '<title>Composition Options</title>' \
|
||||||
|
|
|
@ -17,6 +17,5 @@
|
||||||
</info>
|
</info>
|
||||||
|
|
||||||
<xi:include href="options-composition.xml" />
|
<xi:include href="options-composition.xml" />
|
||||||
<xi:include href="options-service.xml" />
|
|
||||||
|
|
||||||
</book>
|
</book>
|
||||||
|
|
|
@ -183,9 +183,7 @@ runRepl co = do
|
||||||
"Launching a repl for you. To get started:\n\
|
"Launching a repl for you. To get started:\n\
|
||||||
\\n\
|
\\n\
|
||||||
\To see deployment-wide configuration\n\
|
\To see deployment-wide configuration\n\
|
||||||
\ type config. and hit TAB\n\
|
\ type config. and use tab completion\n\
|
||||||
\To see the services\n\
|
|
||||||
\ type config.docker-compose.evaluatedServices TAB or ENTER\n\
|
|
||||||
\To bring the top-level Nixpkgs attributes into scope\n\
|
\To bring the top-level Nixpkgs attributes into scope\n\
|
||||||
\ type :a (config._module.args.pkgs) // { inherit config; }\n\
|
\ type :a (config._module.args.pkgs) // { inherit config; }\n\
|
||||||
\"
|
\"
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
{ lib, pkgs, ... }:
|
|
||||||
|
|
||||||
{ modules, host, name, composition }:
|
|
||||||
let
|
|
||||||
composite = lib.evalModules {
|
|
||||||
check = true;
|
|
||||||
modules = builtinModules ++ modules;
|
|
||||||
};
|
|
||||||
|
|
||||||
builtinModules = [
|
|
||||||
argsModule
|
|
||||||
./modules/service/default-exec.nix
|
|
||||||
./modules/service/docker-compose-service.nix
|
|
||||||
./modules/service/extended-info.nix
|
|
||||||
./modules/service/host-store.nix
|
|
||||||
./modules/service/context.nix
|
|
||||||
./modules/service/image.nix
|
|
||||||
./modules/service/nixos.nix
|
|
||||||
./modules/service/nixos-init.nix
|
|
||||||
];
|
|
||||||
|
|
||||||
argsModule = {
|
|
||||||
_file = ./eval-service.nix;
|
|
||||||
key = ./eval-service.nix;
|
|
||||||
config._module.args.pkgs = lib.mkForce pkgs;
|
|
||||||
config.host = host;
|
|
||||||
config.service.name = name;
|
|
||||||
config.composition = composition;
|
|
||||||
};
|
|
||||||
|
|
||||||
in
|
|
||||||
composite
|
|
|
@ -34,7 +34,7 @@ in
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
arionBaseImage = "${name}:${tag}";
|
arionBaseImage = "${name}:${tag}";
|
||||||
build.imagesToLoad = lib.mkIf (lib.any (s: s.config.service.useHostStore) (lib.attrValues config.docker-compose.evaluatedServices)) [
|
build.imagesToLoad = lib.mkIf (lib.any (s: s.service.useHostStore) (lib.attrValues config.docker-compose.services)) [
|
||||||
{ image = builtImage; imageName = name; imageTag = tag; }
|
{ image = builtImage; imageName = name; imageTag = tag; }
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,13 +9,25 @@
|
||||||
- docker-compose.services
|
- docker-compose.services
|
||||||
|
|
||||||
*/
|
*/
|
||||||
{ pkgs, lib, config, ... }:
|
compositionArgs@{ lib, config, options, pkgs, ... }:
|
||||||
let
|
let
|
||||||
evalService = name: modules: pkgs.callPackage ../../eval-service.nix {} {
|
inherit (lib) types;
|
||||||
inherit name modules;
|
|
||||||
inherit (config) host;
|
service = {
|
||||||
composition = config;
|
imports = [ argsModule ] ++ import ../service/all-modules.nix;
|
||||||
};
|
};
|
||||||
|
argsModule =
|
||||||
|
{ name, # injected by types.submodule
|
||||||
|
...
|
||||||
|
}: {
|
||||||
|
_file = ./docker-compose.nix;
|
||||||
|
key = ./docker-compose.nix;
|
||||||
|
|
||||||
|
config._module.args.pkgs = lib.mkDefault compositionArgs.pkgs;
|
||||||
|
config.host = compositionArgs.config.host;
|
||||||
|
config.composition = compositionArgs.config;
|
||||||
|
config.service.name = name;
|
||||||
|
};
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
@ -44,14 +56,8 @@ in
|
||||||
description = "Attribute set that will be turned into the x-arion section of the docker-compose.yaml file.";
|
description = "Attribute set that will be turned into the x-arion section of the docker-compose.yaml file.";
|
||||||
};
|
};
|
||||||
docker-compose.services = lib.mkOption {
|
docker-compose.services = lib.mkOption {
|
||||||
default = {};
|
type = lib.types.attrsOf (lib.types.submodule service);
|
||||||
type = with lib.types; attrsOf (coercedTo unspecified (a: [a]) (listOf unspecified));
|
description = "An attribute set of service configurations. A service specifies how to run an image as a container.";
|
||||||
description = "A attribute set of service configurations. A service specifies how to run an image. Each of these service configurations is specified using modules whose options are described in the Service Options section.";
|
|
||||||
};
|
|
||||||
docker-compose.evaluatedServices = lib.mkOption {
|
|
||||||
type = lib.types.attrsOf lib.types.attrs;
|
|
||||||
description = "Attribute set of evaluated service configurations.";
|
|
||||||
readOnly = true;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
config = {
|
config = {
|
||||||
|
@ -59,10 +65,9 @@ in
|
||||||
build.dockerComposeYamlText = builtins.toJSON (config.build.dockerComposeYamlAttrs);
|
build.dockerComposeYamlText = builtins.toJSON (config.build.dockerComposeYamlAttrs);
|
||||||
build.dockerComposeYamlAttrs = config.docker-compose.raw;
|
build.dockerComposeYamlAttrs = config.docker-compose.raw;
|
||||||
|
|
||||||
docker-compose.evaluatedServices = lib.mapAttrs evalService config.docker-compose.services;
|
|
||||||
docker-compose.raw = {
|
docker-compose.raw = {
|
||||||
version = "3.4";
|
version = "3.4";
|
||||||
services = lib.mapAttrs (k: c: c.config.build.service) config.docker-compose.evaluatedServices;
|
services = lib.mapAttrs (k: c: c.build.service) config.docker-compose.services;
|
||||||
x-arion = config.docker-compose.extended;
|
x-arion = config.docker-compose.extended;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,12 +4,12 @@ let
|
||||||
|
|
||||||
serviceImages =
|
serviceImages =
|
||||||
lib.mapAttrs addDetails (
|
lib.mapAttrs addDetails (
|
||||||
lib.filterAttrs filterFunction config.docker-compose.evaluatedServices
|
lib.filterAttrs filterFunction config.docker-compose.services
|
||||||
);
|
);
|
||||||
|
|
||||||
filterFunction = serviceName: service:
|
filterFunction = serviceName: service:
|
||||||
builtins.addErrorContext "while evaluating whether the service ${serviceName} defines an image"
|
builtins.addErrorContext "while evaluating whether the service ${serviceName} defines an image"
|
||||||
service.config.image.nixBuild;
|
service.image.nixBuild;
|
||||||
|
|
||||||
addDetails = serviceName: service:
|
addDetails = serviceName: service:
|
||||||
builtins.addErrorContext "while evaluating the image for service ${serviceName}"
|
builtins.addErrorContext "while evaluating the image for service ${serviceName}"
|
||||||
|
|
|
@ -7,14 +7,14 @@
|
||||||
let
|
let
|
||||||
serviceInfo =
|
serviceInfo =
|
||||||
lib.mapAttrs getInfo (
|
lib.mapAttrs getInfo (
|
||||||
lib.filterAttrs filterFunction config.docker-compose.evaluatedServices
|
lib.filterAttrs filterFunction config.docker-compose.services
|
||||||
);
|
);
|
||||||
|
|
||||||
filterFunction = _serviceName: service:
|
filterFunction = _serviceName: service:
|
||||||
# shallow equality suffices for emptiness test
|
# shallow equality suffices for emptiness test
|
||||||
builtins.attrNames service.config.build.extendedInfo != [];
|
builtins.attrNames service.build.extendedInfo != [];
|
||||||
|
|
||||||
getInfo = _serviceName: service: service.config.build.extendedInfo;
|
getInfo = _serviceName: service: service.build.extendedInfo;
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
|
10
src/nix/modules/service/all-modules.nix
Normal file
10
src/nix/modules/service/all-modules.nix
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
[
|
||||||
|
./default-exec.nix
|
||||||
|
./docker-compose-service.nix
|
||||||
|
./extended-info.nix
|
||||||
|
./host-store.nix
|
||||||
|
./context.nix
|
||||||
|
./image.nix
|
||||||
|
./nixos.nix
|
||||||
|
./nixos-init.nix
|
||||||
|
]
|
Loading…
Reference in a new issue