on master help sign in
Merge pull request #347 from obsidiansystems/aa-staticfilesimpure-derivation

Check whether staticFilesImpure is a derivation and build it if so

commitfc1a3d86e95adff9083905f81a9c1c5b0c34237e authorAli Abrar <aliabrar@gmail.com> dateMon 4 Feb 2019, 18:59 (8 years ago) parente7b2d640c35f48
1 file changed+20−5
lib/command/src/Obelisk/Command/Run.hs+20−5
lib/command/src/Obelisk/Command/Run.hs+20−5
@@ -54,11 +54,26 @@ 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+ if isDerivation == "1"
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 $
76+ proc "nix" ["eval", "-f", root, "passthru.staticFilesImpure", "--raw"]
6277 putLog Debug $ "Assets impurely loaded from: " <> assets
6378 runGhcid dotGhciPath $ Just $ unwords
6479 [ "run"