nix-tree 0.4.1 → 0.5.0
raw patch · 5 files changed
+70/−25 lines, 5 files
Files
- CHANGELOG.md +11/−0
- README.md +11/−3
- nix-tree.cabal +1/−1
- src/NixTree/Main.hs +25/−13
- src/NixTree/StorePath.hs +22/−8
CHANGELOG.md view
@@ -1,5 +1,16 @@ # Changelog +## 0.5.0 - 2024-10-06:++* feat: Add `--file` to run nix-tree against attributes from a file. (thanks @blackheaven, PR: [#103])+* fix: Fix a spurious warning when running `nix-tree` as an untrusted user (thanks @Schweber & @bryango, issue [#99], PR: [#100])+* chore: Add an example for running `nix-tree` on a NixOS configuration flake reference (thanks @thenbe, PR: [#97])++[#103]: https://github.com/utdemir/nix-tree/pull/103+[#99]: https://github.com/utdemir/nix-tree/issues/99+[#100]: https://github.com/utdemir/nix-tree/pull/100+[#97]: https://github.com/utdemir/nix-tree/pull/97+ ## 0.4.1 - 2024-04-07: * fix: Restore terminal state properly after exiting (thanks @Atemu, issue: [#88])
README.md view
@@ -31,7 +31,7 @@ ```console $ nix-tree --help-Usage: nix-tree [INSTALLABLE] [--store STORE] [--version] [--derivation] [--impure] [--dot]+Usage: nix-tree [INSTALLABLE] [--store STORE] [--file FILE] [--version] [--derivation] [--impure] [--dot] Interactively browse dependency graphs of Nix derivations. @@ -40,6 +40,7 @@ Paths default to "~/.nix-profile" and "/var/run/current-system" --store STORE The URL of the Nix store, e.g. "daemon" or "https://cache.nixos.org" See "nix help-stores" for supported store types and settings.+ --file FILE Interpret installables as attribute paths relative to the Nix expression stored in file. --version Show the nix-tree version --derivation Operate on the store derivation rather than its outputs --impure Allow access to mutable paths and repositories@@ -48,8 +49,8 @@ Keybindings: 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@@ -99,6 +100,13 @@ ```bash nix-tree /nix/var/nix/profiles/system+```++Run `nix-tree` on a flake reference of a nixosConfiguration:++```bash+nix build --print-out-paths --no-link '.#nixosConfigurations.foo.config.system.build.toplevel'+nix-tree '.#nixosConfigurations.foo.config.system.build.toplevel' ``` Query the binary cache before download, with the `--store` option:
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.4.1+version: 0.5.0 homepage: https://github.com/utdemir/nix-tree license: BSD-3-Clause license-file: LICENSE
src/NixTree/Main.hs view
@@ -19,7 +19,8 @@ data Opts = Opts { oInstallables :: [Installable],- oStore :: String,+ oStore :: Maybe String,+ oFile :: Maybe FilePath, oVersion :: Bool, oDerivation :: Bool, oImpure :: Bool,@@ -51,18 +52,28 @@ ) ) )- <*> Opts.strOption- ( Opts.long "store"- <> Opts.metavar "STORE"- <> Opts.value "auto"- <> Opts.helpDoc- ( Just $- Opts.vsep- [ "The URL of the Nix store, e.g. \"daemon\" or \"https://cache.nixos.org\"",- "See \"nix help-stores\" for supported store types and settings."- ]- )+ <*> optional+ ( Opts.strOption+ ( Opts.long "store"+ <> Opts.metavar "STORE"+ <> Opts.helpDoc+ ( Just $+ Opts.vsep+ [ "The URL of the Nix store, e.g. \"daemon\" or \"https://cache.nixos.org\"",+ "See \"nix help-stores\" for supported store types and settings."+ ]+ )+ ) )+ <*> optional+ ( Opts.strOption+ ( Opts.long "file"+ <> Opts.metavar "FILE"+ <> Opts.helpDoc+ ( Just $ Opts.vsep ["Interpret installables as attribute paths relative to the Nix expression stored in file."]+ )+ )+ ) <*> 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")@@ -112,7 +123,8 @@ StoreEnvOptions { seoIsDerivation = opts & oDerivation, seoIsImpure = opts & oImpure,- seoStoreURL = opts & oStore+ seoStoreURL = opts & oStore,+ seoFile = opts & oFile } withStoreEnv seo installables $ \env' -> do
src/NixTree/StorePath.hs view
@@ -50,10 +50,15 @@ unNixStore NixStore = "/nix/store/" unNixStore (NixStoreCustom fp) = fp -getStoreDir :: FilePath -> IO NixStore+getStoreDir :: Maybe FilePath -> IO NixStore getStoreDir seoNixStore = do let prog = "nix-instantiate"- args = ["--eval", "--expr", "(builtins.storeDir)", "--json", "--option", "store", seoNixStore]+ args =+ ["--eval", "--expr", "(builtins.storeDir)", "--json"]+ ++ ( case seoNixStore of+ Nothing -> []+ Just url -> ["--option", "store", url]+ ) out <- readProcessStdout_ (proc prog args) <&> fmap mkNixStore@@ -149,7 +154,8 @@ { pioIsRecursive :: Bool, pioIsDerivation :: Bool, pioIsImpure :: Bool,- pioStoreURL :: FilePath+ pioStoreURL :: Maybe FilePath,+ pioFile :: Maybe FilePath } getPathInfo :: NixStore -> NixVersion -> PathInfoOptions -> NonEmpty Installable -> IO (NonEmpty (StorePath s (StoreName s) ()))@@ -163,7 +169,14 @@ ++ ["--impure" | options & pioIsImpure] ++ ["--recursive" | options & pioIsRecursive] ++ ["--derivation" | (options & pioIsDerivation) && nixVersion >= Nix2_4]- ++ ["--store", options & pioStoreURL]+ ++ ( case options & pioStoreURL of+ Nothing -> []+ Just url -> ["--store", url]+ )+ ++ ( case options & pioFile of+ Nothing -> []+ Just file -> ["--file", file]+ ) ++ (if nixVersion >= Nix2_4 then ["--extra-experimental-features", "nix-command flakes"] else []) ++ map (toString . installableToText) (toList names) )@@ -205,7 +218,8 @@ data StoreEnvOptions = StoreEnvOptions { seoIsDerivation :: Bool, seoIsImpure :: Bool,- seoStoreURL :: String+ seoStoreURL :: Maybe String,+ seoFile :: Maybe String } withStoreEnv ::@@ -215,7 +229,7 @@ NonEmpty Installable -> (forall s. StoreEnv s () -> m a) -> m a-withStoreEnv StoreEnvOptions {seoIsDerivation, seoIsImpure, seoStoreURL} names cb = do+withStoreEnv StoreEnvOptions {seoIsDerivation, seoIsImpure, seoStoreURL, seoFile} names cb = do nixStore <- liftIO $ getStoreDir seoStoreURL -- See: https://github.com/utdemir/nix-tree/issues/12@@ -230,7 +244,7 @@ getPathInfo nixStore nixVersion- (PathInfoOptions {pioIsDerivation = seoIsDerivation, pioIsRecursive = False, pioIsImpure = seoIsImpure, pioStoreURL = seoStoreURL})+ (PathInfoOptions {pioIsDerivation = seoIsDerivation, pioIsRecursive = False, pioIsImpure = seoIsImpure, pioStoreURL = seoStoreURL, pioFile = seoFile}) names paths <-@@ -238,7 +252,7 @@ getPathInfo nixStore nixVersion- (PathInfoOptions {pioIsDerivation = seoIsDerivation, pioIsRecursive = True, pioIsImpure = seoIsImpure, pioStoreURL = seoStoreURL})+ (PathInfoOptions {pioIsDerivation = seoIsDerivation, pioIsRecursive = True, pioIsImpure = seoIsImpure, pioStoreURL = seoStoreURL, pioFile = seoFile}) (Installable . toText . storeNameToPath . spName <$> roots) let env =