on master help sign in
Merge branch 'develop' into jd-headration-2
commitbf19268d5772c170b4cc34af64f5488d4cab5e93 authorKen Micklas <ken.micklas@obsidian.systems> dateMon 29 Apr 2019, 11:51 (7 years ago) parentfe9bad025d84c3
6 files changed+35−8
ChangeLog.md+2 README.md+1 lib/asset/manifest/obelisk-asset-manifest.cabal+1 lib/asset/manifest/src/Obelisk/Asset/Gather.hs+5−2 lib/command/src/Obelisk/Command.hs+20−1 lib/command/src/Obelisk/Command/Project.hs+6−5
ChangeLog.md+2
@@ -7,6 +7,8 @@ This project's release branch is `master`. This log is written from the perspect
77* Fix crashes of Android apps on 32-bit ARM devices.
88* Provide a way to indicate acceptance of the Android SDK license by passing `config.android_sdk.accept_license = true;` in the arguments to the import of `.obelisk/impl` in the project's `default.nix`.
99* Add `COMPLETE` pragma to `(:/)`. Using this pattern synonym should no longer generate spurious warnings about non-exhaustive pattern matching.
10+* Make asset path hashing strict (see `Obelisk.Asset.Gather`)
11+* Add the `ob shell` command to enter a nix shell for an obelisk project
1012
1113## v0.1.0.0 - 2019-03-29
1214
README.md+1
@@ -24,6 +24,7 @@ Obelisk provides an easy way to develop and deploy your [Reflex](https://github.
2424 nix.binaryCaches = [ "https://cache.nixos.org/" "https://nixcache.reflex-frp.org" ];
2525 nix.binaryCachePublicKeys = [ "ryantrinkle.com-1:JJiAKaRv9mWgpVAz8dwewnZe0AzzEAzPkagE9SP5NWI=" ];
2626 ```
27+ and rebuild your NixOS configuration (e.g. `sudo nixos-rebuild switch`).
2728 1. If you are using another operating system or linux distribution, ensure that these lines are present in your Nix configuration file (`/etc/nix/nix.conf` on most systems; [see full list](https://nixos.org/nix/manual/#sec-conf-file)):
2829 ```
2930 substituters = https://cache.nixos.org https://nixcache.reflex-frp.org
lib/asset/manifest/obelisk-asset-manifest.cabal+1
@@ -17,6 +17,7 @@ library
1717 base
1818 , bytestring
1919 , containers
20+ , deepseq
2021 , directory
2122 , SHA
2223 , filepath
lib/asset/manifest/src/Obelisk/Asset/Gather.hs+5−2
@@ -1,10 +1,12 @@
11{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE BangPatterns #-}
23-- | Functions for collecting up files to be processed by the asset pipeline
34module Obelisk.Asset.Gather
45 ( gatherHashedPaths
56 , toHashedPath
67 ) where
78
9+import Control.DeepSeq
810import Control.Monad (forM)
911import Data.Bits
1012import qualified Data.ByteString.Lazy as LBS
@@ -33,7 +35,7 @@ gatherHashedPaths root = go ""
3335 let relativePath = subdir </> sub
3436 isFile <- doesFileExist $ root </> relativePath
3537 if isFile
36− then do hashedRelativePath <- toHashedPath root relativePath
38+ then do !hashedRelativePath <- force <$> toHashedPath root relativePath
3739 return $ Map.singleton relativePath hashedRelativePath
3840 else go relativePath
3941
@@ -47,7 +49,8 @@ toHashedPath root relativePath = do
4749 contents <- LBS.readFile path
4850 let hashPrefix = T.unpack $ decodeUtf8 $ LBS.toStrict $ toNixBase32 $ bytestringDigest $ sha256 contents
4951 (dir, filename) = splitFileName relativePath
50− return $ normalise $ dir </> (hashPrefix <> "-" <> filename)
52+ !hashedRelativePath = force $ normalise $ dir </> (hashPrefix <> "-" <> filename)
53+ return hashedRelativePath
5154
5255-- | Convert a ByteString to base 32 in the way that Nix does
5356toNixBase32 :: LBS.ByteString -> LBS.ByteString
lib/command/src/Obelisk/Command.hs+20−1
@@ -92,6 +92,7 @@ data ObCommand
9292 | ObCommand_Thunk ThunkCommand
9393 | ObCommand_Repl
9494 | ObCommand_Watch
95+ | ObCommand_Shell ShellOpts
9596 | ObCommand_Internal ObInternal
9697 deriving Show
9798
@@ -103,7 +104,7 @@ data ObInternal
103104inNixShell' :: MonadObelisk m => StaticPtr (ObeliskT IO ()) -> m ()
104105inNixShell' p = withProjectRoot "." $ \root -> do
105106 cmd <- liftIO $ unwords <$> mkCmd -- TODO: shell escape instead of unwords
106− projectShell root False "ghc" cmd
107+ projectShell root False "ghc" (Just cmd)
107108 where
108109 mkCmd = do
109110 argsCfg <- getArgsConfig
@@ -127,6 +128,7 @@ obCommand cfg = hsubparser
127128 , command "thunk" $ info (ObCommand_Thunk <$> thunkCommand) $ progDesc "Manipulate thunk directories"
128129 , command "repl" $ info (pure ObCommand_Repl) $ progDesc "Open an interactive interpreter"
129130 , command "watch" $ info (pure ObCommand_Watch) $ progDesc "Watch current project for errors and warnings"
131+ , command "shell" $ info (ObCommand_Shell <$> shellOpts) $ progDesc "Enter a shell with project dependencies"
130132 ])
131133 <|> subparser
132134 (mconcat
@@ -221,6 +223,21 @@ thunkCommand = hsubparser $ mconcat
221223 , command "pack" $ info (ThunkCommand_Pack <$> some thunkDirectoryParser) $ progDesc "Pack git checkout into thunk that points at the current branch's upstream"
222224 ]
223225
226+data ShellOpts
227+ = ShellOpts
228+ { _shellOpts_shell :: String
229+ , _shellOpts_command :: Maybe String
230+ }
231+ deriving Show
232+
233+shellOpts :: Parser ShellOpts
234+shellOpts = ShellOpts
235+ <$> ( flag' "ghc" (long "ghc" <> help "Enter a shell environment having ghc (default)")
236+ <|> flag "ghc" "ghcjs" (long "ghcjs" <> help "Enter a shell having ghcjs rather than ghc")
237+ <|> strOption (short 'A' <> long "argument" <> metavar "NIXARG" <> help "Use the environment specified by the given nix argument of `shells'")
238+ )
239+ <*> optional (strArgument (metavar "COMMAND"))
240+
224241parserPrefs :: ParserPrefs
225242parserPrefs = defaultPrefs
226243 { prefShowHelpOnEmpty = True
@@ -347,6 +364,8 @@ ob = \case
347364 ThunkCommand_Pack thunks -> forM_ thunks packThunk
348365 ObCommand_Repl -> runRepl
349366 ObCommand_Watch -> inNixShell' $ static runWatch
367+ ObCommand_Shell so -> withProjectRoot "." $ \root ->
368+ projectShell root False (_shellOpts_shell so) (_shellOpts_command so)
350369 ObCommand_Internal icmd -> case icmd of
351370 ObInternal_RunStaticIO k -> liftIO (unsafeLookupStaticPtr @(ObeliskT IO ()) k) >>= \case
352371 Nothing -> failWith $ "ObInternal_RunStaticIO: no such StaticKey: " <> T.pack (show k)
lib/command/src/Obelisk/Command/Project.hs+6−5
@@ -196,20 +196,21 @@ isWritableOnlyBy s uid = fileOwner s == uid && fileMode s .&. 0o22 == 0
196196-- | Run a command in the given shell for the current project
197197inProjectShell :: MonadObelisk m => String -> String -> m ()
198198inProjectShell shellName command = withProjectRoot "." $ \root ->
199− projectShell root True shellName command
199+ projectShell root True shellName (Just command)
200200
201201inImpureProjectShell :: MonadObelisk m => String -> String -> m ()
202202inImpureProjectShell shellName command = withProjectRoot "." $ \root ->
203− projectShell root False shellName command
203+ projectShell root False shellName (Just command)
204204
205−projectShell :: MonadObelisk m => FilePath -> Bool -> String -> String -> m ()
205+projectShell :: MonadObelisk m => FilePath -> Bool -> String -> Maybe String -> m ()
206206projectShell root isPure shellName command = do
207207 (_, _, _, ph) <- createProcess_ "runNixShellAttr" $ setCtlc $ setCwd (Just root) $ proc "nix-shell" $
208208 [ "--pure" | isPure ] <>
209209 [ "-A"
210210 , "shells." <> shellName
211− , "--run", command
212− ]
211+ ] <> case command of
212+ Nothing -> []
213+ Just c -> ["--run", c]
213214 void $ liftIO $ waitForProcess ph
214215
215216setCtlc :: CreateProcess -> CreateProcess