on master help sign in
Merge pull request #580 from obsidiansystems/eac@pin-nixpkgs-shell

Pin <nixpkgs> in obelisk nix-shell's

commitc7f02b34f8137d5644d133d91023813a6a253083 authorElliot Cameron <3noch@users.noreply.github.com> dateTue 17 Dec 2019, 18:16 (7 years ago) parent1a28d676784f85
4 files changed+18−7
ChangeLog.md+1−1 FAQ.md+1−1 lib/command/src/Obelisk/Command.hs+2−1 lib/command/src/Obelisk/Command/Project.hs+14−4
ChangeLog.md+1−1
@@ -11,7 +11,7 @@ This project's release branch is `master`. This log is written from the perspect
1111* Add support in obelisk-route for single parameters in URL paths
1212* Bump reflex-platform so that obelisk now uses reflex-dom 0.5.2.0
1313* 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.
1515* Backport ACMEv2 support in obelisk server to regain LetsEncrypt account creation.
1616* Enable https in `ob run`
1717* `ob run` now handles ghci errors better, and includes a custom ghcid
FAQ.md+1−1
@@ -81,7 +81,7 @@ project's dependencies and,
8181Assuming we are in a project created with `ob init`, `ob run` calls (see
8282`lib/command/src/Obelisk/Command.hs`):
8383
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>'
8585
8686where
8787
lib/command/src/Obelisk/Command.hs+2−1
@@ -267,7 +267,8 @@ mkObeliskConfig :: IO Obelisk
267267mkObeliskConfig = do
268268 cliArgs <- getArgs
269269 -- This function should not use argument parser (full argument parsing happens post handoff)
270− let logLevel = toLogLevel $ "-v" `elem` cliArgs
270+ -- TODO: See if we can use the argument parser with a subset of the parsers to get logging level out.
271+ let logLevel = toLogLevel $ any (`elem` ["-v", "--verbose"]) cliArgs
271272 notInteractive <- not <$> isInteractiveTerm
272273 cliConf <- newCliConfig logLevel notInteractive notInteractive $ \case
273274 ObeliskError_ProcessError (ProcessFailure p code) ann ->
lib/command/src/Obelisk/Command/Project.hs+14−4
@@ -1,6 +1,7 @@
11{-# LANGUAGE FlexibleContexts #-}
22{-# LANGUAGE LambdaCase #-}
33{-# LANGUAGE OverloadedStrings #-}
4+{-# LANGUAGE TemplateHaskell #-}
45module Obelisk.Command.Project
56 ( InitSource (..)
67 , initProject
@@ -23,12 +24,14 @@ import Data.Bits
2324import Data.Function (on)
2425import qualified Data.Text as T
2526import System.Directory
27+import System.Environment (lookupEnv)
2628import System.FilePath
2729import System.IO.Temp
2830import System.IO.Unsafe (unsafePerformIO)
2931import System.Posix (FileStatus, FileMode, CMode (..), UserID, deviceID, fileID, fileMode, fileOwner, getFileStatus, getRealUserID)
3032import System.Posix.Files
3133import System.Process (CreateProcess, cwd, proc, waitForProcess, delegate_ctlc)
34+import System.Which (staticWhich)
3235
3336import GitHub.Data.GitData (Branch)
3437import GitHub.Data.Name (Name)
@@ -241,16 +244,23 @@ inImpureProjectShell shellName command = withProjectRoot "." $ \root ->
241244
242245projectShell :: MonadObelisk m => FilePath -> Bool -> String -> Maybe String -> m ()
243246projectShell 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"
244250 (_, _, _, ph) <- createProcess_ "runNixShellAttr" $ setCtlc $ setCwd (Just root) $ proc "nix-shell" $
245251 [ "default.nix"] <>
246− -- Keep $NIX_PATH in the env for --pure shells so '<nixpkgs>' works in sub-commands
247− -- TODO: Don't use <nixpkgs> for anything!
248− (if isPure then [ "--pure", "--keep", "NIX_PATH" ] else []) <>
252+ ["--pure" | isPure] <>
249253 [ "-A"
250254 , "shells." <> shellName
251255 ] <> case command of
252256 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+ ]
254264 void $ liftIO $ waitForProcess ph
255265
256266setCtlc :: CreateProcess -> CreateProcess