on master help sign in
Merge pull request #561 from obsidiansystems/jb-add-nix-to-ob-run-shell

Provide nix executable to ob run

commit98bd078f4f2b60fa3844b34039323b73fe9d09b9 authorAli Abrar <aliabrar@gmail.com> dateSat 23 Nov 2019, 21:19 (7 years ago) parent0722c557fa01c3
3 files changed+9−4
default.nix+1−1 lib/command/obelisk-command.cabal+1 lib/command/src/Obelisk/Command/Run.hs+7−3
default.nix+1−1
@@ -59,7 +59,7 @@ let
5959 obelisk-asset-serve-snap = self.callCabal2nix "obelisk-asset-serve-snap" (cleanSource ./lib/asset/serve-snap) {};
6060 obelisk-backend = self.callCabal2nix "obelisk-backend" (cleanSource ./lib/backend) {};
6161 obelisk-cliapp = self.callCabal2nix "obelisk-cliapp" (cleanSource ./lib/cliapp) {};
62− obelisk-command = self.callCabal2nix "obelisk-command" (cleanSource ./lib/command) {};
62+ obelisk-command = haskellLib.overrideCabal (self.callCabal2nix "obelisk-command" (cleanSource ./lib/command) {}) { librarySystemDepends = [ pkgs.nix ]; };
6363 obelisk-frontend = self.callCabal2nix "obelisk-frontend" (cleanSource ./lib/frontend) {};
6464 obelisk-run = self.callCabal2nix "obelisk-run" (cleanSource ./lib/run) {};
6565 obelisk-route = self.callCabal2nix "obelisk-route" (cleanSource ./lib/route) {};
lib/command/obelisk-command.cabal+1
@@ -46,6 +46,7 @@ library
4646 , transformers
4747 , unix
4848 , unordered-containers
49+ , which
4950 , yaml
5051 exposed-modules:
5152 Obelisk.App
lib/command/src/Obelisk/Command/Run.hs+7−3
@@ -3,6 +3,7 @@
33{-# LANGUAGE MultiParamTypeClasses #-}
44{-# LANGUAGE OverloadedStrings #-}
55{-# LANGUAGE ScopedTypeVariables #-}
6+{-# LANGUAGE TemplateHaskell #-}
67module Obelisk.Command.Run where
78
89import Control.Exception (bracket)
@@ -32,6 +33,7 @@ import System.Directory
3233import System.FilePath
3334import System.Process (proc)
3435import System.IO.Temp (withSystemTempDirectory)
36+import System.Which (staticWhich)
3537import Data.ByteString (ByteString)
3638
3739import Obelisk.App (MonadObelisk, ObeliskT)
@@ -56,6 +58,8 @@ data CabalPackageInfo = CabalPackageInfo
5658-- NOTE: `run` is not polymorphic like the rest because we use StaticPtr to invoke it.
5759run :: ObeliskT IO ()
5860run = do
61+ let nixPath = $(staticWhich "nix")
62+ nixBuildPath = $(staticWhich "nix-build")
5963 pkgs <- getLocalPkgs
6064 withGhciScript pkgs $ \dotGhciPath -> do
6165 freePort <- getFreePort
@@ -64,7 +68,7 @@ run = do
6468 then root
6569 else "./" <> root
6670 isDerivation <- readProcessAndLogStderr Debug $
67− proc "nix"
71+ proc nixPath
6872 [ "eval"
6973 , "-f"
7074 , root
@@ -76,12 +80,12 @@ run = do
7680 -- Check whether the impure static files are a derivation (and so must be built)
7781 if isDerivation == "1"
7882 then fmap T.strip $ readProcessAndLogStderr Debug $ -- Strip whitespace here because nix-build has no --raw option
79− proc "nix-build"
83+ proc nixBuildPath
8084 [ "--no-out-link"
8185 , "-E", "(import " <> importableRoot <> "{}).passthru.staticFilesImpure"
8286 ]
8387 else readProcessAndLogStderr Debug $
84− proc "nix" ["eval", "-f", root, "passthru.staticFilesImpure", "--raw"]
88+ proc nixPath ["eval", "-f", root, "passthru.staticFilesImpure", "--raw"]
8589 putLog Debug $ "Assets impurely loaded from: " <> assets
8690 runGhcid dotGhciPath $ Just $ unwords
8791 [ "Obelisk.Run.run"