From 1acf889c684cee7a0ed653aff42b33b5042da1d0 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 11 Jan 2025 13:48:46 -0500 Subject: [PATCH] Instll steam and the zfs_clone_send / zfs_clone_recv scripts. --- nix/configuration/configuration.nix | 2 + nix/configuration/roles/chromium/default.nix | 12 +++--- nix/configuration/roles/steam/default.nix | 38 +++++++++++++++++++ nix/configuration/roles/sway/default.nix | 7 ++++ nix/configuration/roles/zfs/default.nix | 18 +++++++++ .../roles/zfs/files/zfs_clone_recv.bash | 13 +++++++ .../roles/zfs/files/zfs_clone_send.bash | 8 ++++ .../util/unfree_polyfill/default.nix | 15 ++++++++ 8 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 nix/configuration/roles/steam/default.nix create mode 100644 nix/configuration/roles/zfs/files/zfs_clone_recv.bash create mode 100644 nix/configuration/roles/zfs/files/zfs_clone_send.bash create mode 100644 nix/configuration/util/unfree_polyfill/default.nix diff --git a/nix/configuration/configuration.nix b/nix/configuration/configuration.nix index 8f36dfa..feadb4d 100644 --- a/nix/configuration/configuration.nix +++ b/nix/configuration/configuration.nix @@ -10,6 +10,7 @@ { imports = [ ./roles/reset + ./util/unfree_polyfill ./roles/iso ./hosts/odo "${ @@ -43,6 +44,7 @@ ./roles/kubernetes ./roles/rust ./roles/media + ./roles/steam ]; nix.settings.experimental-features = [ diff --git a/nix/configuration/roles/chromium/default.nix b/nix/configuration/roles/chromium/default.nix index dbda5a1..fcee893 100644 --- a/nix/configuration/roles/chromium/default.nix +++ b/nix/configuration/roles/chromium/default.nix @@ -14,13 +14,11 @@ (chromium.override { enableWideVine = true; }) ]; - nixpkgs.config.allowUnfreePredicate = - pkg: - builtins.elem (lib.getName pkg) [ - "chromium" - "chromium-unwrapped" - "widevine-cdm" - ]; + allowedUnfree = [ + "chromium" + "chromium-unwrapped" + "widevine-cdm" + ]; environment.persistence."/persist" = lib.mkIf (!config.me.buildingIso) { hideMounts = true; diff --git a/nix/configuration/roles/steam/default.nix b/nix/configuration/roles/steam/default.nix new file mode 100644 index 0000000..4f7a32e --- /dev/null +++ b/nix/configuration/roles/steam/default.nix @@ -0,0 +1,38 @@ +{ + config, + lib, + pkgs, + ... +}: + +{ + imports = [ ]; + + options.me.games = lib.mkOption { + type = lib.types.bool; + default = config.me.graphical; + example = true; + description = "Whether we want to install games."; + }; + + config = ( + lib.mkMerge [ + (lib.mkIf config.me.games { + allowedUnfree = [ + "steam" + "steam-original" + "steam-unwrapped" + "steam-run" + ]; + + programs.steam = { + enable = true; + 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 + }; + }) + ] + ); + +} diff --git a/nix/configuration/roles/sway/default.nix b/nix/configuration/roles/sway/default.nix index c3f6e30..ffe187c 100644 --- a/nix/configuration/roles/sway/default.nix +++ b/nix/configuration/roles/sway/default.nix @@ -392,4 +392,11 @@ in # For mounting drives in pcmanfm services.gvfs.enable = true; + + # Auto-launch sway + environment.loginShellInit = '' + # TODO: This shouldn't be shoe-horned into the sway config + doas iw dev wlan0 set power_save off + [[ "$(tty)" = "/dev/tty1" ]] && exec sway + ''; } diff --git a/nix/configuration/roles/zfs/default.nix b/nix/configuration/roles/zfs/default.nix index fcdba6f..9544643 100644 --- a/nix/configuration/roles/zfs/default.nix +++ b/nix/configuration/roles/zfs/default.nix @@ -5,6 +5,20 @@ ... }: +let + zfs_clone_send = + (pkgs.writeScriptBin "zfs_clone_send" (builtins.readFile ./files/zfs_clone_send.bash)).overrideAttrs + (old: { + buildCommand = "${old.buildCommand}\n patchShebangs $out"; + + }); + zfs_clone_recv = + (pkgs.writeScriptBin "zfs_clone_recv" (builtins.readFile ./files/zfs_clone_recv.bash)).overrideAttrs + (old: { + buildCommand = "${old.buildCommand}\n patchShebangs $out"; + + }); +in { imports = [ ]; @@ -18,4 +32,8 @@ trim.enable = true; }; + environment.systemPackages = with pkgs; [ + zfs_clone_send + zfs_clone_recv + ]; } diff --git a/nix/configuration/roles/zfs/files/zfs_clone_recv.bash b/nix/configuration/roles/zfs/files/zfs_clone_recv.bash new file mode 100644 index 0000000..e51e2c7 --- /dev/null +++ b/nix/configuration/roles/zfs/files/zfs_clone_recv.bash @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +# +# A zfs-send alias that creates a perfect clone with good defaults. +set -euo pipefail +IFS=$'\n\t' +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +# -s if the stream is interrupted, save the partial stream. The stream can then be resumed by doing a zfs send -t token where token is the receive_resume_token prop on the dataset we received into. +# -u Do not mount the filesystem we are receiving. We can always mount afterwards but this avoids issues with streams with mountpoints to places like / +# Can optionally add -F to destroy the dataset in the recv location. +exec zfs recv -s -u "${@}" + +# To delete an interrupted recv, run `zfs receive -A dataset` diff --git a/nix/configuration/roles/zfs/files/zfs_clone_send.bash b/nix/configuration/roles/zfs/files/zfs_clone_send.bash new file mode 100644 index 0000000..92a325d --- /dev/null +++ b/nix/configuration/roles/zfs/files/zfs_clone_send.bash @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# +# A zfs-send alias that creates a perfect clone with good defaults. +set -euo pipefail +IFS=$'\n\t' +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +exec zfs send --compressed --replicate --large-block --embed --verbose --raw "${@}" diff --git a/nix/configuration/util/unfree_polyfill/default.nix b/nix/configuration/util/unfree_polyfill/default.nix new file mode 100644 index 0000000..d744cf4 --- /dev/null +++ b/nix/configuration/util/unfree_polyfill/default.nix @@ -0,0 +1,15 @@ +{ config, lib, ... }: + +let + inherit (builtins) elem; + inherit (lib) getName mkOption; + inherit (lib.types) listOf str; +in +{ + # Pending https://github.com/NixOS/nixpkgs/issues/55674 + options.allowedUnfree = mkOption { + type = listOf str; + default = [ ]; + }; + config.nixpkgs.config.allowUnfreePredicate = p: elem (getName p) config.allowedUnfree; +}