~ruther/nix-tmpactivator

ref: ceb0d409eacee969071c96aba8df5ed505d7dcdf nix-tmpactivator/modules/tmpfiles.nix -rw-r--r-- 2.4 KiB
ceb0d409 — Rutherther feat: many updates a year ago
                                                                                
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
{ config, tmpLib, pkgs, lib, ... }:

let
  inherit (tmpLib) mkTmpFile;

  tmpFiles = lib.lists.filter (file: file.enable) config.tmpfiles.files;
in {
  options = {
    tmpfiles = {
      defaultUser = lib.mkOption {
        type = lib.types.nullOr lib.types.str;
      };
      defaultGroup = lib.mkOption {
        type = lib.types.nullOr lib.types.str;
      };

      files = lib.mkOption {
        type = lib.types.listOf tmpLib.tmpFileType;
        default = [];
        description = ''
          The files to configure.
        '';
      };

      configurationFileLines = lib.mkOption {
        type = lib.types.listOf lib.types.str;
      };

      configurationPackage = lib.mkOption {
        type = lib.types.package;
        description = ''
          This package contains the tmpfiles configuration package
        '';
      };

      activationPackage = lib.mkOption {
        type = lib.types.package;
        description = ''
          This package contains a script for activation of the tmp files using `systemd-tmpfiles`
        '';
      };
    };
  };

  config = {
    # assertions = builtins.map
    #   (file: {
    #     assertion = file.source == null || file.text == null;
    #     message = "Either text or source can be set, not both.";
    #   })
    # tmpFiles;
    #

    tmpfiles.configurationFileLines = builtins.map (file: (tmpLib.mkTmpFile ({
      type = file.type;
      target = file.target;
      mode = file.mode;
      user = if file.user == null then config.tmpfiles.defaultUser else file.user;
      group = if file.group == null then config.tmpfiles.defaultGroup else file.group;
      contents = if file.source != null then file.source else file.text;
    }))) tmpFiles;

    tmpfiles.configurationPackage = pkgs.writeTextFile {
      name = "100-tmpactivator.conf";
      destination = "/lib/tmpfiles.d/100-tmpactivator.conf";
      text = lib.concatStringsSep "\n" config.tmpfiles.configurationFileLines;
    };

    tmpfiles.activationPackage = pkgs.symlinkJoin {
      name = "tmpfiles-activation";

      paths = [
        (pkgs.writeShellScriptBin "activate" ''
          systemd-tmpfiles --create "${config.tmpfiles.configurationPackage}/lib/tmpfiles.d/100-tmpactivator.conf"
        '')
        (pkgs.writeShellScriptBin "deactivate" ''
          systemd-tmpfiles --remove "${config.tmpfiles.configurationPackage}/lib/tmpfiles.d/100-tmpactivator.conf"
        '')
        config.tmpfiles.configurationPackage
      ];
    };
  };
}
Do not follow this link