Added steam and flatpak modules. Fixed steam with impermanence

This commit is contained in:
Aleksandr Lebedev 2025-01-12 19:49:59 +01:00
parent 37f843170a
commit 47412f3ecf
7 changed files with 171 additions and 83 deletions

View file

@ -0,0 +1,19 @@
{
pkgs,
lib,
inputs,
config,
...
}: let
cfg = config.kk.services.flatpak;
in {
imports = [
inputs.nix-flatpak.nixosModules.nix-flatpak
];
options.kk.services.flatpak = {
enable = lib.mkEnableOption "enable flatpaks";
};
config = lib.mkIf cfg.enable {
services.flatpak.enable = true;
};
}

View file

@ -1,57 +1,73 @@
{ config, lib, inputs, ... }:
let
isBtrfs = config.fileSystems."/".fsType == "btrfs";
in
{
imports = [
inputs.impermanence.nixosModules.impermanence
];
fileSystems."/persist".neededForBoot = true;
environment.persistence."/persist/system" = {
config,
lib,
inputs,
...
}: let
isBtrfs = config.fileSystems."/".fsType == "btrfs";
in {
imports = [
inputs.impermanence.nixosModules.impermanence
];
fileSystems."/persist".neededForBoot = true;
environment.persistence."/persist/system" = {
hideMounts = true;
directories = [
"/etc/nixos"
"/var/log"
"/var/lib/bluetooth"
"/var/lib/nixos"
"/var/lib/systemd/coredump"
"/etc/NetworkManager/system-connections"
{ directory = "/var/lib/colord"; user = "colord"; group = "colord"; mode = "u=rwx,g=rx,o="; }
"/etc/nixos"
"/var/log"
"/var/lib/bluetooth"
"/var/lib/nixos"
"/var/lib/flatpak"
"/var/lib/systemd/coredump"
"/etc/NetworkManager/system-connections"
{
directory = "/var/lib/colord";
user = "colord";
group = "colord";
mode = "u=rwx,g=rx,o=";
}
];
files = [
"/etc/machine-id"
{ file = "/var/keys/secret_file"; parentDirectory = { mode = "u=rwx,g=,o="; }; }
];
};
systemd.tmpfiles.rules = [
"d /persist/home/ 0777 root root -" # /persist/home created, owned by root
#"d /persist/home/${username} 0700 ${username} users -" # /persist/home/<user> created, owned by that user
#"d /persist/nixos-config 0700 ${username} users -"
"/etc/machine-id"
{
file = "/var/keys/secret_file";
parentDirectory = {mode = "u=rwx,g=,o=";};
}
];
};
systemd.tmpfiles.rules = [
"d /persist/home/ 0777 root root -" # /persist/home created, owned by root
#"d /persist/home/${username} 0700 ${username} users -" # /persist/home/<user> created, owned by that user
#"d /persist/nixos-config 0700 ${username} users -"
];
programs.fuse.userAllowOther = true;
boot.initrd.postDeviceCommands = lib.mkAfter (if isBtrfs then ''
mkdir /btrfs_tmp
mount /dev/root_vg/root /btrfs_tmp
if [[ -e /btrfs_tmp/root ]]; then
mkdir -p /btrfs_tmp/old_roots
timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/root)" "+%Y-%m-%-d_%H:%M:%S")
mv /btrfs_tmp/root "/btrfs_tmp/old_roots/$timestamp"
fi
programs.fuse.userAllowOther = true;
boot.initrd.postDeviceCommands = lib.mkAfter (
if isBtrfs
then ''
mkdir /btrfs_tmp
mount /dev/root_vg/root /btrfs_tmp
if [[ -e /btrfs_tmp/root ]]; then
mkdir -p /btrfs_tmp/old_roots
timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/root)" "+%Y-%m-%-d_%H:%M:%S")
mv /btrfs_tmp/root "/btrfs_tmp/old_roots/$timestamp"
fi
delete_subvolume_recursively() {
IFS=$'\n'
for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do
delete_subvolume_recursively "/btrfs_tmp/$i"
done
btrfs subvolume delete "$1"
}
delete_subvolume_recursively() {
IFS=$'\n'
for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do
delete_subvolume_recursively "/btrfs_tmp/$i"
done
btrfs subvolume delete "$1"
}
for i in $(find /btrfs_tmp/old_roots/ -maxdepth 1 -mtime +30); do
delete_subvolume_recursively "$i"
done
for i in $(find /btrfs_tmp/old_roots/ -maxdepth 1 -mtime +30); do
delete_subvolume_recursively "$i"
done
btrfs subvolume create /btrfs_tmp/root
umount /btrfs_tmp
'' else '''');
btrfs subvolume create /btrfs_tmp/root
umount /btrfs_tmp
''
else ''''
);
}

View file

@ -1,34 +1,37 @@
{ username, inputs, ... }:
{
imports = [
inputs.impermanence.nixosModules.home-manager.impermanence
];
home.persistence."/persist/home/${username}" = {
username,
inputs,
...
}: {
imports = [
inputs.impermanence.nixosModules.home-manager.impermanence
];
home.persistence."/persist/home/${username}" = {
directories = [
"Downloads"
"Music"
"Pictures"
"Documents"
"Videos"
"VMs"
"Git"
"nixos-config"
"blender"
".gnupg"
".ssh"
".nixops"
".local/share/keyrings"
".local/share/direnv"
{
directory = ".local/share/Steam";
#method = "symlink";
}
".steam"
".mozilla"
".local/share/TelegramDesktop"
".config/solaar"
".config/kdeconnect"
".config/blender"
"Downloads"
"Music"
"Pictures"
"Documents"
"Videos"
"VMs"
"Git"
"nixos-config"
"blender"
".gnupg"
".ssh"
".nixops"
".local/share/keyrings"
".local/share/direnv"
#{
# directory = ".local/share/Steam";
# method = "symlink";
#}
#".steam"
".mozilla"
".local/share/TelegramDesktop"
".config/solaar"
".config/kdeconnect"
".config/blender"
];
files = [
".screenrc"

View file

@ -0,0 +1,29 @@
{
pkgs,
lib,
config,
hwconfig,
...
}: let
cfg = config.kk.steam;
in {
options.kk.steam = {
enable = lib.mkEnableOption "Enable steam";
};
config = lib.mkIf cfg.enable (
if hwconfig.useImpermanence
then {
kk.services.flatpak.enable = lib.mkForce true;
services.flatpak.packages = ["com.valvesoftware.Steam"];
}
else {
programs.steam = {
enable = !hwconfig.useImpermanence;
remotePlay.openFirewall = true; # Open ports in the firewall for Steam Remote Play
dedicatedServer.openFirewall = true; # Open ports in the firewall for Source Dedicated Server
localNetworkGameTransfers.openFirewall = true; # Open ports in the firewall for Steam Local Network Game Transfers
};
}
);
}