[GH-ISSUE #134] Scripts don't work while running ironbar under a systemd service NixOS #7097

Closed
opened 2026-05-23 02:52:28 +01:00 by JakeStanger · 17 comments
Owner

Originally created by @yavko on GitHub (May 1, 2023).
Original GitHub issue: https://github.com/JakeStanger/ironbar/issues/134

Describe the bug

Scripts don't work while running ironbar under a systemd service

To Reproduce
Steps to reproduce the behavior:

  1. Use script
  2. See error

Expected behavior

Scripts work

System information:

  • Distro: NixOS unstable (aka 23.05)
  • Compositor: Hyprland
  • Ironbar version: 0.11 (latest commit on master)

Configuration

Config (generated json from nix)
{
  "anchor_to_edges": true,
  "center": [
    {
      "bar": [
        {
          "class": "music-img-img",
          "src": "{{poll:5000:playerctl metadata mpris:artUrl}}",
          "type": "image"
        }
      ],
      "class": "music-img",
      "name": "music-img",
      "on_mouse_enter": {
        "cmd": "/nix/store/7kaxirybmsqz1wnq290aj9fifwgdisjx-mctrls-shower/bin/mctrls-shower"
      },
      "on_mouse_exit": {
        "cmd": "/nix/store/c6swqv9dw2sbiw5zsxar5f3s5zl1m0ix-mctrls-hider/bin/mctrls-hider"
      },
      "type": "custom"
    },
    {
      "format": "{title}",
      "icons": {
        "pause": "icon:media-playback-pause",
        "play": "icon:media-playback-start"
      },
      "music_dir": "/home/yavor/Music",
      "on_mouse_enter": {
        "cmd": "/nix/store/7kaxirybmsqz1wnq290aj9fifwgdisjx-mctrls-shower/bin/mctrls-shower"
      },
      "on_mouse_exit": {
        "cmd": "/nix/store/c6swqv9dw2sbiw5zsxar5f3s5zl1m0ix-mctrls-hider/bin/mctrls-hider"
      },
      "player_type": "mpris",
      "show_status_icon": false,
      "truncate": "end",
      "type": "music"
    },
    {
      "bar": [
        {
          "class": "music-ctrls-prev",
          "label": "玲",
          "on_click": "!/nix/store/nxip05k3sg7m937vvavjpfdak6k3ica0-iron-previous/bin/iron-previous",
          "type": "button"
        },
        {
          "class": "music-ctrls-pp",
          "label": "{{poll:100:/nix/store/jha3arpk5fpcspbam0nkdrrdsvx79l09-pp-icon/bin/pp-icon}}",
          "on_click": "!/nix/store/rqacrmlhvwnmp90i88wmmx14bismvjp2-iron-play-pause/bin/iron-play-pause",
          "type": "button"
        },
        {
          "class": "music-ctrls-next",
          "label": "怜",
          "on_click": "!/nix/store/qf2246j28xybmz7h9yb23nxi4b0yhm13-iron-next/bin/iron-next",
          "type": "button"
        }
      ],
      "class": "music-ctrls",
      "name": "music-ctrls",
      "on_mouse_enter": {
        "cmd": "/nix/store/7kaxirybmsqz1wnq290aj9fifwgdisjx-mctrls-shower/bin/mctrls-shower"
      },
      "on_mouse_exit": {
        "cmd": "/nix/store/c6swqv9dw2sbiw5zsxar5f3s5zl1m0ix-mctrls-hider/bin/mctrls-hider"
      },
      "show_if": {
        "cmd": "/nix/store/i9mm84k7myf1fis2xgnbsqxj3jd1ygn6-mctrls-checker/bin/mctrls-checker",
        "interval": 500,
        "mode": "poll"
      },
      "transition_type": "slide_start",
      "type": "custom"
    }
  ],
  "end": [
    {
      "type": "tray"
    },
    {
      "format": [
        " {cpu_percent}%",
        " {memory_percent}%"
      ],
      "type": "sys_info"
    },
    {
      "bar": [
        {
          "label": "",
          "name": "power-btn",
          "on_click": "popup:toggle",
          "type": "button"
        }
      ],
      "class": "power-menu",
      "popup": [
        {
          "orientation": "vertical",
          "type": "box",
          "widgets": [
            {
              "label": "Power menu",
              "name": "header",
              "type": "label"
            },
            {
              "type": "box",
              "widgets": [
                {
                  "class": "power-btn",
                  "label": "<span font-size='40pt'></span>",
                  "on_click": "!shutdown now",
                  "type": "button"
                },
                {
                  "class": "power-btn",
                  "label": "<span font-size='40pt'></span>",
                  "on_click": "!reboot",
                  "type": "button"
                }
              ]
            },
            {
              "label": "Uptime: {{30000:/nix/store/ws0j8bcqxcy08d664cbbbg6j0xlg1vg6-fmt-uptime/bin/fmt-uptime}}",
              "name": "uptime",
              "type": "label"
            }
          ]
        }
      ],
      "tooltip": "Up: {{30000:/nix/store/ws0j8bcqxcy08d664cbbbg6j0xlg1vg6-fmt-uptime/bin/fmt-uptime}}",
      "type": "custom"
    },
    {
      "format": "%l:%M %P",
      "type": "clock"
    }
  ],
  "height": 32,
  "icon_theme": "Papirus-Dark",
  "position": "top",
  "start": [
    {
      "bar": [
        {
          "label": "",
          "on_click": "!hyprctl dispatch exec \"zsh -c 'rofi -show drun'\"",
          "type": "button"
        }
      ],
      "class": "nix-launcher",
      "name": "nix-launcher",
      "type": "custom"
    },
    {
      "all_monitors": false,
      "name_map": {
        "1": "●",
        "10": "●",
        "2": "●",
        "3": "●",
        "4": "●",
        "5": "●",
        "6": "●",
        "7": "●",
        "8": "●",
        "9": "●"
      },
      "type": "workspaces"
    }
  ]
}

Additional context

Works while executing normally, and not under systemd service

Screenshots

image

From journalctl and is same for like every occurance of the issue, which is like a lot cuz its polling (and retrying? I presume)

Originally created by @yavko on GitHub (May 1, 2023). Original GitHub issue: https://github.com/JakeStanger/ironbar/issues/134 **Describe the bug** Scripts don't work while running ironbar under a systemd service **To Reproduce** Steps to reproduce the behavior: 1. Use script 2. See error **Expected behavior** Scripts work **System information:** - Distro: NixOS unstable (aka 23.05) - Compositor: Hyprland - Ironbar version: 0.11 (latest commit on master) **Configuration** <details><summary>Config (generated json from nix)</summary> ```json { "anchor_to_edges": true, "center": [ { "bar": [ { "class": "music-img-img", "src": "{{poll:5000:playerctl metadata mpris:artUrl}}", "type": "image" } ], "class": "music-img", "name": "music-img", "on_mouse_enter": { "cmd": "/nix/store/7kaxirybmsqz1wnq290aj9fifwgdisjx-mctrls-shower/bin/mctrls-shower" }, "on_mouse_exit": { "cmd": "/nix/store/c6swqv9dw2sbiw5zsxar5f3s5zl1m0ix-mctrls-hider/bin/mctrls-hider" }, "type": "custom" }, { "format": "{title}", "icons": { "pause": "icon:media-playback-pause", "play": "icon:media-playback-start" }, "music_dir": "/home/yavor/Music", "on_mouse_enter": { "cmd": "/nix/store/7kaxirybmsqz1wnq290aj9fifwgdisjx-mctrls-shower/bin/mctrls-shower" }, "on_mouse_exit": { "cmd": "/nix/store/c6swqv9dw2sbiw5zsxar5f3s5zl1m0ix-mctrls-hider/bin/mctrls-hider" }, "player_type": "mpris", "show_status_icon": false, "truncate": "end", "type": "music" }, { "bar": [ { "class": "music-ctrls-prev", "label": "玲", "on_click": "!/nix/store/nxip05k3sg7m937vvavjpfdak6k3ica0-iron-previous/bin/iron-previous", "type": "button" }, { "class": "music-ctrls-pp", "label": "{{poll:100:/nix/store/jha3arpk5fpcspbam0nkdrrdsvx79l09-pp-icon/bin/pp-icon}}", "on_click": "!/nix/store/rqacrmlhvwnmp90i88wmmx14bismvjp2-iron-play-pause/bin/iron-play-pause", "type": "button" }, { "class": "music-ctrls-next", "label": "怜", "on_click": "!/nix/store/qf2246j28xybmz7h9yb23nxi4b0yhm13-iron-next/bin/iron-next", "type": "button" } ], "class": "music-ctrls", "name": "music-ctrls", "on_mouse_enter": { "cmd": "/nix/store/7kaxirybmsqz1wnq290aj9fifwgdisjx-mctrls-shower/bin/mctrls-shower" }, "on_mouse_exit": { "cmd": "/nix/store/c6swqv9dw2sbiw5zsxar5f3s5zl1m0ix-mctrls-hider/bin/mctrls-hider" }, "show_if": { "cmd": "/nix/store/i9mm84k7myf1fis2xgnbsqxj3jd1ygn6-mctrls-checker/bin/mctrls-checker", "interval": 500, "mode": "poll" }, "transition_type": "slide_start", "type": "custom" } ], "end": [ { "type": "tray" }, { "format": [ " {cpu_percent}%", " {memory_percent}%" ], "type": "sys_info" }, { "bar": [ { "label": "", "name": "power-btn", "on_click": "popup:toggle", "type": "button" } ], "class": "power-menu", "popup": [ { "orientation": "vertical", "type": "box", "widgets": [ { "label": "Power menu", "name": "header", "type": "label" }, { "type": "box", "widgets": [ { "class": "power-btn", "label": "<span font-size='40pt'></span>", "on_click": "!shutdown now", "type": "button" }, { "class": "power-btn", "label": "<span font-size='40pt'></span>", "on_click": "!reboot", "type": "button" } ] }, { "label": "Uptime: {{30000:/nix/store/ws0j8bcqxcy08d664cbbbg6j0xlg1vg6-fmt-uptime/bin/fmt-uptime}}", "name": "uptime", "type": "label" } ] } ], "tooltip": "Up: {{30000:/nix/store/ws0j8bcqxcy08d664cbbbg6j0xlg1vg6-fmt-uptime/bin/fmt-uptime}}", "type": "custom" }, { "format": "%l:%M %P", "type": "clock" } ], "height": 32, "icon_theme": "Papirus-Dark", "position": "top", "start": [ { "bar": [ { "label": "", "on_click": "!hyprctl dispatch exec \"zsh -c 'rofi -show drun'\"", "type": "button" } ], "class": "nix-launcher", "name": "nix-launcher", "type": "custom" }, { "all_monitors": false, "name_map": { "1": "●", "10": "●", "2": "●", "3": "●", "4": "●", "5": "●", "6": "●", "7": "●", "8": "●", "9": "●" }, "type": "workspaces" } ] } ``` </details> **Additional context** Works while executing normally, and not under systemd service **Screenshots** ![image](https://user-images.githubusercontent.com/15178513/235396027-10150f02-7166-4e48-8085-c0dba3aa5191.png) > From journalctl and is same for like every occurance of the issue, which is like a lot cuz its polling (and retrying? I presume)
Author
Owner

@yavko commented on GitHub (May 1, 2023):

Also forgot to mention, it only doesn't happen with on_click scripts/cmd, example: !do_something

<!-- gh-comment-id:1529292131 --> @yavko commented on GitHub (May 1, 2023): Also forgot to mention, it only doesn't happen with `on_click` scripts/cmd, example: `!do_something`
Author
Owner

@JakeStanger commented on GitHub (May 1, 2023):

I think I know why - the program is spawned as just sh but systemd won't check PATH. Before I fix, can you confirm /bin/sh exists on NixOS pls?

<!-- gh-comment-id:1529678232 --> @JakeStanger commented on GitHub (May 1, 2023): I think I know why - the program is spawned as just `sh` but systemd won't check PATH. Before I fix, can you confirm `/bin/sh` exists on NixOS pls?
Author
Owner

@yavko commented on GitHub (May 1, 2023):

I think I know why - the program is spawned as just sh but systemd won't check PATH. Before I fix, can you confirm /bin/sh exists on NixOS pls?

It does
image

<!-- gh-comment-id:1529772753 --> @yavko commented on GitHub (May 1, 2023): > I think I know why - the program is spawned as just `sh` but systemd won't check PATH. Before I fix, can you confirm `/bin/sh` exists on NixOS pls? It does ![image](https://user-images.githubusercontent.com/15178513/235466820-0b2af34f-6a72-4721-be37-71135c257f4a.png)
Author
Owner

@JakeStanger commented on GitHub (May 1, 2023):

If you get a min let me know if the linked PR sorts this.

<!-- gh-comment-id:1530135813 --> @JakeStanger commented on GitHub (May 1, 2023): If you get a min let me know if the linked PR sorts this.
Author
Owner

@yavko commented on GitHub (May 2, 2023):

Why not just eliminate all usage of sh? Also it's even more broken since I last tried, works fine in terminal, but here is the error i get in systemd
image

not sure if its from this PR, or just from other master changes

<!-- gh-comment-id:1530818908 --> @yavko commented on GitHub (May 2, 2023): Why not just eliminate all usage of `sh`? Also it's even more broken since I last tried, works fine in terminal, but here is the error i get in systemd ![image](https://user-images.githubusercontent.com/15178513/235573300-3a1c67bb-549a-4c84-bc43-6bbddbb26443.png) > not sure if its from this PR, or just from other master changes
Author
Owner

@yavko commented on GitHub (May 2, 2023):

Update after restarting my computer an hour ago before I left for school I noticed ironbar started (through systemd) but the script still did not work, I think issue is with the pipe or something

<!-- gh-comment-id:1531679614 --> @yavko commented on GitHub (May 2, 2023): Update after restarting my computer an hour ago before I left for school I noticed ironbar started (through systemd) but the script still did not work, I think issue is with the pipe or something
Author
Owner

@JakeStanger commented on GitHub (May 2, 2023):

Why not just eliminate all usage of sh?

Firstly because it would make this issue worse - systemd units do not read PATH because they have no idea of it, so it would add the requirement for every script to use the absolute path. Also because being able to do bash scripting in your config is neat, and I'd rather not lose that.

Also it's even more broken since I last tried, works fine in terminal, but here is the error i get in systemd

I'm not sure what's causing that, but it sure ain't the PR as that literally changes the sh calls to /bin/sh. I've also not merged any changes to the Wayland code yet. I'd imagine this is likely another issue with running under systemd you'd not encountered up until now (possibly again because it won't read any env vars unless you specifically write them into the unit, or maybe some nix things).


I'll try launching it from a systemd unit when I get time and see what happens, but might be a few days as I've got a lot on rn.

<!-- gh-comment-id:1532224769 --> @JakeStanger commented on GitHub (May 2, 2023): > Why not just eliminate all usage of `sh`? Firstly because it would make this issue worse - systemd units do not read PATH because they have no idea of it, so it would add the requirement for every script to use the absolute path. Also because being able to do bash scripting in your config is neat, and I'd rather not lose that. > Also it's even more broken since I last tried, works fine in terminal, but here is the error i get in systemd I'm not sure what's causing that, but it sure ain't the PR as that literally changes the `sh` calls to `/bin/sh`. I've also not merged any changes to the Wayland code yet. I'd imagine this is likely another issue with running under systemd you'd not encountered up until now (possibly again because it won't read any env vars unless you specifically write them into the unit, or maybe some nix things). --- I'll try launching it from a systemd unit when I get time and see what happens, but might be a few days as I've got a lot on rn.
Author
Owner

@yavko commented on GitHub (May 3, 2023):

Firstly because it would make this issue worse - systemd units do not read PATH because they have no idea of it, so it would add the requirement for every script to use the absolute path. Also because being able to do bash scripting in your config is neat, and I'd rather not lose that.

makes sense, then

I'm not sure what's causing that, but it sure ain't the PR as that literally changes the sh calls to /bin/sh. I've also not merged any changes to the Wayland code yet. I'd imagine this is likely another issue with running under systemd you'd not encountered up until now (possibly again because it won't read any env vars unless you specifically write them into the unit, or maybe some nix things).

Not sure either but it went away

<!-- gh-comment-id:1532326954 --> @yavko commented on GitHub (May 3, 2023): > Firstly because it would make this issue worse - systemd units do not read PATH because they have no idea of it, so it would add the requirement for every script to use the absolute path. Also because being able to do bash scripting in your config is neat, and I'd rather not lose that. makes sense, then > I'm not sure what's causing that, but it sure ain't the PR as that literally changes the sh calls to /bin/sh. I've also not merged any changes to the Wayland code yet. I'd imagine this is likely another issue with running under systemd you'd not encountered up until now (possibly again because it won't read any env vars unless you specifically write them into the unit, or maybe some nix things). Not sure either but it went away
Author
Owner

@JakeStanger commented on GitHub (May 7, 2023):

Have just tested this myself, and it works fine on Arch using the 0.12.0 release build (without the PR).

I used the following systemd user service file:

❯ cat .config/systemd/user/ironbar.service 
[Unit]
Description=Ironbar

[Service]
ExecStart=/usr/bin/ironbar
Restart=on-failure
RestartSec=1s

[Install]
WantedBy=default.target

With a very basic script:

let {
  $test = { type = "script" cmd = "echo 'hello world'"}
} in {
  start = [ $test ]
}

image

I suspect there's something weird going on with Nix.

<!-- gh-comment-id:1537471788 --> @JakeStanger commented on GitHub (May 7, 2023): Have just tested this myself, and it works fine on Arch using the 0.12.0 release build (without the PR). I used the following systemd user service file: ``` ❯ cat .config/systemd/user/ironbar.service [Unit] Description=Ironbar [Service] ExecStart=/usr/bin/ironbar Restart=on-failure RestartSec=1s [Install] WantedBy=default.target ``` With a very basic script: ``` let { $test = { type = "script" cmd = "echo 'hello world'"} } in { start = [ $test ] } ``` ![image](https://user-images.githubusercontent.com/5057870/236687475-4967e7c0-354e-4d1e-be2c-3b8b53c0891d.png) I suspect there's something weird going on with Nix.
Author
Owner

@yavko commented on GitHub (May 7, 2023):

I suspect there's something weird going on with Nix.

It probably is, mine is super similar

its the one I have autogenerated with the flake

[Install]
WantedBy=hyprland-session.target
WantedBy=sway-session.target

[Service]
ExecStart=/nix/store/z8a1n04wsrmylr683rd75z9w8n6ryy88-ironbar-0.11.0+date=2023-05-01_31a57ae/bin/ironbar
Type=simple

[Unit]
Description=Systemd service for Ironbar
Requires=graphical-session.target
<!-- gh-comment-id:1537501096 --> @yavko commented on GitHub (May 7, 2023): > I suspect there's something weird going on with Nix. It probably is, mine is super similar > its the one I have autogenerated with the flake ```ini [Install] WantedBy=hyprland-session.target WantedBy=sway-session.target [Service] ExecStart=/nix/store/z8a1n04wsrmylr683rd75z9w8n6ryy88-ironbar-0.11.0+date=2023-05-01_31a57ae/bin/ironbar Type=simple [Unit] Description=Systemd service for Ironbar Requires=graphical-session.target ```
Author
Owner

@yavko commented on GitHub (May 7, 2023):

Could you try running the nix version under arch?

sudo pacman -S nix
mkdir -p ~/.config/nix
echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf
nix build

then the built thing from a service?

<!-- gh-comment-id:1537501701 --> @yavko commented on GitHub (May 7, 2023): Could you try running the nix version under arch? ```sh sudo pacman -S nix mkdir -p ~/.config/nix echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf nix build ``` then the built thing from a service?
Author
Owner

@JakeStanger commented on GitHub (May 7, 2023):

Just tested using the same config as I used before (not managed through nix) and your systemd user unit, and it works fine

<!-- gh-comment-id:1537521869 --> @JakeStanger commented on GitHub (May 7, 2023): Just tested using the same config as I used before (not managed through nix) and your systemd user unit, and it works fine
Author
Owner

@yavko commented on GitHub (May 7, 2023):

Just tested using the same config as I used before (not managed through nix) and your systemd user unit, and it works fine

Weird, let me get back trace working to see why it wont get output

<!-- gh-comment-id:1537522112 --> @yavko commented on GitHub (May 7, 2023): > Just tested using the same config as I used before (not managed through nix) and your systemd user unit, and it works fine Weird, let me get back trace working to see why it wont get output
Author
Owner

@yavko commented on GitHub (May 7, 2023):

Before even adding the environment variable, it seems path is just gone, not only that, the mpris widget doesn't work anymore ?!? Let me try rebooting
EDIT: Music works, I'm just dumb

<!-- gh-comment-id:1537523049 --> @yavko commented on GitHub (May 7, 2023): Before even adding the environment variable, it seems path is just gone, not only that, the mpris widget doesn't work anymore ?!? Let me try rebooting EDIT: Music works, I'm just dumb
Author
Owner

@JakeStanger commented on GitHub (May 7, 2023):

I've just tried { type = "script" cmd = "echo $PATH"} with the Nix build/systemd unit on Arch and that does work as expected with the full path.

<!-- gh-comment-id:1537523988 --> @JakeStanger commented on GitHub (May 7, 2023): I've just tried `{ type = "script" cmd = "echo $PATH"}` with the Nix build/systemd unit on Arch and that does work as expected with the full path.
Author
Owner

@yavko commented on GitHub (May 7, 2023):

Just tested using the same config as I used before (not managed through nix) and your systemd user unit, and it works fine

Figured it out, so typical nix thing, in my scripts I didn't add runtime deps, so yeah ..., I am sorry for wasting your time on this, but actually you did fix it with that PR, since it's referenced directly, and sh isn't in path, maybe? So yeah just merge it. This issue has been weird as it kept having different error messages, once again I am sorry.

<!-- gh-comment-id:1537526828 --> @yavko commented on GitHub (May 7, 2023): > Just tested using the same config as I used before (not managed through nix) and your systemd user unit, and it works fine Figured it out, so typical nix thing, in my scripts I didn't add runtime deps, so yeah ..., I am sorry for wasting your time on this, but actually you did fix it with that PR, since it's referenced directly, and sh isn't in path, maybe? So yeah just merge it. This issue has been weird as it kept having different error messages, once again I am sorry.
Author
Owner

@JakeStanger commented on GitHub (May 7, 2023):

No need to apologise, issues like this are commonplace in software dev and sometimes you just need to whittle your way down to find the actual issue, and often it's hidden in plain sight. I'm glad we managed to get there :)

<!-- gh-comment-id:1537535672 --> @JakeStanger commented on GitHub (May 7, 2023): No need to apologise, issues like this are commonplace in software dev and sometimes you just need to whittle your way down to find the actual issue, and often it's hidden in plain sight. I'm glad we managed to get there :)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
JakeStanger/ironbar#7097
No description provided.