summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstuebinm2021-05-17 17:11:47 +0200
committerstuebinm2021-05-17 17:11:47 +0200
commitaeb24f296fe339187d2c94f57b144f8d45f554b9 (patch)
tree7071116a5da5de48a302621cecce5c66ed5c978b
parent49c079b623bbbf56cbab607b1008e3f537f50935 (diff)
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).
-rw-r--r--nix-modules/docker-nixos-modules.nix21
1 files 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 ? <nixpkgs>
-, 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