My system says wpctl is located : /nix/store/8jks1bd8g5a7fkc2r519m6nmlxar6jx3-system-path/bin/wpctl but I don’t know what to use for ${pkgs.*} to get this path?
But I feel like I am doing this entirely wrong since my terminal running bash has no issue running the script.
What is the correct way to write these scripts like this?
I also ran this in the script without success:
#!/usr/bin/env bash
And this doesn’t work in polybar, but does in my terminal, though it is noticably slower
{ pkgs, ... }:
{
home.packages = [
(pkgs.writeShellApplication {
name = "volume.sh"; # this will be the name of the binary
runtimeInputs = [ pkgs.wireplumber pkgs.gawk ]; # Dependencies go here
# Note that no shebang is necessary, writeShellApplication will prepend
# it.
#
# Also note that there is no need to reference the package, the
# runtimeInputs will take care of adding `bin` directory to this script's
# path
text = ''
wpctl ... | awk ...
'';
})
];
}
Ok, I did that and it still works in the terminal, however polybar is still not happy about the command. The output on the bar is now /bin/sh: line 1: volume.sh: command not found My polybar is basically like so:
If you only want to use this volume control script in your polybar, you can use something like:
...
"module/volume" = {
type = "custom/ipc";
hook-0 = lib.getExe (pkgs.writeShellApplication {
name = "volume.sh"; # this will be the name of the binary
runtimeInputs = [ pkgs.wireplumber pkgs.gawk ]; # Dependencies go here
# Note that no shebang is necessary, writeShellApplication will prepend
# it.
#
# Also note that there is no need to reference the package, the
# runtimeInputs will take care of adding `bin` directory to this script's
# path
text = ''
wpctl ... | awk ...
'';
});
initial = 1;
};
I actually want it to a separate script I can call, because there are other uses for calling the script separately. But, I do want it to be used in polybar primarily
You could combine the two in one file if you want and do something like this:
{ pkgs, ... }:
let
script = pkgs.writeShellApplication {
name = "volume.sh"; # this will be the name of the binary
runtimeInputs = [ pkgs.wireplumber pkgs.gawk ]; # Dependencies go here
# Note that no shebang is necessary, writeShellApplication will prepend
# it.
#
# Also note that there is no need to reference the package, the
# runtimeInputs will take care of adding `bin` directory to this script's
# path
text = ''
wpctl ... | awk ...
'';
}
in
{
home.packages = [ script ];
services.polybar = {
enable = true;
config = {
...
"module/volume" = {
type = "custom/ipc";
hook-0 = lib.getExe script;
initial = 1;
};
};
};
}
If you want to define your script as a separate Nix file, you should probably structure it like a package and use callPackage to import it.
volume.nix:
{
writeShellApplication,
wireplumber,
gawk,
# any other dependencies from pkgs go here
# all this will be injected by callPackage
}:
writeShellApplication {
name = "volume.sh";
runtimeInputs = [ wireplumber gawk ];
# ...
}
home.nix:
{ config, pkgs, ... }:
let scripts = {
volume = pkgs.callPackage scripts/volume.nix { };
};
in {...}