From 0eae3c428916c77a69d301825e5c38c49a1f9313 Mon Sep 17 00:00:00 2001 From: Utku Demir Date: Mon, 8 Nov 2021 19:27:51 +1300 Subject: [PATCH] fix: Automatically enable nix-command experimental feature on Nix>=2.4 --- CHANGELOG.md | 1 + src/NixTree/StorePath.hs | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1420dff..3c2f08d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/src/NixTree/StorePath.hs b/src/NixTree/StorePath.hs index aeb8ceb..e6d5bb8 100644 --- a/src/NixTree/StorePath.hs +++ b/src/NixTree/StorePath.hs @@ -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) ) )