on master help sign in
Check whether staticFilesImpure is a derivation and build it if so
6f4bf74Ali Abrar
lib/command/src/Obelisk/Command/Run.hs+18−5
@@ -54,11 +54,24 @@ run = do
54 pkgs <- getLocalPkgs
54 pkgs <- getLocalPkgs
55 withGhciScript pkgs $ \dotGhciPath -> do
55 withGhciScript pkgs $ \dotGhciPath -> do
56 freePort <- getFreePort
56 freePort <- getFreePort
57− assets <- withProjectRoot "." $ \root ->
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"
58− -- `--raw` is not available with old nix-instantiate. It drops quotation
68+ -- `--raw` is not available with old nix-instantiate. It drops quotation
59− -- marks and trailing newline, so is very convenient for shelling out.
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)
60− readProcessAndLogStderr Debug $
72+ readProcessAndLogStderr Debug $ if isDerivation == "1"
73+ then proc "nix-build" ["-E", "(import " <> importableRoot <> "{}).passthru.staticFilesImpure"]
61− proc "nix" ["eval", "-f", root, "passthru.staticFilesImpure", "--raw"]
74+ else proc "nix" ["eval", "-f", root, "passthru.staticFilesImpure", "--raw"]
62 putLog Debug $ "Assets impurely loaded from: " <> assets
75 putLog Debug $ "Assets impurely loaded from: " <> assets
63 runGhcid dotGhciPath $ Just $ unwords
76 runGhcid dotGhciPath $ Just $ unwords
64 [ "run"
77 [ "run"