I would like to initiate a nix-shell
(if unfamiliar with Nix), this can be thought of as a bashs hell that loads a particular environment, somewhat expensively). Once initiated as a separate process, I'd like to be able to send commands to that shell and retrieve the results. There is the potential for some complexity here related to concurrency issues, but I thought shelly might be able to simply handle it like this:
#!/usr/bin/env stack
{- stack script --nix --resolver lts-14.27
--package async
--package shelly
-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ExtendedDefaultRules #-}
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
import Shelly
main :: IO ()
main = shelly $ do
run_ "nix-shell" ["-p", "cargo"]
run_ "cargo" []
In the first run_
, we initiate a shell that has the cargo
command available, which we should then be able to run using the second call to run_
. However, this results in an error where the PATH does not seem to be correct - strangely it no longer containers even nix-shell
in the path.
I'd be open to suggestions on how to do this using various approaches, not necessarily with shelly.