mirror of
https://codeberg.org/leana8959/.files.git
synced 2026-02-01 14:29:40 +00:00
fix manage script
It now work with nixos-rebuild repl properly
This commit is contained in:
parent
f0c393977f
commit
acf4bba56d
1 changed files with 14 additions and 11 deletions
|
|
@ -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 /= '"')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue