Closed thedavidmeister closed 1 year ago
There is overlap here but I'm not sure these two things are exactly equivalent. JSON config format would be cool, that's one aspect.
The rest of the request you're quoting from it looks like you're ticking off in #77 but I don't see a complete solution in there. What I'm wondering is: does a command format exist that will not reinitialise the Nix shell if it is already active? Then I can use the same command to run integration tests efficiently whether I am in a Nix environment or not- thus removing the need for developers to "reason about whether they’re in “normal mode” or “nix mode”".
@pospi this is pretty different, there is already native parseJson
type functionality in nix so it would just be "if holonix.json exists, use it"
what type of command do you mean?
does a command format exist that will not reinitialise the Nix shell if it is already active?
So the conditions I want to satisfy are to create some "command" wrapping an "underlying command" such that:
Basically because for newcomers, having those things as 2 separate commands which require you to reason about "am I inside Nix?" in order to know which run to run is a barrier to entry.
@pospi ok, so some kind of "ensure nix" command/script
you really just need some environment variable that you trust to indicate that you're in nix
printenv | grep NIX
gives a bunch of options (look for something that exists in the shell but not outside)
something like $IN_NIX_SHELL
(which can be empty/pure/impure i think) looks perfect as it's also compatible with detection inside an actual nixos machine
echo 'if [[ -z $IN_NIX_SHELL ]]; then nix-shell; fi;' >> ensure-nix.sh
chmod +x ensure-nix.sh
./ensure-nix.sh
./ensure-nix.sh
from here you can guard any further commands you want to run with ./ensure-nix.sh
at the start
I figured there might be something like that and was thinking about looping back to say so, so thanks for jumping ahead (:
I don't think it's quite this simple though, and I lack the bash-fu to know how to deal with subshells. But what will happen with the solution above AFAIK is that nix-shell
will halt the ensure-nix.sh
script and execution will only be picked back up when it exits.
The thing I can't figure out in the approach I'm trying is just bash syntax- I need to unpack all args into a single-quoted string in order to pass to nix-shell --run
AFAIK?
if [[ -z $IN_NIX_SHELL ]]; then
nix-shell --run "$@"
else
eval "$@"
fi
The goal is that you could basically just prepend this script name to any command you might need to run and have it execute as you would expect. I've been testing with ensure-nix.sh which npm
, for example.
@pospi oh yes, i thought that's what you wanted, to be dropped into a shell if needed
yes if you want to make it "one shot" then do something like --run
I still don't really know how to do it... looks like passing multiple shell args as a single arg isn't a thing that can really be done robustly? Surely there is another way to get nix-shell
to accept a multi-word command to run?
the less nix-fu that beginners need to get started and keep moving, the better
one clear hurdle is the "scary" nix language
once you are familiar with the nix syntax it is easy to forget that it isn't immediately obvious these are all analogous:
nix:
json:
but, there is a 1:1 mapping that makes sense, so nix natively supports parsing JSON files as nix data, so we should be able to update the
default.nix
boilerplate to try aholonix.json
file if it existsthis would make the boilerplate look gnarlier, but the config more familiar to anyone who has used e.g. package.json style configuration
given that
package.json
is used to define"scripts"
that work withnpm run ...
in almost the same way (conceptually, i.e. putting bins on the path) asnix-shell --run ...
(but limited to the node ecosystem), i'm hoping there's a way to makeholonix.json
"feel like home" for more peoplefrom @pospi in the forums
https://forum.holochain.org/t/what-is-the-worst-of-holonix-onboarding-2019-q3/547/3?u=thedavidmeister