~ruther/nixos-config

ref: f01cb3c7ea06cf5fbd09f45d29b9f85ba437662d nixos-config/home/modules/profiles/desktop/dwl/default.nix -rw-r--r-- 5.9 KiB
f01cb3c7 — Frantisek Bohacek feat: add kanshi to manage monitors on wayland 11 months 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
{ lib, inputs, config, pkgs, ... }:

let
  # TODO save only those that are on in somewhere like tmp,
  # after enable is called, wake up only these if the file exists
  wlopmScreens = operation: pkgs.writeShellApplication {
    name = "wlopm-all-screens-${operation}";
    runtimeInputs = [
      pkgs.wlopm
      pkgs.gawk
      pkgs.findutils
    ];
    text = ''
      screens=$(wlopm | awk '{print $1}')
      echo "$screens" | xargs -l wlopm --${operation}
    '';
  };

  wlopmDisableScreens = wlopmScreens "off";
  wlopmEnableScreens = wlopmScreens "on";
in {
  imports = [
  ];

  options = {
    profiles.desktop.dwl = {
      enable = lib.mkEnableOption "dwl";
    };
  };

  config = lib.mkIf config.profiles.desktop.dwl.enable {
    profiles.desktop.enable = true;
    systemd.user.targets.wlr-session = {
      Unit = {
        Description = "A target that is enabled when starting Dwl";
        Requires = [ "graphical-session.target" "wm-services.target" ];
        PartOf = [ "graphical-session.target" ];
      };
    };

    home.file.".sessions/start-dwl".source = pkgs.writeShellScript "start-dwl" ''
    export XDG_CURRENT_DESKTOP=wlroots XDG_BACKEND=wayland QT_QPA_PLATFORM=wayland MOZ_ENABLE_WAYLAND=1 _JAVA_AWT_WM_NONREPARENTING=1
        dwl -s "${pkgs.writeShellScript "dwl-internal" ''
          dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP DISPLAY
          systemctl start --user wlr-session.target
        ''}" &
      pid=$!
      # Put something here
      wait $pid
      systemctl stop --user graphical-session.target
    '';

    home.file.".config/dwl/scripts/brightness.sh".source = ../qtile/config/brightness.sh;
    home.file.".config/dwl/scripts/print.sh".source = pkgs.writeShellScript "print.sh" ''
      #!/bin/sh -e

      out="$HOME/screens/$(date +%Y/%Y%m%d_%H%M%S).png"

      while getopts o:s arg; do case $arg in
        o) out="$OPTARG" ;;
        s) sel="$(slurp -o)" ;;
        ?|*) echo "usage: shot [-s] [-o out]" >&2; exit 1 ;;
      esac; done

      grim ''${sel:+ -g "$sel"} "$out"
      echo "$out"
      wl-copy -t image/png < "$out"
    '';
    home.file.".config/dwl/sequence-detector.config.json".source = ../qtile/config/sequence-detector.config.json;

    home.packages = [
      # Clipboard
      pkgs.cliphist
      pkgs.wl-clipboard
      # PrintScreening
      pkgs.grim
      pkgs.slurp
      # pkgs.wldash
      pkgs.imv
      # DWL control
      inputs.self.packages.${pkgs.system}.dwlb
      inputs.self.packages.${pkgs.system}.dwlmsg
      pkgs.wlr-randr
      pkgs.wlrctl
      pkgs.wlopm
      pkgs.kanshi

      ((pkgs.dwl.override {
        conf = ./config.h;
      }).overrideAttrs (oldAttrs: {
        buildInputs = oldAttrs.buildInputs ++ [
          pkgs.libdrm
          pkgs.fcft
        ];
        src = pkgs.fetchFromGitHub {
          owner = "Rutherther";
          repo = "dwl";
          rev = "ea81b93e3b29fc39c83c1c92bc025e30b71b376e";
          hash = "sha256-RDWIWuVjR525541ME2dolAQYN1t5BWy1ifY+cno8PVM=";
        };
      }))
    ];

    xdg.portal = {
      enable = true;
      configPackages = [ pkgs.xdg-desktop-portal-wlr ];
      extraPortals = [ pkgs.xdg-desktop-portal-wlr ];
    };

    programs = {
      swaylock = {
        enable = true;
        settings = {
          color = "808080";
          indicator-radius = 100;
          show-failed-attempts = true;
        };
      };
    };

    services.cliphist = {
      enable = true;
      systemdTarget = "wlr-session.target";
    };

    services.swayidle = {
      enable = true;
      events = [
        { event = "before-sleep"; command = "${lib.getExe pkgs.swaylock} -Ff"; }
        { event = "lock"; command = "${lib.getExe pkgs.swaylock} -Ff"; }
      ];
      timeouts = [
        { timeout = 300; command = lib.getExe wlopmDisableScreens; resumeCommand = lib.getExe wlopmEnableScreens; }
        { timeout = 1800; command = "${lib.getExe' pkgs.systemd "systemctl"} suspend"; }
      ];
    };

    services.kanshi = {
      enable = true;
      systemdTarget = "wlr-session.target";
      profiles = {
        ntb = {
          outputs = [
            { criteria = "eDP-1"; status = "enable"; mode = "1920x1200"; position = "0,0"; }
          ];
        };
        docked-1 = {
          outputs = [
            { criteria = "DP-7"; position = "1920,0"; }
            { criteria = "DP-8"; position = "3840,0"; }
            { criteria = "DP-9"; position = "0,0"; }
            { criteria = "eDP-1"; status = "disable"; }
          ];
        };
        docked-2 = {
          outputs = [
            { criteria = "DP-10"; position = "1920,0"; }
            { criteria = "DP-11"; position = "3840,0"; }
            { criteria = "DP-12"; position = "0,0"; }
            { criteria = "eDP-1"; status = "disable"; }
          ];
        };
      };
    };

    services.gammastep = {
      enable = true;
      temperature.night = 3000;
      latitude = 50.2332933;
      longitude = 14.3225926;
    };

    systemd.user.services.swayidle = {
      Install.WantedBy = lib.mkForce [ "wlr-session.target" ];
      Unit.PartOf = lib.mkForce [ "wlr-session.target" ];
    };

    systemd.user.services.gammastep = {
      Unit.After = lib.mkForce [ "wlr-session.target" ];
      Unit.PartOf = lib.mkForce [ "wlr-session.target" ];
      Install.WantedBy = lib.mkForce [ "wlr-session.target" ];
    };

    programs.waybar = {
      enable = true;
      package = pkgs.waybar.overrideAttrs (oldAttrs: {
        patches = (oldAttrs.patches or []) ++ [
          (pkgs.fetchpatch {
            url = "https://github.com/Rutherther/Waybar/commit/98b08880409cfd1277dc491b2f89de39a5107e50.patch";
            hash = "sha256-qnMnjL8ejGEO9SeIEclez1OISY7poKimr4Hu+ngKnxA=";
          })
        ];
      });
      systemd = {
        enable = true;
        target = "wlr-session.target";
      };
      style = ./waybar/style.css;
    };

    xdg.configFile."waybar/config.jsonc".source = ./waybar/config.jsonc;
    # xdg.configFile."waybar/style.css".source = ./waybar/style.css;

  };
}
Do not follow this link