mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-09-11 07:15:54 +03:00
Merge pull request #297517 from kira-bruneau/nixos-containers
nixos/nixos-containers: require mounts for bind mount host paths
This commit is contained in:
commit
f0034ee975
@ -834,7 +834,10 @@ in
|
||||
script = startScript containerConfig;
|
||||
postStart = postStartScript containerConfig;
|
||||
serviceConfig = serviceDirectives containerConfig;
|
||||
unitConfig.RequiresMountsFor = lib.optional (!containerConfig.ephemeral) "${stateDirectory}/%i";
|
||||
unitConfig.RequiresMountsFor = lib.optional (!containerConfig.ephemeral) "${stateDirectory}/%i"
|
||||
++ builtins.map
|
||||
(d: if d.hostPath != null then d.hostPath else d.mountPoint)
|
||||
(builtins.attrValues cfg.bindMounts);
|
||||
environment.root = if containerConfig.ephemeral then "/run/nixos-containers/%i" else "${stateDirectory}/%i";
|
||||
} // (
|
||||
optionalAttrs containerConfig.autoStart
|
||||
|
@ -219,6 +219,7 @@ in {
|
||||
containers-physical_interfaces = handleTest ./containers-physical_interfaces.nix {};
|
||||
containers-portforward = handleTest ./containers-portforward.nix {};
|
||||
containers-reloadable = handleTest ./containers-reloadable.nix {};
|
||||
containers-require-bind-mounts = handleTest ./containers-require-bind-mounts.nix {};
|
||||
containers-restart_networking = handleTest ./containers-restart_networking.nix {};
|
||||
containers-tmpfs = handleTest ./containers-tmpfs.nix {};
|
||||
containers-unified-hierarchy = handleTest ./containers-unified-hierarchy.nix {};
|
||||
|
35
nixos/tests/containers-require-bind-mounts.nix
Normal file
35
nixos/tests/containers-require-bind-mounts.nix
Normal file
@ -0,0 +1,35 @@
|
||||
import ./make-test-python.nix ({ lib, ... }: {
|
||||
name = "containers-require-bind-mounts";
|
||||
meta.maintainers = with lib.maintainers; [ kira-bruneau ];
|
||||
|
||||
nodes.machine = {
|
||||
containers.require-bind-mounts = {
|
||||
bindMounts = { "/srv/data" = {}; };
|
||||
config = {};
|
||||
};
|
||||
|
||||
virtualisation.fileSystems = {
|
||||
"/srv/data" = {
|
||||
fsType = "tmpfs";
|
||||
options = [ "noauto" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
machine.wait_for_unit("default.target")
|
||||
|
||||
assert "require-bind-mounts" in machine.succeed("nixos-container list")
|
||||
assert "down" in machine.succeed("nixos-container status require-bind-mounts")
|
||||
assert "inactive" in machine.fail("systemctl is-active srv-data.mount")
|
||||
|
||||
with subtest("bind mount host paths must be mounted to run container"):
|
||||
machine.succeed("nixos-container start require-bind-mounts")
|
||||
assert "up" in machine.succeed("nixos-container status require-bind-mounts")
|
||||
assert "active" in machine.succeed("systemctl status srv-data.mount")
|
||||
|
||||
machine.succeed("systemctl stop srv-data.mount")
|
||||
assert "down" in machine.succeed("nixos-container status require-bind-mounts")
|
||||
assert "inactive" in machine.fail("systemctl is-active srv-data.mount")
|
||||
'';
|
||||
})
|
Loading…
Reference in New Issue
Block a user