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

nixos/steam: add option extraPackages fontPackages, fix CJK fonts on client #312268

Merged
merged 2 commits into from
May 26, 2024

Conversation

Cryolitia
Copy link
Member

@Cryolitia Cryolitia commented May 16, 2024

Description of changes

  1. Add a new option programs.steam.extraPackages to add to the Steam environment.
  2. Add config.fonts.packages to extraPackages to fix all Chinese and Japanese text in the Steam interface display as boxes ("tofu"). As we use the existing fonts on the system, this avoids closure impact. It was first came up by nixos/steam: support using system fonts in Steam interface #302591 that reverted by Revert "nixos/steam: ensure Steam picks up font packages" #302748
  3. Add dependencies required by gamescope, to fix undefined symbols in X11 session. Came up by @BillHuang2001 in Packaging Request: GameScope #162562 (comment) .
    - fix steam: gamescope fails to launch when used from within steam #214275
  4. Format nixos/modules/programs/steam.nix by nixfmt-rfc-style
  5. Add a new option programs.steam.fontPackages, just let user to choose whatever font they like, to end argue in nixos/steam: include fonts from system #302862

This PR has tested on my machine.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.05 Release Notes (or backporting 23.05 and 23.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

CC:


Add a 👍 reaction to pull requests you find important.

Copy link
Contributor

@pluiedev pluiedev left a comment

Choose a reason for hiding this comment

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

Slight wording change

nixos/modules/programs/steam.nix Outdated Show resolved Hide resolved
@K900
Copy link
Contributor

K900 commented May 22, 2024

Please just add those two packages unconditionally into the standard Steam fhsenv, and please check if fonts.fontconfig.cache32Bit without any of the changes here fixes your Steam fonts.

@Cryolitia
Copy link
Member Author

Cryolitia commented May 22, 2024

image
On my machine, fonts.fontconfig.cache32Bit not works for me.

In case of providing font packages to steam and setting as fontconfig:

    fontconfig = {
      defaultFonts = {
        emoji = [
          "Source Han Serif SC"
          "JetBrainsMono Nerd Font"
          "Noto Color Emoji"
        ];
        monospace = [
          "Source Han Serif SC"
          "Sarasa Mono SC"
          "JetBrainsMono Nerd Font Mono"
        ];
        sansSerif = [ "Source Han Serif SC" ];
        serif = [ "Source Han Serif SC" ];
      };
      cache32Bit = true;
    };

@K900
Copy link
Contributor

K900 commented May 22, 2024

Is there an easy way to test this locally? I don't see anything wrong with that screenshot.

@Cryolitia
Copy link
Member Author

Cryolitia commented May 22, 2024

Is there an easy way to test this locally? I don't see anything wrong with that screenshot.

I set Source Han Serif SC. All CJK should be serif whatever the application actually asked. For example, CJK in kitty is serif. But steam is still sans. To proof that steam is not following font-config.

@K900
Copy link
Contributor

K900 commented May 22, 2024

And adding the font to the fhsenv actually makes it work? Can you run fc-match in the fhsenv?

@eclairevoyant
Copy link
Member

eclairevoyant commented May 22, 2024

For fonts, it's very likely we just need to enable fonts.fontconfig.cache32Bit and Steam will work automagically with system fonts.

This doesn't work for me.

image

Feel free to check https://store.steampowered.com/app/1647250/KUUKIYOMI_3_Consider_It_More_and_More__Father_to_Son/ as an example.

If I use both fonts.fontconfig.cache32Bit and add config.fonts.packages to extraPkgs, it's the same as simply adding config.fonts.packages to extraPkgs, i.e. fontconfig is still ignored.

@Cryolitia
Copy link
Member Author

In case of providing font packages to steam and setting as fontconfig:

And in case of not providing, steam is still Tofu block.

@Cryolitia
Copy link
Member Author

Cryolitia commented May 22, 2024

And adding the font to the fhsenv actually makes it work? Can you run fc-match in the fhsenv?

Adding the fonts to the fhsenv just make steam to pick up a lucky font , still not following font-config. It was discussed in #302862 (comment) . @CoelacanthusHex reports that steam follows font-config on her Arch Linux, that's sth. weird on NixOS......

@Cryolitia
Copy link
Member Author

log.txt
The log of the case of not providing font packages to the fhsenv, and font-config like:

    fontconfig = {
      defaultFonts = {
        emoji = [
          "Source Han Serif SC"
          "JetBrainsMono Nerd Font"
          "Noto Color Emoji"
        ];
        monospace = [
          "Source Han Serif SC"
          "Sarasa Mono SC"
          "JetBrainsMono Nerd Font Mono"
        ];
        sansSerif = [ "Source Han Serif SC" ];
        serif = [ "Source Han Serif SC" ];
      };
      cache32Bit = true;
    };

@CoelacanthusHex
Copy link
Contributor

log.txt The log of the case of not providing font packages to the fhsenv, and font-config like:

Steam query Arial font instead generic font sans-serif from fontconfig. You can set fallback font for Arial to enforce steam use it.
For example, I set it to sans-serif so steam will use my default sans-serif font. But remember this rule MUST be before the rule you set default sans-serif font.
https://github.com/CoelacanthusHex/dotfiles/blob/465d5b7e3b821ad14b257549a75b94c5e3addd85/fontconfig/.config/fontconfig/conf.d/49-replace-latin.conf#L47-L52
You can use another font here.
And if you want this rule only affect steam, add another test rule in match:

    <test name="prgname" compare="contains" ignore-blanks="true">
      <string>steam</string>
    </test>

@K900
Copy link
Contributor

K900 commented May 22, 2024

That is still wrong. Please add the packages directly to the fhsenv.

@K900
Copy link
Contributor

K900 commented May 26, 2024

Can you drop the reformat change? There's likely going to be a treewide format at some point, and it's going to cause merge conflicts on other changes.

description = ''
Font packages to use in Steam.

Defaults to system fonts, but could be overridden to use other fonts — useful for users who would like to customize CJK fonts used in Steam. According to the [upstream issue](https://github.com/ValveSoftware/steam-for-linux/issues/10422#issuecomment-1944396010), steam only follows the fontconfig in user's home.
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, small nitpicks: "Steam" should be capitalized, and "fontconfig" isn't entirely accurate. Maybe just remove that sentence entirely?

Copy link
Member Author

@Cryolitia Cryolitia May 26, 2024

Choose a reason for hiding this comment

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

Sorry, my English is poor. But I think we do need to notice users somewhere.

The Steam's behavior is irregular(not read system-side fontconfig). Users may not notice that. They may not use home-manager or these things to config user-side fontconfig, and just believe that steam don't follows fontconfig at all. Then they may use varity kinds of hack to fix it in a worse way.

For example, introducing the whole fonts.packages to Steam without user-side fontconfig seems to broken the Japanese if they install a 「草书」font, or something even weirder happens in other languages.

related discussion: #302862 (comment)

CJK fonts and display are indeed a very difficult problem. Apart from the speakers of the language themselves, even we don't know how to satisfy each other, or what problems the fonts we use will cause for each other.

@K900
Copy link
Contributor

K900 commented May 26, 2024

All right, let's merge it and we can iterate later. Thanks!

@K900
Copy link
Contributor

K900 commented May 26, 2024

Actually the current version doesn't pass EditorConfig. Please fix that.

@Cryolitia
Copy link
Member Author

Re-tested on my computer, all looks good

@Cryolitia
Copy link
Member Author

Actually the current version doesn't pass EditorConfig. Please fix that.

Apologize, fixed

@Cryolitia Cryolitia changed the title nixos/steam: add option extraPackages, fix CJK fonts on client nixos/steam: add option extraPackages fontPackages, fix CJK fonts on client May 26, 2024
@K900 K900 merged commit 8de5bd2 into NixOS:master May 26, 2024
24 checks passed
@Cryolitia Cryolitia deleted the steam branch May 26, 2024 22:52
@jian-lin jian-lin added the backport release-24.05 Backport PR automatically label May 26, 2024
Copy link
Contributor

@gador
Copy link
Contributor

gador commented May 27, 2024

This caused a build failure for me:

A definition for option `programs.steam.fontPackages."[definition 1-entry 24]"' is not of type `package'. Definition values:
       - In `/nix/store/mw4dx9syd793x0s5z4rq88mrh2i65vxm-source/nixos/modules/programs/steam.nix': "/nix/store/r4qnpfh6s2s6d0kw938syll5pp3gy76c-ghostscript-with-X-10.02.1/share/ghostscript/fonts

probably caused by my config:

fonts = {
    enableGhostscriptFonts = true;
}

Which adds

config = mkIf config.fonts.enableGhostscriptFonts {
    fonts.packages = [ "${pkgs.ghostscript}/share/ghostscript/fonts" ];
  };

source

@Cryolitia
Copy link
Member Author

This caused a build failure for me:

A definition for option `programs.steam.fontPackages."[definition 1-entry 24]"' is not of type `package'. Definition values:
       - In `/nix/store/mw4dx9syd793x0s5z4rq88mrh2i65vxm-source/nixos/modules/programs/steam.nix': "/nix/store/r4qnpfh6s2s6d0kw938syll5pp3gy76c-ghostscript-with-X-10.02.1/share/ghostscript/fonts

probably caused by my config:

fonts = {
    enableGhostscriptFonts = true;
}

Which adds

config = mkIf config.fonts.enableGhostscriptFonts {
    fonts.packages = [ "${pkgs.ghostscript}/share/ghostscript/fonts" ];
  };

source

I found it a history of 17 years not changed……

94b7b93

Do we really need to use it like these today in 2024...... CC @edolstra

@Cryolitia
Copy link
Member Author

Cryolitia commented May 27, 2024

@gador Could you please turn to #315149 to discuss , this thread has too many participants.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants