Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

steam: init with option to install adwaita theme #696

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

brckd
Copy link
Contributor

@brckd brckd commented Dec 23, 2024

This adds the steam module and its adwaitaForSteam.enable option, which installs Adwaita for Steam with the Stylix color palette. This is a slightly modifed version of #551 (comment) and resolves #551. Note that Adwaita for Steam is installed directly on the host system using an activation script.

Preview Adwaita for Steam with the Catppuccin Mocha theme applied by Stylix

Adwaita for Steam preview

@reedrw Are you OK with me using most parts of your suggested code here?

@brckd brckd force-pushed the steam/init-adwaita-for-steam branch from eadc2fa to 7108ef4 Compare December 23, 2024 22:00
@brckd
Copy link
Contributor Author

brckd commented Dec 25, 2024

In case the uncontained nature of the activation script is a problem, I can try to implement the solution suggested in #551 (comment).

Copy link
Collaborator

@trueNAHO trueNAHO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reedrw Are you OK with me using most parts of your suggested code here?

Ideally, their contribution should be acknowledged by specifying their Git credentials with a Co-authored-by: tag in the commit body.

modules/steam/hm.nix Outdated Show resolved Hide resolved
modules/steam/hm.nix Outdated Show resolved Hide resolved
(lib.mkIf cfg.adwaitaForSteam.enable {
home.packages = with pkgs; [adwsteamgtk];

home.activation.adwaitaForSteam = let
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case the uncontained nature of the activation script is a problem, I can try to implement the solution suggested in #551 (comment).

Is it possible to make this reproducible? ${lib.getExe pkgs.adwsteamgtk} --install does not sound very reproducible.

Copy link
Contributor Author

@brckd brckd Dec 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One could probably run this script in a stdenv and extract the relevant files, or better yet, extract them from the source repository.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracting the necessary files from the source repo is definitely the best solution, as the activation hook hack isn't easily reversible should a user choose to disable it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

modules/steam/hm.nix Outdated Show resolved Hide resolved
@brckd brckd force-pushed the steam/init-adwaita-for-steam branch from 94c9912 to 46553d7 Compare December 26, 2024 22:36
modules/steam/custom.mustache Outdated Show resolved Hide resolved
@reedrw
Copy link

reedrw commented Dec 27, 2024

Looking into the install script, it seems that the only file directly overwritten is library.css (located at ~/.local/share/Steam/steamui/css/library.css), while the stylesheets and custom colorscheme are copied directly from the source repo into ~/.local/share/Steam/steamui/adwaita. I think it should be possible to do everything besides library.css purely.

Running the install script in stdenv is quite easy, see proof of concept here:

pkgs.stdenv.mkDerivation (self: {
  name = "Adwaita-for-Steam";
  version = "3.1";

  src = pkgs.fetchFromGitHub {
    owner = "tkashkin";
    repo = "Adwaita-for-Steam";
    rev = "v${self.version}";
    sha256 = "sha256-V2Ps4jP7UeoXTY1q7gLbWVQW9WwUzMM6RPYUvNDAJ0I=";
  };

  buildInputs = with pkgs; [
    python3
  ];

  buildPhase = ''
    mkdir -p $out/steamui/css
    touch $out/steamui/css/library.css
    python3 install.py -t $out
  '';
});

I think running the install script in stdenv is a fairly good way to do things, as it will make it easy to customize the install parameters through our home-manager module

@brckd
Copy link
Contributor Author

brckd commented Dec 28, 2024

This looks perfect! It's both flexible by using the official CLI and it's isolated by being wrapped in a derivation. I'll try to integrate your solution into the stylix module tomorrow.

@reedrw
Copy link

reedrw commented Dec 28, 2024

it seems that the only file directly overwritten is library.css (located at ~/.local/share/Steam/steamui/css/library.css)

Even better, if this file goes missing, steam will just redownload the stock version, so it should be fine to let home-manager link this as well

Edit: nevermind. Steam will redownload library.css if it is a symlink

@brckd
Copy link
Contributor Author

brckd commented Dec 29, 2024

Edit: nevermind. Steam will redownload library.css if it is a symlink

Related comment tkashkin/Adwaita-for-Steam#120 (comment). I wonder if there is any way to circumvent this, like symlinking a read only parent directory to prevent steam from writing to it. Otherwise, the only option to uninstall the theme might be to run a script that removes the library.css whenever the theme is disabled.
Judging from tkashkin/Adwaita-for-Steam#120 it seems like overriding the file wasn't required before, but is now.

Edit: Symlinking parent directories seems to leave steam in a startup loop.

@brckd
Copy link
Contributor Author

brckd commented Dec 30, 2024

@reedw I found the reason this version wasn't working! It seems like the css/library.css file is padded to match the filesize of the same file generated by Steam. This isn't the case in the stdenv because the file generated by Steam isn't provided.
This is probably also the reason symlinking didn't work, because the symlink itself doesn't match the filesize of the original file. I will try if we can pad the symlink in the same way to circumvent Steam's check.

Edit: This doesn't seem possible because Home Manager can't read local files in pure evaluation.

@reedrw
Copy link

reedrw commented Dec 31, 2024

This is probably also the reason symlinking didn't work

Within bootstrap_log.txt (~/.local/share/Steam/logs/bootstrap_log.txt) I see the following line:

BVerifyInstalledFiles: bad symlink ( steamui/css/library.css -> /nix/store/qdi8s371hjx3c32avyygns388aflgyfk-home-manager-files/.local/share/Steam/steamui/css/library.css, expected non-symlink )

So I assume Steam is not happy with it being a symlink whatsoever

@brckd
Copy link
Contributor Author

brckd commented Jan 1, 2025

The only solution I can imagine is to run a specified version of steam to replicate the local configuration and then run the script in the same container.

@trueNAHO
Copy link
Collaborator

trueNAHO commented Jan 1, 2025

Any way we can conveniently patch Steam or wrap it:

wrapProgram $out/bin/steam \
  --please-work /nix/store/<HASH>-home-manager-files/.local/share/Steam/steamui/css/library.css

@brckd
Copy link
Contributor Author

brckd commented Jan 1, 2025

I'm not familiar with wrapProgram, so what I'm about to say may turn out completely wrong, but I think any attempt automating the generation of Steam's default theme will fail. AFAIK the theme is generated when the Steam GUI first starts up during the Updating Steam dialogue. Since the Steam binary lacks any CLI capabilities, it's impossible to reproducibly control this progress. The dialogue usually takes quite long as well. which would make automating it very inefficient. We would probably have to start Steam and listen for when the theme file is created to stop the application again.

@brckd
Copy link
Contributor Author

brckd commented Jan 1, 2025

I just found this useful information.

Every time you start Steam, it checks the integrity of every file and re-downloads files that have been changed.
To prevent this, add the -noverifyfiles and -norepairfiles flags to your steam shortcut

Sadly this was the only documentation I found on Steam's CLI capabilities so far. But I was able to confirm that running steam -noverifyfiles -norepairfiles with a non-padded library.css file worked. This solution would successfully install and display the custom theme, but it will miss CSS declaration for components not covered by the custom theme, making the app less usable.

Edit: There is some useful information on Steam's CLI in https://developer.valvesoftware.com/wiki/Command_line_options#Steam

@brckd
Copy link
Contributor Author

brckd commented Jan 1, 2025

I'm not familiar with wrapProgram, so what I'm about to say may turn out completely wrong, but I think any attempt automating the generation of Steam's default theme will fail. AFAIK the theme is generated when the Steam GUI first starts up during the Updating Steam dialogue. Since the Steam binary lacks any CLI capabilities, it's impossible to reproducibly control this progress. The dialogue usually takes quite long as well. which would make automating it very inefficient. We would probably have to start Steam and listen for when the theme file is created to stop the application again.

Forget what I said, SteamCMD seems to be "updating Steam" the same way the GUI does. It even downloads the required theme files. This solves most of the problems I was pointing to. I only have to see if this works without logging in too.

Edit: Derivations don't have access to the internet so this doesn't work.

@brckd
Copy link
Contributor Author

brckd commented Jan 4, 2025

Edit: Derivations don't have access to the internet so this doesn't work.

What I meant by this is that SteamCMD, which is used to generate the library.css required by the theme, requires internet access to fetch its files. This is usually not possible in derivations, but as https://discourse.nixos.org/t/how-do-i-access-internet-inside-nix-build/7671/5 suggests, we could use a fixed-output derivation. But this only works if the returned files always matches the same hash. Sounds like a plan, right?

@trueNAHO
Copy link
Collaborator

trueNAHO commented Jan 4, 2025

But this only works if the returned files always matches the same hash.

If we fetch an unpinned version, like the latest version, instead of a pinned version, this solution will inevitably break in the future.

Seems like Steam itself is the problem...

Sounds like a plan, right?

@danth, do you know how we could resolve this issue?

@brckd brckd force-pushed the steam/init-adwaita-for-steam branch from e686d4d to 321e43b Compare January 5, 2025 01:23
brckd and others added 5 commits January 6, 2025 17:36
This adds the steam module and its adwaitaForSteam.enable option which
installs Adwaita for Steam with the Stylix color palette. Note that
Adwaita for Steam is installed directly on the host system using an
activation script.

Co-authored-by: Reed <[email protected]>
@brckd brckd force-pushed the steam/init-adwaita-for-steam branch from 321e43b to 73df133 Compare January 6, 2025 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

steam: add support using Adwaita-for-Steam
3 participants