Home manager, hyprland.nix syntax/ translation issue

I’m not even sure how to describe my issue the right way. but after a few days online research im drawing blanks. I hope someone might have an answer for my weird issue.

I have setup Nixos with home manager and hyprland. In my home.nix i import hyprland.nix. I wrote the config in the nix format, because it was suggested in a tutorial and i kinda get the syntax, roughly.

In that hyprland.nix file i have a keybind to use grim, slurp and swappy to take a screenshot, with this command:

grim -g "$(slurp)" - | swappy -f -

this works in the terminal, to use it in the config i put it in “” like the other keybinds:

"$mod, k, exec, grim -g "$(slurp)" - | swappy -f -"

but when i use it in the config and try to home-manager switch im getting an error. i assume its because of the double use of the “” . This leads to string$(slurp)string. which seems to be the problem. I have looked around and found no solution and didnt find help on the nix language cheat sheet.

I also cant edit the symlink in the nix store and dont think this would be a proper solution. Is there a proper solution, other than writing the config as .conf or using a different program to take screenshots?

any input is highly appreciated!

I think you need to escape quotes like this:

"SUPER, k, exec, grim -g \"$(slurp)\" - | swappy -f -"
1 Like

Or you use double single quotes, so you don’t need to escape ":

''$mod, k, exec, grim -g "$(slurp)" - | swappy -f -''
1 Like

thanks @MatthieuB ans @TLATER

both suggestions work. i appreciate the help!