A stable replacement for nix run in haskell
nix cli

feat: don't print stacktrace on io errors

They are most likely caused by Nix failing so it has most likely already printed the error

weethet.eurosky.social 033c7b2d f8b2300e

verified
+44 -40
+44 -40
app/Main.hs
··· 248 248 ++ ["-E" | buildExpr opts /= Nothing] 249 249 ++ if buildReadonlyMode opts then ["--readonly-mode"] else ["--read-write-mode"] 250 250 251 + run :: [Text] -> IO () 252 + run passthrough = do 253 + opts_ <- 254 + execParser $ 255 + info 256 + (buildOptionsParser <**> helper) 257 + (fullDesc <> progDesc "nix-run - run a Nix application" <> OA.header "nix-run - run a Nix application") 258 + opts <- verifyNoConflicts opts_ 259 + 260 + case buildExpr opts of 261 + Just exprText -> do 262 + binPath <- 263 + toString 264 + <$> fromMaybe 265 + (mainProgram opts exprText) 266 + (buildBinary opts <&> pure) 267 + outPath <- binOutputOrOut opts exprText 268 + let attr = buildAttrs opts 269 + let attrArgs = maybe [] (("-A" :) . one) attr 270 + void $ 271 + readProcessText 272 + "nix-build" 273 + (["--no-out-link", "-E", exprText] ++ attrArgs ++ nixBuildArgs opts) 274 + "" 275 + executeFile (outPath </> "bin" </> binPath) False (map toString passthrough) Nothing 276 + Nothing -> do 277 + let file = getFile opts 278 + binPath <- 279 + toString 280 + <$> fromMaybe 281 + (mainProgram opts file) 282 + (buildBinary opts <&> pure) 283 + outPath <- binOutputOrOut opts file 284 + let attr = getAttr opts 285 + let attrArgs = maybe [] (("-A" :) . one) attr 286 + void $ 287 + readProcessText 288 + "nix-build" 289 + (["--no-out-link", file] ++ attrArgs ++ nixBuildArgs opts) 290 + "" 291 + executeFile (outPath </> "bin" </> binPath) False (map toString passthrough) Nothing 292 + 251 293 main :: IO () 252 294 main = do 253 295 args <- getArgs 254 296 let (ours, rest) = break (== "--") args 255 297 let passthrough = map toText $ maybe [] tail (nonEmpty rest) 256 298 257 - withArgs ours $ do 258 - opts_ <- 259 - execParser $ 260 - info 261 - (buildOptionsParser <**> helper) 262 - (fullDesc <> progDesc "nix-run - run a Nix application" <> OA.header "nix-run - run a Nix application") 263 - opts <- verifyNoConflicts opts_ 264 - 265 - case buildExpr opts of 266 - Just exprText -> do 267 - binPath <- 268 - toString 269 - <$> fromMaybe 270 - (mainProgram opts exprText) 271 - (buildBinary opts <&> pure) 272 - outPath <- binOutputOrOut opts exprText 273 - let attr = buildAttrs opts 274 - let attrArgs = maybe [] (("-A" :) . one) attr 275 - void $ 276 - readProcessText 277 - "nix-build" 278 - (["--no-out-link", "-E", exprText] ++ attrArgs ++ nixBuildArgs opts) 279 - "" 280 - executeFile (outPath </> "bin" </> binPath) False (map toString passthrough) Nothing 281 - Nothing -> do 282 - let file = getFile opts 283 - binPath <- 284 - toString 285 - <$> fromMaybe 286 - (mainProgram opts file) 287 - (buildBinary opts <&> pure) 288 - outPath <- binOutputOrOut opts file 289 - let attr = getAttr opts 290 - let attrArgs = maybe [] (("-A" :) . one) attr 291 - void $ 292 - readProcessText 293 - "nix-build" 294 - (["--no-out-link", file] ++ attrArgs ++ nixBuildArgs opts) 295 - "" 296 - executeFile (outPath </> "bin" </> binPath) False (map toString passthrough) Nothing 299 + withArgs ours $ catch @IEX.IOError (run passthrough) $ \exn -> 300 + print exn