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

17
flake.lock generated
View file

@ -768,6 +768,22 @@
"type": "github" "type": "github"
} }
}, },
"nix-flatpak": {
"locked": {
"lastModified": 1734128415,
"narHash": "sha256-HLwdVNxpuTsLlM3tCkpbQU6yCehdgf3kOS1G2SDlkzY=",
"owner": "gmodena",
"repo": "nix-flatpak",
"rev": "8bdc2540da516006d07b04019eb57ae0781a04b3",
"type": "github"
},
"original": {
"owner": "gmodena",
"ref": "latest",
"repo": "nix-flatpak",
"type": "github"
}
},
"nix-formatter-pack": { "nix-formatter-pack": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": [
@ -3213,6 +3229,7 @@
"impermanence": "impermanence", "impermanence": "impermanence",
"neovim": "neovim", "neovim": "neovim",
"nix-darwin": "nix-darwin", "nix-darwin": "nix-darwin",
"nix-flatpak": "nix-flatpak",
"nix-gaming": "nix-gaming", "nix-gaming": "nix-gaming",
"nix-on-droid": "nix-on-droid", "nix-on-droid": "nix-on-droid",
"nixos-facter-modules": "nixos-facter-modules", "nixos-facter-modules": "nixos-facter-modules",

View file

@ -11,7 +11,7 @@
}; };
hyprland.url = "github:hyprwm/Hyprland"; hyprland.url = "github:hyprwm/Hyprland";
stylix.url = "github:danth/stylix"; stylix.url = "github:danth/stylix";
#nix-flatpak.url = "github:GermanBread/declarative-flatpak/stable-v3"; nix-flatpak.url = "github:gmodena/nix-flatpak/?ref=latest";
apple-silicon-support.url = "github:tpwrules/nixos-apple-silicon"; apple-silicon-support.url = "github:tpwrules/nixos-apple-silicon";
#nur.url = "github:nix-community/NUR"; #nur.url = "github:nix-community/NUR";

View file

@ -19,6 +19,8 @@
inputs.disko.nixosModules.default inputs.disko.nixosModules.default
./modules/firefox ./modules/firefox
./modules/flatpak
./modules/steam
./modules/services/autoupgrade ./modules/services/autoupgrade
./modules/sops ./modules/sops
./hosts/${hwconfig.hostname} ./hosts/${hwconfig.hostname}
@ -73,6 +75,13 @@
# networking.proxy.default = "http://user:password@proxy:port/"; # networking.proxy.default = "http://user:password@proxy:port/";
# networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain"; # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";
#flatpak
kk.services.flatpak.enable = true;
services.flatpak.packages = [
"com.super_productivity.SuperProductivity"
"net.cozic.joplin_desktop"
];
# Enable networking # Enable networking
networking.networkmanager.enable = true; networking.networkmanager.enable = true;
@ -247,13 +256,6 @@
security.polkit.enable = true; security.polkit.enable = true;
programs.steam = {
enable = hwconfig.system == "x86_64-linux";
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
};
#programs.thunar = { #programs.thunar = {
# enable = true; # enable = true;
# plugins = with pkgs.xfce; [ # plugins = with pkgs.xfce; [
@ -338,6 +340,8 @@
# enableSSHSupport = true; # enableSSHSupport = true;
# }; # };
kk.steam.enable = hwconfig.system == "x86_64-linux";
# List services that you want to enable: # List services that you want to enable:
# Enable the OpenSSH daemon. # Enable the OpenSSH daemon.

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

View file

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