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
nixpkgs <- readNixpkgsPath
void $ readProcessFriendly "nixos-rebuild" (action : nixosRebuildArgs nixpkgs host <> extraArgs)
exitWith =<< transparentProcess "nixos-rebuild" (action : nixosRebuildArgs nixpkgs host <> extraArgs)
( "install" : host
: (partitionArgs -> (manageArgs, extraArgs))
) ->
manageArgs `showHelpOr` do
nixpkgs <- readNixpkgsPath
void $ readProcessFriendly "nixos-install" (nixosInstallArgs nixpkgs host <> extraArgs)
exitWith =<< transparentProcess "nixos-install" (nixosInstallArgs nixpkgs host <> extraArgs)
_ -> putStr help >> exitFailure
@ -79,8 +79,10 @@ quote x = "\"" <> x <> "\""
blueForeground :: String -> String
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
$ "Executing: " <> (quote . blueForeground) (showCommandForUser cmdName args)
(_, _, _, pid) <- createProcess
@ -89,8 +91,13 @@ readProcessFriendly cmdName args = do
, std_out = UseHandle stdout
, std_err = UseHandle stderr
}
_ <- waitForProcess pid
pure ""
waitForProcess pid
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 =
@ -100,5 +107,6 @@ readNixpkgsPath =
, "-E"
, "let sources = import ./npins; in sources.nixpkgs.outPath"
]
""
where
clean = filter (\c -> c /= '\n' && c /= '"')