From aeb24f296fe339187d2c94f57b144f8d45f554b9 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Mon, 17 May 2021 17:11:47 +0200 Subject: nix oci container: add escape hatch to docker config This now allows to write arbitrary values into the config of the docker containers generated, if so desired. It also now creates working directories /before/ executing any preStart scripts (which would lead to crashes before). --- nix-modules/docker-nixos-modules.nix | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/nix-modules/docker-nixos-modules.nix b/nix-modules/docker-nixos-modules.nix index 6ab2785..d14144d 100644 --- a/nix-modules/docker-nixos-modules.nix +++ b/nix-modules/docker-nixos-modules.nix @@ -1,5 +1,6 @@ { nixpkgsPath ? -, ociconfig +, dockerConfig +, nixConfig , name , ...}: @@ -40,7 +41,7 @@ let config = pkgs.lib.evalModules { modules = [ systemModule - ociconfig + nixConfig "${nixpkgsPath}/nixos/modules/misc/assertions.nix" ]; }; @@ -66,7 +67,7 @@ in pkgs.dockerTools.buildImage { # scripts that are started when the docker container runs. # Note that many features of the systemd.services config # are just ignored (e.g. no auto-restarts yet) - config = with pkgs.lib; with pkgs.lib.strings; { + config = with pkgs.lib; with pkgs.lib.strings; dockerConfig // { Cmd = pkgs.writeScript "main-entrypoint" ("#!${pkgs.dash.outPath}/bin/dash\n" + concatStrings (map (command: "${command}&\n") @@ -75,7 +76,13 @@ in pkgs.dockerTools.buildImage { (pkgs.writeScript "systemd-script-${name}" '' #!${pkgs.dash.outPath}/bin/dash - set -ue + set -xue + + # set up working directory + ${optionalString (service ? serviceConfig + && service.serviceConfig ? WorkingDirectory) '' + mkdir -p ${service.serviceConfig.WorkingDirectory} + cd ${service.serviceConfig.WorkingDirectory} ''} # run the prestart script ${optionalString (service ? preStart) '' @@ -84,12 +91,6 @@ in pkgs.dockerTools.buildImage { echo ${name}: starting ... - # set up working directory - ${optionalString (service ? serviceConfig - && service.serviceConfig ? WorkingDirectory) '' - mkdir -p ${service.serviceConfig.WorkingDirectory} - cd ${service.serviceConfig.WorkingDirectory} ''} - # set up environment variables ${optionalString (service ? environment) (concatStrings -- cgit v1.2.3