aboutsummaryrefslogtreecommitdiff
path: root/src/libcmd/command.hh
AgeCommit message (Collapse)Author
2023-03-31Ensure all headers have `#pragma once` and are in API docsJohn Ericson
`///@file` makes them show up in the internal API dos. A tiny few were missing `#pragma once`.
2023-03-27Merge pull request #7763 from obsidiansystems/installable-wide-infoEelco Dolstra
Stratify `ExtraPathInfo` along `Installable` hierarchy
2023-03-24Stratify `ExtraPathInfo` along `Installable` hierarchyJohn Ericson
Instead of having a bunch of optional fields, have a few subclasses which can have mandatory fields. Additionally, the new `getExtraPathInfo`, and `nixpkgsFlakeRef`, are moved to `InstallableValue`. I did these things because https://github.com/NixOS/rfcs/pull/134 ; with these things moved to `InstallableValue`, the base `Installable` no longer depends on libexpr! This is a major step towards that. Also, add a bunch of doc comments for sake of the internal API docs.
2023-03-21Add a "help" categoryEelco Dolstra
This makes the help commands show up prominently at the top of the 'nix' manpage.
2023-03-15Make command infra less stateful and more regularJohn Ericson
Already, we had classes like `BuiltPathsCommand` and `StorePathsCommand` which provided alternative `run` virtual functions providing the implementation with more arguments. This was a very nice and easy way to make writing command; just fill in the virtual functions and it is fairly clear what to do. However, exception to this pattern were `Installable{,s}Command`. These two classes instead just had a field where the installables would be stored, and various side-effecting `prepare` and `load` machinery too fill them in. Command would wish out those fields. This isn't so clear to use. What this commit does is make those command classes like the others, with richer `run` functions. Not only does this restore the pattern making commands easier to write, it has a number of other benefits: - `prepare` and `load` are gone entirely! One command just hands just hands off to the next. - `useDefaultInstallables` because `defaultInstallables`. This takes over `prepare` for the one case that needs it, and provides enough flexiblity to handle `nix repl`'s idiosyncratic migration. - We can use `ref` instead of `std::shared_ptr`. The former must be initialized (so it is like Rust's `Box` rather than `Option<Box>`, This expresses the invariant that the installable are in fact initialized much better. This is possible because since we just have local variables not fields, we can stop worrying about the not-yet-initialized case. - Fewer lines of code! (Finally I have a large refactor that makes the number go down not up...) - `nix repl` is now implemented in a clearer way. The last item deserves further mention. `nix repl` is not like the other installable commands because instead working from once-loaded installables, it needs to be able to load them again and again. To properly support this, we make a new superclass `RawInstallablesCommand`. This class has the argument parsing and completion logic, but does *not* hand off parsed installables but instead just the raw string arguments. This is exactly what `nix repl` needs, and allows us to instead of having the logic awkwardly split between `prepare`, `useDefaultInstallables,` and `load`, have everything right next to each other. I think this will enable future simplifications of that argument defaulting logic, but I am saving those for a future PR --- best to keep code motion and more complicated boolean expression rewriting separate steps. The "diagnostic ignored `-Woverloaded-virtual`" pragma helps because C++ doesn't like our many `run` methods. In our case, we don't mind the shadowing it all --- it is *intentional* that the derived class only provides a `run` method, and doesn't call any of the overridden `run` methods. Helps with https://github.com/NixOS/rfcs/pull/134
2023-03-08Fix uninitialized readFromStdIn variableEelco Dolstra
This was causing random failures in tests/ca/substitute.ca: 'nix copy --file ./content-addressed.nix' wouldn't get the default installable '.' applied in InstallablesCommand::load(), so it would do nothing.
2023-03-05clarify definition of "installable"Valentin Gagarin
the term was hard to discover, as its definition and explanation were in a very long document lacking an overview section. search did not help because it occurs so often. - clarify wording in the definition - add an overview of installable types - add "installable" to glossary - link to definition from occurrences of the term - be more precise about where store derivation outputs are processed - installable Nix expressions must evaluate to a derivation Co-authored-by: Adam Joseph <54836058+amjoseph-nixpkgs@users.noreply.github.com>
2023-02-28feat: read installable paths from stdinTimothy DeHerrera
Resolves #7437 for new `nix` commands only by adding a `--stdin` flag. If paths are also passed on the cli they will be combined with the ones from standard input.
2023-02-20Make `--read-only` a separate mixinJohn Ericson
It is independent of SourceExprCommand, which is about parsing installables, except for the fact that parsing installables is one of the many things influenced by read-only mode.
2023-02-20Split out `CmdRepl` and `editorFor`John Ericson
The REPL itself and the `nix repl` CLI are conceptually different things, and thus deserve to be in different files.
2023-02-04Scope down `--derivation` to just the commands that use itJohn Ericson
Per the old FIXME, this flag was on too many commands, and mostly ignored. Now it is just on the commands where it actually has an effect. Per https://github.com/NixOS/nix/issues/7261, I would still like to get rid of it entirely, but that is a separate project. This change should be good with or without doing that.
2022-07-12Merge pull request #6693 from ncfavier/complete-flake-inputsThéophane Hufschmitt
Improve shell completion of flake inputs
2022-07-11Merge branch 'master' into ignore-tryBen Burdette
2022-07-11Fix flake input completion for `InstallablesCommand`sNaïm Favier
Defers completion of flake inputs until the whole command line is parsed so that we know what flakes we need to complete the inputs of. Previously, `nix build flake --update-input <Tab>` always behaved like `nix build . --update-input <Tab>`.
2022-06-20Complete flake inputs for all given flakesNaïm Favier
Allow `nix build flake1 flake2 --update-input <Tab>` to complete the inputs of both flakes. Also do tilde expansion so that `nix build ~/flake --update-input <Tab>` works.
2022-06-02Merge branch 'master' into nix-repl-flakesTom Bereknyei
2022-06-02ignore-try flagBen Burdette
2022-05-25back to ref<EvalState> in NixReplBen Burdette
2022-05-25Style tweaksEelco Dolstra
2022-05-22changning repl to use EvalState& instead of refBen Burdette
2022-05-18repl: provide backward compat with legacy usageTom Bereknyei
2022-05-18repl: use installablesTom Bereknyei
2022-05-18repl: allow loading installables from CLITom Bereknyei
repl: search installable with findAlongAttrPath repl: refactor handling of args repl: temp
2022-05-15remove extra argumentBen Burdette
2022-05-05traceable_allocatorBen Burdette
2022-05-05Style fixesEelco Dolstra
In particular, use std::make_shared and enumerate(). Also renamed some fields to fit naming conventions.
2022-04-28Merge branch 'master' into debug-merge-masterBen Burdette
2022-04-21don't use full Pos for findPackageFilename/editorForpennae
only file and line of the returned position were ever used, it wasn't actually used a position. as such we may as well use a path+int pair for only those two values and remove a use of Pos that would not work well with a position table.
2022-04-19Merge pull request #6128 from ncfavier/fix-completionEelco Dolstra
Shell completion improvements
2022-04-15Merge branch 'master' into debug-exploratory-PRBen Burdette
2022-04-08remove 'debugError', dead codeBen Burdette
2022-04-07Merge remote-tracking branch 'upstream/master' into upstream-mergeBen Burdette
2022-03-26nix eval: Add option `read-only`Erik Arvstedt
2022-03-07Accept and discard fragments in getFlakeRefForCompletionNaïm Favier
Otherwise trying to complete `nix build foo#bar --update-input <Tab>` fails with "unexpected fragment"
2022-03-02Move installables-related operationsEelco Dolstra
2022-02-04Merge branch 'master' into debug-stepBen Burdette
2022-01-18Add command 'nix store copy-log'Eelco Dolstra
Fixes #5222.
2022-01-18Factor out --from / --to logicEelco Dolstra
2021-12-27add DebugTrace for the current errorBen Burdette
2021-12-23DebugTraceBen Burdette
2021-12-20:d errorBen Burdette
2021-11-25Merge branch 'master' into debug-mergeBen Burdette
2021-09-27run(): MoveEelco Dolstra
2021-09-10Make installables constEelco Dolstra
2021-09-02Add FIXMEEelco Dolstra
2021-07-22Use eval-store in more placesEelco Dolstra
In particular, this now works: $ nix path-info --eval-store auto --store https://cache.nixos.org nixpkgs#hello Previously this would fail as it would try to upload the hello .drv to cache.nixos.org. Now the .drv is instantiated in the local store, and then we check for the existence of the outputs in cache.nixos.org.
2021-07-22Support --eval-store in nix-instantiate and nix-buildEelco Dolstra
2021-07-22Add --eval-store optionEelco Dolstra
2021-05-17Enfore the use of properly built paths in libcmdregnat
Replace `DerivedPathWithHints` by a new `BuiltPath` type that serves as a proof that the corresponding path has been built.
2021-05-12DerivedPathWithHints -> BuiltPathregnat
Just a renaming for now