nix-tree 0.5.0 → 0.6.0
raw patch · 5 files changed
+66/−8 lines, 5 files
Files
- CHANGELOG.md +10/−0
- nix-tree.cabal +1/−1
- src/NixTree/App.hs +16/−2
- src/NixTree/Main.hs +15/−2
- src/NixTree/StorePath.hs +24/−3
CHANGELOG.md view
@@ -1,5 +1,15 @@ # Changelog +## 0.6.0 - 2025-01-11:++* feat: Show signatures of store paths (thanks @caspervk, PR: [#107])+* fix: Fix default nix-tree invocation not working when one of the default directories is not a store path (thanks @sg-qwt, @GrigorenkoPV, issue #[106], pr #[109], #[110])++[#107]: https://github.com/utdemir/nix-tree/pull/107+[#106]: https://github.com/utdemir/nix-tree/issues/106+[#109]: https://github.com/utdemir/nix-tree/pull/109+[#110]: https://github.com/utdemir/nix-tree/pull/110+ ## 0.5.0 - 2024-10-06: * feat: Add `--file` to run nix-tree against attributes from a file. (thanks @blackheaven, PR: [#103])
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.5.0+version: 0.6.0 homepage: https://github.com/utdemir/nix-tree license: BSD-3-Clause license-file: LICENSE
src/NixTree/App.hs view
@@ -150,7 +150,8 @@ StorePath { spName, spPayload = PathStats {psTotalSize, psAddedSize},- spRefs+ spRefs,+ spSignatures } -> let color = if null spRefs@@ -158,7 +159,10 @@ else identity in color $ B.hBox- [ B.txt (storeNameToShortText spName)+ [ if null spSignatures+ then B.txt " "+ else B.txt "✓ ",+ B.txt (storeNameToShortText spName) & underlineWhen SortOrderAlphabetical & B.padRight (B.Pad 1) & B.padRight B.Max,@@ -372,6 +376,7 @@ renderInfoPane env = let selected = selectedPath env immediateParents = psImmediateParents $ spPayload selected+ signatures = spSignatures selected in B.vBox [ let (f, s) = storeNameToSplitShortText (spName selected) in B.txt f B.<+> underlineWhen SortOrderAlphabetical (B.txt s),@@ -381,6 +386,15 @@ ] & intersperse (B.txt " | ") & B.hBox,+ B.txt $+ "Signatures: "+ <> if null signatures+ then "✗"+ else+ ( signatures+ & map npsKeyName+ & T.intercalate ", "+ ), B.txt $ if null immediateParents then "Immediate Parents: -"
src/NixTree/Main.hs view
@@ -8,7 +8,7 @@ import NixTree.PathStats import qualified Options.Applicative as Opts import qualified Options.Applicative.Help.Pretty as Opts-import System.Directory (XdgDirectory (XdgState), doesDirectoryExist, getHomeDirectory, getXdgDirectory)+import System.Directory (XdgDirectory (XdgState), doesDirectoryExist, getHomeDirectory, getXdgDirectory, pathIsSymbolicLink) import System.Exit (ExitCode (..)) import System.FilePath ((</>)) import System.IO (hPutStrLn)@@ -91,6 +91,17 @@ hPutStrLn stderr . toString $ "Error: " <> msg exitWith (ExitFailure 1) +isValidRoot :: FilePath -> IO Bool+isValidRoot path = do+ isExistingDirectory <- doesDirectoryExist path+ if isExistingDirectory+ then -- We need to check that it's a symlink (presumably to nix store),+ -- because if it is just a directory, nix will try to interpret it as a flake.+ -- We do doesDirectoryExist before pathIsSymbolicLink,+ -- because the latter will fail if the path does not exist.+ pathIsSymbolicLink path+ else return False+ main :: IO () main = do opts <-@@ -108,11 +119,13 @@ [] -> do home <- getHomeDirectory nixXdgDirectory <- getXdgDirectory XdgState "nix/profile"+ homeManagerDirectory <- getXdgDirectory XdgState "nix/profiles/home-manager" roots <- filterM- doesDirectoryExist+ isValidRoot [ home </> ".nix-profile", nixXdgDirectory,+ homeManagerDirectory, "/var/run/current-system" ] case roots of
src/NixTree/StorePath.hs view
@@ -4,6 +4,7 @@ storeNameToText, storeNameToShortText, storeNameToSplitShortText,+ NixPathSignature (..), StorePath (..), Installable (..), StoreEnv (..),@@ -140,7 +141,8 @@ { spName :: StoreName s, spSize :: Int, spRefs :: [ref],- spPayload :: payload+ spPayload :: payload,+ spSignatures :: [NixPathSignature] } deriving (Show, Eq, Ord, Functor, Generic) @@ -187,7 +189,7 @@ mapM infoToStorePath infos where- infoToStorePath NixPathInfo {npiPath, npiNarSize, npiReferences} = do+ infoToStorePath NixPathInfo {npiPath, npiNarSize, npiReferences, npiSignatures} = do name <- mkStoreNameIO npiPath refs <- filter (/= name) <$> mapM mkStoreNameIO npiReferences return $@@ -195,6 +197,7 @@ { spName = name, spRefs = refs, spSize = npiNarSize,+ spSignatures = npiSignatures, spPayload = () } mkStoreNameIO p =@@ -372,9 +375,25 @@ data NixPathInfo = NixPathInfo { npiPath :: FilePath, npiNarSize :: Int,- npiReferences :: [FilePath]+ npiReferences :: [FilePath],+ npiSignatures :: [NixPathSignature] } +data NixPathSignature = NixPathSignature+ { npsKeyName :: Text,+ npsSignature :: Text+ }+ deriving (Show, Eq, Ord, NFData, Generic)++instance FromJSON NixPathSignature where+ parseJSON (String t) =+ case T.splitOn ":" t of+ [key, sig]+ | not (T.null key) && not (T.null sig) ->+ return $ NixPathSignature key sig+ _ -> fail "Expecting a string in the form of 'key:sig'."+ parseJSON _ = fail "Expecting a string."+ data NixPathInfoResult = NixPathInfoValid NixPathInfo | NixPathInfoInvalid FilePath@@ -386,6 +405,7 @@ <$> obj .: "path" <*> obj .: "narSize" <*> obj .: "references"+ <*> obj .: "signatures" ) ) <|> ( do@@ -403,6 +423,7 @@ path <$> obj .: "narSize" <*> obj .: "references"+ <*> obj .: "signatures" ) parse2_19 (path, Null) = return $ NixPathInfoInvalid path parse2_19 (_, _) = fail "Expecting an object or null"