@@ -60,7 +60,7 @@ import Text.ShellEscape (bash, bytes)
6060import GitHub.Data.GitData (Branch)
6161import GitHub.Data.Name (Name)
6262
63−import Obelisk.App (MonadObelisk)
63+import Obelisk.App (MonadObelisk, runObelisk, getObelisk)
6464import Obelisk.CliApp
6565import Obelisk.Command.Nix
6666import Obelisk.Command.Thunk
@@ -374,9 +374,7 @@ findProjectAssets root = do
374374 -- Check whether the impure static files are a derivation (and so must be built)
375375 if isDerivation == "1"
376376 then do
377− _ <- readProcessAndLogStderr Debug $ setCwd (Just root) $
378− proc nixBuildExePath staticFilesDrvSymlinkArgs
379−
377+ _ <- buildStaticFilesDerivationAndSymlink root
380378 pure (AssetSource_Derivation, T.pack $ root </> "static.out")
381379 else fmap (AssetSource_Files,) $ readProcessAndLogStderr Debug $ setCwd (Just root) $
382380 proc nixExePath ["eval", "-f", ".", "passthru.staticFilesImpure", "--raw"]
@@ -390,42 +388,47 @@ getHaskellManifestProjectPath root = fmap T.strip $ readProcessAndLogStderr Debu
390388 , "(let a = import ./. {}; in a.passthru.processedStatic.haskellManifest)"
391389 ]
392390
393−staticFilesDrvSymlinkArgs :: [String]
394−staticFilesDrvSymlinkArgs =
395− [ "-o", "static.out"
396− , "-E", "(import ./. {}).passthru.staticFilesImpure"
397− ]
398−
399391-- | Watch the project directory for file changes and check whether those file changes
400392-- cause changes in the static files nix derivation. If so, rebuild it.
401393watchStaticFilesDerivation
402− :: MonadObelisk m
394+ :: (MonadIO m, MonadObelisk m)
403395 => FilePath
404396 -> m ()
405397watchStaticFilesDerivation root = do
406− cfg <- getCliConfig
407− drv0 <- liftIO runShowDrv
398+ ob <- getObelisk
399+ drv0 <- showDerivation
408400 liftIO $ runHeadlessApp $ do
409401 pb <- getPostBuild
410402 checkForChanges <- watchDirectoryTree defaultConfig (root <$ pb) (const True)
411− drv <- performEvent $ liftIO runShowDrv <$ checkForChanges
403+ drv <- performEvent $ ffor checkForChanges $ \_ ->
404+ liftIO $ runObelisk ob showDerivation
412405 drvs <- foldDyn (\new (_, old, _) -> (old, new, old /= new)) (drv0, drv0, False) drv
413406 out <- throttleBatchWithLag
414− (\e -> performEvent $ ffor e $ \_ -> liftIO $ void runDrvBuild)
407+ (\e -> performEvent $ ffor e $ \_ -> liftIO $ runObelisk ob $
408+ buildStaticFilesDerivationAndSymlink root >> pure ())
415409 (void $ ffilter (^._3) $ updated drvs)
416− performEvent_ $ ffor out $ \_ ->
417− runCli cfg $
418− putLog Informational "Static assets rebuilt and symlinked to static.out"
410+ performEvent_ $ ffor out $ \_ -> runObelisk ob $
411+ putLog Notice "Static assets rebuilt and symlinked to static.out"
419412 pure never
420413 where
421− showDrv :: Proc.CreateProcess
422− showDrv = (Proc.proc nixExePath
423− [ "show-derivation"
424− , "-f", "."
425− , "passthru.staticFilesImpure"
426− ]) { Proc.cwd = Just root }
427− runShowDrv :: IO String
428− runShowDrv = Proc.readCreateProcess showDrv ""
429− runDrvBuild :: IO String
430− runDrvBuild = Proc.readCreateProcess
431− ((Proc.proc nixBuildExePath staticFilesDrvSymlinkArgs) { Proc.cwd = Just root }) ""
414+ showDerivation :: MonadObelisk m => m Text
415+ showDerivation = readProcessAndLogStderr Debug $
416+ setCwd (Just root) $ ProcessSpec
417+ { _processSpec_createProcess = Proc.proc nixExePath
418+ [ "show-derivation"
419+ , "-f", "."
420+ , "passthru.staticFilesImpure"
421+ ]
422+ , _processSpec_overrideEnv = Nothing
423+ }
424+
425+buildStaticFilesDerivationAndSymlink :: MonadObelisk m => FilePath -> m Text
426+buildStaticFilesDerivationAndSymlink root = readProcessAndLogStderr Debug $
427+ setCwd (Just root) $ ProcessSpec
428+ { _processSpec_createProcess = Proc.proc
429+ nixBuildExePath
430+ [ "-o", "static.out"
431+ , "-E", "(import ./. {}).passthru.staticFilesImpure"
432+ ]
433+ , _processSpec_overrideEnv = Nothing
434+ }