summaryrefslogtreecommitdiffstats
path: root/tests/finix/xdg.nix
blob: e074858fbd68b24291da34bfafdd45ad45cabaa7 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
{
  hjemModule,
  hjemTest,
  lib,
  formats,
  writeText,
}: let
  userHome = "/home/alice";
in
  hjemTest {
    name = "hjem-xdg-finix";
    nodes = {
      node1 = {
        imports = [hjemModule];

        services.getty.enable = true;
        services.mdevd.enable = true;

        users.groups.alice = {};
        users.users.alice = {
          isNormalUser = true;
          home = userHome;
          password = "";
        };

        hjem.linker = null;
        hjem.users = {
          alice = {
            enable = true;
            files = {
              "foo" = {
                text = "Hello world!";
              };
            };
            xdg = {
              cache = {
                directory = userHome + "/customCacheDirectory";
                files = {
                  "foo" = {
                    text = "Hello world!";
                  };
                };
              };
              config = {
                directory = userHome + "/customConfigDirectory";
                files = {
                  "bar.json" = {
                    generator = lib.generators.toJSON {};
                    value = {bar = "Hello second world!";};
                  };
                };
              };
              data = {
                directory = userHome + "/customDataDirectory";
                files = {
                  "baz.toml" = {
                    generator = (formats.toml {}).generate "baz.toml";
                    value = {baz = "Hello third world!";};
                  };
                };
              };
              state = {
                directory = userHome + "/customStateDirectory";
                files = {
                  "foo" = {
                    source = writeText "file-bar" "Hello fourth world!";
                  };
                };
              };

              mime-apps = {
                added-associations."text/html" = ["firefox.desktop" "zen.desktop"];
                removed-associations."text/xml" = ["thunderbird.desktop"];
                default-applications."text/html" = "firefox.desktop";
              };
            };
          };
        };
      };
    };

    testScript = ''
      machine.wait_until_succeeds("initctl cond get task/hjem-activate-alice/success")

      with subtest("XDG basedir spec files created by Hjem"):
        machine.succeed("[ -L ~alice/customCacheDirectory/foo ]")
        machine.succeed("grep \"Hello world!\" ~alice/customCacheDirectory/foo")
        machine.succeed("[ -L ~alice/customConfigDirectory/bar.json ]")
        machine.succeed("grep \"Hello second world!\" ~alice/customConfigDirectory/bar.json")
        machine.succeed("[ -L ~alice/customDataDirectory/baz.toml ]")
        machine.succeed("grep \"Hello third world!\" ~alice/customDataDirectory/baz.toml")
        # Same name as cache test file to verify proper merging
        machine.succeed("[ -L ~alice/customStateDirectory/foo ]")
        machine.succeed("grep \"Hello fourth world!\" ~alice/customStateDirectory/foo")

      with subtest("XDG mime-apps spec file created by Hjem"):
        machine.succeed("[ -L ~alice/customConfigDirectory/mimeapps.list ]")
        machine.succeed("grep \"text/xml\" ~alice/customConfigDirectory/mimeapps.list")

      with subtest("Basic test file for Hjem"):
        machine.succeed("[ -L ~alice/foo ]") # Same name as cache test file to verify proper merging
        machine.succeed("grep \"Hello world!\" ~alice/foo")
    '';
  }