Skip to content

treewide: remove redundant stylix.image escaping and string coercion#2134

Merged
trueNAHO merged 3 commits intonix-community:masterfrom
trueNAHO:treewide-remove-redundant-stylix.image-escaping-and-string-coercion
Jan 14, 2026
Merged

treewide: remove redundant stylix.image escaping and string coercion#2134
trueNAHO merged 3 commits intonix-community:masterfrom
trueNAHO:treewide-remove-redundant-stylix.image-escaping-and-string-coercion

Conversation

@trueNAHO
Copy link
Copy Markdown
Member

@trueNAHO trueNAHO commented Jan 8, 2026

commit 3f6651a26e0127654e6b24a3616239e2eaaf392b
Author: NAHO
Date:   2026-01-09 19:39:44 +0100

    stylix/palette: use derivation arguments instead of string interpolation

    Co-authored-by: Matt Sturgeon

 stylix/palette.nix | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

commit ca1bc329e91039435450d19c0e31655c1efd3f0f
Author: NAHO
Date:   2026-01-08 20:55:49 +0100

    stylix/palette: coerce derivations to store paths

    Coerce derivations to store paths to ensure non-null values are
    stringified store paths with valid string contexts.

    Fixes: 838df8b8ad7d ("stylix: improve `stylix.image` type (#1414)")

    Co-authored-by: Matt Sturgeon

 stylix/palette.nix | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

commit 61c9f4dd1435e0723fe675d44459a88b9203418d
Author: NAHO
Date:   2026-01-08 21:18:36 +0100

    treewide: remove redundant stylix.image escaping and string coercion

    Remove redundant shell escaping and string coercion as stylix.image is
    guaranteed to be a stringified store path with a valid string context
    and no special characters.

    Fixes: 3499e3ec704b ("treewide: properly quote stylix.image when used as a shell argument")

 modules/hyprlock/hm.nix  | 4 +---
 modules/hyprpaper/hm.nix | 2 +-
 2 files changed, 2 insertions(+), 4 deletions(-)

@stylix-automation stylix-automation bot added topic: nixos NixOS target topic: home-manager Home Manager target topic: modules /modules/ subsystem topic: stylix /stylix/ subsystem labels Jan 8, 2026
@stylix-automation stylix-automation bot requested a review from MrSom3body January 8, 2026 20:45
@0xda157
Copy link
Copy Markdown
Contributor

0xda157 commented Jan 8, 2026

cc @MattSturgeon

Copy link
Copy Markdown
Member

@MattSturgeon MattSturgeon left a comment

Choose a reason for hiding this comment

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

Initial review from my phone, so hard to test or view full context.

Comment thread stylix/palette.nix Outdated
Comment thread modules/grub/nixos.nix Outdated
Copy link
Copy Markdown
Contributor

@MrSom3body MrSom3body left a comment

Choose a reason for hiding this comment

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

hyprlock works :)

@trueNAHO trueNAHO force-pushed the treewide-remove-redundant-stylix.image-escaping-and-string-coercion branch from 835c1c7 to 949b4ec Compare January 9, 2026 15:01
@stylix-automation stylix-automation bot requested a review from MrSom3body January 9, 2026 15:01
@trueNAHO trueNAHO force-pushed the treewide-remove-redundant-stylix.image-escaping-and-string-coercion branch from 949b4ec to cb5ae97 Compare January 9, 2026 18:50
Co-authored-by: Matt Sturgeon <matt@sturgeon.me.uk>
@trueNAHO trueNAHO force-pushed the treewide-remove-redundant-stylix.image-escaping-and-string-coercion branch from cb5ae97 to c4ae2ea Compare January 9, 2026 18:57
@trueNAHO trueNAHO added the backport: release-25.11 To be backported to the release-25.11 stable branch label Jan 10, 2026
Copy link
Copy Markdown
Member

@MattSturgeon MattSturgeon left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM

Comment thread modules/grub/nixos.nix Outdated
Copy link
Copy Markdown
Contributor

@MrSom3body MrSom3body left a comment

Choose a reason for hiding this comment

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

LGTM hyprlock still works

trueNAHO and others added 2 commits January 14, 2026 15:54
Coerce derivations to store paths to ensure non-null values are
stringified store paths with valid string contexts.

Fixes: 838df8b ("stylix: improve `stylix.image` type (nix-community#1414)")

Co-authored-by: Matt Sturgeon <matt@sturgeon.me.uk>
Remove redundant shell escaping and string coercion as stylix.image is
guaranteed to be a stringified store path with a valid string context
and no special characters.

