@@ -20,11 +20,17 @@ import Control.Lens ((.~), (?~), (<&>))
20import Control.Monad
20import Control.Monad
21import Control.Monad.IO.Class (liftIO)
21import Control.Monad.IO.Class (liftIO)
22import Control.Monad.State
22import Control.Monad.State
23+import qualified Data.Aeson as Json
23import Data.Bits
24import Data.Bits
25+import qualified Data.ByteString.Lazy as BSL
24import Data.Default (def)
26import Data.Default (def)
25import Data.Function ((&), on)
27import Data.Function ((&), on)
26import Data.List (isInfixOf)
28import Data.List (isInfixOf)
30+import Data.Text (Text)
27import qualified Data.Text as T
31import qualified Data.Text as T
32+import Data.Text.Encoding (decodeUtf8)
33+import Data.Traversable (for)
28import System.Directory
34import System.Directory
29import System.Environment (lookupEnv)
35import System.Environment (lookupEnv)
30import System.FilePath
36import System.FilePath
@@ -240,8 +246,6 @@ filePermissionIsSafe s umask = not fileWorldWritable && fileGroupWritable <= uma
240 fileGroupWritable = fileMode s .&. 0o020 == 0o020
246 fileGroupWritable = fileMode s .&. 0o020 == 0o020
241 umaskGroupWritable = umask .&. 0o020 == 0
247 umaskGroupWritable = umask .&. 0o020 == 0
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"]'
245-- | Nix syntax requires relative paths to be prefixed by @./@ or
249-- | Nix syntax requires relative paths to be prefixed by @./@ or
246-- @../@. This will make a 'FilePath' that can be embedded in a Nix
250-- @../@. This will make a 'FilePath' that can be embedded in a Nix
247-- expression.
251-- expression.
@@ -249,9 +253,9 @@ toNixPath :: FilePath -> FilePath
249toNixPath root | "/" `isInfixOf` root = root
253toNixPath root | "/" `isInfixOf` root = root
250 | otherwise = "./" <> root
254 | otherwise = "./" <> root
253−nixShellWithPkgs :: MonadObelisk m => FilePath -> Bool -> [String] -> Maybe String -> m ()
256+nixShellWithPkgs :: MonadObelisk m => FilePath -> Bool -> Map Text FilePath -> Maybe String -> m ()
254−nixShellWithPkgs root isPure packageNames command = do
257+nixShellWithPkgs root isPure packageNamesAndPaths command = do
258+ packageNamesAndAbsPaths <- liftIO $ for packageNamesAndPaths makeAbsolute
255 nixpkgsPath <- fmap T.strip $ readProcessAndLogStderr Debug $ setCwd (Just root) $
259 nixpkgsPath <- fmap T.strip $ readProcessAndLogStderr Debug $ setCwd (Just root) $
256 proc nixExePath ["eval", "(import .obelisk/impl {}).nixpkgs.path"]
260 proc nixExePath ["eval", "(import .obelisk/impl {}).nixpkgs.path"]
257 nixRemote <- liftIO $ lookupEnv "NIX_REMOTE"
261 nixRemote <- liftIO $ lookupEnv "NIX_REMOTE"
@@ -260,9 +264,15 @@ nixShellWithPkgs root isPure packageNames command = do
260 & nixShellConfig_pure .~ isPure
264 & nixShellConfig_pure .~ isPure
261 & nixShellConfig_common . nixCmdConfig_target .~ (def
265 & nixShellConfig_common . nixCmdConfig_target .~ (def
262 & target_path .~ Nothing
266 & target_path .~ Nothing
263− & target_expr ?~ "{ root, shell-pkgs }: ((import root {}).passthru.self.extend (self: super: { shells-ghc = shell-pkgs; })).project.shells.ghc"
268+ "{root, pkgs}: ((import root {}).passthru.__unstable__.self.extend (self: super: {\
269+ \shellPackages = builtins.fromJSON pkgs; })\
270+ \).project.shells.ghc"
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)
266 & nixShellConfig_run .~ (command <&> \c -> mconcat
276 & nixShellConfig_run .~ (command <&> \c -> mconcat
267 [ "export NIX_PATH=nixpkgs=", T.unpack nixpkgsPath, "; "
277 [ "export NIX_PATH=nixpkgs=", T.unpack nixpkgsPath, "; "
268 , maybe "" (\v -> "export NIX_REMOTE=" <> v <> "; ") nixRemote
278 , maybe "" (\v -> "export NIX_REMOTE=" <> v <> "; ") nixRemote