diff --git a/flake.lock b/flake.lock index 57bf3d0..3f854b8 100644 --- a/flake.lock +++ b/flake.lock @@ -768,6 +768,22 @@ "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": { "inputs": { "nixpkgs": [ @@ -3213,6 +3229,7 @@ "impermanence": "impermanence", "neovim": "neovim", "nix-darwin": "nix-darwin", + "nix-flatpak": "nix-flatpak", "nix-gaming": "nix-gaming", "nix-on-droid": "nix-on-droid", "nixos-facter-modules": "nixos-facter-modules", diff --git a/flake.nix b/flake.nix index 1af1595..0c75fc9 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ }; hyprland.url = "github:hyprwm/Hyprland"; 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"; #nur.url = "github:nix-community/NUR"; diff --git a/nixos/configuration.nix b/nixos/configuration.nix index 33a17e8..9876425 100644 --- a/nixos/configuration.nix +++ b/nixos/configuration.nix @@ -19,6 +19,8 @@ inputs.disko.nixosModules.default ./modules/firefox + ./modules/flatpak + ./modules/steam ./modules/services/autoupgrade ./modules/sops ./hosts/${hwconfig.hostname} @@ -73,6 +75,13 @@ # networking.proxy.default = "http://user:password@proxy:port/"; # 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 networking.networkmanager.enable = true; @@ -247,13 +256,6 @@ 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 = { # enable = true; # plugins = with pkgs.xfce; [ @@ -338,6 +340,8 @@ # enableSSHSupport = true; # }; + kk.steam.enable = hwconfig.system == "x86_64-linux"; + # List services that you want to enable: # Enable the OpenSSH daemon. diff --git a/nixos/modules/flatpak/default.nix b/nixos/modules/flatpak/default.nix new file mode 100644 index 0000000..af7e69d --- /dev/null +++ b/nixos/modules/flatpak/default.nix @@ -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; + }; +} diff --git a/nixos/modules/impermanence/default.nix b/nixos/modules/impermanence/default.nix index e9e4af8..4ad2af6 100644 --- a/nixos/modules/impermanence/default.nix +++ b/nixos/modules/impermanence/default.nix @@ -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/ 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/ 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 '''' + ); } diff --git a/nixos/modules/impermanence/home.nix b/nixos/modules/impermanence/home.nix index bb9be0e..6b34848 100644 --- a/nixos/modules/impermanence/home.nix +++ b/nixos/modules/impermanence/home.nix @@ -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" diff --git a/nixos/modules/steam/default.nix b/nixos/modules/steam/default.nix new file mode 100644 index 0000000..4c1b80d --- /dev/null +++ b/nixos/modules/steam/default.nix @@ -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 + }; + } + ); +}