mirror of
https://github.com/fscotto/infra.git
synced 2026-05-30 15:39:58 +00:00
Previously the task hardcoded GRUB_CMDLINE_LINUX to a fixed string containing nymph's rd.luks.uuid, rootflags and apparmor parameters, clobbering whatever the host had. Switch to an idempotent lineinfile-with-backrefs loop that appends nouveau.modeset=0 and nvidia-drm.modeset=1 only when missing, preserving the existing kernel cmdline. grub-mkconfig now runs only when the cmdline changed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
47 lines
1.6 KiB
YAML
47 lines
1.6 KiB
YAML
---
|
|
- name: Ensure NVIDIA kernel parameters are present in GRUB cmdline
|
|
tags: [packages, nvidia]
|
|
ansible.builtin.lineinfile:
|
|
path: /etc/default/grub
|
|
backrefs: true
|
|
regexp: '^(GRUB_CMDLINE_LINUX="(?!.*{{ item | regex_escape }}).*)"$'
|
|
line: '\1 {{ item }}"'
|
|
loop:
|
|
- nouveau.modeset=0
|
|
- nvidia-drm.modeset=1
|
|
register: nymph_grub_cmdline
|
|
|
|
- name: Regenerate GRUB configuration
|
|
tags: [packages, nvidia]
|
|
ansible.builtin.command: grub-mkconfig -o /boot/grub/grub.cfg
|
|
changed_when: true
|
|
when: nymph_grub_cmdline is changed
|
|
|
|
- name: Configure NVIDIA power management for hybrid graphics
|
|
tags: [packages, nvidia]
|
|
ansible.builtin.copy:
|
|
dest: /etc/modprobe.d/nvidia-power-management.conf
|
|
content: |
|
|
options nvidia "NVreg_DynamicPowerManagement=0x02"
|
|
owner: root
|
|
group: root
|
|
mode: "0644"
|
|
|
|
- name: Install prime-run wrapper script for NVIDIA PRIME offload
|
|
tags: [nvidia, dotfiles, dotfiles:host]
|
|
ansible.builtin.copy:
|
|
src: "{{ playbook_dir }}/../dotfiles/nymph/.local/bin/prime-run"
|
|
dest: "{{ user_home }}/.local/bin/prime-run"
|
|
owner: "{{ username }}"
|
|
group: "{{ user_group }}"
|
|
mode: "0755"
|
|
force: false
|
|
|
|
- name: Wrap alacritty with prime-run for NVIDIA PRIME offload
|
|
tags: [nvidia, dotfiles, dotfiles:desktop, dotfiles:host]
|
|
ansible.builtin.lineinfile:
|
|
path: "{{ user_home }}/.config/i3/config"
|
|
regexp: '^bindsym \$mod\+Return exec --no-startup-id /usr/bin/alacritty'
|
|
line: 'bindsym $mod+Return exec --no-startup-id ~/.local/bin/prime-run /usr/bin/alacritty'
|
|
when: "'i3' in (desktop_sessions_enabled | default([]))"
|