diff --git a/nix/packages/by-name/manage/src/Main.hs b/nix/packages/by-name/manage/src/Main.hs index d8f1e535..dc112e47 100755 --- a/nix/packages/by-name/manage/src/Main.hs +++ b/nix/packages/by-name/manage/src/Main.hs @@ -2,6 +2,7 @@ {-# LANGUAGE LambdaCase #-} {-# LANGUAGE ViewPatterns #-} +import Control.Monad import System.Environment import System.Exit import System.IO @@ -22,18 +23,14 @@ main = do ) -> manageArgs `showHelpOr` do nixpkgs <- readNixpkgsPath - -- NOTE: It seems like nom is able to do some pty magic and can print out to terminal in real time. - -- I thought this would be blocking? - readProcessFriendly "nixos-rebuild" (action : nixosRebuildArgs nixpkgs host <> extraArgs) "" - >>= putStr + void $ readProcessFriendly "nixos-rebuild" (action : nixosRebuildArgs nixpkgs host <> extraArgs) ( "install" : host : (partitionArgs -> (manageArgs, extraArgs)) ) -> manageArgs `showHelpOr` do nixpkgs <- readNixpkgsPath - readProcessFriendly "nixos-install" (nixosInstallArgs nixpkgs host <> extraArgs) "" - >>= putStr + void $ readProcessFriendly "nixos-install" (nixosInstallArgs nixpkgs host <> extraArgs) _ -> putStr help >> exitFailure @@ -82,11 +79,18 @@ quote x = "\"" <> x <> "\"" blueForeground :: String -> String blueForeground x = "\ESC[34m" <> x <> "\ESC[0m" -readProcessFriendly :: String -> [String] -> String -> IO String -readProcessFriendly x args stdin_ = do +readProcessFriendly :: String -> [String] -> IO String +readProcessFriendly cmdName args = do hPutStrLn stderr - $ "Executing: " <> (quote . blueForeground) (showCommandForUser x args) - readProcess x args stdin_ + $ "Executing: " <> (quote . blueForeground) (showCommandForUser cmdName args) + (_, _, _, pid) <- createProcess + ( proc cmdName args + ) { std_in = UseHandle stdin + , std_out = UseHandle stdout + , std_err = UseHandle stderr + } + _ <- waitForProcess pid + pure "" readNixpkgsPath :: IO StorePath readNixpkgsPath = @@ -96,6 +100,5 @@ readNixpkgsPath = , "-E" , "let sources = import ./npins; in sources.nixpkgs.outPath" ] - "" where clean = filter (\c -> c /= '\n' && c /= '"')