about summary refs log tree commit diff
path: root/nixos/tests/docker-rootless.nix
blob: e2a926eb3cb0edc150139ffa58c84c0cd0c01529 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# This test runs docker and checks if simple container starts

import ./make-test-python.nix ({ lib, pkgs, ...} : {
  name = "docker-rootless";
  meta = with pkgs.lib.maintainers; {
    maintainers = [ abbradar ];
  };

  nodes = {
    machine = { pkgs, ... }: {
      virtualisation.docker.rootless.enable = true;

      users.users.alice = {
        uid = 1000;
        isNormalUser = true;
      };
    };
  };

  testScript = { nodes, ... }:
    let
      user = nodes.machine.config.users.users.alice;
      sudo = lib.concatStringsSep " " [
        "XDG_RUNTIME_DIR=/run/user/${toString user.uid}"
        "DOCKER_HOST=unix:///run/user/${toString user.uid}/docker.sock"
        "sudo" "--preserve-env=XDG_RUNTIME_DIR,DOCKER_HOST" "-u" "alice"
      ];
    in ''
      machine.wait_for_unit("multi-user.target")

      machine.succeed("loginctl enable-linger alice")
      machine.wait_until_succeeds("${sudo} systemctl --user is-active docker.service")

      machine.succeed("tar cv --files-from /dev/null | ${sudo} docker import - scratchimg")
      machine.succeed(
          "${sudo} docker run -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10"
      )
      machine.succeed("${sudo} docker ps | grep sleeping")
      machine.succeed("${sudo} docker stop sleeping")
    '';
})