on master help sign in
Merge pull request #347 from obsidiansystems/aa-staticfilesimpure-derivation
fc1a3d8Ali Abrar
lib/command/src/Obelisk/Command/Run.hs+20−5
@@ -54,11 +54,26 @@ 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)
72+ if isDerivation == "1"
60− readProcessAndLogStderr Debug $
73+ then fmap T.strip $ readProcessAndLogStderr Debug $ -- Strip whitespace here because nix-build has no --raw option
74+ proc "nix-build" ["-E", "(import " <> importableRoot <> "{}).passthru.staticFilesImpure"]
75+ else readProcessAndLogStderr Debug $
61− proc "nix" ["eval", "-f", root, "passthru.staticFilesImpure", "--raw"]
76+ proc "nix" ["eval", "-f", root, "passthru.staticFilesImpure", "--raw"]
62 putLog Debug $ "Assets impurely loaded from: " <> assets
77 putLog Debug $ "Assets impurely loaded from: " <> assets
63 runGhcid dotGhciPath $ Just $ unwords
78 runGhcid dotGhciPath $ Just $ unwords
64 [ "run"
79 [ "run"