Enabling cups for printing via SALT seems more complicated than I expected

I’m trying to figure out the correct way to turn on the cups service via SALT so I can print through a usb cable. I know I can enable cups in a dom0 terminal via qvm-service [VMNAME] cups --enable. But I want to learn how to do this with SALT, so I can set it in a .sls file and configure any new Qubes installs super easily.

I have previously enabled /srv/user_salt and have used it to configure various qubes in the past. So my basic SALT set up works.

From online reading (GitHub - QubesOS/qubes-mgmt-salt-dom0-qvm) I added the following code snipped to my sys-usb.sls file.

{% if grains['id'] == 'dom0' %} 

sys-usb-setup: 
  qvm.vm: 
### Some code removed for this post that isn't relevant to cups ###
    - features: 
      - enable: 
        - service.cups 

{% endif %}

Then in a dom0 terminal I run sudo qubesctl --targets sys-usb state.sls sys-usb saltenv=user. When I look at the qubesctl output, it doesn’t throw any errors. It seems to confirm that cups is now in the output.

Because my sys-usb is a disposable qube, I used the SALT code from above and applied it to the appvm that is the disposable template for sys-usb, and for the template to the appvm.

I then turn off the template, and the appvm that is the disposable template for sys-usb. Then I restart sys-usb so all the changes can propagate through the chain.

But when I check /var/run/qubes-service/ there isn’t a file named cups there. To make that file appear, I seem to have to run qvm-service sys-usb cups --enable from a terminal in dom0.

I ran qvm-service sys-usb cups --enable to get my printer working initially. Later, when I started this SALT journey, I ran qvm-service sys-usb cups --disable because I thought it would give me a blank slate. But maybe if qvm-service and SALT disagree, qvm-service always wins?

I suspect I could use file.manage to make the cups file appear in /var/run/qubes-service/, using SALT, but that feels like a hacky way to do this, when in the documentation there is a way in SALT to set services.

As an aside, do I need to enable cups in the template, the appvm that services as the disposable template, and the disposable? Since the cups file lives in /var, I thought maybe turning cups on in the template would be enough. But on the other hand, the need for a file to be placed in /var kind of implies that qubes OS has some extra requirements around services, which could imply that cups enabled in appvm and disposable might be enough (or even in just the disposable)? My end goal is to have the disposable automatically have cups running whenever I turn it on, with the minimum number of other qubes having to have cups on to enable it in the disposable.

So yeah, I’m curious what might be causing my SALT thing to fail. I’m also open to reading links if people know a specific page which might go over my woes.

You are targeting any qube except dom0.

I’m curious about the output here, what is the result with --show-output? Anyway, you are running qvm-service inside sys-usb :slight_smile:

Change the {% if %} condition and remove the --target option and you should get something working.

I made an error while manually typing out my SALT code from dom0 into forum.qubes-os.org

The SALT snippet already contains the correct {% if grains['id'] == 'dom0' %} line. So that wasn’t the problem. I also updated this in my first post. Good catch though.

Give me a min to grab the relevant qubesctl --show-output info

Why not copy-paste?

Can’t use the typical keyboard shortcuts for “global” copy and paste to move text in and out of dom0. Have to use command line qvm-copy-to-vm or something like it. I don’t remember the command offhand.

No need to use command-line to copy from dom0 :slight_smile:

1 Like

I didn’t know about the “copy dom0 clipboard” widget. Thanks! Do you know if there is a way to activate that with just a keyboard shortcut instead of needing the mouse?

As for the SALT code:

- features: 
  - enable: 
    - service.cups

I went back through my .sls files. I thought I had updated 3 (one for template, one for appvm, one for sys-usb), but I had only updated two. That alone could explain everything.

Given my poor coding performance here, I need to run some more tests before asking for additional help. Otherwise I’ll waste peoples time just to uncover I didn’t do what I thought I did…

1 Like

Use widget-click.sh clipboard with a keyboard shortcut:

1 Like