nix-tree 0.2.1 → 0.3.0
raw patch · 6 files changed
+80/−37 lines, 6 files
Files
- CHANGELOG.md +10/−2
- README.md +12/−3
- nix-tree.cabal +2/−2
- src/NixTree/App.hs +3/−3
- src/NixTree/Main.hs +39/−21
- src/NixTree/StorePath.hs +14/−6
CHANGELOG.md view
@@ -1,10 +1,18 @@ # Changelog +## 0.3.0 - 2022-11-26:++* feat: Improved help text.+* feat: Allow passing '--impure' flag to Nix (issue: [#40][]) +* fix: Use -O1 instead of -O2 to save on compile times.++[#40]: https://github.com/utdemir/nix-tree/issues/40+ ## 0.2.1 - 2022-10-24: -* fix: Fix excessive memory use when using why-depends on large dependency graphs (issue: [@31][])+* fix: Fix excessive memory use when using why-depends on large dependency graphs (issue: [#31][]) -[#25]: https://github.com/utdemir/nix-tree/issues/31+[#31]: https://github.com/utdemir/nix-tree/issues/31 ## 0.2.0 - 2022-01-02:
README.md view
@@ -31,8 +31,17 @@ ``` $ nix-tree --help-Usage: nix-tree [paths...] [-h|--help] [--version]- Paths default to $HOME/.nix-profile and /var/run/current-system.+Usage: nix-tree [--version] [--derivation] [INSTALLABLE]+ Interactively browse dependency graphs of Nix derivations.++Available options:+ --version Show the nix-tree version.+ --derivation Operate on the store derivation rather than its+ outputs.+ INSTALLABLE A store path or a flake reference. Paths default to+ "~/.nix-profile" and "/var/run/current-system".+ -h,--help Show this help text+ Keybindings: hjkl/Arrow Keys : Navigate w : Open why-depends mode@@ -40,7 +49,7 @@ s : Change sort order y : Yank selected path to clipboard ? : Show help- q/Esc: : Quit / close modal+ q/Esc : Quit / close modal ``` ### Glossary
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.2.1+version: 0.3.0 homepage: https://github.com/utdemir/nix-tree license: BSD-3-Clause license-file: LICENSE@@ -65,7 +65,7 @@ executable nix-tree import: common-options- ghc-options: -Wunused-packages -O2 -threaded -with-rtsopts=-N+ ghc-options: -Wunused-packages -threaded -with-rtsopts=-N main-is: NixTree/Main.hs hs-source-dirs: src default-language: Haskell2010
src/NixTree/App.hs view
@@ -407,12 +407,12 @@ T.intercalate "\n" [ "hjkl/Arrow Keys : Navigate",- "w : Open why-depends mode",- "/ : Open search mode",+ "w : Open why-depends modal",+ "/ : Open search modal", "s : Change sort order", "y : Yank selected path to clipboard", "? : Show help",- "q/Esc: : Quit / close modal"+ "q/Esc : Quit / close modal" ] helpNotice :: Notice
src/NixTree/Main.hs view
@@ -7,19 +7,21 @@ import NixTree.App import NixTree.PathStats import qualified Options.Applicative as Opts+import qualified Options.Applicative.Help.Pretty as Opts import System.Directory (doesDirectoryExist, getHomeDirectory) import System.Exit (ExitCode (..)) import System.FilePath ((</>))-import System.IO (hPutStr, hPutStrLn)+import System.IO (hPutStrLn) import System.ProgressBar hiding (msg) version :: Text version = VERSION_nix_tree data Opts = Opts- { oVersion :: Bool,+ { oInstallables :: [Installable],+ oVersion :: Bool, oDerivation :: Bool,- oInstallables :: [Installable]+ oImpure :: Bool } optsParser :: Opts.ParserInfo Opts@@ -27,34 +29,44 @@ Opts.info (parser <**> Opts.helper) $ mconcat [ Opts.progDesc "Interactively browse dependency graphs of Nix derivations.",- Opts.fullDesc+ Opts.fullDesc,+ Opts.footerDoc (Just keybindingsHelp) ] where parser :: Opts.Parser Opts parser = Opts- <$> Opts.switch (Opts.long "version" <> Opts.help "Show the nix-tree version.")- <*> Opts.switch (Opts.long "derivation" <> Opts.help "Operate on the store derivation rather than its outputs.")- <*> many (Opts.strArgument @Text (Opts.metavar "INSTALLABLE" <> Opts.help "A store path or a flake reference.") <&> Installable)+ <$> many+ ( Installable+ <$> Opts.strArgument @Text+ ( Opts.metavar "INSTALLABLE"+ <> Opts.helpDoc+ ( Just $+ "A store path or a flake reference."+ Opts.<$$> "Paths default to \"~/.nix-profile\" and \"/var/run/current-system\""+ )+ )+ )+ <*> Opts.switch (Opts.long "version" <> Opts.help "Show the nix-tree version")+ <*> Opts.switch (Opts.long "derivation" <> Opts.help "Operate on the store derivation rather than its outputs")+ <*> Opts.switch (Opts.long "impure" <> Opts.help "Allow access to mutable paths and repositories") -usage :: Text-usage =- unlines- [ "Usage: nix-tree [paths...] [-h|--help] [--version]",- " Paths default to $HOME/.nix-profile and /var/run/current-system.",- "Keybindings:",- unlines . map (" " <>) . lines $ helpText- ]+ keybindingsHelp :: Opts.Doc+ keybindingsHelp =+ "Keybindings:"+ Opts.<$$> (Opts.indent 2 . Opts.vsep $ map (Opts.text . toString) (lines helpText)) -usageAndFail :: Text -> IO a-usageAndFail msg = do+showAndFail :: Text -> IO a+showAndFail msg = do hPutStrLn stderr . toString $ "Error: " <> msg- hPutStr stderr $ toString usage exitWith (ExitFailure 1) main :: IO () main = do- opts <- Opts.execParser optsParser+ opts <-+ Opts.customExecParser+ (Opts.prefs $ Opts.columns 120)+ optsParser when (opts & oVersion) $ do putTextLn $ "nix-tree " <> version@@ -72,10 +84,16 @@ "/var/run/current-system" ] case roots of- [] -> usageAndFail "No store path given."+ [] -> showAndFail "No store path given." p : ps -> return . fmap (Installable . toText) $ p :| ps - withStoreEnv (opts & oDerivation) installables $ \env' -> do+ let seo =+ StoreEnvOptions+ { seoIsDerivation = opts & oDerivation,+ seoIsImpure = opts & oImpure+ }++ withStoreEnv seo installables $ \env' -> do let env = calculatePathStats env' allPaths = seAll env
src/NixTree/StorePath.hs view
@@ -7,6 +7,7 @@ StorePath (..), Installable (..), StoreEnv (..),+ StoreEnvOptions (..), withStoreEnv, seLookup, seAll,@@ -138,7 +139,8 @@ data PathInfoOptions = PathInfoOptions { pioIsRecursive :: Bool,- pioIsDerivation :: Bool+ pioIsDerivation :: Bool,+ pioIsImpure :: Bool } getPathInfo :: NixStore -> NixVersion -> PathInfoOptions -> NonEmpty Installable -> IO (NonEmpty (StorePath s (StoreName s) ()))@@ -149,6 +151,7 @@ ( proc "nix" ( ["path-info", "--json"]+ ++ (if options & pioIsImpure then ["--impure"] else []) ++ (if options & pioIsRecursive then ["--recursive"] else []) ++ (if (options & pioIsDerivation) && nixVersion >= Nix2_4 then ["--derivation"] else []) ++ (if nixVersion >= Nix2_4 then ["--extra-experimental-features", "nix-command flakes"] else [])@@ -189,20 +192,25 @@ } deriving (Functor, Generic, NFData) +data StoreEnvOptions = StoreEnvOptions+ { seoIsDerivation :: Bool,+ seoIsImpure :: Bool+ }+ withStoreEnv :: forall m a. MonadIO m =>- Bool ->+ StoreEnvOptions -> NonEmpty Installable -> (forall s. StoreEnv s () -> m a) -> m a-withStoreEnv isDerivation names cb = do+withStoreEnv StoreEnvOptions {seoIsDerivation, seoIsImpure} names cb = do nixStore <- liftIO getNixStore -- See: https://github.com/utdemir/nix-tree/issues/12 nixVersion <- liftIO getNixVersion - when (isDerivation && nixVersion < Nix2_4) $+ when (seoIsDerivation && nixVersion < Nix2_4) $ liftIO $ hPutStrLn stderr "Warning: --derivation flag is ignored on Nix versions older than 2.4." @@ -211,7 +219,7 @@ getPathInfo nixStore nixVersion- (PathInfoOptions {pioIsDerivation = isDerivation, pioIsRecursive = False})+ (PathInfoOptions {pioIsDerivation = seoIsDerivation, pioIsRecursive = False, pioIsImpure = seoIsImpure}) names paths <-@@ -219,7 +227,7 @@ getPathInfo nixStore nixVersion- (PathInfoOptions {pioIsDerivation = isDerivation, pioIsRecursive = True})+ (PathInfoOptions {pioIsDerivation = seoIsDerivation, pioIsRecursive = True, pioIsImpure = seoIsImpure}) (Installable . toText . storeNameToPath . spName <$> roots) let env =