on be4fc06 help sign in
5 files changed+91−94
since splitsnapshots
unifiedsplit
default.nix+35−34 dep/reflex-platform/github.json+3−3 lib/command/src/Obelisk/Command/Deploy.hs+16−13 lib/command/src/Obelisk/Command/Thunk.hs+34−42 lib/executable-config/default.nix+3−2
default.nix+35−34
@@ -329,40 +329,39 @@ in rec {
329329 });
330330 in allConfig;
331331 in (mkProject (projectDefinition args)).projectConfig);
332− mainProjectOut = projectOut { inherit system; };
332+ projectOutHost = projectOut { inherit system; };
333333 serverOn = projectInst: version: serverExe
334334 projectInst.ghc.backend
335− mainProjectOut.ghcjs.frontend
335+ projectOutHost.ghcjs.frontend
336336 projectInst.passthru.staticFiles
337337 projectInst.passthru.__closureCompilerOptimizationLevel
338338 version;
339− linuxExe = serverOn (projectOut { system = "x86_64-linux"; });
340339 dummyVersion = "Version number is only available for deployments";
341− in mainProjectOut // {
342− __unstable__.profiledObRun = let
343− profiled = projectOut { inherit system; enableLibraryProfiling = true; };
344− exeSource = builtins.toFile "ob-run.hs" ''
345− {-# LANGUAGE NoImplicitPrelude #-}
346− {-# LANGUAGE PackageImports #-}
347− module Main where
348−
349− -- Explicitly import Prelude from base lest there be multiple modules called Prelude
350− import "base" Prelude (IO, (++), read)
351−
352− import "base" Control.Exception (finally)
353− import "reflex" Reflex.Profiled (writeProfilingData)
354− import "base" System.Environment (getArgs)
355−
356− import qualified "obelisk-run" Obelisk.Run
357− import qualified Frontend
358− import qualified Backend
359−
360− main :: IO ()
361− main = do
362− [portStr, assets, profFileName] <- getArgs
363− Obelisk.Run.run (read portStr) (Obelisk.Run.runServeAsset assets) Backend.backend Frontend.frontend
364− `finally` writeProfilingData (profFileName ++ ".rprof")
365− '';
340+ profiledObRun =
341+ let
342+ profiled = projectOut { inherit system; enableLibraryProfiling = true; };
343+ exeSource = builtins.toFile "ob-run-profiled.hs" ''
344+ {-# LANGUAGE NoImplicitPrelude #-}
345+ {-# LANGUAGE PackageImports #-}
346+ module Main where
347+
348+ -- Explicitly import Prelude from base lest there be multiple modules called Prelude
349+ import "base" Prelude (IO, (++), read)
350+
351+ import "base" Control.Exception (finally)
352+ import "reflex" Reflex.Profiled (writeProfilingData)
353+ import "base" System.Environment (getArgs)
354+
355+ import qualified "obelisk-run" Obelisk.Run
356+ import qualified Frontend
357+ import qualified Backend
358+
359+ main :: IO ()
360+ main = do
361+ [portStr, assets, profFileName] <- getArgs
362+ Obelisk.Run.run (read portStr) (Obelisk.Run.runServeAsset assets) Backend.backend Frontend.frontend
363+ `finally` writeProfilingData (profFileName ++ ".rprof")
364+ '';
366365 in nixpkgs.runCommand "ob-run" {
367366 buildInputs = [ (profiled.ghc.ghcWithPackages (p: [p.backend p.frontend])) ];
368367 } ''
@@ -370,14 +369,16 @@ in rec {
370369 mkdir -p $out/bin
371370 ghc -x hs -prof -fno-prof-auto -threaded ob-run.hs -o $out/bin/ob-run
372371 '';
373−
374− linuxExeConfigurable = linuxExe;
375− linuxExe = linuxExe dummyVersion;
376− exe = serverOn mainProjectOut dummyVersion;
372+ in projectOutHost // lib.makeExtensible (self: {
373+ __unstable__.profiledObRun = profiledObRun;
374+ exeConfigurable = { system, version }: serverOn (projectOut { inherit system; }) version;
375+ exe = self.exeConfigurable { inherit system; version = dummyVersion; };
376+ linuxExeConfigurable = version: self.exeConfigurable { system = "x86_64-linux"; inherit version; };
377+ linuxExe = self.linuxExeConfigurable dummyVersion;
377378 server = args@{ hostName, adminEmail, routeHost, enableHttps, version, module ? serverModules.mkBaseEc2 }:
378− server (args // { exe = linuxExe version; });
379+ server (args // { exe = self.linuxExeConfigurable version; });
379380 obelisk = import (base' + "/.obelisk/impl") {};
380− };
381+ });
381382 haskellPackageSets = {
382383 inherit (reflex-platform) ghc ghcjs;
383384 };
dep/reflex-platform/github.json+3−3
@@ -1,8 +1,8 @@
11{
22 "owner": "reflex-frp",
33 "repo": "reflex-platform",
4− "branch": "develop",
4+ "branch": "eac@tweaks-from-wrinkl",
55 "private": false,
6− "rev": "c21ec7036c8351185cd2feef9ce577b6a61c4f22",
7− "sha256": "0m4sdpz6qvngralpyprrbvsyi2zmfh2l3q5vhihwfp3842blvbfg"
6+ "rev": "9cc0dc1e7c854b7c9d07269919b39b9ee75148ed",
7+ "sha256": "079wfal0qqccl5mwlmh4v6shqrx9rls36j5nwcnmz9wdj9p0rz11"
88}
lib/command/src/Obelisk/Command/Deploy.hs+16−13
@@ -17,6 +17,7 @@ import Data.Bits
1717import qualified Data.ByteString.Lazy as BSL
1818import Data.Default
1919import qualified Data.Map as Map
20+import Data.Maybe (isJust)
2021import qualified Data.Set as Set
2122import Data.String.Here.Interpolated (i)
2223import qualified Data.Text as T
@@ -125,14 +126,15 @@ deployPush deployPath getNixBuilders = do
125126 route <- readDeployConfig deployPath $ "config" </> "common" </> "route"
126127 routeHost <- getHostFromRoute enableHttps route
127128 let srcPath = deployPath </> "src"
128− thunkPtr <- readThunk srcPath >>= \case
129− Right (ThunkData_Packed _ ptr) -> return ptr
129+ thunkPtr' <- readThunk srcPath >>= \case
130+ Right (ThunkData_Packed _ ptr) -> return $ Just ptr
130131 Right ThunkData_Checkout -> do
131132 checkGitCleanStatus srcPath True >>= \case
132− True -> packThunk (ThunkPackConfig False (ThunkConfig Nothing)) srcPath
133− False -> failWith $ T.pack $ "ob deploy push: ensure " <> srcPath <> " has no pending changes and latest is pushed upstream."
133+ True -> Just <$> packThunk (ThunkPackConfig False (ThunkConfig Nothing)) srcPath
134+ False -> Nothing <$ putLog Warning "Skipping packing of src thunk; won't be able to automatically commit this deployment"
135+ -- failWith $ T.pack $ "ob deploy push: ensure " <> srcPath <> " has no pending changes and latest is pushed upstream."
134136 Left err -> failWith $ "ob deploy push: couldn't read src thunk: " <> T.pack (show err)
135− let version = show . _thunkRev_commit $ _thunkPtr_rev thunkPtr
137+ let version' = show . _thunkRev_commit . _thunkPtr_rev <$> thunkPtr'
136138 builders <- getNixBuilders
137139 let moduleFile = deployPath </> "module.nix"
138140 moduleFileExists <- liftIO $ doesFileExist moduleFile
@@ -149,7 +151,7 @@ deployPush deployPath getNixBuilders = do
149151 [ strArg "hostName" host
150152 , strArg "adminEmail" adminEmail
151153 , strArg "routeHost" routeHost
152− , strArg "version" version
154+ , strArg "version" $ maybe "Deployment was done with a dirty source tree" id version'
153155 , boolArg "enableHttps" enableHttps
154156 ] <> [rawArg "module" ("import " <> toNixPath moduleFile) | moduleFileExists ])
155157 & nixCmdConfig_builders .~ builders
@@ -179,13 +181,14 @@ deployPush deployPath getNixBuilders = do
179181 , "/nix/var/nix/profiles/system/bin/switch-to-configuration switch"
180182 ]
181183 ]
182− isClean <- checkGitCleanStatus deployPath True
183− when (not isClean) $ do
184− withSpinner "Committing changes to Git" $ do
185− callProcessAndLogOutput (Debug, Error) $ proc "git"
186− ["-C", deployPath, "add", "."]
187− callProcessAndLogOutput (Debug, Error) $ proc "git"
188− ["-C", deployPath, "commit", "-m", "New deployment"]
184+ when (isJust version') $ do
185+ isClean <- checkGitCleanStatus deployPath True
186+ when (not isClean) $ do
187+ withSpinner "Committing changes to Git" $ do
188+ callProcessAndLogOutput (Debug, Error) $ proc "git"
189+ ["-C", deployPath, "add", "."]
190+ callProcessAndLogOutput (Debug, Error) $ proc "git"
191+ ["-C", deployPath, "commit", "-m", "New deployment"]
189192 putLog Notice $ "Deployed => " <> T.pack route
190193 where
191194 callProcess' envMap cmd args = do
lib/command/src/Obelisk/Command/Thunk.hs+34−42
@@ -26,9 +26,8 @@ import qualified Data.ByteString.Lazy as LBS
2626import Data.Containers.ListUtils (nubOrd)
2727import Data.Default
2828import Data.Either.Combinators (fromRight', rightToMaybe)
29−import Data.Foldable (toList)
29+import Data.Foldable (for_, toList)
3030import Data.Function ((&))
31−import Data.Functor ((<&>))
3231import Data.Git.Ref (Ref)
3332import qualified Data.Git.Ref as Ref
3433import qualified Data.List as L
@@ -238,35 +237,38 @@ matchThunkSpecToDir
238237 -> Set FilePath -- ^ Set of file paths relative to the given directory
239238 -> m ThunkData
240239matchThunkSpecToDir thunkSpec dir dirFiles = do
241− case nonEmpty (toList $ dirFiles `Set.difference` expectedPaths) of
242− Just fs -> throwError $ ReadThunkError_UnrecognizedPaths $ (dir </>) <$> fs
243− Nothing -> pure ()
244− case nonEmpty (toList $ requiredPaths `Set.difference` dirFiles) of
245− Just fs -> throwError $ ReadThunkError_MissingPaths $ (dir </>) <$> fs
246− Nothing -> pure ()
247− datas <- fmap toList $ flip Map.traverseMaybeWithKey (_thunkSpec_files thunkSpec) $ \expectedPath -> \case
248− ThunkFileSpec_AttrCache -> Nothing <$ dirMayExist expectedPath
249− ThunkFileSpec_CheckoutIndicator -> liftIO (doesDirectoryExist (dir </> expectedPath)) <&> \case
250− False -> Nothing
251− True -> Just ThunkData_Checkout
252− ThunkFileSpec_FileMatches expectedContents -> handle (\(e :: IOError) -> throwError $ ReadThunkError_FileError e) $ do
253− actualContents <- liftIO (T.readFile $ dir </> expectedPath)
254− case T.strip expectedContents == T.strip actualContents of
255− True -> pure Nothing
256− False -> throwError $ ReadThunkError_FileDoesNotMatch (dir </> expectedPath) expectedContents
257− ThunkFileSpec_Ptr parser -> handle (\(e :: IOError) -> throwError $ ReadThunkError_FileError e) $ do
258− let path = dir </> expectedPath
259− liftIO (doesFileExist path) >>= \case
260− False -> pure Nothing
261− True -> do
262− actualContents <- liftIO $ LBS.readFile path
263− case parser actualContents of
264− Right v -> pure $ Just (ThunkData_Packed thunkSpec v)
265− Left e -> throwError $ ReadThunkError_UnparseablePtr (dir </> expectedPath) e
266−
267− case nonEmpty datas of
268− Nothing -> throwError ReadThunkError_UnrecognizedThunk
269− Just xs -> fold1WithM xs $ \a b -> either throwError pure (mergeThunkData a b)
240+ isCheckout <- fmap or $ flip Map.traverseWithKey (_thunkSpec_files thunkSpec) $ \expectedPath -> \case
241+ ThunkFileSpec_CheckoutIndicator -> liftIO (doesDirectoryExist (dir </> expectedPath))
242+ _ -> pure False
243+ case isCheckout of
244+ True -> pure ThunkData_Checkout
245+ False -> do
246+ for_ (nonEmpty (toList $ dirFiles `Set.difference` expectedPaths)) $ \fs ->
247+ throwError $ ReadThunkError_UnrecognizedPaths $ (dir </>) <$> fs
248+ for_ (nonEmpty (toList $ requiredPaths `Set.difference` dirFiles)) $ \fs ->
249+ throwError $ ReadThunkError_MissingPaths $ (dir </>) <$> fs
250+ datas <- fmap toList $ flip Map.traverseMaybeWithKey (_thunkSpec_files thunkSpec) $ \expectedPath -> \case
251+ ThunkFileSpec_AttrCache -> Nothing <$ dirMayExist expectedPath
252+ ThunkFileSpec_CheckoutIndicator -> pure Nothing -- Handled above
253+ ThunkFileSpec_FileMatches expectedContents -> handle (\(e :: IOError) -> throwError $ ReadThunkError_FileError e) $ do
254+ actualContents <- liftIO (T.readFile $ dir </> expectedPath)
255+ case T.strip expectedContents == T.strip actualContents of
256+ True -> pure Nothing
257+ False -> throwError $ ReadThunkError_FileDoesNotMatch (dir </> expectedPath) expectedContents
258+ ThunkFileSpec_Ptr parser -> handle (\(e :: IOError) -> throwError $ ReadThunkError_FileError e) $ do
259+ let path = dir </> expectedPath
260+ liftIO (doesFileExist path) >>= \case
261+ False -> pure Nothing
262+ True -> do
263+ actualContents <- liftIO $ LBS.readFile path
264+ case parser actualContents of
265+ Right v -> pure $ Just (thunkSpec, v)
266+ Left e -> throwError $ ReadThunkError_UnparseablePtr (dir </> expectedPath) e
267+
268+ uncurry ThunkData_Packed <$> case nonEmpty datas of
269+ Nothing -> throwError ReadThunkError_UnrecognizedThunk
270+ Just xs -> fold1WithM xs $ \a@(_, ptrA) (_, ptrB) ->
271+ if ptrA == ptrB then pure a else throwError $ ReadThunkError_AmbiguousPackedState ptrA ptrB
270272 where
271273 rootPathsOnly = Set.fromList . mapMaybe takeRootDir . Map.keys
272274 takeRootDir = fmap NonEmpty.head . nonEmpty . splitPath
@@ -282,15 +284,6 @@ matchThunkSpecToDir thunkSpec dir dirFiles = do
282284 True -> throwError $ ReadThunkError_UnrecognizedPaths $ expectedPath :| []
283285 False -> pure ()
284286
285− -- Combine 'ThunkData' from different files, preferring "Checkout" over "Packed"
286− mergeThunkData ThunkData_Checkout ThunkData_Checkout = Right ThunkData_Checkout
287− mergeThunkData ThunkData_Checkout ThunkData_Packed{} = Left bothPackedAndUnpacked
288− mergeThunkData ThunkData_Packed{} ThunkData_Checkout = Left bothPackedAndUnpacked
289− mergeThunkData a@(ThunkData_Packed _ ptrA) (ThunkData_Packed _ ptrB) =
290− if ptrA == ptrB then Right a else Left $ ReadThunkError_AmbiguousPackedState ptrA ptrB
291−
292− bothPackedAndUnpacked = ReadThunkError_UnrecognizedState "Both packed data and checkout present"
293−
294287 fold1WithM (x :| xs) f = foldM f x xs
295288
296289readThunkWith
@@ -305,8 +298,7 @@ readThunkWith specTypes dir = do
305298 Left e -> putLog Debug [i|Thunk specification ${_thunkSpec_name spec} did not match ${dir}: ${e}|] *> loop rest
306299 x@(Right _) -> x <$ putLog Debug [i|Thunk specification ${_thunkSpec_name spec} matched ${dir}|]
307300
308−-- | Read a thunk and validate that it is exactly a packed thunk.
309−-- If additional data is present, fail.
301+-- | Read a packed or unpacked thunk based on predefined thunk specifications.
310302readThunk :: (MonadObelisk m) => FilePath -> m (Either ReadThunkError ThunkData)
311303readThunk = readThunkWith thunkSpecTypes
312304
lib/executable-config/default.nix+3−2
@@ -5,13 +5,14 @@
55{ lib
66, runCommand
77, obeliskCleanSource
8+, staticDirName ? ""
89}:
910
1011let
1112 injectConfig = config: assets: runCommand "inject-config" {} (''
1213 set -x
13− mkdir -p $out
14− cp --no-preserve=mode -Lr "${assets}" $out/static
14+ mkdir -p "$out"/'${staticDirName}'
15+ cp --no-preserve=mode -Lr "${assets}"/. "$out"/'${staticDirName}'/
1516 chmod +w "$out"
1617 '' + lib.optionalString (!(builtins.isNull config)) ''
1718 if ! mkdir $out/config; then