chore/manage: fix bug where nixpkgs store path is ""

This commit is contained in:
Primrose 2026-01-31 16:12:14 +01:00
parent acf4bba56d
commit 895173460a
Signed by: primrose
GPG key ID: 4E887A4CA9714ADA

View file

@ -23,14 +23,14 @@ main = do
) -> ) ->
manageArgs `showHelpOr` do manageArgs `showHelpOr` do
nixpkgs <- readNixpkgsPath nixpkgs <- readNixpkgsPath
void $ readProcessFriendly "nixos-rebuild" (action : nixosRebuildArgs nixpkgs host <> extraArgs) exitWith =<< transparentProcess "nixos-rebuild" (action : nixosRebuildArgs nixpkgs host <> extraArgs)
( "install" : host ( "install" : host
: (partitionArgs -> (manageArgs, extraArgs)) : (partitionArgs -> (manageArgs, extraArgs))
) -> ) ->
manageArgs `showHelpOr` do manageArgs `showHelpOr` do
nixpkgs <- readNixpkgsPath nixpkgs <- readNixpkgsPath
void $ readProcessFriendly "nixos-install" (nixosInstallArgs nixpkgs host <> extraArgs) exitWith =<< transparentProcess "nixos-install" (nixosInstallArgs nixpkgs host <> extraArgs)
_ -> putStr help >> exitFailure _ -> putStr help >> exitFailure
@ -79,8 +79,10 @@ 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] -> IO String -- |
readProcessFriendly cmdName args = do -- Run with a shared std{in,out,err}
transparentProcess :: String -> [String] -> IO ExitCode
transparentProcess cmdName args = do
hPutStrLn stderr hPutStrLn stderr
$ "Executing: " <> (quote . blueForeground) (showCommandForUser cmdName args) $ "Executing: " <> (quote . blueForeground) (showCommandForUser cmdName args)
(_, _, _, pid) <- createProcess (_, _, _, pid) <- createProcess
@ -89,8 +91,13 @@ readProcessFriendly cmdName args = do
, std_out = UseHandle stdout , std_out = UseHandle stdout
, std_err = UseHandle stderr , std_err = UseHandle stderr
} }
_ <- waitForProcess pid waitForProcess pid
pure ""
readProcessFriendly :: String -> [String] -> String -> IO String
readProcessFriendly cmdName args inp = do
hPutStrLn stderr
$ "Executing: " <> (quote . blueForeground) (showCommandForUser cmdName args)
readProcess cmdName args inp
readNixpkgsPath :: IO StorePath readNixpkgsPath :: IO StorePath
readNixpkgsPath = readNixpkgsPath =
@ -100,5 +107,6 @@ 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 /= '"')