on master help sign in
command: Mark extra shell features as unstable, use shellPackages
323e52eElliot Cameron
default.nix+1−1
@@ -351,7 +351,7 @@ in rec {
351 ios = self.__iosWithConfig (self.base + "/config");
351 ios = self.__iosWithConfig (self.base + "/config");
352
352
353 passthru = {
353 passthru = {
354− self = allConfig;
354+ __unstable__.self = allConfig;
355 inherit (self)
355 inherit (self)
356 staticFilesImpure processedStatic
356 staticFilesImpure processedStatic
357 __iosWithConfig __androidWithConfig
357 __iosWithConfig __androidWithConfig
lib/command/src/Obelisk/Command/Project.hs+17−7
@@ -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)
29+import Data.Map (Map)
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
242
248
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−
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
251
255
252−
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
267+ & target_expr ?~
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"
264 )
271 )
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+ ]
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
lib/command/src/Obelisk/Command/Run.hs+9−5
@@ -6,6 +6,7 @@
6{-# LANGUAGE TupleSections #-}
6{-# LANGUAGE TupleSections #-}
7module Obelisk.Command.Run where
7module Obelisk.Command.Run where
8
8
9+import Control.Arrow ((&&&))
9import Control.Exception (Exception, bracket)
10import Control.Exception (Exception, bracket)
10import Control.Monad (filterM, unless)
11import Control.Monad (filterM, unless)
11import Control.Monad.Except (runExceptT, throwError)
12import Control.Monad.Except (runExceptT, throwError)
@@ -16,8 +17,11 @@ import Data.Either
16import Data.Foldable (for_, toList)
17import Data.Foldable (for_, toList)
17import Data.List.Extra (dropPrefix)
18import Data.List.Extra (dropPrefix)
18import qualified Data.List.NonEmpty as NE
19import qualified Data.List.NonEmpty as NE
20+import Data.Map (Map)
21+import qualified Data.Map as Map
19import Data.Maybe
22import Data.Maybe
20import qualified Data.Set as Set
23import qualified Data.Set as Set
24+import Data.Text (Text)
21import qualified Data.Text as T
25import qualified Data.Text as T
22import Data.Traversable (for)
26import Data.Traversable (for)
23import Debug.Trace (trace)
27import Debug.Trace (trace)
@@ -243,6 +247,9 @@ parsePackagesOrFail dirs = do
243
247
244 pure packageInfos
248 pure packageInfos
245
249
250+packageInfoToNamePathMap :: [CabalPackageInfo] -> Map Text FilePath
251+packageInfoToNamePathMap = Map.fromList . map (_cabalPackageInfo_packageName &&& _cabalPackageInfo_packageRoot)
252+
246-- | Create ghci configuration to load the given packages
253-- | Create ghci configuration to load the given packages
247withGhciScript
254withGhciScript
248 :: MonadObelisk m
255 :: MonadObelisk m
@@ -285,9 +292,7 @@ runGhciRepl
285runGhciRepl packages dotGhci = withProjectRoot "." $ \root ->
292runGhciRepl packages dotGhci = withProjectRoot "." $ \root ->
286 -- NOTE: We do *not* want to use $(staticWhich "ghci") here because we need the
293 -- NOTE: We do *not* want to use $(staticWhich "ghci") here because we need the
287 -- ghc that is provided by the shell in the user's project.
294 -- ghc that is provided by the shell in the user's project.
288− nixShellWithPkgs root True packageNames $ Just $ "ghci " <> makeBaseGhciOptions dotGhci -- TODO: Shell escape
295+ nixShellWithPkgs root True (packageInfoToNamePathMap packages) $ Just $ "ghci " <> makeBaseGhciOptions dotGhci -- TODO: Shell escape
289− where
290− packageNames = map (T.unpack . _cabalPackageInfo_packageName) packages
291
296
292-- | Run ghcid
297-- | Run ghcid
293runGhcid
298runGhcid
@@ -297,9 +302,8 @@ runGhcid
297 -> Maybe String -- ^ Optional command to run at every reload
302 -> Maybe String -- ^ Optional command to run at every reload
298 -> m ()
303 -> m ()
299runGhcid dotGhci packages mcmd = withProjectRoot "." $ \root ->
304runGhcid dotGhci packages mcmd = withProjectRoot "." $ \root ->
300− nixShellWithPkgs root True packageNames (Just $ unwords $ ghcidExePath : opts) -- TODO: Shell escape
305+ nixShellWithPkgs root True (packageInfoToNamePathMap packages) (Just $ unwords $ ghcidExePath : opts) -- TODO: Shell escape
301 where
306 where
302− packageNames = map (T.unpack . _cabalPackageInfo_packageName) packages
303 opts =
307 opts =
304 [ "-W"
308 [ "-W"
305 --TODO: The decision of whether to use -fwarn-redundant-constraints should probably be made by the user
309 --TODO: The decision of whether to use -fwarn-redundant-constraints should probably be made by the user