summaryrefslogtreecommitdiffstats
path: root/nixos/tests/envfs.nix
blob: a209b2c8db2c09850792cd106a3596f74ff07c4d (plain)
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
{
  pkgs,
  systemdStage1,
  ...
}:

let
  pythonShebang = pkgs.writeScript "python-shebang" ''
    #!/usr/bin/python
    print("OK")
  '';

  bashShebang = pkgs.writeScript "bash-shebang" ''
    #!/usr/bin/bash
    echo "OK"
  '';
in
{
  name = "envfs";

  nodes.machine = {
    services.envfs.enable = true;
    boot.initrd.systemd.enable = systemdStage1;
  };

  testScript = ''
    start_all()
    machine.wait_until_succeeds("mountpoint -q /usr/bin/")
    machine.succeed(
        "PATH=${pkgs.coreutils}/bin /usr/bin/cp --version",
        # check fallback paths
        "PATH= /usr/bin/sh --version",
        "PATH= /usr/bin/env --version",
        "PATH= test -e /usr/bin/sh",
        "PATH= test -e /usr/bin/env",
        # also picks up PATH that was set after execve
        "! /usr/bin/hello",
        "PATH=${pkgs.hello}/bin /usr/bin/hello",
    )

    out = machine.succeed("PATH=${pkgs.python3}/bin ${pythonShebang}")
    print(out)
    assert out == "OK\n"

    out = machine.succeed("PATH=${pkgs.bash}/bin ${bashShebang}")
    print(out)
    assert out == "OK\n"
  '';
}