@@ -20,11 +20,17 @@ import Control.Lens ((.~), (?~), (<&>))
2020import Control.Monad
2121import Control.Monad.IO.Class (liftIO)
2222import Control.Monad.State
23+import qualified Data.Aeson as Json
2324import Data.Bits
25+import qualified Data.ByteString.Lazy as BSL
2426import Data.Default (def)
2527import Data.Function ((&), on)
2628import Data.List (isInfixOf)
29+import Data.Map (Map)
30+import Data.Text (Text)
2731import qualified Data.Text as T
32+import Data.Text.Encoding (decodeUtf8)
33+import Data.Traversable (for)
2834import System.Directory
2935import System.Environment (lookupEnv)
3036import System.FilePath
@@ -240,8 +246,6 @@ filePermissionIsSafe s umask = not fileWorldWritable && fileGroupWritable <= uma
240246 fileGroupWritable = fileMode s .&. 0o020 == 0o020
241247 umaskGroupWritable = umask .&. 0o020 == 0
242248
243−-- nix-shell -E '{ root, shell-pkgs }: ((import root {}).passthru.self.extend (self: super: { shells-ghc = shell-pkgs; })).project.shells.ghc' --arg root ./. --arg shell-pkgs '["backend"]'
244−
245249-- | Nix syntax requires relative paths to be prefixed by @./@ or
246250-- @../@. This will make a 'FilePath' that can be embedded in a Nix
247251-- expression.
@@ -249,9 +253,9 @@ toNixPath :: FilePath -> FilePath
249253toNixPath root | "/" `isInfixOf` root = root
250254 | otherwise = "./" <> root
251255
252−
253−nixShellWithPkgs :: MonadObelisk m => FilePath -> Bool -> [String] -> Maybe String -> m ()
254−nixShellWithPkgs root isPure packageNames command = do
256+nixShellWithPkgs :: MonadObelisk m => FilePath -> Bool -> Map Text FilePath -> Maybe String -> m ()
257+nixShellWithPkgs root isPure packageNamesAndPaths command = do
258+ packageNamesAndAbsPaths <- liftIO $ for packageNamesAndPaths makeAbsolute
255259 nixpkgsPath <- fmap T.strip $ readProcessAndLogStderr Debug $ setCwd (Just root) $
256260 proc nixExePath ["eval", "(import .obelisk/impl {}).nixpkgs.path"]
257261 nixRemote <- liftIO $ lookupEnv "NIX_REMOTE"
@@ -260,9 +264,15 @@ nixShellWithPkgs root isPure packageNames command = do
260264 & nixShellConfig_pure .~ isPure
261265 & nixShellConfig_common . nixCmdConfig_target .~ (def
262266 & target_path .~ Nothing
263− & target_expr ?~ "{ root, shell-pkgs }: ((import root {}).passthru.self.extend (self: super: { shells-ghc = shell-pkgs; })).project.shells.ghc"
267+ & target_expr ?~
268+ "{root, pkgs}: ((import root {}).passthru.__unstable__.self.extend (self: super: {\
269+ \shellPackages = builtins.fromJSON pkgs; })\
270+ \).project.shells.ghc"
264271 )
265− & nixShellConfig_common . nixCmdConfig_args .~ [rawArg "root" $ toNixPath root, rawArg "shell-pkgs" ("[" <> unwords (map show packageNames) <> "]")]
272+ & nixShellConfig_common . nixCmdConfig_args .~
273+ [ rawArg "root" $ toNixPath root
274+ , strArg "pkgs" (T.unpack $ decodeUtf8 $ BSL.toStrict $ Json.encode packageNamesAndAbsPaths)
275+ ]
266276 & nixShellConfig_run .~ (command <&> \c -> mconcat
267277 [ "export NIX_PATH=nixpkgs=", T.unpack nixpkgsPath, "; "
268278 , maybe "" (\v -> "export NIX_REMOTE=" <> v <> "; ") nixRemote