Fixes: 3499e3e ("treewide: properly quote stylix.image when used as a shell argument")
@trueNAHO trueNAHO force-pushed the treewide-remove-redundant-stylix.image-escaping-and-string-coercion branch from c4ae2ea to 61c9f4d Compare January 14, 2026 14:54
@trueNAHO trueNAHO merged commit 3894cae into nix-community:master Jan 14, 2026
5 checks passed
@stylix-automation
Copy link
Copy Markdown
Contributor

Backport failed for release-25.11, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin release-25.11
git worktree add -d .worktree/backport-2134-to-release-25.11 origin/release-25.11
cd .worktree/backport-2134-to-release-25.11
git switch --create backport-2134-to-release-25.11
git cherry-pick -x 3f6651a26e0127654e6b24a3616239e2eaaf392b ca1bc329e91039435450d19c0e31655c1efd3f0f 61c9f4dd1435e0723fe675d44459a88b9203418d

@mattkang
Copy link
Copy Markdown

mattkang commented Jan 17, 2026

I think this commit may have broken something for me. Now getting:

error: A definition for option `home-manager.users.user.stylix.image' is not of type `null or (path in the Nix store or absolute path convertible to it)'

@trueNAHO
Copy link
Copy Markdown
Member Author

I think this commit may have broken something for me. Now getting:

error: A definition for option `home-manager.users.user.stylix.image' is not of type `null or (path in the Nix store or absolute path convertible to it)'

What is your stylix.image declaration? Currently, we only test fetchurl derivations:

dark = fetchurl {
name = "mountains.jpg";
url = "https://unsplash.com/photos/ZqLeQDjY6fY/download?ixid=M3wxMjA3fDB8MXxhbGx8fHx8fHx8fHwxNzE2MzY1NDY4fA&force=true";
hash = "sha256-Dm/0nKiTFOzNtSiARnVg7zM0J1o+EuIdUQ3OAuasM58=";
};
light =
let
image = fetchurl {
name = "three-bicycles.jpg";
url = "https://unsplash.com/photos/hwLAI5lRhdM/download?ixid=M3wxMjA3fDB8MXxhbGx8fHx8fHx8fHwxNzE2MzYxNDcwfA&force=true";
hash = "sha256-S0MumuBGJulUekoGI2oZfUa/50Jw0ZzkqDDu1nRkFUA=";
};
# Create a path containing a space to test that `stylix.image` is
# correctly quoted when used as a shell argument. We have to use a
# directory as the parent because derivation names themselves cannot
# contain spaces.
directory = runCommandLocal "three-bicycles" { } ''
mkdir "$out"
cp ${image} "$out/three bicycles.jpg"
'';
in
"${directory}/three bicycles.jpg";

@mattkang
Copy link
Copy Markdown

mattkang commented Jan 18, 2026

@trueNAHO Using a local image in home folder

stylix.image = "${config.users.users.user.home}/Pictures/wallpaper.png";

Is there a reason why pathInStore is being used? I was not able to find good documentation on this. The best I found was here

@MattSturgeon
Copy link
Copy Markdown
Member

patgInStore is used because the option type is converting paths out-of-store into stable dependencies, by copying them to the nix store. It correctly reflects the intended type.

In your case, you're defining a path-like string, not an actual path that can be copied to store.

For most users, referencing a path outside of your config via a string would be a subtle bug, but the option type could be relaxed to accommodate these (non-path, non-drv) path-like strings and assume they are already present in the resulting system, without creating a proper dependency on the file.

@MattSturgeon
Copy link
Copy Markdown
Member

To preserve the original behaviour, coercedTo path (p: "${p}") path could be used, but the type's description ought to be customised in this case to properly convey "any absolute path, but if convertible to a store-path this is done automatically".

(
  coercedTo path (p: "${p}") path
  // {
    description = path.description + ", copied to store if possible";
  }
)

@trueNAHO
Copy link
Copy Markdown
Member Author

Using a local image in home folder

stylix.image = "${config.users.users.user.home}/Pictures/wallpaper.png";

Is there a reason why pathInStore is being used?

As mentioned in #2134 (comment), pathInStore is the correct and intended behavior. Using absolute impure paths is an unintended instance of Hyrum's Law. Considering the pathInStore guarantee will eventually be removed either way, I opened #2150.

To preserve the original behaviour, coercedTo path (p: "${p}") path could be used, but the type's description ought to be customised in this case to properly convey "any absolute path, but if convertible to a store-path this is done automatically".

(
  coercedTo path (p: "${p}") path
  // {
    description = path.description + ", copied to store if possible";
  }
)

With #2150, it would be better to consider the store copying aspect as an implementation detail that is irrelvant to end-users, especially because the store copy cannot be guaranteed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport: release-25.11 To be backported to the release-25.11 stable branch topic: home-manager Home Manager target topic: modules /modules/ subsystem topic: nixos NixOS target topic: stylix /stylix/ subsystem

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants