on master help sign in
Merge pull request #580 from obsidiansystems/eac@pin-nixpkgs-shell
c7f02b3Elliot Cameron
ChangeLog.md+1−1
@@ -11,7 +11,7 @@ This project's release branch is `master`. This log is written from the perspect
11* Add support in obelisk-route for single parameters in URL paths
11* Add support in obelisk-route for single parameters in URL paths
12* Bump reflex-platform so that obelisk now uses reflex-dom 0.5.2.0
12* Bump reflex-platform so that obelisk now uses reflex-dom 0.5.2.0
13* Use a `--pure` nix shell in `ob run` for parity with `ob repl` and more resilience against "works on my machine".
13* Use a `--pure` nix shell in `ob run` for parity with `ob repl` and more resilience against "works on my machine".
14−* Use `--keep NIX_PATH` for all pure shells so references to `<nixpkgs>` continues to work.
14+* Pin usages of `<nixpkgs>` in obelisk thunks, etc. to the nixpkgs used by the project's obelisk impl.
15* Backport ACMEv2 support in obelisk server to regain LetsEncrypt account creation.
15* Backport ACMEv2 support in obelisk server to regain LetsEncrypt account creation.
16* Enable https in `ob run`
16* Enable https in `ob run`
17* `ob run` now handles ghci errors better, and includes a custom ghcid
17* `ob run` now handles ghci errors better, and includes a custom ghcid
FAQ.md+1−1
@@ -81,7 +81,7 @@ project's dependencies and,
81Assuming we are in a project created with `ob init`, `ob run` calls (see
81Assuming we are in a project created with `ob init`, `ob run` calls (see
82`lib/command/src/Obelisk/Command.hs`):
82`lib/command/src/Obelisk/Command.hs`):
83
83
84− nix-shell --pure --keep NIX_PATH -A shells.ghc --run 'ob --no-handoff internal run-static-io <real-run-function>'
84+ nix-shell --pure -A shells.ghc --run 'ob --no-handoff internal run-static-io <real-run-function>'
85
85
86where
86where
87
87
lib/command/src/Obelisk/Command.hs+2−1
@@ -267,7 +267,8 @@ mkObeliskConfig :: IO Obelisk
267mkObeliskConfig = do
267mkObeliskConfig = do
268 cliArgs <- getArgs
268 cliArgs <- getArgs
269 -- This function should not use argument parser (full argument parsing happens post handoff)
269 -- This function should not use argument parser (full argument parsing happens post handoff)
270+ -- TODO: See if we can use the argument parser with a subset of the parsers to get logging level out.
270− let logLevel = toLogLevel $ "-v" `elem` cliArgs
271+ let logLevel = toLogLevel $ any (`elem` ["-v", "--verbose"]) cliArgs
271 notInteractive <- not <$> isInteractiveTerm
272 notInteractive <- not <$> isInteractiveTerm
272 cliConf <- newCliConfig logLevel notInteractive notInteractive $ \case
273 cliConf <- newCliConfig logLevel notInteractive notInteractive $ \case
273 ObeliskError_ProcessError (ProcessFailure p code) ann ->
274 ObeliskError_ProcessError (ProcessFailure p code) ann ->
lib/command/src/Obelisk/Command/Project.hs+14−4
@@ -1,6 +1,7 @@
1{-# LANGUAGE FlexibleContexts #-}
1{-# LANGUAGE FlexibleContexts #-}
2{-# LANGUAGE LambdaCase #-}
2{-# LANGUAGE LambdaCase #-}
3{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE OverloadedStrings #-}
4+{-# LANGUAGE TemplateHaskell #-}
4module Obelisk.Command.Project
5module Obelisk.Command.Project
5 ( InitSource (..)
6 ( InitSource (..)
6 , initProject
7 , initProject
@@ -23,12 +24,14 @@ import Data.Bits
23import Data.Function (on)
24import Data.Function (on)
24import qualified Data.Text as T
25import qualified Data.Text as T
25import System.Directory
26import System.Directory
27+import System.Environment (lookupEnv)
26import System.FilePath
28import System.FilePath
27import System.IO.Temp
29import System.IO.Temp
28import System.IO.Unsafe (unsafePerformIO)
30import System.IO.Unsafe (unsafePerformIO)
29import System.Posix (FileStatus, FileMode, CMode (..), UserID, deviceID, fileID, fileMode, fileOwner, getFileStatus, getRealUserID)
31import System.Posix (FileStatus, FileMode, CMode (..), UserID, deviceID, fileID, fileMode, fileOwner, getFileStatus, getRealUserID)
30import System.Posix.Files
32import System.Posix.Files
31import System.Process (CreateProcess, cwd, proc, waitForProcess, delegate_ctlc)
33import System.Process (CreateProcess, cwd, proc, waitForProcess, delegate_ctlc)
34+import System.Which (staticWhich)
32
35
33import GitHub.Data.GitData (Branch)
36import GitHub.Data.GitData (Branch)
34import GitHub.Data.Name (Name)
37import GitHub.Data.Name (Name)
@@ -241,16 +244,23 @@ inImpureProjectShell shellName command = withProjectRoot "." $ \root ->
241
244
242projectShell :: MonadObelisk m => FilePath -> Bool -> String -> Maybe String -> m ()
245projectShell :: MonadObelisk m => FilePath -> Bool -> String -> Maybe String -> m ()
243projectShell root isPure shellName command = do
246projectShell root isPure shellName command = do
247+ let nixPath = $(staticWhich "nix")
248+ nixpkgsPath <- fmap T.strip $ readProcessAndLogStderr Debug $ proc nixPath ["eval", "(import .obelisk/impl {}).nixpkgs.path"]
249+ nixRemote <- liftIO $ lookupEnv "NIX_REMOTE"
244 (_, _, _, ph) <- createProcess_ "runNixShellAttr" $ setCtlc $ setCwd (Just root) $ proc "nix-shell" $
250 (_, _, _, ph) <- createProcess_ "runNixShellAttr" $ setCtlc $ setCwd (Just root) $ proc "nix-shell" $
245 [ "default.nix"] <>
251 [ "default.nix"] <>
246− -- Keep $NIX_PATH in the env for --pure shells so '<nixpkgs>' works in sub-commands
252+ ["--pure" | isPure] <>
247− -- TODO: Don't use <nixpkgs> for anything!
248− (if isPure then [ "--pure", "--keep", "NIX_PATH" ] else []) <>
249 [ "-A"
253 [ "-A"
250 , "shells." <> shellName
254 , "shells." <> shellName
251 ] <> case command of
255 ] <> case command of
252 Nothing -> []
256 Nothing -> []
253− Just c -> ["--run", c]
257+ Just c ->
258+ -- TODO: Escape nixpkgsPath and nixRemote
259+ [ "--run"
260+ , "export NIX_PATH=nixpkgs=" <> T.unpack nixpkgsPath <> "; " <>
261+ maybe "" (\v -> "export NIX_REMOTE=" <> v <> "; ") nixRemote <>
262+ c
263+ ]
254 void $ liftIO $ waitForProcess ph
264 void $ liftIO $ waitForProcess ph
255
265
256setCtlc :: CreateProcess -> CreateProcess
266setCtlc :: CreateProcess -> CreateProcess