on master help sign in
Move findProjectAssets to Obelisk.Command.Project
eea6d5bMatthew Bauer
lib/command/src/Obelisk/Command/Project.hs+25−1
@@ -5,6 +5,7 @@ module Obelisk.Command.Project
5 ( InitSource (..)
5 ( InitSource (..)
6 , findProjectObeliskCommand
6 , findProjectObeliskCommand
7 , findProjectRoot
7 , findProjectRoot
8+ , findProjectAssets
8 , initProject
9 , initProject
9 , nixShellRunConfig
10 , nixShellRunConfig
10 , nixShellRunProc
11 , nixShellRunProc
@@ -50,7 +51,7 @@ import Obelisk.App (MonadObelisk)
50import Obelisk.CliApp
51import Obelisk.CliApp
51import Obelisk.Command.Nix
52import Obelisk.Command.Nix
52import Obelisk.Command.Thunk
53import Obelisk.Command.Thunk
53−import Obelisk.Command.Utils (nixExePath)
54+import Obelisk.Command.Utils (nixExePath, nixBuildExePath)
54
55
55--TODO: Make this module resilient to random exceptions
56--TODO: Make this module resilient to random exceptions
56
57
@@ -307,3 +308,26 @@ projectShell root isPure shellName command = do
307 & nixShellConfig_common . nixCmdConfig_target . target_path ?~ "default.nix"
308 & nixShellConfig_common . nixCmdConfig_target . target_path ?~ "default.nix"
308 & nixShellConfig_common . nixCmdConfig_target . target_attr ?~ ("shells." <> shellName)
309 & nixShellConfig_common . nixCmdConfig_target . target_attr ?~ ("shells." <> shellName)
309 void $ liftIO $ waitForProcess ph
310 void $ liftIO $ waitForProcess ph
311+
312+findProjectAssets :: MonadObelisk m => FilePath -> m Text
313+findProjectAssets root = do
314+ let importableRoot = toNixPath root
315+ isDerivation <- readProcessAndLogStderr Debug $
316+ proc nixExePath
317+ [ "eval"
318+ , "-f"
319+ , root
320+ , "(let a = import " <> importableRoot <> " {}; in toString (a.reflex.nixpkgs.lib.isDerivation a.passthru.staticFilesImpure))"
321+ , "--raw"
322+ -- `--raw` is not available with old nix-instantiate. It drops quotation
323+ -- marks and trailing newline, so is very convenient for shelling out.
324+ ]
325+ -- Check whether the impure static files are a derivation (and so must be built)
326+ if isDerivation == "1"
327+ then fmap T.strip $ readProcessAndLogStderr Debug $ -- Strip whitespace here because nix-build has no --raw option
328+ proc nixBuildExePath
329+ [ "--no-out-link"
330+ , "-E", "(import " <> importableRoot <> "{}).passthru.staticFilesImpure"
331+ ]
332+ else readProcessAndLogStderr Debug $
333+ proc nixExePath ["eval", "-f", root, "passthru.staticFilesImpure", "--raw"]
lib/command/src/Obelisk/Command/Run.hs+4−24
@@ -47,10 +47,10 @@ import qualified System.Info
47import System.IO.Temp (withSystemTempDirectory)
47import System.IO.Temp (withSystemTempDirectory)
48
48
49import Obelisk.App (MonadObelisk)
49import Obelisk.App (MonadObelisk)
50−import Obelisk.CliApp (Severity (..) , failWith, putLog, proc, readCreateProcessWithExitCode, readProcessAndLogStderr)
50+import Obelisk.CliApp (Severity (..) , failWith, putLog, proc, readCreateProcessWithExitCode)
51−import Obelisk.Command.Project (obeliskDirName, toObeliskDir, withProjectRoot, nixShellWithPkgs, toNixPath)
51+import Obelisk.Command.Project (obeliskDirName, toObeliskDir, withProjectRoot, nixShellWithPkgs, findProjectAssets)
52import Obelisk.Command.Thunk (attrCacheFileName)
52import Obelisk.Command.Thunk (attrCacheFileName)
53−import Obelisk.Command.Utils (findExePath, ghcidExePath, nixBuildExePath, nixExePath)
53+import Obelisk.Command.Utils (findExePath, ghcidExePath)
54
54
55data CabalPackageInfo = CabalPackageInfo
55data CabalPackageInfo = CabalPackageInfo
56 { _cabalPackageInfo_packageFile :: FilePath
56 { _cabalPackageInfo_packageFile :: FilePath
@@ -76,27 +76,7 @@ run = withProjectRoot "." $ \root -> do
76 pkgs <- fmap toList . parsePackagesOrFail =<< getLocalPkgs root
76 pkgs <- fmap toList . parsePackagesOrFail =<< getLocalPkgs root
77 withGhciScript pkgs root $ \dotGhciPath -> do
77 withGhciScript pkgs root $ \dotGhciPath -> do
78 freePort <- getFreePort
78 freePort <- getFreePort
79− assets <- do
79+ assets <- findProjectAssets root
80− let importableRoot = toNixPath root
81− isDerivation <- readProcessAndLogStderr Debug $
82− proc nixExePath
83− [ "eval"
84− , "-f"
85− , root
86− , "(let a = import " <> importableRoot <> " {}; in toString (a.reflex.nixpkgs.lib.isDerivation a.passthru.staticFilesImpure))"
87− , "--raw"
88− -- `--raw` is not available with old nix-instantiate. It drops quotation
89− -- marks and trailing newline, so is very convenient for shelling out.
90− ]
91− -- Check whether the impure static files are a derivation (and so must be built)
92− if isDerivation == "1"
93− then fmap T.strip $ readProcessAndLogStderr Debug $ -- Strip whitespace here because nix-build has no --raw option
94− proc nixBuildExePath
95− [ "--no-out-link"
96− , "-E", "(import " <> importableRoot <> "{}).passthru.staticFilesImpure"
97− ]
98− else readProcessAndLogStderr Debug $
99− proc nixExePath ["eval", "-f", root, "passthru.staticFilesImpure", "--raw"]
100 putLog Debug $ "Assets impurely loaded from: " <> assets
80 putLog Debug $ "Assets impurely loaded from: " <> assets
101 runGhcid root True dotGhciPath pkgs $ Just $ unwords
81 runGhcid root True dotGhciPath pkgs $ Just $ unwords
102 [ "Obelisk.Run.run"
82 [ "Obelisk.Run.run"