aboutsummaryrefslogtreecommitdiff
path: root/src/libcmd/command.hh
AgeCommit message (Collapse)Author
2024-03-25Merge pull request #8817 from iFreilicht/flake-update-lock-overhaulThéophane Hufschmitt
Overhaul `nix flake update` and `nix flake lock` UX (cherry picked from commit 12a0ae73dbb37becefa5a442eb4532ff0de9ce65) Change-Id: Iff3b4f4235ebb1948ec612036b39ab29e4ca22b2
2024-03-25Overhaul completions, redo #6693 (#8131)John Ericson
As I complained in https://github.com/NixOS/nix/pull/6784#issuecomment-1421777030 (a comment on the wrong PR, sorry again!), #6693 introduced a second completions mechanism to fix a bug. Having two completion mechanisms isn't so nice. As @thufschmitt also pointed out, it was a bummer to go from `FlakeRef` to `std::string` when collecting flake refs. Now it is `FlakeRefs` again. The underlying issue that sought to work around was that completion of arguments not at the end can still benefit from the information from latter arguments. To fix this better, we rip out that change and simply defer all completion processing until after all the (regular, already-complete) arguments have been passed. In addition, I noticed the original completion logic used some global variables. I do not like global variables, because even if they save lines of code, they also obfuscate the architecture of the code. I got rid of them moved them to a new `RootArgs` class, which now has `parseCmdline` instead of `Args`. The idea is that we have many argument parsers from subcommands and what-not, but only one root args that owns the other per actual parsing invocation. The state that was global is now part of the root args instead. This did, admittedly, add a bunch of new code. And I do feel bad about that. So I went and added a lot of API docs to try to at least make the current state of things clear to the next person. -- This is needed for RFC 134 (tracking issue #7868). It was very hard to modularize `Installable` parsing when there were two completion arguments. I wouldn't go as far as to say it is *easy* now, but at least it is less hard (and the completions test finally passed). Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io> Change-Id: If18cd5be78da4a70635e3fdcac6326dbfeea71a5 (cherry picked from commit 67eb37c1d0de28160cd25376e51d1ec1b1c8305b)
2024-03-04Merge pull request #9167 from obsidiansystems/pre-overhaul-completionseldritch horrors
Improve tests and docs prior to refactoring completions (cherry picked from commit 5442d9b47298389918d1f38d20f768a80ffc2369) Change-Id: Ief99ac2cd9c92981a9a522d15b9c3daf99182c9d
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