#!/bin/bash
echo "options nvidia_drm modeset=1" | sudo tee /etc/modprobe.d/nvidia.conf > /dev/null;

{
    echo "options nvidia NVreg_PreserveVideoMemoryAllocations=1";
    echo "options nvidia NVreg_TemporaryFilePath=/var/tmp";
} | sudo tee /etc/modprobe.d/nvidia-power-management.conf > /dev/null;

sudo sed -i \
    -e "/^HOOKS=(.* kms /{" \
        -e "h; s/^/#/; p;" \
        -e "g; s/ kms / /" \
    -e "}" \
    /etc/mkinitcpio.conf;

sudo mkinitcpio -P;

sudo systemctl enable \
    nvidia-suspend.service \
    nvidia-hibernate.service \
    nvidia-resume.service;

sudo rmmod nouveau && sudo modprobe nvidia || true;