aboutsummaryrefslogtreecommitdiffstats
path: root/modules/desktop/eww/bar/bar.nix
blob: 98b40036f53708622344f5735a9589e1c4cedb37 (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
{
  config,
  lib,
  pkgs,
  ...
}:
{
  config = lib.mkIf config.desktop.enable {
    programs.eww.yuckConfig =
      let
        mkLuaScript =
          {
            name,
            path,
            description ? "",
            lua ? pkgs.luajit,
            luaPackages ? (_: [ ]),
            deps ? [ ],
            gobjectIntrospection ? false,
          }:
          let
            luaEnv = lua.withPackages luaPackages;
            pathPrefix = lib.concatStringsSep ":" ([ "${luaEnv}/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 = mkLuaScript {
          name = "eww-system-stats";
          path = ./system-stats.lua;
          description = "Emit {cpu, ram, net} as JSON.";
          luaPackages = ps: [
            ps.lua-cjson
            ps.luaposix
          ];
          deps = [
            pkgs.iw
            pkgs.iproute2
            pkgs.pamixer
            pkgs.inotify-tools
            pkgs.dmidecode
          ];
        };

        niri-status = mkLuaScript {
          name = "niri-status";
          path = pkgs.writeText "eww-niri-status.lua" (
            builtins.replaceStrings
              [ "@@impala-icon@@" "@@bluetui-icon@@" "@@yazi-icon@@" ]
              [
                config.desktop.icons.apps.impala
                config.desktop.icons.apps.bluetui
                config.desktop.icons.apps.yazi
              ]
              (builtins.readFile ./niri-status.lua)
          );
          description = "Emit workspace and active window information list.";
          luaPackages = ps: [
            ps.lgi
            ps.lua-cjson
          ];
          deps = [ config.desktop.niri.package ];
          gobjectIntrospection = true;
        };
      in
      builtins.replaceStrings
        [
          "@@bash@@"
          "@@niri-status-script@@"
          "@@system-stats-script@@"
        ]
        [
          (lib.getExe config.terminal.bash.package)
          (lib.getExe niri-status)
          (lib.getExe system-stats)
        ]
        (builtins.readFile ./bar.yuck);
  };
}