Salt/Jinja Context to generate a `.desktop` file to configure my desktop menu

Please guidance and resources.

I am writing an .sls to configure my desktop menu, but I’m failing and I need help to understand what is wrong. I inserted some tracing calls like: do salt.log.warning( str ), and that has helped, but I still think I must put more reading on Salt/Jinja context.

Output from sudo qubesctl --show-output state.highstate


[WARNING ] calling cp_files()
[WARNING ] inside for loop, vm:
[WARNING ] sec-blue
[WARNING ] inside kitty.set_vm( vm ), argument:
[WARNING ] sec-blue
[WARNING ] inside for loop, vm:
[WARNING ] sec-red
[WARNING ] inside kitty.set_vm( vm ), argument:
[WARNING ] sec-red
[WARNING ] 
sec-blue-menus-kitty-file:
  file.managed:
    - names:
      - ~/.local/share/qubes-appmenus/sec-blue/apps/org.qubes-os.vm.sec-blue.kitty.desktop:
        - source: salt://menus/org.qubes-os.vm.template.kitty.desktop
sec-blue-menus-kitty-icon:
  file.managed:
    - names:
      - ~/.local/share/qubes-appmenus/sec-blue/apps.icons/kitty.png
        - source: salt://menus/kitty.png

sec-blue-menus-conf-script:
  cmd.run:
    - require:
      - sec-blue-menus-kitty-file
    - name: 'bash $HOME/bkp/conf-salt/menus/conf-menus.sh sec-blue'

sec-red-menus-kitty-file:
  file.managed:
    - names:
      - ~/.local/share/qubes-appmenus/sec-red/apps/org.qubes-os.vm.sec-red.kitty.desktop:
        - source: salt://menus/org.qubes-os.vm.template.kitty.desktop
sec-red-menus-kitty-icon:
  file.managed:
    - names:
      - ~/.local/share/qubes-appmenus/sec-red/apps.icons/kitty.png
        - source: salt://menus/kitty.png

sec-red-menus-conf-script:
  cmd.run:
    - require:
      - sec-red-menus-kitty-file
    - name: 'bash $HOME/bkp/conf-salt/menus/conf-menus.sh sec-red'

[WARNING ] inside for loop, vm:
[WARNING ] sec-blue
[WARNING ] inside kitty.set_vm( vm ), argument:
[WARNING ] sec-blue
[WARNING ] inside for loop, vm:
[WARNING ] sec-red
[WARNING ] inside kitty.set_vm( vm ), argument:
[WARNING ] sec-red
[CRITICAL] Rendering SLS 'user:menus.conf' failed: mapping values are not allowed in this context


local:
    Data failed to compile:
----------
    Rendering SLS 'user:menus.conf' failed: mapping values are not allowed in this context
DOM0 configuration failed, not continuing

menus/conf.sls

# menus/conf.sls
# user: dom0:

{% set vms = [ 
     'sec-blue', 'sec-red'
] %}
{% set apps = [ 
     'kitty', 'vlc'
] %}

{% import "menus/org.qubes-os.vm.template.kitty.desktop" as kitty with context %}

{% macro cp_files( vms )%}
{% for vm in vms %}
{% do salt.log.warning( 'inside for loop, vm:' ) -%}
{% do salt.log.warning( vm ) -%}
{{ kitty.set_vm( vm ) }}
{{vm}}-menus-kitty-file:
  file.managed:
    - names:
      - ~/.local/share/qubes-appmenus/{{vm}}/apps/org.qubes-os.vm.{{vm}}.kitty.desktop:
        - source: salt://menus/org.qubes-os.vm.template.kitty.desktop
{{vm}}-menus-kitty-icon:
  file.managed:
    - names:
      - ~/.local/share/qubes-appmenus/{{vm}}/apps.icons/kitty.png
        - source: salt://menus/kitty.png

