~ruther/nix-tmpactivator

ref: 36039e24788d5577829ef2aa357cad7b423f7487 nix-tmpactivator/modules/systemd.nix -rw-r--r-- 2.3 KiB
36039e24 — Rutherther feat: add removal records for home files 1 year, 5 days 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
84
85
86
87
88
89
90
91
92
{ config, lib, utils, ... }:

let
  inherit (utils) systemdUtils;

  inherit
    (systemdUtils.lib)
    makeUnit
    generateUnits
    targetToUnit
    serviceToUnit
    sliceToUnit
    socketToUnit
    timerToUnit
    pathToUnit;

  cfg = config.systemd;

in {
  options = {
    systemd = {
      units = lib.mkOption {
        default = {};
        type = systemdUtils.types.units;
      };
      services = lib.mkOption {
        default = {};
        type = systemdUtils.types.services;
      };
      slices = lib.mkOption {
        default = {};
        type = systemdUtils.types.slices;
      };
      paths = lib.mkOption {
        default = {};
        type = systemdUtils.types.paths;
      };
      sockets = lib.mkOption {
        default = {};
        type = systemdUtils.types.sockets;
      };
      targets = lib.mkOption {
        default = {};
        type = systemdUtils.types.targets;
      };
      timers = lib.mkOption {
        default = {};
        type = systemdUtils.types.timers;
      };

      unitsPackage = lib.mkOption {
        type = lib.types.package;
      };

      package = lib.mkOption {
        default = "systemd";
      };
      globalEnvironment = lib.mkOption {
        default = {};
      };
    };

  };

  config = {
    systemd.units = with lib;
         mapAttrs' (n: v: nameValuePair "${n}.path"    (pathToUnit    n v)) cfg.paths
      // mapAttrs' (n: v: nameValuePair "${n}.service" (serviceToUnit n v)) cfg.services
      // mapAttrs' (n: v: nameValuePair "${n}.slice"   (sliceToUnit   n v)) cfg.slices
      // mapAttrs' (n: v: nameValuePair "${n}.socket"  (socketToUnit  n v)) cfg.sockets
      // mapAttrs' (n: v: nameValuePair "${n}.target"  (targetToUnit  n v)) cfg.targets
      // mapAttrs' (n: v: nameValuePair "${n}.timer"   (timerToUnit   n v)) cfg.timers;

    systemd.unitsPackage = generateUnits {
      type = "user";
      inherit (cfg) units;
      upstreamUnits = [];
      upstreamWants = [];
      package = "systemd";
      packages = [];
    };

    # home.file.".config/systemd/user".source = generateUnits {
    #   type = "user";
    #   inherit (cfg) units;
    # };
    #
    home.file = lib.mapAttrs' (name: conf: (lib.nameValuePair ".config/systemd/user/${name}" {
      source = "${config.systemd.unitsPackage}/${name}";
    })) config.systemd.units;
  };
}
Do not follow this link