Skip to content

Commit

Permalink
nixos/containers: fix imperative containers
Browse files Browse the repository at this point in the history
Fixes #67174.
  • Loading branch information
uvNikita committed Aug 21, 2019
1 parent bacf561 commit 578d712
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions nixos/modules/virtualisation/containers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ let
startScript = cfg:
''
mkdir -p -m 0755 "$root/etc" "$root/var/lib"
mkdir -p -m 0700 "$root/var/lib/private" "$root/root"
mkdir -p -m 0700 "$root/var/lib/private" "$root/root" /run/containers
if ! [ -e "$root/etc/os-release" ]; then
touch "$root/etc/os-release"
fi
Expand Down Expand Up @@ -248,7 +248,7 @@ let

Type = "notify";

RuntimeDirectory = [ "containers" ] ++ lib.optional cfg.ephemeral "containers/%i";
RuntimeDirectory = lib.optional cfg.ephemeral "containers/%i";

# Note that on reboot, systemd-nspawn returns 133, so this
# unit will be restarted. On poweroff, it returns 0, so the
Expand Down Expand Up @@ -683,8 +683,15 @@ in
unit = {
description = "Container '%i'";

unitConfig.RequiresMountsFor = "/var/lib/containers/%i";

path = [ pkgs.iproute ];

environment = {
root = "/var/lib/containers/%i";
INSTANCE = "%i";
};

preStart = preStartScript dummyConfig;

script = startScript dummyConfig;
Expand Down Expand Up @@ -722,14 +729,13 @@ in
}
else {});
in
unit // {
recursiveUpdate unit {
preStart = preStartScript containerConfig;
script = startScript containerConfig;
postStart = postStartScript containerConfig;
serviceConfig = serviceDirectives containerConfig;
unitConfig.RequiresMountsFor = lib.optional (!containerConfig.ephemeral) "/var/lib/containers/%i";
environment.root = if containerConfig.ephemeral then "/run/containers/%i" else "/var/lib/containers/%i";
environment.INSTANCE = "%i";
} // (
if containerConfig.autoStart then
{
Expand Down

0 comments on commit 578d712

Please sign in to comment.