zaphyra's git: nixfiles

zaphyra's nixfiles

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 
{
  config,
  lib,
  pkgs,
  ...
}:
{

  options.common.programs.niri.enable = lib.mkEnableOption "niri";
  config = lib.mkIf config.common.programs.niri.enable {
    programs.niri.enable = true;

    systemd.user.services."niri" = {
      # Niri ships with a `niri.service` unit, so the configuration here is
      # actually a drop-in override. Environment variables here should be forced
      # to be `{ }`, otherwise a default `PATH` for services is injected here,
      # clearing all inherited paths and making the WM totally unuseable without
      # `/run/current-system/sw/bin`, `q/etc/profiles/per-user/<username>/bin` and
      # potentially other paths.
      environment = lib.mkForce { };
      bindsTo = [
        "graphical-session.target"
        "niri-session.target"
      ];
      before = [
        "graphical-session.target"
        "niri-session.target"
      ];
    };

    systemd.user.targets."niri-session" = {
      description = "Current Niri graphical user session";
      documentation = [ "man:systemd.special(7)" ];
      requires = [ "basic.target" ];
      unitConfig.RefuseManualStart = true;
      unitConfig.StopWhenUnneeded = true;
    };

    # `maid-activation.service` finishes before `graphical-session-pre.target`,
    # so services dependent on a graphical environment won't run without another
    # activation.
    # See <https://github.com/viperML/nix-maid/issues/53>.
    systemd.user.services."maid-graphical-session-activation" = {
      wantedBy = [ "graphical-session.target" ];
      after = [ "graphical-session.target" ];
      serviceConfig.Type = "oneshot";
      serviceConfig.ExecStart = "${lib.getExe' pkgs.systemd "systemctl"} --user restart maid-activation.service";
      serviceConfig.RemainAfterExit = true;
    };

    # `nixos-fake-graphical-session.target` breaks some default systemd targets'
    # semantics, such as `graphical-session.target`, when using most WMs.
    # See <https://github.com/viperML/nix-maid/issues/56>
    systemd.user.targets."nixos-fake-graphical-session".enable = false;
  };
}