on master help sign in
Merge pull request #294 from obsidiansystems/pure-assets-lib
d5db37cLuigy Leon
default.nix+3−2
@@ -152,7 +152,7 @@ in rec {
152 set -euo pipefail
152 set -euo pipefail
153 touch "$out"
153 touch "$out"
154 mkdir -p "$symlinked"
154 mkdir -p "$symlinked"
155− obelisk-asset-manifest-generate "$src" "${builtins.toString src}" "$haskellManifest" ${packageName} ${moduleName} "$symlinked"
155+ obelisk-asset-manifest-generate "$src" "$haskellManifest" ${packageName} ${moduleName} "$symlinked"
156 '';
156 '';
157
157
158 compressedJs = frontend: optimizationLevel: pkgs.runCommand "compressedJs" { buildInputs = [ pkgs.closurecompiler ]; } ''
158 compressedJs = frontend: optimizationLevel: pkgs.runCommand "compressedJs" { buildInputs = [ pkgs.closurecompiler ]; } ''
@@ -273,6 +273,7 @@ in rec {
273 backendName = "backend";
273 backendName = "backend";
274 commonName = "common";
274 commonName = "common";
275 staticName = "obelisk-generated-static";
275 staticName = "obelisk-generated-static";
276+ staticFilesImpure = if lib.isDerivation staticFiles then staticFiles else toString staticFiles;
276 processedStatic = processAssets { src = staticFiles; };
277 processedStatic = processAssets { src = staticFiles; };
277 # The packages whose names and roles are defined by this package
278 # The packages whose names and roles are defined by this package
278 predefinedPackages = lib.filterAttrs (_: x: x != null) {
279 predefinedPackages = lib.filterAttrs (_: x: x != null) {
@@ -324,7 +325,7 @@ in rec {
324 nixpkgs.obeliskExecutableConfig.platforms.ios.inject injectableConfig processedStatic.symlinked;
325 nixpkgs.obeliskExecutableConfig.platforms.ios.inject injectableConfig processedStatic.symlinked;
325 } // ios;
326 } // ios;
326 };
327 };
327− passthru = { inherit android ios packages overrides tools shellToolOverrides withHoogle staticFiles __closureCompilerOptimizationLevel; };
328+ passthru = { inherit android ios packages overrides tools shellToolOverrides withHoogle staticFiles staticFilesImpure __closureCompilerOptimizationLevel; };
328 };
329 };
329 in mkProject (projectDefinition args));
330 in mkProject (projectDefinition args));
330 serverOn = sys: config: version: serverExe
331 serverOn = sys: config: version: serverExe
lib/asset/manifest/src-bin/generate.hs+1−2
@@ -7,11 +7,10 @@ import System.Environment
7main :: IO ()
7main :: IO ()
8main = do
8main = do
9 --TODO: Usage
9 --TODO: Usage
10− [root, rootLocalPath, haskellTarget, packageName, moduleName, fileTarget] <- getArgs
10+ [root, haskellTarget, packageName, moduleName, fileTarget] <- getArgs
11 paths <- gatherHashedPaths root
11 paths <- gatherHashedPaths root
12 writeStaticProject paths haskellTarget $ StaticConfig
12 writeStaticProject paths haskellTarget $ StaticConfig
13 { _staticConfig_packageName = T.pack packageName
13 { _staticConfig_packageName = T.pack packageName
14 , _staticConfig_moduleName = T.pack moduleName
14 , _staticConfig_moduleName = T.pack moduleName
15− , _staticConfig_rootPath = rootLocalPath
16 }
15 }
17 copyAndSymlink paths root fileTarget
16 copyAndSymlink paths root fileTarget
lib/asset/manifest/src/Obelisk/Asset/Promoted.hs+1−9
@@ -28,7 +28,6 @@ import qualified Data.Map as Map
28data StaticConfig = StaticConfig
28data StaticConfig = StaticConfig
29 { _staticConfig_packageName :: Text --TODO: Better type
29 { _staticConfig_packageName :: Text --TODO: Better type
30 , _staticConfig_moduleName :: Text --TODO: Better type
30 , _staticConfig_moduleName :: Text --TODO: Better type
31− , _staticConfig_rootPath :: FilePath
32 }
31 }
33
32
34writeStaticProject :: Map FilePath FilePath -> FilePath -> StaticConfig -> IO ()
33writeStaticProject :: Map FilePath FilePath -> FilePath -> StaticConfig -> IO ()
@@ -41,14 +40,7 @@ writeStaticProject paths target cfg = do
41 Just (name, parents) -> (name, target </> "src" </> T.unpack (T.intercalate "/" $ reverse parents))
40 Just (name, parents) -> (name, target </> "src" </> T.unpack (T.intercalate "/" $ reverse parents))
42 createDirectoryIfMissing True moduleDirPath
41 createDirectoryIfMissing True moduleDirPath
43 modContents <- staticModuleFile modName paths
42 modContents <- staticModuleFile modName paths
44− T.writeFile (moduleDirPath </> T.unpack modName' <.> "hs") $ appendRootPath (_staticConfig_rootPath cfg) modContents
43+ T.writeFile (moduleDirPath </> T.unpack modName' <.> "hs") modContents
45−
46−appendRootPath :: FilePath -> Text -> Text
47−appendRootPath fp txt = T.unlines
48− [ txt
49− , "staticRootPath :: FilePath"
50− , "staticRootPath = \"" <> T.pack fp <> "\""
51− ]
52
44
53staticCabalFile :: StaticConfig -> Text
45staticCabalFile :: StaticConfig -> Text
54staticCabalFile cfg = T.unlines
46staticCabalFile cfg = T.unlines
lib/command/src/Obelisk/Command/Project.hs+1−1
@@ -145,7 +145,7 @@ findProjectRoot target = do
145 (result, _) <- liftIO $ runStateT (walkToProjectRoot target targetStat myUid) []
145 (result, _) <- liftIO $ runStateT (walkToProjectRoot target targetStat myUid) []
146 return result
146 return result
147
147
148−withProjectRoot :: MonadObelisk m => FilePath -> (FilePath -> m ()) -> m ()
148+withProjectRoot :: MonadObelisk m => FilePath -> (FilePath -> m a) -> m a
149withProjectRoot target f = findProjectRoot target >>= \case
149withProjectRoot target f = findProjectRoot target >>= \case
150 Nothing -> failWith "Must be used inside of an Obelisk project"
150 Nothing -> failWith "Must be used inside of an Obelisk project"
151 Just root -> f root
151 Just root -> f root
lib/command/src/Obelisk/Command/Run.hs+20−5
@@ -26,16 +26,19 @@ import Hpack.Config
26import Hpack.Render
26import Hpack.Render
27import Hpack.Yaml
27import Hpack.Yaml
28import Language.Haskell.Extension
28import Language.Haskell.Extension
29−import Network.Socket
29+import Network.Socket hiding (Debug)
30import System.Directory
30import System.Directory
31import System.FilePath
31import System.FilePath
32+import System.Process (proc)
32import System.IO.Temp (withSystemTempDirectory)
33import System.IO.Temp (withSystemTempDirectory)
33import Data.ByteString (ByteString)
34import Data.ByteString (ByteString)
34
35
35import Obelisk.App (MonadObelisk, ObeliskT)
36import Obelisk.App (MonadObelisk, ObeliskT)
37+import Obelisk.CliApp
38+ ( CliT (..), HasCliConfig, Severity (..)
36−import Obelisk.CliApp (CliT (..), HasCliConfig, Severity (..), callCommand, failWith, getCliConfig, putLog,
39+ , callCommand, failWith, getCliConfig, putLog
37− runCli)
40+ , readProcessAndLogStderr, runCli)
38−import Obelisk.Command.Project (inProjectShell)
41+import Obelisk.Command.Project (inProjectShell, withProjectRoot)
39
42
40data CabalPackageInfo = CabalPackageInfo
43data CabalPackageInfo = CabalPackageInfo
41 { _cabalPackageInfo_packageRoot :: FilePath
44 { _cabalPackageInfo_packageRoot :: FilePath
@@ -51,7 +54,19 @@ run = do
51 pkgs <- getLocalPkgs
54 pkgs <- getLocalPkgs
52 withGhciScript pkgs $ \dotGhciPath -> do
55 withGhciScript pkgs $ \dotGhciPath -> do
53 freePort <- getFreePort
56 freePort <- getFreePort
54− runGhcid dotGhciPath $ Just $ unwords ["run", show freePort, "(runServeAsset Obelisk.Generated.Static.staticRootPath)", "Backend.backend", "Frontend.frontend"]
57+ assets <- withProjectRoot "." $ \root ->
58+ -- `--raw` is not available with old nix-instantiate. It drops quotation
59+ -- marks and trailing newline, so is very convenient for shelling out.
60+ readProcessAndLogStderr Debug $
61+ proc "nix" ["eval", "-f", root, "passthru.staticFilesImpure", "--raw"]
62+ putLog Debug $ "Assets impurely loaded from: " <> assets
63+ runGhcid dotGhciPath $ Just $ unwords
64+ [ "run"
65+ , show freePort
66+ , "(runServeAsset " ++ show assets ++ ")"
67+ , "Backend.backend"
68+ , "Frontend.frontend"
69+ ]
55
70
56runRepl :: MonadObelisk m => m ()
71runRepl :: MonadObelisk m => m ()
57runRepl = do
72runRepl = do