Skip to content

Commit

Permalink
feat: show cache signature(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
caspervk committed Jan 7, 2025
1 parent 6cd7c6f commit e75f74a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
16 changes: 13 additions & 3 deletions src/NixTree/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,19 @@ renderList highlightSort =
StorePath
{ spName,
spPayload = PathStats {psTotalSize, psAddedSize},
spRefs
spRefs,
spSignatures
} ->
let color =
if null spRefs
then B.withAttr attrTerminal
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,
Expand Down Expand Up @@ -372,12 +376,18 @@ renderInfoPane :: AppEnv s -> B.Widget Widgets
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),
[ B.txt $ "NAR Size: " <> prettySize (spSize selected),
underlineWhen SortOrderClosureSize . B.txt $ "Closure Size: " <> prettySize (psTotalSize $ spPayload selected),
underlineWhen SortOrderAddedSize . B.txt $ "Added Size: " <> prettySize (psAddedSize $ spPayload selected)
underlineWhen SortOrderAddedSize . B.txt $ "Added Size: " <> prettySize (psAddedSize $ spPayload selected),
B.txt $
"Signatures: "
<> if null signatures
then ""
else (map (\s -> (fromMaybe "?" (viaNonEmpty head (T.splitOn ":" (T.pack s))))) signatures) & T.intercalate ", "
]
& intersperse (B.txt " | ")
& B.hBox,
Expand Down
11 changes: 8 additions & 3 deletions src/NixTree/StorePath.hs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ data StorePath s ref payload = StorePath
{ spName :: StoreName s,
spSize :: Int,
spRefs :: [ref],
spPayload :: payload
spPayload :: payload,
spSignatures :: [String]
}
deriving (Show, Eq, Ord, Functor, Generic)

Expand Down Expand Up @@ -187,14 +188,15 @@ getPathInfo nixStore nixVersion options names = do

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 $
StorePath
{ spName = name,
spRefs = refs,
spSize = npiNarSize,
spSignatures = npiSignatures,
spPayload = ()
}
mkStoreNameIO p =
Expand Down Expand Up @@ -372,7 +374,8 @@ storeEnvToDot env =
data NixPathInfo = NixPathInfo
{ npiPath :: FilePath,
npiNarSize :: Int,
npiReferences :: [FilePath]
npiReferences :: [FilePath],
npiSignatures :: [String]
}

data NixPathInfoResult
Expand All @@ -386,6 +389,7 @@ parse2_18 (Object obj) =
<$> obj .: "path"
<*> obj .: "narSize"
<*> obj .: "references"
<*> obj .: "signatures"
)
)
<|> ( do
Expand All @@ -403,6 +407,7 @@ parse2_19 (path, Object obj) =
path
<$> obj .: "narSize"
<*> obj .: "references"
<*> obj .: "signatures"
)
parse2_19 (path, Null) = return $ NixPathInfoInvalid path
parse2_19 (_, _) = fail "Expecting an object or null"
Expand Down

0 comments on commit e75f74a

Please sign in to comment.