fix: Automatically enable nix-command experimental feature on Nix>=2.4

This commit is contained in:
Utku Demir 2021-11-08 19:27:51 +13:00
parent 551d152910
commit 0eae3c4289
No known key found for this signature in database
GPG Key ID: F3F8629C3E0BF60B
2 changed files with 8 additions and 5 deletions

View File

@ -2,6 +2,7 @@
## Unreleased
* fix: Automatically enable the required 'nix-command' experimental feature on Nix >= 2.4
* fix: Do not refresh screen periodically unless necessary
## 0.1.8 - 2021-09-06:

View File

@ -106,28 +106,30 @@ mkStorePaths names = do
-- > the output of given derivation; to actually work on the derivation you need to pass
-- > --derivation.
isAtLeastNix24 <- (>= Just "2.4") <$> getNixVersion
let (derivations, outputs) =
partition
(\i -> ".drv" `T.isSuffixOf` storeNameToText i)
(NE.toList names)
(++)
<$> maybe (return []) (getPathInfo nixStore False) (NE.nonEmpty outputs)
<*> maybe (return []) (getPathInfo nixStore (True && isAtLeastNix24)) (NE.nonEmpty derivations)
<$> maybe (return []) (getPathInfo nixStore isAtLeastNix24 False) (NE.nonEmpty outputs)
<*> maybe (return []) (getPathInfo nixStore isAtLeastNix24 True) (NE.nonEmpty derivations)
where
getNixVersion :: IO (Maybe Text)
getNixVersion = do
out <- decodeUtf8 . BL.toStrict <$> readProcessStdout_ (proc "nix" ["--version"])
return . viaNonEmpty last $ T.splitOn " " out
getPathInfo :: NixStore -> Bool -> NonEmpty (StoreName s) -> IO [StorePath s (StoreName s) ()]
getPathInfo nixStore isDrv names = do
getPathInfo :: NixStore -> Bool -> Bool -> NonEmpty (StoreName s) -> IO [StorePath s (StoreName s) ()]
getPathInfo nixStore isAtLeastNix24 isDrv names = do
infos <-
decode @[NixPathInfoResult]
<$> readProcessStdout_
( proc
"nix"
( ["path-info", "--recursive", "--json"]
++ (if isDrv then ["--derivation"] else [])
++ (if isAtLeastNix24 then ["--extra-experimental-features", "nix-command"] else [])
++ (if isDrv && isAtLeastNix24 then ["--derivation"] else [])
++ map storeNameToPath (toList names)
)
)