Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add --file flag (#64) #103

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/NixTree/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ version = VERSION_nix_tree
data Opts = Opts
{ oInstallables :: [Installable],
oStore :: Maybe String,
oFile :: Maybe FilePath,
oVersion :: Bool,
oDerivation :: Bool,
oImpure :: Bool,
Expand Down Expand Up @@ -64,6 +65,15 @@ optsParser =
)
)
)
<*> 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")
Expand Down Expand Up @@ -113,7 +123,8 @@ main = do
StoreEnvOptions
{ seoIsDerivation = opts & oDerivation,
seoIsImpure = opts & oImpure,
seoStoreURL = opts & oStore
seoStoreURL = opts & oStore,
seoFile = opts & oFile
}

withStoreEnv seo installables $ \env' -> do
Expand Down
16 changes: 11 additions & 5 deletions src/NixTree/StorePath.hs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ data PathInfoOptions = PathInfoOptions
{ pioIsRecursive :: Bool,
pioIsDerivation :: Bool,
pioIsImpure :: Bool,
pioStoreURL :: Maybe FilePath
pioStoreURL :: Maybe FilePath,
pioFile :: Maybe FilePath
}

getPathInfo :: NixStore -> NixVersion -> PathInfoOptions -> NonEmpty Installable -> IO (NonEmpty (StorePath s (StoreName s) ()))
Expand All @@ -172,6 +173,10 @@ getPathInfo nixStore nixVersion options names = do
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)
)
Expand Down Expand Up @@ -213,7 +218,8 @@ data StoreEnv s payload = StoreEnv
data StoreEnvOptions = StoreEnvOptions
{ seoIsDerivation :: Bool,
seoIsImpure :: Bool,
seoStoreURL :: Maybe String
seoStoreURL :: Maybe String,
seoFile :: Maybe String
}

withStoreEnv ::
Expand All @@ -223,7 +229,7 @@ withStoreEnv ::
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
Expand All @@ -238,15 +244,15 @@ withStoreEnv StoreEnvOptions {seoIsDerivation, seoIsImpure, seoStoreURL} names c
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 <-
liftIO $
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 =
Expand Down
Loading