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