Nvidia-settings command in /usr/share/sddm/scripts/Xsetup not executed at startup?

Hello,

Just migrated from endeavourOS where I put a command in /usr/share/sddm/scripts/Xsetup to apply custom settings to my gpu at startup. It worked like a charm, but not with cachyOS ! The desktop environment and display manager are the same (plasma/sddm).

Do I miss something ?

Thanks !

EDIT : I don’t see the command in logs during boot. Also tried to switch to /usr/bin/bash as interpreter for root, but without success.

Did you make the script executable?

Otherwise, in my case, I use an nvidia-smi command at boot up but not using sddm scripts path to execute it. Instead, I create a service (unit file) which executes my script (systemd) when booting up my system. Maybe that’s helpful:

https://wiki.archlinux.org/title/Systemd#

Please, can you share with good settings for nvidia in full or any link for full guides from A to Z?

Did I understand correctly that you migrated via reinstallation or just by adding our repositories? If you did a full CachyOS installation, please note that we do not use X11 for SDDM by default, so your script simply shouldn’t run. You need to switch to using X11 again via creating the /etc/sddm.conf.d/10-no-wayland.conf file:

[General]
DisplayServer=x11

Otherwise you need to find another way to automatically execute script.

You can also try add nvidia-settings command to /usr/share/sddm/scripts/wayland-session, but I can’t guarantee this will work correctly as it depends on what exactly you want.

Hi,

It’s a fresh install. I actually have two VMs with a fresh install of EndeavourOS and CachyOS respectively.

The Xsetup solution worked out of the box with EndeavourOS but failed with CachyOS.

I don’t think the command in wayland-session will work because my comprehension is that it will be sent without root permission but it is needed for nvidia-settings.

I’ll give a try with the different solutions you mentionned to test what works, but perphaps the best way is actually to use systemd as @uKsu mentionned.

This solution worked! :slightly_smiling_face:

I tried to create a systemd service but without great success so far. I will take a deeper look at it to make it work.

Thanks everyone!

If you’re interested in the service approach, maybe I can guide you a little bit. Might be handy.

So, if it’s a root specific script, meaning you want it to be executed by root, then I create a folder under /root for my scripts. Of course, you can basically have it anywhere you want but it’s the way I do things so, in case you want your script to be somewhere else, then adjust:

sudo mkdir /root/.scripts

The above is just a directory I create for all these scripts I want to run under root and so I remember where they are. Again, you can have them where you like really. Just adjust the path accordingly.

Note that you should replace <> with whatever you want for your specific use case.

Create your script file:

sudo nano /root/.scripts/<yourscriptname>.sh

Then add the content of your script inside, save and exit. Use what editor you want of course, it’s just for simplicity.

sudo chmod +x /root/.scripts/<yourscriptname>.sh

Then we create the unit file:

sudo nano /etc/systemd/system/<yourscriptname>.service

Add something like this:

[Unit]
Description=<Write a description of what the script is doing.>
After=multi-user.target

[Service]
ExecStart=/root/.scripts/<yourscriptname>.sh
Type=simple

[Install]
WantedBy=multi-user.target
Alias=<InCaseYouWantADifferentNameUseAnotherHere>.service

“Description” and “Alias” is not really needed but can be handy. If you don’t need or want, just remove the whole line.

Now:

sudo chmod 664 /etc/systemd/system/<yourscriptname>.service

Enable the service:

sudo systemctl enable <yourscriptname>.service

Reboot.

To verify if it got executed after boot, you can do this:

journalctl -b | grep <yourscriptname>

Hope that helps.

Thanks for the tutorial!

Actually, my issue seems to be that the display is not yet initialized when the command is sent.

févr. 19 19:31:58 cachyos-main nvidia-startup.sh[679]: ERROR: The control display is undefined; please run `nvidia-settings --help` for usage information.
févr. 19 19:31:58 cachyos-main systemd[1]: nvidia-startup.service: Main process exited, code=exited, status=1/FAILURE
févr. 19 19:31:58 cachyos-main systemd[1]: nvidia-startup.service: Failed with result 'exit-code'.

I saw there is an “After=” key that can be used. I’m trying to figure which one has to be called before my script.

What happens when you execute the commands within your script when you’re logged in? Or when you execute your script manually once logged in? Does it work then? If you see the same error, maybe it’s because the DISPLAY variable is not set.

You can check if it’s there with:

printenv | grep DISPLAY

If you see something like:

DISPLAY=:0

You could try to add this to your script before the nvidia-settings command:

export DISPLAY=:0

The result of

printenv | grep DISPLAY

is

WAYLAND_DISPLAY=wayland-0
DISPLAY=:1

Tried

export DISPLAY=:1

in the script but without effect.

The command

sudo nvidia-settings -a '[gpu:0]/GPUFanControlState=1' -a '[fan:0]/GPUTargetFanSpeed=35'

works and returns

Attribute 'GPUFanControlState' (cachyos-main:1[gpu:0]) assigned value 1.
Attribute 'GPUTargetFanSpeed' (cachyos-main:1[fan:0]) assigned value 35

The command

nvidia-settings --help

suggests it’s certainly related to the display

  -a ASSIGN, --assign=ASSIGN
      The ASSIGN argument to the '--assign' command line option is of the form:

        {DISPLAY}/{attribute name}[{display devices}]={value}

      This assigns the attribute {attribute name} to the value {value} on the X Display {DISPLAY}.  {DISPLAY} follows the usual {host}:{display}.{screen} syntax of the DISPLAY environment variable and is optional; when it is not specified, then it is implied following the same rule as the --ctrl-display option.  I
      f the X screen is not specified, then the assignment is made to all X screens.  Note that the '/' is only required when {DISPLAY} is present.

      {DISPLAY} can additionally include a target specification to direct an assignment to something other than an X screen.  A target specification is contained within brackets and consists of a target type name, a colon, and the target id.  The target type name can be one of "screen", "gpu", "framelock", "fan",
      "thermalsensor", "svp", or "dpy"; the target id is the index into the list of targets (for that target type).  The target specification can be used in {DISPLAY} wherever an X screen can be used, following the syntax {host}:{display}[{target_type}:{target_id}].  See the output of

        nvidia-settings -q all

      for information on which target types can be used with which attributes.  See the output of

         nvidia-settings -q screens -q gpus -q framelocks -q fans -q thermalsensors -q svps -q dpys

      for lists of targets for each target type.

      The [{display devices}] portion is also optional; if it is not specified, then the attribute is assigned to all display devices.

      Some examples:

        -a FSAA=5
        -a localhost:0.0/DigitalVibrance[CRT-0]=0
        --assign="SyncToVBlank=1"
        -a [gpu:0]/DigitalVibrance[DFP-1]=63

Then I tried to put

nvidia-settings -a 'cachyos-main:1[gpu:0]/GPUFanControlState=1' -a 'cachyos-main:1[fan:0]/GPUTargetFanSpeed=35'

in the script, but without success , nor with

nvidia-settings --assign 'cachyos-main:1' -a '[gpu:0]/GPUFanControlState=1' -a '[fan:0]/GPUTargetFanSpeed=35'

Okay, then that means DISPLAY is set. However, did you try to run your script once you’re logged in and do you see a dfferent/same behaviour?

Edit:
Alright, I assume, when I reread your message, it does work when you execute it after you’re logged in. Then I’m out of advise I can give you, unfortunately.

That’s right. :slight_smile: Thanks for the help so far!

I will post details as soon as I find what is missing.