on master help sign in
Check whether staticFilesImpure is a derivation and build it if so
commit6f4bf74a696c0521af1946ce62cafe2044046538 authorAli Abrar <aliabrar@gmail.com> dateTue 29 Jan 2019, 11:57 (8 years ago) parentba37ab1
1 file changed+18−5
lib/command/src/Obelisk/Command/Run.hs+18−5
lib/command/src/Obelisk/Command/Run.hs+18−5
@@ -54,11 +54,24 @@ run = do
5454 pkgs <- getLocalPkgs
5555 withGhciScript pkgs $ \dotGhciPath -> do
5656 freePort <- getFreePort
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"]
57+ assets <- withProjectRoot "." $ \root -> do
58+ let importableRoot = if "/" `isInfixOf` root
59+ then root
60+ else "./" <> root
61+ isDerivation <- readProcessAndLogStderr Debug $
62+ proc "nix"
63+ [ "eval"
64+ , "-f"
65+ , root
66+ , "(let a = import " <> importableRoot <> " {}; in toString (a.reflex.nixpkgs.lib.isDerivation a.passthru.staticFilesImpure))"
67+ , "--raw"
68+ -- `--raw` is not available with old nix-instantiate. It drops quotation
69+ -- marks and trailing newline, so is very convenient for shelling out.
70+ ]
71+ -- Check whether the impure static files are a derivation (and so must be built)
72+ readProcessAndLogStderr Debug $ if isDerivation == "1"
73+ then proc "nix-build" ["-E", "(import " <> importableRoot <> "{}).passthru.staticFilesImpure"]
74+ else proc "nix" ["eval", "-f", root, "passthru.staticFilesImpure", "--raw"]
6275 putLog Debug $ "Assets impurely loaded from: " <> assets
6376 runGhcid dotGhciPath $ Just $ unwords
6477 [ "run"