on master help sign in
Make path optional on nix-* command

this would be necessary for `nix-build --expr` which it does not take a path

commit3c16beab39bb1e79b5d1f5b4f6a0229261bbc442 authorLuigy Leon <luichi.19@gmail.com> dateThu 1 Nov 2018, 17:53 (8 years ago) parentede7d56
3 files changed+12−10
lib/command/src/Obelisk/Command/Deploy.hs+1−1 lib/command/src/Obelisk/Command/Nix.hs+9−7 lib/command/src/Obelisk/Command/Thunk.hs+2−2
lib/command/src/Obelisk/Command/Deploy.hs+1−1
@@ -99,7 +99,7 @@ deployPush deployPath getNixBuilders = do
9999 builders <- getNixBuilders
100100 buildOutput <- nixCmd $ NixCmd_Build $ def
101101 & nixCmdConfig_target .~Target
102− { _target_path = srcPath
102+ { _target_path = Just srcPath
103103 , _target_attr = Just "server.system"
104104 }
105105 & nixBuildConfig_outLink .~ OutLink_None
lib/command/src/Obelisk/Command/Nix.hs+9−7
@@ -33,6 +33,7 @@ import Control.Lens
3333import Data.Bool (bool)
3434import Data.Default
3535import Data.List (intercalate)
36+import Data.Maybe
3637import Data.Monoid ((<>))
3738import qualified Data.Text as T
3839import System.Process (proc)
@@ -42,14 +43,14 @@ import Obelisk.CliApp
4243
4344-- | What to build
4445data Target = Target
45− { _target_path :: FilePath
46+ { _target_path :: Maybe FilePath
4647 , _target_attr :: Maybe String
4748 }
4849makeClassy ''Target
4950
5051instance Default Target where
5152 def = Target
52− { _target_path = "."
53+ { _target_path = Just "."
5354 , _target_attr = Nothing
5455 }
5556
@@ -83,7 +84,7 @@ instance Default NixCommonConfig where
8384 def = NixCommonConfig def mempty mempty
8485
8586runNixCommonConfig :: NixCommonConfig -> [FilePath]
86−runNixCommonConfig cfg = mconcat [[path], attrArg, args, buildersArg]
87+runNixCommonConfig cfg = mconcat [maybeToList path, attrArg, args, buildersArg]
8788 where
8889 path = _target_path $ _nixCmdConfig_target cfg
8990 attr = _target_attr $ _nixCmdConfig_target cfg
@@ -151,7 +152,7 @@ instance Default NixCmd where
151152 def = NixCmd_Build def
152153
153154nixCmd :: MonadObelisk m => NixCmd -> m FilePath
154−nixCmd cmdCfg = withSpinner' ("Running " <> cmd <> " on " <> desc) (Just $ const $ "Built " <> desc) $ do
155+nixCmd cmdCfg = withSpinner' ("Running " <> cmd <> desc) (Just $ const $ "Built " <> desc) $ do
155156 output <- readProcessAndLogStderr Debug $ proc (T.unpack cmd) $ options
156157 -- Remove final newline that Nix appends
157158 Just (outPath, '\n') <- pure $ T.unsnoc output
@@ -169,6 +170,7 @@ nixCmd cmdCfg = withSpinner' ("Running " <> cmd <> " on " <> desc) (Just $ const
169170 , cfg' ^. nixCommonConfig
170171 )
171172 path = commonCfg ^. nixCmdConfig_target . target_path
172− desc = T.pack $ path <> maybe ""
173− (\a -> " [" <> a <> "]")
174− (commonCfg ^. nixCmdConfig_target . target_attr)
173+ desc = T.pack $ mconcat $ catMaybes
174+ [ (" on " <>) <$> path
175+ , (\a -> " [" <> a <> "]") <$> (commonCfg ^. nixCmdConfig_target . target_attr)
176+ ]
lib/command/src/Obelisk/Command/Thunk.hs+2−2
@@ -505,7 +505,7 @@ nixBuildThunkAttrWithCache thunkDir attr = do
505505 _ <- nixCmd $ NixCmd_Build$ def
506506 Lens.& nixBuildConfig_outLink Lens..~ OutLink_IndirectRoot cachePath
507507 Lens.& nixCmdConfig_target Lens..~ Target
508− { _target_path = thunkDir
508+ { _target_path = Just thunkDir
509509 , _target_attr = Just attr
510510 }
511511 return cachePath
@@ -526,7 +526,7 @@ nixBuildAttrWithCache exprPath attr = do
526526 _ -> nixCmd $ NixCmd_Build $ def
527527 Lens.& nixBuildConfig_outLink Lens..~ OutLink_None
528528 Lens.& nixCmdConfig_target Lens..~ Target
529− { _target_path = exprPath
529+ { _target_path = Just exprPath
530530 , _target_attr = Just attr
531531 }
532532