2 Aug 2024 |
| @dykeaura:matrix.org left the room. | 19:36:51 |
3 Aug 2024 |
| Víctor Martínez joined the room. | 10:34:55 |
Gaétan Lepage | Hey,
Is it possible to escape a ${foo} in a nix string ? | 17:10:39 |
Philip Taron (UTC-8) | Welcome to Nix 2.18.5. Type :? for help.
nix-repl> ''
''${foo}
''
"\${foo}\n"
nix-repl> ''''${foo}''
"\${foo}"
| 17:14:25 |
emily | just putting this here to scare you ''''\'''${a}'' | 17:18:06 |
Gaétan Lepage | Thanks... I'm not super sure to make it work in my case though
substituteInPlace src/python/CMakeLists.txt \
--replace-fail "find_package(pybind11 ${PYBIND11_VER} QUIET)" "find_package(pybind11 QUIET)"
| 17:18:10 |
emily | pybind11 ''${PYBIND11_VER} | 17:18:20 |
Gaétan Lepage | which is already in a postPatch = '' | 17:18:28 |
emily | welcome to the worst string syntax in the universe! | 17:18:30 |
emily | oh, but also your "" will cause problems | 17:18:43 |
emily | because bash will also try to expand it | 17:18:47 |
emily | so you need 'find_package(pybind11 ''${PYBIND11_VER} QUIET)' | 17:18:53 |
Gaétan Lepage | ERROR: pattern find_package\(pybind11\ \ QUIET\) doesn't match anything | 17:18:59 |
emily | In reply to @emilazy:matrix.org because bash will also try to expand it because ^ | 17:19:09 |
Gaétan Lepage | Ok, so going with a proper patch file might be the best option here then | 17:19:32 |
emily | I mean, you can just do --replace-fail 'find_package(pybind11 ''${PYBIND11_VER} QUIET)' 'find_package(pybind11 QUIET)' | 17:19:50 |
emily | that's not so bad | 17:19:54 |
Gaétan Lepage | In reply to @emilazy:matrix.org that's not so bad It worked thanks ! | 17:26:02 |
Matt Sturgeon | In reply to @emilazy:matrix.org welcome to the worst string syntax in the universe! Nix's indented string syntax is always fun!
'' to start/end
''' renders literally as ''
''$ renders literally as $ And leading newlines before the first non-blank line are striped (though not trailing lines) | 18:27:32 |
emily | oh, you think that's the worst part? try ''\' . or $${ . | 18:29:02 |
emily | In reply to @emilazy:matrix.org just putting this here to scare you ''''\'''${a}'' hence ^ :) | 18:29:28 |
| @gunboat_diplomat:matrix.org left the room. | 18:36:29 |
| requiem33 joined the room. | 18:40:26 |
Qyriad | Sometimes it can just be clearer to just do something like
let bashFoo = "\${foo}"; in ''
echo "${bashFoo}"
'';
just to avoid this madness | 22:06:42 |
4 Aug 2024 |
Matt Sturgeon | If it's a large enough block of text to justify it, you can always put it in a separate file and readFile it. If you also need to include a handful of nix vars/expressions in the string, you could map them to bash vars using lib.toShellVars :
{
env = {
foo = "bar";
sum = 1 + 2;
hello = lib.getExe pkgs.hello;
PATH = lib.makeBinPath [
pkgs.git
pkgs.cowsay
];
};
text = ''
${lib.toShellVars env}
export PATH
${builtins.readFile ./script.sh}
'';
}
| 00:05:43 |
Matt Sturgeon | * If it's a large enough block of text to justify it, you can always put it in a separate file and readFile it. If you also need to include a handful of nix vars/expressions in the string, you could map them to bash vars using lib.toShellVars :
rec {
env = {
foo = "bar";
sum = 1 + 2;
hello = lib.getExe pkgs.hello;
PATH = lib.makeBinPath [
pkgs.git
pkgs.cowsay
];
};
text = ''
${lib.toShellVars env}
export PATH
${builtins.readFile ./script.sh}
'';
}
| 00:06:03 |
| NixOS Moderation Bot banned @fjeauntyd:matrix.org (racism). | 10:26:05 |
| @thomasjm:matrix.org left the room. | 12:10:17 |
| tacticaltaco joined the room. | 22:05:48 |
5 Aug 2024 |
| whopteron joined the room. | 12:24:52 |