From 02d319acf615252f080c08f0593eab41a7ef2c2d Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sun, 29 Sep 2019 23:44:53 +0200 Subject: [PATCH] Expose composition to services --- doc/manual/default.nix | 2 +- src/nix/eval-service.nix | 5 +++-- src/nix/modules/composition/docker-compose.nix | 6 +++++- src/nix/modules/service/{host.nix => context.nix} | 6 ++++++ 4 files changed, 15 insertions(+), 4 deletions(-) rename src/nix/modules/service/{host.nix => context.nix} (56%) diff --git a/doc/manual/default.nix b/doc/manual/default.nix index ff2096c..03522ab 100644 --- a/doc/manual/default.nix +++ b/doc/manual/default.nix @@ -69,7 +69,7 @@ let 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 = 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)) ''; }; diff --git a/src/nix/eval-service.nix b/src/nix/eval-service.nix index cb866ba..2ab731b 100644 --- a/src/nix/eval-service.nix +++ b/src/nix/eval-service.nix @@ -1,6 +1,6 @@ { lib, pkgs, ... }: -{ modules, host, name }: +{ modules, host, name, composition }: let composite = lib.evalModules { check = true; @@ -13,7 +13,7 @@ let ./modules/service/docker-compose-service.nix ./modules/service/extended-info.nix ./modules/service/host-store.nix - ./modules/service/host.nix + ./modules/service/context.nix ./modules/service/image.nix ./modules/service/nixos.nix ./modules/service/nixos-init.nix @@ -25,6 +25,7 @@ let config._module.args.pkgs = lib.mkForce pkgs; config.host = host; config.service.name = name; + config.composition = composition; }; in diff --git a/src/nix/modules/composition/docker-compose.nix b/src/nix/modules/composition/docker-compose.nix index c223f68..1891bbf 100644 --- a/src/nix/modules/composition/docker-compose.nix +++ b/src/nix/modules/composition/docker-compose.nix @@ -11,7 +11,11 @@ */ { pkgs, lib, config, ... }: let - evalService = name: modules: pkgs.callPackage ../../eval-service.nix {} { inherit name modules; inherit (config) host; }; + evalService = name: modules: pkgs.callPackage ../../eval-service.nix {} { + inherit name modules; + inherit (config) host; + composition = config; + }; in { diff --git a/src/nix/modules/service/host.nix b/src/nix/modules/service/context.nix similarity index 56% rename from src/nix/modules/service/host.nix rename to src/nix/modules/service/context.nix index 3ba2ee8..10854e2 100644 --- a/src/nix/modules/service/host.nix +++ b/src/nix/modules/service/context.nix @@ -7,5 +7,11 @@ The composition-level host option values. ''; }; + composition = lib.mkOption { + type = lib.types.attrs; + description = '' + The composition configuration. + ''; + }; }; }