about summary refs log tree commit diff
path: root/nixos/tests/systemd-portabled.nix
blob: ef38258b0d866a50ab9deb929dfeb5bcf9f414dc (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
42
43
44
45
46
47
48
49
50
51
import ./make-test-python.nix ({pkgs, lib, ...}: let
  demo-program = pkgs.writeShellScriptBin "demo" ''
      while ${pkgs.coreutils}/bin/sleep 3; do
          echo Hello World > /dev/null
      done
  '';
  demo-service = pkgs.writeText "demo.service" ''
    [Unit]
    Description=demo service
    Requires=demo.socket
    After=demo.socket

    [Service]
    Type=simple
    ExecStart=${demo-program}/bin/demo
    Restart=always

    [Install]
    WantedBy=multi-user.target
    Also=demo.socket
  '';
  demo-socket = pkgs.writeText "demo.socket" ''
    [Unit]
    Description=demo socket

    [Socket]
    ListenStream=/run/demo.sock
    SocketMode=0666

    [Install]
    WantedBy=sockets.target
  '';
  demo-portable = pkgs.portableService {
    pname = "demo";
    version = "1.0";
    description = ''A demo "Portable Service" for a shell program built with nix'';
    units = [ demo-service demo-socket ];
  };
in {

  name = "systemd-portabled";
  nodes.machine = {};
  testScript = ''
    machine.succeed("portablectl")
    machine.wait_for_unit("systemd-portabled.service")
    machine.succeed("portablectl attach --now --runtime ${demo-portable}/demo_1.0.raw")
    machine.wait_for_unit("demo.service")
    machine.succeed("portablectl detach --now --runtime demo_1.0")
    machine.fail("systemctl status demo.service")
  '';
})