Sleep failing, can't use script due to int issue

My system has had a few problems with suspending, after some investigation I found the issue lied in

Apr 24 06:35:36 nixos kernel: xhci_hcd 0000:00:14.0: PM: pci_pm_suspend(): hcd_pci_suspend returns -16

As found in journalctl

Searching online I found this post which seemed to work for most people

Doing a sudo find / -name system-sleep -type d showed the directory I needed was in /nix/store so no modifying if I’m correct I thus tried putting it in my configuration.nix using

  systemd.sleep.extraConfig = ''
    if [ "${1}" == "pre" ]; then
      echo "Disable broken xhci module before suspending at $(date)..." > /tmp/systemd_suspend_test
      grep XHC.*enable /proc/acpi/wakeup && echo XHC > /proc/acpi/wakeup
    elif [ "${1}" == "post" ]; then
      # Do the thing you want after resume here, e.g.:
      echo "Enable broken xhci module at wakeup from $(date)" >> /tmp/systemd_suspend_test
      grep XHC.*disable /proc/acpi/wakeup && echo XHC > /proc/acpi/wakeup
    fi
    '';

However I end up with the error:

          247|   systemd.sleep.extraConfig = ''
          248|     if [ "${1}" == "pre" ]; then
             |           ^
          249|       echo "Disable broken xhci module before suspending at $(date)..." > /tmp/systemd_suspend_test

       error: cannot coerce an integer to a string: 1

Not sure why this error is happening here, why does it want to coerce to a string?
On a side note am I implementing this correctly?

Escape the $ with two single quotes: ''$
Else nix will treat it as nix code.

I’ve no idea if the code is correct though.

1 Like

That managed to run it, I’ll mark this as the solution if my computer consistently suspends for the next few days, thanks :slight_smile: