Mount ai-media storage on demand from the Backup volume

This commit is contained in:
2026-11-03 23:31:29 +01:00
parent bde34e19f4
commit 775840d3ef
7 changed files with 126 additions and 1 deletions

View File

@@ -8,6 +8,9 @@ gemini_cli_deploy_enabled: false
gemini_cli_uninstall_enabled: true
chatgpt_desktop_enabled: true
desktop_ai_media_enabled: true
desktop_ai_media_external_storage_enabled: true
desktop_ai_media_external_mountpoint: /run/media/fscotto/Backup
desktop_ai_media_external_source: /run/media/fscotto/Backup/ai-media
host_packages:
- podman

View File

@@ -2,6 +2,9 @@
desktop_ai_media_enabled: false
desktop_ai_media_root: "{{ user_home }}/.local/share/ai-media"
desktop_ai_media_build_root: "{{ user_home }}/.local/share/ai-media-build"
desktop_ai_media_external_storage_enabled: false
desktop_ai_media_external_mountpoint: ""
desktop_ai_media_external_source: ""
desktop_ai_media_debian_snapshot: "20261013T000000Z"
desktop_ai_media_base_image: >-
docker.io/library/python@sha256:34386ef0cb081344d7ec1c103ba398e6e9f64e9ab3a1509accc92a4e24a07258

View File

@@ -15,12 +15,23 @@ for line in pathlib.Path("/proc/self/mountinfo").read_text().splitlines():
fields, description = line.split(" - ", 1)
mount = re.sub(r"\\([0-7]{3})", lambda m: chr(int(m[1], 8)), fields.split()[4])
mounts.append((pathlib.Path(mount), description.split()[0]))
covering = [(p, kind) for p, kind in mounts if root == p or root.is_relative_to(p)]
automount_at_root = any(p == root and kind == "autofs" for p, kind in mounts)
backing_mount_at_root = any(
p == root and kind != "autofs" for p, kind in mounts
)
if automount_at_root and not backing_mount_at_root:
raise SystemExit("Media storage automount is not active; refusing to start")
covering = [
(p, kind) for p, kind in mounts
if kind != "autofs" and (root == p or root.is_relative_to(p))
]
if covering:
selected = max(covering, key=lambda entry: len(entry[0].parts))
if selected[1] not in local_filesystems:
raise SystemExit("Media storage is not on a local filesystem; refusing to start")
for mount, kind in mounts:
if mount == root and kind == "autofs":
continue
if mount.is_relative_to(root) and kind not in local_filesystems:
raise SystemExit("Non-local mount beneath media storage; refusing to start")
sync_roots = []

View File

@@ -0,0 +1,4 @@
---
- name: Reload systemd units
ansible.builtin.systemd_service:
daemon_reload: true

View File

@@ -1,4 +1,86 @@
---
- name: Configure on-demand external ai-media storage
become: true
when: desktop_ai_media_external_storage_enabled | bool
tags: [ai_media, ai_media_storage]
block:
- name: Validate external ai-media storage paths
ansible.builtin.assert:
that:
- desktop_ai_media_external_mountpoint is match('^/run/media/[^/]+/[^/]+$')
- desktop_ai_media_external_source.startswith(desktop_ai_media_external_mountpoint + '/')
- desktop_ai_media_external_source != desktop_ai_media_external_mountpoint
- desktop_ai_media_root.startswith(user_home + '/')
- desktop_ai_media_root != user_home
- name: Derive external source mount unit name
ansible.builtin.command:
argv:
- systemd-escape
- -p
- --suffix=mount
- "{{ desktop_ai_media_external_mountpoint }}"
register: desktop_ai_media_external_source_mount_unit
changed_when: false
check_mode: false
- name: Derive ai-media bind mount unit name
ansible.builtin.command:
argv:
- systemd-escape
- -p
- --suffix=mount
- "{{ desktop_ai_media_root }}"
register: desktop_ai_media_bind_mount_unit
changed_when: false
check_mode: false
- name: Derive ai-media bind automount unit name
ansible.builtin.command:
argv:
- systemd-escape
- -p
- --suffix=automount
- "{{ desktop_ai_media_root }}"
register: desktop_ai_media_bind_automount_unit
changed_when: false
check_mode: false
- name: Create ai-media mount destination in the user home
ansible.builtin.file:
path: "{{ desktop_ai_media_root }}"
state: directory
owner: "{{ username }}"
group: "{{ username }}"
mode: "0700"
- name: Install ai-media bind mount unit
ansible.builtin.template:
src: ai-media-bind.mount.j2
dest: "/etc/systemd/system/{{ desktop_ai_media_bind_mount_unit.stdout }}"
owner: root
group: root
mode: "0644"
notify: Reload systemd units
- name: Install ai-media bind automount unit
ansible.builtin.template:
src: ai-media-bind.automount.j2
dest: "/etc/systemd/system/{{ desktop_ai_media_bind_automount_unit.stdout }}"
owner: root
group: root
mode: "0644"
notify: Reload systemd units
- name: Flush systemd unit changes
ansible.builtin.meta: flush_handlers
- name: Enable and start ai-media bind automount
ansible.builtin.systemd_service:
name: "{{ desktop_ai_media_bind_automount_unit.stdout }}"
enabled: true
state: started
- name: Configure isolated desktop media tools as the desktop user
become: false
block:

View File

@@ -0,0 +1,10 @@
[Unit]
Description=On-demand ai-media bind mount from the Backup LUKS volume
ConditionPathIsDirectory={{ desktop_ai_media_root }}
[Automount]
Where={{ desktop_ai_media_root }}
TimeoutIdleSec=5min
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,12 @@
[Unit]
Description=Bind mount ai-media from the Backup LUKS volume
RequiresMountsFor={{ desktop_ai_media_external_mountpoint }}
After={{ desktop_ai_media_external_source_mount_unit.stdout }}
BindsTo={{ desktop_ai_media_external_source_mount_unit.stdout }}
ConditionPathIsMountPoint={{ desktop_ai_media_external_mountpoint }}
ConditionPathIsDirectory={{ desktop_ai_media_external_source }}
[Mount]
What={{ desktop_ai_media_external_source }}
Where={{ desktop_ai_media_root }}
Options=bind