| I AI'd if --impure can be enabled by default and just now stumbled on a feature I hadn't heard about before! The option allow-unsafe-native-code-during-evaluation gives you a new builtin function called builtins.exec which can be used like this:
nix-repl> :p builtins.fromJSON (builtins.exec [ ./test.fish ])
{
active = true;
age = 25;
name = "test-user";
tags = [
"developer"
"nix"
"json"
];
}
# test.fish
#! /usr/bin/env fish
echo "''"
echo '
{
"name": "test-user",
"age": 25,
"active": true,
"tags": ["developer", "nix", "json"]
}'
echo "''"
(It parses output as a Nix expression so i had to wrap the json in '' '' so it's treated as a string by Nix)
I'm definitely gonna dive deeper into usecases for this, as everything Nix it'll stall evaluation so don't do extremely slow things :)
|