Mako - hm - extraConfig

I am trying to run a script inside of my waybar config, which I have defined in my home-manager config.

It is looking for a command it can run when I click on it’s button like this:

on-click = "some-command";

In the past, I have written my bash scripts inside the double-quotes, being careful to always use ${pkgs.package}/bin/command instead of command, but this is a pain to write/edit/maintain.

I assume I can somehow use writeShellScript, but when I tried this:

on-click = pkgs.writeShellScript "" ''
  some-command
'';

it didn’t work.

Is there a problem with my syntax?

What exactly does “does not work” mean?

Any errors? If yes, which?

Though you probably need to quote the expression:

on-click = "${pkgs.writeShellScript "" ''
  some-command
''}";

One clarification, I have added the on-click option to my idle-inhibitor module to perform an action using makoctl.

What I have tried above builds just fine, but I don’t get the desired results. It seems that either the command is not being run, or is getting an error. The command runs just fine when run from the command line. I don’t know where to look for logs.

I tried what you suggested, but I get the same results.

Is some-command in your PATH? i.e. The package that the program is part of is pulled into your home-manger derivation?

If not, then the shell (defaults to bash) is going to complain that it can’t find the program. pkgs.writeShellScript simply creates a derivation that instantiates to a single executable file (with the contents being the hashbang and your script verbatim). i.e. Any commands in your script have use a fully specified path or be part of the inherited/setup of the shell in which it executes (i.e end up in PATH).

Now if you don’t want to specify the full program path (e.g. ${pkgs.firefox}/bin/firefox), and instead rely on PATH, you could create a wrapper which adds this program onto your PATH (via makeWrapper and similar).

some-command is not in my PATH, and in fact is a couple of bash statements. This is why I am attempting to use writeShellScript. Seems perfectly suited for the job.

The problem is that I don’t know how to diagnose. I know I have the correct bash statements. They work from the command line.

I do use Mako, but I don’t think I have any actions setup on the notifications I generate (so I’m not much help on that end). However, you can verify your script by looking at whats instantiated (possibly even executing it yourself) and determine that part is working as you expect:

When you do your home-manager switch, messages will be output about the derivations that will be instantiated (I believe these actually bubble up from nix-build/nix-instantiate being called by the home-manager script). Messages along the lines of building hash-xyz.drv. If you open that derivation file (the xyz name is the first argument you pass to writeShellScript), the first line will specify the out path (which in this case is the shell script that it built). You can open (or execute if applicable) this file and ensure it looks/executes as you expect.

Additionally/Alternatively, since your dealing with a service (Mako) you may want to add some system logging to your script to see what its actually doing. If your using a systemd distribution, adding systemd-cat -t myScript -p 0 echo 'message' lines into your script will add the log message message to your syslog. Again if using systemd, you can then browse the syslog for your message(s) by executing journalctl -e .

I’m beginning to think it’s a problem with waybar. I can’t get on-click to launch any command, in any module.

Can anyone confirm any working on-click items in any modules?

Edit: Could this be related to the fact that there is a specific hyprland fork of waybar? For instance, workspaces don’t work in the main line waybar.

Anyone know if anyone is packaging the hyprland fork of waybar for NixOS?