mirror of
https://github.com/hercules-ci/arion.git
synced 2024-11-26 10:05:39 +03:00
Use proper submodule for services
This commit is contained in:
parent
8d3e68c167
commit
83a9d4668f
1
doc/manual/.gitignore
vendored
1
doc/manual/.gitignore
vendored
@ -1,3 +1,2 @@
|
||||
manual.html
|
||||
options-composition.xml
|
||||
options-service.xml
|
||||
|
@ -17,7 +17,7 @@ docbookxsl = http://docbook.sourceforge.net/release/xsl/current
|
||||
|
||||
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 \
|
||||
$(docbookxsl)/profiling/profile.xsl manual.xml | \
|
||||
$(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 $<
|
||||
sed -e 's/<!DOCTYPE.*//' -e 's/<?asciidoc-[a-z]*?>//' -i $@
|
||||
|
||||
options-composition.xml options-service.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
|
||||
options-composition.xml:
|
||||
echo "options-composition.xml should be written by the derivation. Are you running in 'nix-shell -A manual'?"; exit 1; fi
|
||||
|
||||
install: all
|
||||
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" {} ''
|
||||
mkdir $out
|
||||
ln -s ${compositionOptions.optionsDocBook} $out/options-composition.xml
|
||||
ln -s ${serviceOptions.optionsDocBook} $out/options-service.xml
|
||||
'';
|
||||
|
||||
manual = stdenv.mkDerivation {
|
||||
@ -105,11 +88,6 @@ let
|
||||
'';
|
||||
prePatch = ''
|
||||
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 \
|
||||
--replace 'xml:id="appendix-configuration-options"' 'xml:id="appendix-composition-options"' \
|
||||
--replace '<title>Configuration Options</title>' '<title>Composition Options</title>' \
|
||||
|
@ -17,6 +17,5 @@
|
||||
</info>
|
||||
|
||||
<xi:include href="options-composition.xml" />
|
||||
<xi:include href="options-service.xml" />
|
||||
|
||||
</book>
|
||||
|
@ -183,9 +183,7 @@ runRepl co = do
|
||||
"Launching a repl for you. To get started:\n\
|
||||
\\n\
|
||||
\To see deployment-wide configuration\n\
|
||||
\ type config. and hit TAB\n\
|
||||
\To see the services\n\
|
||||
\ type config.docker-compose.evaluatedServices TAB or ENTER\n\
|
||||
\ type config. and use tab completion\n\
|
||||
\To bring the top-level Nixpkgs attributes into scope\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 = {
|
||||
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; }
|
||||
];
|
||||
};
|
||||
|
@ -9,12 +9,24 @@
|
||||
- docker-compose.services
|
||||
|
||||
*/
|
||||
{ pkgs, lib, config, ... }:
|
||||
compositionArgs@{ lib, config, options, pkgs, ... }:
|
||||
let
|
||||
evalService = name: modules: pkgs.callPackage ../../eval-service.nix {} {
|
||||
inherit name modules;
|
||||
inherit (config) host;
|
||||
composition = config;
|
||||
inherit (lib) types;
|
||||
|
||||
service = {
|
||||
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
|
||||
@ -44,14 +56,8 @@ in
|
||||
description = "Attribute set that will be turned into the x-arion section of the docker-compose.yaml file.";
|
||||
};
|
||||
docker-compose.services = lib.mkOption {
|
||||
default = {};
|
||||
type = with lib.types; attrsOf (coercedTo unspecified (a: [a]) (listOf unspecified));
|
||||
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;
|
||||
type = lib.types.attrsOf (lib.types.submodule service);
|
||||
description = "An attribute set of service configurations. A service specifies how to run an image as a container.";
|
||||
};
|
||||
};
|
||||
config = {
|
||||
@ -59,10 +65,9 @@ in
|
||||
build.dockerComposeYamlText = builtins.toJSON (config.build.dockerComposeYamlAttrs);
|
||||
build.dockerComposeYamlAttrs = config.docker-compose.raw;
|
||||
|
||||
docker-compose.evaluatedServices = lib.mapAttrs evalService config.docker-compose.services;
|
||||
docker-compose.raw = {
|
||||
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;
|
||||
};
|
||||
};
|
||||
|
@ -4,12 +4,12 @@ let
|
||||
|
||||
serviceImages =
|
||||
lib.mapAttrs addDetails (
|
||||
lib.filterAttrs filterFunction config.docker-compose.evaluatedServices
|
||||
lib.filterAttrs filterFunction config.docker-compose.services
|
||||
);
|
||||
|
||||
filterFunction = serviceName: service:
|
||||
builtins.addErrorContext "while evaluating whether the service ${serviceName} defines an image"
|
||||
service.config.image.nixBuild;
|
||||
service.image.nixBuild;
|
||||
|
||||
addDetails = serviceName: service:
|
||||
builtins.addErrorContext "while evaluating the image for service ${serviceName}"
|
||||
|
@ -7,14 +7,14 @@
|
||||
let
|
||||
serviceInfo =
|
||||
lib.mapAttrs getInfo (
|
||||
lib.filterAttrs filterFunction config.docker-compose.evaluatedServices
|
||||
lib.filterAttrs filterFunction config.docker-compose.services
|
||||
);
|
||||
|
||||
filterFunction = _serviceName: service:
|
||||
# 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
|
||||
{
|
||||
|
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 New Issue
Block a user