nix-tree 0.3.1 → 0.3.2
raw patch · 5 files changed
+50/−12 lines, 5 files
Files
- CHANGELOG.md +7/−0
- README.md +10/−3
- nix-tree.cabal +1/−1
- src/Data/InvertedIndex.hs +3/−3
- src/NixTree/StorePath.hs +29/−5
CHANGELOG.md view
@@ -1,5 +1,12 @@ # Changelog +## 0.3.2 - 2023-11-28:++* fix: Support new path-info syntax introduced in nix 2.19 (thanks @SuperSandro2000, @GrigorenkoPV9, issue: [#67][], PR: [#68][])++[#67]: https://github.com/utdemir/nix-tree/issues/67+[#68]: https://github.com/utdemir/nix-tree/issues/68+ ## 0.3.1 - 2022-12-10: * fix: Update 'brick' library (thanks @ncfavier, PR: [#47][])
README.md view
@@ -85,6 +85,12 @@ nix-tree --derivation 'nixpkgs#asciiquarium' ``` +Run `nix-tree` on your current nixos system:++```bash+nix-tree /nix/var/nix/profiles/system+```+ ## Contributing All contributions, issues and feature requests are welcome.@@ -93,6 +99,7 @@ ## Related tools -* [nix-du](https://github.com/symphorien/nix-du)-* [nix-query-tree-viewer](https://github.com/cdepillabout/nix-query-tree-viewer)-* [nix-visualize](https://github.com/craigmbooth/nix-visualize)+* [nix-du](https://github.com/symphorien/nix-du): Visualise which gc-roots to delete to free some space in your nix store+* [nix-melt](https://github.com/nix-community/nix-melt): A ranger-like flake.lock viewer+* [nix-query-tree-viewer](https://github.com/cdepillabout/nix-query-tree-viewer): GTK viewer for the output of `nix-store --query --tree`+* [nix-visualize](https://github.com/craigmbooth/nix-visualize): Uses the Nix package manager to visualize the dependencies of a given package
nix-tree.cabal view
@@ -3,7 +3,7 @@ name: nix-tree synopsis: Interactively browse a Nix store paths dependencies description: A terminal curses application to browse a Nix store paths dependencies-version: 0.3.1+version: 0.3.2 homepage: https://github.com/utdemir/nix-tree license: BSD-3-Clause license-file: LICENSE
src/Data/InvertedIndex.hs view
@@ -18,7 +18,7 @@ } deriving (Generic, Show) -instance NFData a => NFData (InvertedIndex a)+instance (NFData a) => NFData (InvertedIndex a) iiInsert :: Text -> a -> InvertedIndex a -> InvertedIndex a iiInsert txt val InvertedIndex {iiElems, iiUnigrams, iiBigrams, iiTrigrams} =@@ -35,7 +35,7 @@ orig (setToMap (Set.singleton txt) chrs) -iiFromList :: Foldable f => f (Text, a) -> InvertedIndex a+iiFromList :: (Foldable f) => f (Text, a) -> InvertedIndex a iiFromList = foldl' (flip (uncurry iiInsert))@@ -65,7 +65,7 @@ | otherwise = using trigramsOf iiTrigrams where lowerTxt = Text.toLower txt- using :: Ord c => (Text -> Set c) -> Map c (Set Text) -> Map Text a+ using :: (Ord c) => (Text -> Set c) -> Map c (Set Text) -> Map Text a using getGrams m = Map.intersection m (setToMap () (getGrams txt)) & Map.elems
src/NixTree/StorePath.hs view
@@ -19,7 +19,10 @@ ) where -import Data.Aeson (FromJSON (..), Value (..), decode, (.:))+import Data.Aeson (FromJSON (..), Object, Value (..), decode, (.:))+import qualified Data.Aeson.Key as K+import qualified Data.Aeson.KeyMap as KM+import Data.Aeson.Types (Parser) import qualified Data.ByteString.Lazy as BL import qualified Data.HashMap.Strict as HM import qualified Data.HashSet as HS@@ -110,7 +113,9 @@ -- split by ".", take the first two, and convert them to numbers (major, minor) <- do- let maT : miT : _ = T.splitOn "." ver+ (maT, miT) <- case T.splitOn "." ver of+ p1 : p2 : _ -> Just (p1, p2)+ _ -> Nothing ma <- readMaybe @Natural (toString maT) mi <- readMaybe @Natural (toString miT) return (ma, mi)@@ -146,7 +151,7 @@ getPathInfo :: NixStore -> NixVersion -> PathInfoOptions -> NonEmpty Installable -> IO (NonEmpty (StorePath s (StoreName s) ())) getPathInfo nixStore nixVersion options names = do infos <-- decode @[NixPathInfoResult]+ decode @NixPathOutput <$> readProcessStdout_ ( proc "nix"@@ -159,7 +164,7 @@ ) ) >>= maybe (fail "Failed parsing nix path-info output.") return- >>= mapM assertValidInfo+ >>= mapM assertValidInfo . npoResults >>= maybe (fail "invariant violation: getPathInfo returned []") return . nonEmpty mapM infoToStorePath infos@@ -199,7 +204,7 @@ withStoreEnv :: forall m a.- MonadIO m =>+ (MonadIO m) => StoreEnvOptions -> NonEmpty Installable -> (forall s. StoreEnv s () -> m a) ->@@ -342,3 +347,22 @@ return $ NixPathInfoInvalid path ) parseJSON _ = fail "Expecting an object."++newtype NixPathOutput = NixPathOutput+ { npoResults :: [NixPathInfoResult]+ }++obj2LegacyArray :: Object -> Parser [Value]+obj2LegacyArray obj = mapM ((Object <$>) . addPathKey) (KM.toList obj)+ where+ addPathKey :: (K.Key, Value) -> Parser Object+ addPathKey (key, Object info) = return $ KM.insert "path" (String $ K.toText key) info+ addPathKey (_, _) = fail "Expecting an object"++instance FromJSON NixPathOutput where+ parseJSON (Array a) = NixPathOutput <$> mapM parseJSON (toList a)+ parseJSON (Object o) = do+ legacyArray <- obj2LegacyArray o+ result <- mapM parseJSON legacyArray+ return $ NixPathOutput result+ parseJSON _ = fail "Expecting an array (nix<=2.18) or an object with mapping from path to info (nix>=2.19)."