1 import ../make-test-python.nix (
5 maintainers = lib.teams.podman.members;
9 podman = { pkgs, ... }: {
10 virtualisation.podman.enable = true;
16 docker = { pkgs, ... }: {
17 virtualisation.podman.enable = true;
19 virtualisation.podman.dockerSocket.enable = true;
21 environment.systemPackages = [
27 extraGroups = [ "podman" ];
30 users.users.mallory = {
40 def su_cmd(cmd, user = "alice"):
41 cmd = shlex.quote(cmd)
42 return f"su {user} -l -c {cmd}"
45 podman.wait_for_unit("sockets.target")
46 docker.wait_for_unit("sockets.target")
49 with subtest("Run container as root with runc"):
50 podman.succeed("tar cv --files-from /dev/null | podman import - scratchimg")
52 "podman run --runtime=runc -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10"
54 podman.succeed("podman ps | grep sleeping")
55 podman.succeed("podman stop sleeping")
56 podman.succeed("podman rm sleeping")
58 with subtest("Run container as root with crun"):
59 podman.succeed("tar cv --files-from /dev/null | podman import - scratchimg")
61 "podman run --runtime=crun -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10"
63 podman.succeed("podman ps | grep sleeping")
64 podman.succeed("podman stop sleeping")
65 podman.succeed("podman rm sleeping")
67 with subtest("Run container as root with the default backend"):
68 podman.succeed("tar cv --files-from /dev/null | podman import - scratchimg")
70 "podman run -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10"
72 podman.succeed("podman ps | grep sleeping")
73 podman.succeed("podman stop sleeping")
74 podman.succeed("podman rm sleeping")
76 # start systemd session for rootless
77 podman.succeed("loginctl enable-linger alice")
78 podman.succeed(su_cmd("whoami"))
81 with subtest("Run container rootless with runc"):
82 podman.succeed(su_cmd("tar cv --files-from /dev/null | podman import - scratchimg"))
85 "podman run --runtime=runc -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10"
88 podman.succeed(su_cmd("podman ps | grep sleeping"))
89 podman.succeed(su_cmd("podman stop sleeping"))
90 podman.succeed(su_cmd("podman rm sleeping"))
92 with subtest("Run container rootless with crun"):
93 podman.succeed(su_cmd("tar cv --files-from /dev/null | podman import - scratchimg"))
96 "podman run --runtime=crun -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10"
99 podman.succeed(su_cmd("podman ps | grep sleeping"))
100 podman.succeed(su_cmd("podman stop sleeping"))
101 podman.succeed(su_cmd("podman rm sleeping"))
103 with subtest("Run container rootless with the default backend"):
104 podman.succeed(su_cmd("tar cv --files-from /dev/null | podman import - scratchimg"))
107 "podman run -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10"
110 podman.succeed(su_cmd("podman ps | grep sleeping"))
111 podman.succeed(su_cmd("podman stop sleeping"))
112 podman.succeed(su_cmd("podman rm sleeping"))
114 with subtest("Run container with init"):
116 "tar cv -C ${pkgs.pkgsStatic.busybox} . | podman import - busybox"
118 pid = podman.succeed("podman run --rm busybox readlink /proc/self").strip()
120 pid = podman.succeed("podman run --rm --init busybox readlink /proc/self").strip()
123 with subtest("A podman member can use the docker cli"):
124 docker.succeed(su_cmd("docker version"))
126 with subtest("Run container via docker cli"):
127 docker.succeed("docker network create default")
128 docker.succeed("tar cv --files-from /dev/null | podman import - scratchimg")
130 "docker run -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin localhost/scratchimg /bin/sleep 10"
132 docker.succeed("docker ps | grep sleeping")
133 docker.succeed("podman ps | grep sleeping")
134 docker.succeed("docker stop sleeping")
135 docker.succeed("docker rm sleeping")
136 docker.succeed("docker network rm default")
138 with subtest("A podman non-member can not use the docker cli"):
139 docker.fail(su_cmd("docker version", user="mallory"))
141 # TODO: add docker-compose test