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 ## Unreleased
* fix: Automatically enable the required 'nix-command' experimental feature on Nix >= 2.4
* fix: Do not refresh screen periodically unless necessary * fix: Do not refresh screen periodically unless necessary
## 0.1.8 - 2021-09-06: ## 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 -- > the output of given derivation; to actually work on the derivation you need to pass
-- > --derivation. -- > --derivation.
isAtLeastNix24 <- (>= Just "2.4") <$> getNixVersion isAtLeastNix24 <- (>= Just "2.4") <$> getNixVersion
let (derivations, outputs) = let (derivations, outputs) =
partition partition
(\i -> ".drv" `T.isSuffixOf` storeNameToText i) (\i -> ".drv" `T.isSuffixOf` storeNameToText i)
(NE.toList names) (NE.toList names)
(++) (++)
<$> maybe (return []) (getPathInfo nixStore False) (NE.nonEmpty outputs) <$> maybe (return []) (getPathInfo nixStore isAtLeastNix24 False) (NE.nonEmpty outputs)
<*> maybe (return []) (getPathInfo nixStore (True && isAtLeastNix24)) (NE.nonEmpty derivations) <*> maybe (return []) (getPathInfo nixStore isAtLeastNix24 True) (NE.nonEmpty derivations)
where where
getNixVersion :: IO (Maybe Text) getNixVersion :: IO (Maybe Text)
getNixVersion = do getNixVersion = do
out <- decodeUtf8 . BL.toStrict <$> readProcessStdout_ (proc "nix" ["--version"]) out <- decodeUtf8 . BL.toStrict <$> readProcessStdout_ (proc "nix" ["--version"])
return . viaNonEmpty last $ T.splitOn " " out return . viaNonEmpty last $ T.splitOn " " out
getPathInfo :: NixStore -> Bool -> NonEmpty (StoreName s) -> IO [StorePath s (StoreName s) ()] getPathInfo :: NixStore -> Bool -> Bool -> NonEmpty (StoreName s) -> IO [StorePath s (StoreName s) ()]
getPathInfo nixStore isDrv names = do getPathInfo nixStore isAtLeastNix24 isDrv names = do
infos <- infos <-
decode @[NixPathInfoResult] decode @[NixPathInfoResult]
<$> readProcessStdout_ <$> readProcessStdout_
( proc ( proc
"nix" "nix"
( ["path-info", "--recursive", "--json"] ( ["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) ++ map storeNameToPath (toList names)
) )
) )