From 27040532bdfa2dcfb5c557cfb2e50bc7c01d38cd Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 15 Sep 2021 18:13:47 +0200 Subject: [PATCH] modules: programs: steam: respect XDG conventions Steam wants to pollute HOME with `.steam*` files and folders, which are useless and annoying. We want to make sure the wrappers are preferred when installing, so use `lib.hiPrio` to ensure they get chosen. --- modules/programs/steam.nix | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/modules/programs/steam.nix b/modules/programs/steam.nix index e9f2a2b..dbdc0ce 100644 --- a/modules/programs/steam.nix +++ b/modules/programs/steam.nix @@ -1,15 +1,39 @@ -{ config, lib, ... }: +{ config, lib, pkgs, ... }: let cfg = config.my.programs.steam; in { options.my.programs.steam = with lib; { enable = mkEnableOption "steam configuration"; + + dataDir = mkOption { + type = types.str; + default = "$XDG_DATA_HOME/steamlib"; + example = "/mnt/steam/"; + description = '' + Which directory should be used as HOME to run steam. + ''; + }; }; config = lib.mkIf cfg.enable { programs.steam = { enable = true; }; + + environment.systemPackages = builtins.map lib.hiPrio [ + # Respect XDG conventions, leave my HOME alone + (pkgs.writeScriptBin "steam" '' + #!/bin/sh + mkdir -p "${cfg.dataDir}" + HOME="${cfg.dataDir}" exec ${pkgs.steam}/bin/steam "$@" + '') + # Same, for GOG and other such games + (pkgs.writeScriptBin "steam-run" '' + #!/bin/sh + mkdir -p "${cfg.dataDir}" + HOME="${cfg.dataDir}" exec ${pkgs.steam-run-native}/bin/steam-run "$@" + '') + ]; }; }