on master help sign in
Merge branch 'master' into ts-dont-store-config
commit53f2e91581c7db468f993c1cf0242d3abf471ad1 authorLuigy Leon <luichi.19@gmail.com> dateTue 13 Nov 2018, 13:55 (8 years ago) parent41c5d9a59456f3
10 files changed+211−122
README.md+2−2 default.nix+7−2 dep/reflex-platform/github.json+2−2 lib/asset/manifest/src-bin/generate.hs+1−2 lib/asset/manifest/src/Obelisk/Asset/Promoted.hs+1−9 lib/command/src/Obelisk/Command/Deploy.hs+53−55 lib/command/src/Obelisk/Command/Nix.hs+113−34 lib/command/src/Obelisk/Command/Project.hs+1−1 lib/command/src/Obelisk/Command/Run.hs+20−5 lib/command/src/Obelisk/Command/Thunk.hs+11−10
README.md+2−2
@@ -47,13 +47,13 @@ Obelisk provides an easy way to develop and deploy your [Reflex](https://github.
4747When developing on obelisk itself you may launch `ghcid` for the corresponding project as follows. For example to launch ghcid for `lib/backend` project:
4848
4949```
50−nix-shell -A obelisk.obelisk-backend.env --run "cd lib/backend && ghcid -c 'cabal new-repl'"
50+nix-shell -A obeliskEnvs.obelisk-backend --run "cd lib/backend && ghcid -c 'cabal new-repl'"
5151```
5252
5353Or to launch ghcid for `lib/command` project:
5454
5555```
56−nix-shell -A obelisk.obelisk-command.env --run "cd lib/command && ghcid -c 'cabal new-repl'"
56+nix-shell -A obeliskEnvs.obelisk-command --run "cd lib/command && ghcid -c 'cabal new-repl'"
5757```
5858
5959### Accessing private repositories
default.nix+7−2
@@ -114,6 +114,9 @@ let
114114 # The haskell environment used to build Obelisk itself, e.g. the 'ob' command
115115 ghcObelisk = reflex-platform.ghc;
116116
117+ # Development environments for obelisk packages.
118+ ghcObeliskEnvs = pkgs.lib.mapAttrs (n: v: reflex-platform.workOn ghcObelisk v) ghcObelisk;
119+
117120 inherit (import ./lib/asset/assets.nix { inherit nixpkgs; }) mkAssets;
118121
119122 haskellLib = pkgs.haskell.lib;
@@ -125,6 +128,7 @@ in rec {
125128 pathGit = ./.; # Used in CI by the migration graph hash algorithm to correctly ignore files.
126129 path = reflex-platform.filterGit ./.;
127130 obelisk = ghcObelisk;
131+ obeliskEnvs = ghcObeliskEnvs;
128132 command = ghcObelisk.obelisk-command;
129133 shell = pinBuildInputs "obelisk-shell" ([command] ++ commandRuntimeDeps pkgs) [];
130134
@@ -152,7 +156,7 @@ in rec {
152156 set -euo pipefail
153157 touch "$out"
154158 mkdir -p "$symlinked"
155− obelisk-asset-manifest-generate "$src" "${builtins.toString src}" "$haskellManifest" ${packageName} ${moduleName} "$symlinked"
159+ obelisk-asset-manifest-generate "$src" "$haskellManifest" ${packageName} ${moduleName} "$symlinked"
156160 '';
157161
158162 compressedJs = frontend: optimizationLevel: pkgs.runCommand "compressedJs" { buildInputs = [ pkgs.closurecompiler ]; } ''
@@ -272,6 +276,7 @@ in rec {
272276 backendName = "backend";
273277 commonName = "common";
274278 staticName = "obelisk-generated-static";
279+ staticFilesImpure = if lib.isDerivation staticFiles then staticFiles else toString staticFiles;
275280 processedStatic = processAssets { src = staticFiles; };
276281 # The packages whose names and roles are defined by this package
277282 predefinedPackages = lib.filterAttrs (_: x: x != null) {
@@ -323,7 +328,7 @@ in rec {
323328 nixpkgs.obeliskExecutableConfig.platforms.ios.inject injectableConfig processedStatic.symlinked;
324329 } // ios;
325330 };
326− passthru = { inherit android ios packages overrides tools shellToolOverrides withHoogle staticFiles __closureCompilerOptimizationLevel; };
331+ passthru = { inherit android ios packages overrides tools shellToolOverrides withHoogle staticFiles staticFilesImpure __closureCompilerOptimizationLevel; };
327332 };
328333 in mkProject (projectDefinition args));
329334 serverOn = sys: version: serverExe
dep/reflex-platform/github.json+2−2
@@ -2,6 +2,6 @@
22 "owner": "reflex-frp",
33 "repo": "reflex-platform",
44 "branch": "develop",
5− "rev": "018576456043fe8372a0332c93245a4a620c1fb7",
6− "sha256": "0qhnyyf96iajz97pbqfsw2l1kkbr1yq3bvw3qhjk031vdrkv7b7y"
5+ "rev": "a721a268120908c9902a8b20509e6983b7088161",
6+ "sha256": "1w3ka16qsxkilvhvn7vdywhnhaybv6z587rmjbbqz0qmd9rlk8yc"
77}
lib/asset/manifest/src-bin/generate.hs+1−2
@@ -7,11 +7,10 @@ import System.Environment
77main :: IO ()
88main = do
99 --TODO: Usage
10− [root, rootLocalPath, haskellTarget, packageName, moduleName, fileTarget] <- getArgs
10+ [root, haskellTarget, packageName, moduleName, fileTarget] <- getArgs
1111 paths <- gatherHashedPaths root
1212 writeStaticProject paths haskellTarget $ StaticConfig
1313 { _staticConfig_packageName = T.pack packageName
1414 , _staticConfig_moduleName = T.pack moduleName
15− , _staticConfig_rootPath = rootLocalPath
1615 }
1716 copyAndSymlink paths root fileTarget
lib/asset/manifest/src/Obelisk/Asset/Promoted.hs+1−9
@@ -28,7 +28,6 @@ import qualified Data.Map as Map
2828data StaticConfig = StaticConfig
2929 { _staticConfig_packageName :: Text --TODO: Better type
3030 , _staticConfig_moduleName :: Text --TODO: Better type
31− , _staticConfig_rootPath :: FilePath
3231 }
3332
3433writeStaticProject :: Map FilePath FilePath -> FilePath -> StaticConfig -> IO ()
@@ -41,14 +40,7 @@ writeStaticProject paths target cfg = do
4140 Just (name, parents) -> (name, target </> "src" </> T.unpack (T.intercalate "/" $ reverse parents))
4241 createDirectoryIfMissing True moduleDirPath
4342 modContents <- staticModuleFile modName paths
44− T.writeFile (moduleDirPath </> T.unpack modName' <.> "hs") $ appendRootPath (_staticConfig_rootPath cfg) modContents
45−
46−appendRootPath :: FilePath -> Text -> Text
47−appendRootPath fp txt = T.unlines
48− [ txt
49− , "staticRootPath :: FilePath"
50− , "staticRootPath = \"" <> T.pack fp <> "\""
51− ]
43+ T.writeFile (moduleDirPath </> T.unpack modName' <.> "hs") modContents
5244
5345staticCabalFile :: StaticConfig -> Text
5446staticCabalFile cfg = T.unlines
lib/command/src/Obelisk/Command/Deploy.hs+53−55
@@ -12,7 +12,7 @@ import Control.Monad.IO.Class (liftIO)
1212import Data.Bits
1313import Data.Default
1414import qualified Data.Map as Map
15−import Data.Maybe
15+import qualified Data.Set as Set
1616import qualified Data.Text as T
1717import qualified Data.Text.IO as T
1818import System.Directory
@@ -82,7 +82,7 @@ setupObeliskImpl deployDir = do
8282
8383deployPush :: MonadObelisk m => FilePath -> m [String] -> m ()
8484deployPush deployPath getNixBuilders = do
85− host <- readDeployConfig deployPath "backend_hosts"
85+ hosts <- Set.fromList . filter (/= mempty) . lines <$> readDeployConfig deployPath "backend_hosts"
8686 adminEmail <- readDeployConfig deployPath "admin_email"
8787 enableHttps <- read <$> readDeployConfig deployPath "enable_https"
8888 route <- readDeployConfig deployPath $ "config" </> "common" </> "route"
@@ -97,59 +97,57 @@ deployPush deployPath getNixBuilders = do
9797 Left err -> failWith $ "ob deploy push: couldn't read src thunk: " <> T.pack (show err)
9898 let version = show . _thunkRev_commit $ _thunkPtr_rev thunkPtr
9999 builders <- getNixBuilders
100− buildOutput <- nixBuild $ def
101− { _nixBuildConfig_target = Target
102− { _target_path = srcPath
103− , _target_attr = Just "server.system"
104− }
105− , _nixBuildConfig_outLink = OutLink_None
106− , _nixBuildConfig_args =
107− [ strArg "hostName" host
108− , strArg "adminEmail" adminEmail
109− , strArg "routeHost" routeHost
110− , strArg "version" version
111− , boolArg "enableHttps" enableHttps
112− ]
113− , _nixBuildConfig_builders = builders
114− }
115− let result = listToMaybe $ lines buildOutput
116− forM_ result $ \res -> do
117− let knownHostsPath = deployPath </> "backend_known_hosts"
118− sshOpts = sshArgs knownHostsPath (deployPath </> "ssh_key") False
119− deployAndSwitch outputPath = do
120− withSpinner "Uploading closure" $ do
121− callProcess'
122− (Map.fromList [("NIX_SSHOPTS", unwords sshOpts)])
123− "nix-copy-closure" ["-v", "--to", "root@" <> host, "--gzip", outputPath]
124−
125− withSpinner "Uploading config" $ do
126− callProcessAndLogOutput (Notice, Warning) $
127− proc "rsync"
128− [ "-e ssh " <> unwords sshOpts
129− , "-qarvz"
130− , deployPath </> "config"
131− , "root@" <> host <> ":/var/lib/backend"
132− ]
133−
134− withSpinner "Switching to new configuration" $ do
135− callProcessAndLogOutput (Notice, Warning) $
136− proc "ssh" $ sshOpts <>
137− [ "root@" <> host
138− , unwords
139− [ "nix-env -p /nix/var/nix/profiles/system --set " <> outputPath
140− , "&&"
141− , "/nix/var/nix/profiles/system/bin/switch-to-configuration switch"
142− ]
143− ]
144− deployAndSwitch res
145− isClean <- checkGitCleanStatus deployPath True
146− when (not isClean) $ do
147− withSpinner "Commiting changes to Git" $ do
148− callProcessAndLogOutput (Debug, Error) $ proc "git"
149− ["-C", deployPath, "add", "."]
150− callProcessAndLogOutput (Debug, Error) $ proc "git"
151− ["-C", deployPath, "commit", "-m", "New deployment"]
152− putLog Notice $ "Deployed => " <> T.pack route
100+ buildOutputByHost <- ifor (Map.fromSet (const ()) hosts) $ \host () -> do
101+ --TODO: What does it mean if this returns more or less than 1 line of output?
102+ [result] <- fmap lines $ nixCmd $ NixCmd_Build $ def
103+ & nixCmdConfig_target .~ Target
104+ { _target_path = Just srcPath
105+ , _target_attr = Just "server.system"
106+ , _target_expr = Nothing
107+ }
108+ & nixBuildConfig_outLink .~ OutLink_None
109+ & nixCmdConfig_args .~
110+ [ strArg "hostName" host
111+ , strArg "adminEmail" adminEmail
112+ , strArg "routeHost" routeHost
113+ , strArg "version" version
114+ , boolArg "enableHttps" enableHttps
115+ ]
116+ & nixCmdConfig_builders .~ builders
117+ pure result
118+ let knownHostsPath = deployPath </> "backend_known_hosts"
119+ sshOpts = sshArgs knownHostsPath (deployPath </> "ssh_key") False
120+ withSpinner "Uploading closures" $ ifor_ buildOutputByHost $ \host outputPath -> do
121+ callProcess'
122+ (Map.fromList [("NIX_SSHOPTS", unwords sshOpts)])
123+ "nix-copy-closure" ["-v", "--to", "root@" <> host, "--gzip", outputPath]
124+ withSpinner "Uploading config" $ ifor_ buildOutputByHost $ \host _ -> do
125+ callProcessAndLogOutput (Notice, Warning) $
126+ proc "rsync"
127+ [ "-e ssh " <> unwords sshOpts
128+ , "-qarvz"
129+ , deployPath </> "config"
130+ , "root@" <> host <> ":/var/lib/backend"
131+ ]
132+ --TODO: Create GC root so we're sure our closure won't go away during this time period
133+ withSpinner "Switching to new configuration" $ ifor_ buildOutputByHost $ \host outputPath -> do
134+ callProcessAndLogOutput (Notice, Warning) $
135+ proc "ssh" $ sshOpts <>
136+ [ "root@" <> host
137+ , unwords
138+ [ "nix-env -p /nix/var/nix/profiles/system --set " <> outputPath
139+ , "&&"
140+ , "/nix/var/nix/profiles/system/bin/switch-to-configuration switch"
141+ ]
142+ ]
143+ isClean <- checkGitCleanStatus deployPath True
144+ when (not isClean) $ do
145+ withSpinner "Commiting changes to Git" $ do
146+ callProcessAndLogOutput (Debug, Error) $ proc "git"
147+ ["-C", deployPath, "add", "."]
148+ callProcessAndLogOutput (Debug, Error) $ proc "git"
149+ ["-C", deployPath, "commit", "-m", "New deployment"]
150+ putLog Notice $ "Deployed => " <> T.pack route
153151 where
154152 callProcess' envMap cmd args = do
155153 processEnv <- Map.toList . (envMap <>) . Map.fromList <$> liftIO getEnvironment
lib/command/src/Obelisk/Command/Nix.hs+113−34
@@ -6,10 +6,19 @@
66{-# LANGUAGE OverloadedStrings #-}
77{-# LANGUAGE Rank2Types #-}
88{-# LANGUAGE ScopedTypeVariables #-}
9+{-# LANGUAGE TemplateHaskell #-}
910{-# LANGUAGE TypeApplications #-}
1011module Obelisk.Command.Nix
11− ( nixBuild
12+ ( nixCmd
13+ , NixCmd (..)
14+ , nixCmdConfig_target
15+ , nixCmdConfig_args
16+ , nixCmdConfig_builders
1217 , NixBuildConfig (..)
18+ , nixBuildConfig_outLink
19+ , NixInstantiateConfig (..)
20+ , nixInstantiateConfig_eval
21+ , NixCommonConfig (..)
1322 , Target (..)
1423 , OutLink (..)
1524 , Arg (..)
@@ -18,9 +27,13 @@ module Obelisk.Command.Nix
1827 , strArg
1928 ) where
2029
30+import Control.Monad (guard)
31+import Control.Lens
32+
2133import Data.Bool (bool)
2234import Data.Default
2335import Data.List (intercalate)
36+import Data.Maybe
2437import Data.Monoid ((<>))
2538import qualified Data.Text as T
2639import System.Process (proc)
@@ -28,25 +41,19 @@ import System.Process (proc)
2841import Obelisk.App (MonadObelisk)
2942import Obelisk.CliApp
3043
31−-- | Where to put nix-build output
32−data OutLink
33− = OutLink_Default
34− | OutLink_None
35− | OutLink_IndirectRoot FilePath
36−
37−instance Default OutLink where
38− def = OutLink_Default
39−
4044-- | What to build
4145data Target = Target
42− { _target_path :: FilePath
46+ { _target_path :: Maybe FilePath
4347 , _target_attr :: Maybe String
48+ , _target_expr :: Maybe String
4449 }
50+makeClassy ''Target
4551
4652instance Default Target where
4753 def = Target
48− { _target_path = "."
54+ { _target_path = Just "."
4955 , _target_attr = Nothing
56+ , _target_expr = Nothing
5057 }
5158
5259data Arg
@@ -68,36 +75,108 @@ cliFromArgs = concatMap $ \case
6875 Arg_Str k v -> ["--argstr", k, v]
6976 Arg_Expr k v -> ["--arg", k, v]
7077
71−data NixBuildConfig = NixBuildConfig
72− { _nixBuildConfig_target :: Target
73− , _nixBuildConfig_outLink :: OutLink
74− , _nixBuildConfig_args :: [Arg]
75− , _nixBuildConfig_builders :: [String]
78+data NixCommonConfig = NixCommonConfig
79+ { _nixCmdConfig_target :: Target
80+ , _nixCmdConfig_args :: [Arg]
81+ , _nixCmdConfig_builders :: [String]
7682 }
83+makeClassy ''NixCommonConfig
7784
78−instance Default NixBuildConfig where
79− def = NixBuildConfig def def mempty mempty
85+instance Default NixCommonConfig where
86+ def = NixCommonConfig def mempty mempty
8087
81−nixBuild :: MonadObelisk m => NixBuildConfig -> m FilePath
82−nixBuild cfg = withSpinner' ("Running nix-build on " <> desc) (Just $ const $ "Built " <> desc) $ do
83− output <- readProcessAndLogStderr Debug $ proc "nix-build" $ mconcat
84− [[path], attrArg, args, outLink, buildersArg]
85− -- Remove final newline that Nix appends
86− Just (outPath, '\n') <- pure $ T.unsnoc output
87− pure $ T.unpack outPath
88+runNixCommonConfig :: NixCommonConfig -> [FilePath]
89+runNixCommonConfig cfg = mconcat [maybeToList path, attrArg, exprArg, args, buildersArg]
8890 where
89− path = _target_path $ _nixBuildConfig_target cfg
90− attr = _target_attr $ _nixBuildConfig_target cfg
91+ path = _target_path $ _nixCmdConfig_target cfg
92+ attr = _target_attr $ _nixCmdConfig_target cfg
93+ expr = _target_expr $ _nixCmdConfig_target cfg
9194 attrArg = case attr of
9295 Nothing -> []
9396 Just a -> ["-A", a]
94− args = cliFromArgs $ _nixBuildConfig_args cfg
95− outLink = case _nixBuildConfig_outLink cfg of
97+ exprArg = case expr of
98+ Nothing -> []
99+ Just a -> ["-E", a]
100+ args = cliFromArgs $ _nixCmdConfig_args cfg
101+ buildersArg = case _nixCmdConfig_builders cfg of
102+ [] -> []
103+ builders -> ["--builders", intercalate ";" builders]
104+
105+-- | Where to put nix-build output
106+data OutLink
107+ = OutLink_Default
108+ | OutLink_None
109+ | OutLink_IndirectRoot FilePath
110+
111+instance Default OutLink where
112+ def = OutLink_Default
113+
114+data NixBuildConfig = NixBuildConfig
115+ { _nixBuildConfig_common :: NixCommonConfig
116+ , _nixBuildConfig_outLink :: OutLink
117+ }
118+makeLenses ''NixBuildConfig
119+
120+instance HasNixCommonConfig NixBuildConfig where
121+ nixCommonConfig = nixBuildConfig_common
122+
123+instance Default NixBuildConfig where
124+ def = NixBuildConfig def def
125+
126+runNixBuildConfig :: NixBuildConfig -> [FilePath]
127+runNixBuildConfig cfg = mconcat
128+ [ runNixCommonConfig $ cfg ^. nixCommonConfig
129+ , case _nixBuildConfig_outLink cfg of
96130 OutLink_Default -> []
97131 OutLink_None -> ["--no-out-link"]
98132 OutLink_IndirectRoot l -> ["--out-link", l]
99− desc = T.pack $ path <> maybe "" (\a -> " [" <> a <> "]") attr
100− buildersArg = case _nixBuildConfig_builders cfg of
101− [] -> []
102− builders -> ["--builders", intercalate ";" builders]
133+ ]
103134
135+data NixInstantiateConfig = NixInstantiateConfig
136+ { _nixInstantiateConfig_common :: NixCommonConfig
137+ , _nixInstantiateConfig_eval :: Bool
138+ }
139+makeLenses ''NixInstantiateConfig
140+
141+instance HasNixCommonConfig NixInstantiateConfig where
142+ nixCommonConfig = nixInstantiateConfig_common
143+
144+instance Default NixInstantiateConfig where
145+ def = NixInstantiateConfig def False
146+
147+runNixInstantiateConfig :: NixInstantiateConfig -> [FilePath]
148+runNixInstantiateConfig cfg = mconcat
149+ [ runNixCommonConfig $ cfg ^. nixCommonConfig
150+ , "--eval" <$ guard (_nixInstantiateConfig_eval cfg)
151+ ]
152+
153+data NixCmd
154+ = NixCmd_Build NixBuildConfig
155+ | NixCmd_Instantiate NixInstantiateConfig
156+
157+instance Default NixCmd where
158+ def = NixCmd_Build def
159+
160+nixCmd :: MonadObelisk m => NixCmd -> m FilePath
161+nixCmd cmdCfg = withSpinner' ("Running " <> cmd <> desc) (Just $ const $ "Built " <> desc) $ do
162+ output <- readProcessAndLogStderr Debug $ proc (T.unpack cmd) $ options
163+ -- Remove final newline that Nix appends
164+ Just (outPath, '\n') <- pure $ T.unsnoc output
165+ pure $ T.unpack outPath
166+ where
167+ (cmd, options, commonCfg) = case cmdCfg of
168+ NixCmd_Build cfg' ->
169+ ( "nix-build"
170+ , runNixBuildConfig cfg'
171+ , cfg' ^. nixCommonConfig
172+ )
173+ NixCmd_Instantiate cfg' ->
174+ ( "nix-instantiate"
175+ , runNixInstantiateConfig cfg'
176+ , cfg' ^. nixCommonConfig
177+ )
178+ path = commonCfg ^. nixCmdConfig_target . target_path
179+ desc = T.pack $ mconcat $ catMaybes
180+ [ (" on " <>) <$> path
181+ , (\a -> " [" <> a <> "]") <$> (commonCfg ^. nixCmdConfig_target . target_attr)
182+ ]
lib/command/src/Obelisk/Command/Project.hs+1−1
@@ -145,7 +145,7 @@ findProjectRoot target = do
145145 (result, _) <- liftIO $ runStateT (walkToProjectRoot target targetStat myUid) []
146146 return result
147147
148−withProjectRoot :: MonadObelisk m => FilePath -> (FilePath -> m ()) -> m ()
148+withProjectRoot :: MonadObelisk m => FilePath -> (FilePath -> m a) -> m a
149149withProjectRoot target f = findProjectRoot target >>= \case
150150 Nothing -> failWith "Must be used inside of an Obelisk project"
151151 Just root -> f root
lib/command/src/Obelisk/Command/Run.hs+20−5
@@ -26,16 +26,19 @@ import Hpack.Config
2626import Hpack.Render
2727import Hpack.Yaml
2828import Language.Haskell.Extension
29−import Network.Socket
29+import Network.Socket hiding (Debug)
3030import System.Directory
3131import System.FilePath
32+import System.Process (proc)
3233import System.IO.Temp (withSystemTempDirectory)
3334import Data.ByteString (ByteString)
3435
3536import Obelisk.App (MonadObelisk, ObeliskT)
36−import Obelisk.CliApp (CliT (..), HasCliConfig, Severity (..), callCommand, failWith, getCliConfig, putLog,
37− runCli)
38−import Obelisk.Command.Project (inProjectShell)
37+import Obelisk.CliApp
38+ ( CliT (..), HasCliConfig, Severity (..)
39+ , callCommand, failWith, getCliConfig, putLog
40+ , readProcessAndLogStderr, runCli)
41+import Obelisk.Command.Project (inProjectShell, withProjectRoot)
3942
4043data CabalPackageInfo = CabalPackageInfo
4144 { _cabalPackageInfo_packageRoot :: FilePath
@@ -51,7 +54,19 @@ run = do
5154 pkgs <- getLocalPkgs
5255 withGhciScript pkgs $ \dotGhciPath -> do
5356 freePort <- getFreePort
54− runGhcid dotGhciPath $ Just $ unwords ["run", show freePort, "(runServeAsset Obelisk.Generated.Static.staticRootPath)", "Backend.backend", "Frontend.frontend"]
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"]
62+ putLog Debug $ "Assets impurely loaded from: " <> assets
63+ runGhcid dotGhciPath $ Just $ unwords
64+ [ "run"
65+ , show freePort
66+ , "(runServeAsset " ++ show assets ++ ")"
67+ , "Backend.backend"
68+ , "Frontend.frontend"
69+ ]
5570
5671runRepl :: MonadObelisk m => m ()
5772runRepl = do
lib/command/src/Obelisk/Command/Thunk.hs+11−10
@@ -33,6 +33,7 @@ module Obelisk.Command.Thunk
3333
3434import Control.Applicative
3535import Control.Exception (displayException, try)
36+import qualified Control.Lens as Lens
3637import Control.Lens.Indexed hiding ((<.>))
3738import Control.Monad
3839import Control.Monad.Catch (handle)
@@ -501,13 +502,13 @@ nixBuildThunkAttrWithCache thunkDir attr = do
501502 Just c -> return c
502503 Nothing -> do
503504 putLog Warning $ T.pack $ mconcat [thunkDir, ": ", attr, " not cached, building ..."]
504− _ <- nixBuild $ def
505− { _nixBuildConfig_target = Target
506− { _target_path = thunkDir
505+ _ <- nixCmd $ NixCmd_Build$ def
506+ Lens.& nixBuildConfig_outLink Lens..~ OutLink_IndirectRoot cachePath
507+ Lens.& nixCmdConfig_target Lens..~ Target
508+ { _target_path = Just thunkDir
507509 , _target_attr = Just attr
510+ , _target_expr = Nothing
508511 }
509− , _nixBuildConfig_outLink = OutLink_IndirectRoot cachePath
510− }
511512 return cachePath
512513
513514-- | Build a nix attribute, and cache the result if possible
@@ -523,13 +524,13 @@ nixBuildAttrWithCache exprPath attr = do
523524 readThunk exprPath >>= \case
524525 -- Only packed thunks are cached. in particular, checkouts are not
525526 Right (ThunkData_Packed _) -> nixBuildThunkAttrWithCache exprPath attr
526− _ -> nixBuild $ def
527− { _nixBuildConfig_target = Target
528− { _target_path = exprPath
527+ _ -> nixCmd $ NixCmd_Build $ def
528+ Lens.& nixBuildConfig_outLink Lens..~ OutLink_None
529+ Lens.& nixCmdConfig_target Lens..~ Target
530+ { _target_path = Just exprPath
529531 , _target_attr = Just attr
532+ , _target_expr = Nothing
530533 }
531− , _nixBuildConfig_outLink = OutLink_None
532− }
533534
534535-- | Safely update thunk using a custom action
535536--