aboutsummaryrefslogtreecommitdiffstats
path: root/modules/desktop/eww/yuck.nix
blob: 1fde829282183edc6f430cb0edfa5b26fc3056ac (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
{
  config,
  lib,
  pkgs,
  ...
}:
{
  config = lib.mkIf config.desktop.enable {
    programs.eww.yuckConfig =
      let
        mkPythonScript =
          {
            name,
            path,
            description ? "",
            python ? pkgs.python3,
            pythonPackages ? (ps: [ ]),
            deps ? [ ],
            gobjectIntrospection ? false,
          }:
          let
            pythonEnv = python.withPackages pythonPackages;
            pathPrefix = lib.concatStringsSep ":" (
              [ "${pythonEnv}/bin" ] ++ map (p: "${lib.getBin p}/bin") deps
            );
          in
          pkgs.stdenv.mkDerivation {
            pname = name;
            version = "0.1.0";
            src = path;
            dontUnpack = true;
            meta = lib.optionalAttrs (description != "") { inherit description; } // {
              mainProgram = name;
            };

            nativeBuildInputs =
              lib.optionals gobjectIntrospection [
                pkgs.wrapGAppsHook3
                pkgs.gobject-introspection
              ]
              ++ lib.optional (!gobjectIntrospection) pkgs.makeWrapper;
            buildInputs = lib.optionals gobjectIntrospection [ pkgs.gtk3 ];

            installPhase = ''
              mkdir -p $out/bin
              install -m755 $src $out/bin/${name}
              patchShebangs $out/bin/${name}
            '';

            # wrapGAppsHook3 wraps every executable in $out/bin automatically,
            # setting GI_TYPELIB_PATH etc. from buildInputs' closure. With
            # gobjectIntrospection = false a plain wrapProgram only extends PATH.
            preFixup =
              if gobjectIntrospection then
                ''
                  gappsWrapperArgs+=(--prefix PATH : "${pathPrefix}")
                ''
              else
                ''
                  wrapProgram $out/bin/${name} --prefix PATH : "${pathPrefix}"
                '';
          };

        system-stats = mkPythonScript {
          name = "eww-system-stats";
          path = ./system-stats.py;
          description = "Emit {cpu, ram, net} as JSON.";
          deps = [
            pkgs.iw
            pkgs.iproute2
            pkgs.pamixer
            pkgs.inotify-tools
            pkgs.dmidecode
          ];
        };

        workspaces = mkPythonScript {
          name = "eww-workspaces";
          path = ./workspaces.py;
          description = "Emit workspace list with each focused-app icon, driven by niri's event-stream.";
          pythonPackages = (ps: [ ps.pygobject3 ]);
          deps = [ config.desktop.niri.package ];
          gobjectIntrospection = true;
        };

        activate-windows = mkPythonScript {
          name = "eww-activate-windows";
          path = ./activate-windows.py;
          description = "Emit icons for windows on the active niri workspace via event-stream.";
          pythonPackages = (ps: [ ps.pygobject3 ]);
          deps = [ config.desktop.niri.package ];
          gobjectIntrospection = true;
        };
      in
      builtins.replaceStrings
        [
          "@@workspaces-script@@"
          "@@windows-script@@"
          "@@systemstats-script@@"
          "@@icon-offline@@"
          "@@icon-wifi@@"
          "@@icon-ethernet@@"
          "@@icon-cpu@@"
          "@@icon-ram@@"
          "@@icon-audio@@"
          "@@icon-calendar@@"
        ]
        [
          (lib.getExe workspaces)
          (lib.getExe activate-windows)
          (lib.getExe system-stats)
          (toString ../../../assets/icons/bar/offline.svg)
          (toString ../../../assets/icons/bar/wifi.svg)
          (toString ../../../assets/icons/bar/ethernet.svg)
          (toString ../../../assets/icons/bar/cpu.svg)
          (toString ../../../assets/icons/bar/ram.svg)
          (toString ../../../assets/icons/bar/audio.svg)
          (toString ../../../assets/icons/bar/calendar.svg)
        ]
        (builtins.readFile ./bar.yuck);
  };
}