{{vm}}-menus-conf-script:
  cmd.run:
    - require:
      - {{vm}}-menus-kitty-file
    - name: 'bash $HOME/bkp/conf-salt/menus/conf-menus.sh {{vm}}'
{% endfor %}
{% endmacro %}

{% do salt.log.warning( 'calling cp_files()' ) -%}
# {% do salt.log.warning( cp_files( vms ) ) -%}
{{ cp_files( vms )}}


menus/org.qubes-os.vm.template.kitty.desktop

{% set vm = '' %}
{% macro set_vm ( i )%}
{% do salt.log.warning( 'inside kitty.set_vm( vm ), argument:' ) -%}
{% do salt.log.warning( i ) -%}
{% set vm = i %}
{% endmacro %}

[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
X-Qubes-VmName={{vm}}
X-Qubes-AppName=kitty
Icon=/home/xr/.local/share/qubes-appmenus/{{vm}}/apps.icons/kitty.png
Name={{vm}}: kitty
GenericName={{vm}}: Terminal emulator
Comment=A fast, feature full, GPU based terminal emulator
Categories=System;TerminalEmulator;X-Qubes-VM;
Exec=qvm-run -q -a --service -- {{vm}} qubes.StartApp+kitty
X-Qubes-DispvmExec=qvm-run -q -a --service --dispvm={{vm}} -- qubes.StartApp+kitty

menus/conf-menus.sh

#!/bin/bash
VM=$1

xdg-desktop-menu uninstall ~/.local/share/desktop-directories/qubes-vm-directory-${VM}.directory ~/.local/share/qubes-appmenus/sec-red/apps/org.qubes-os.vm.${VM}.thunderbird.desktop

xdg-desktop-menu install ~/.local/share/desktop-directories/qubes-vm-directory-${VM}.directory ~/.local/share/qubes-appmenus/sec-red/apps/org.qubes-os.vm.${VM}.kitty.desktop

Qubes: 4.1.2

I see a whole different approach by @unman here:
(https://github.com/unman/shaker/tree/main/mutt)

If I configure template VM menus, do all subsequent machines inherit it? - In this case, should I be just applying the SLS to my templates and forgetting about it on instances?

I’m not an expert but I stumbled across this error today and someone on a github issue Failed: mapping values are not allowed in this context · Issue #58910 · saltstack/salt · GitHub pointed out that there was a missing colon somewhere. Maybe there, after the first .../kitty.png ?

1 Like

Brilliant @parulin, thank you. This makes it work and leads me to file.managed giving me a series of:

Parent directory not present,

(which I solved switching the ~ for the absolute path),
and the cmd.run gave me several errors that I corrected changing the script’s path to absolute paths, adding the {{vm}} rather than the sec-red on the path.

And then i find out:

  1. Thunderbolt menu item is not removed.

  2. The desktop file was not generated by jinja, as the kitty menu item appears as {{vm}}: kitty, when it should be sec-red: kitty and sec-blue: kitty

This is solved now. As I stated above, by chance I stumbled up on:
(https://github.com/unman/shaker/tree/main/mutt)

And from there I manged to boil down the two only formulas needed:

  • qvm.features > menu-items and default-menu-items
  • qvm-sync-appmenus

The frustrating bit is we will not find it at (https://github.com/QubesOS/qubes-mgmt-salt-dom0-qvm/blob/master/README.rst#qvm-features). Is there any other place we can find these details, please?

menu-kitty:
  qvm.features:
    - require:
      - desktop-kitty
    - name: sec-blue 
    - set:
      - menu-items: "kitty.desktop"
      - default-menu-items: "kitty.desktop"

'qvm-sync-appmenus sec-blue':
  cmd.run:
    - require:
      - menu-kitty
    - runas: d0-user
1 Like

What details are you looking for? (Sorry I’m not undersdanting what “these details” refers to! :grimacing:)

The formula (nowhere documented), and the command (qvm-sync-appmenus)…

The definition of qvm.features is here:

And qvm-sync-appmenus:

1 Like