diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2021-09-14 19:05:28 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2021-09-14 19:32:33 +0200 |
commit | 817562e6946fa44c253beb76a36d85b55fd9c14d (patch) | |
tree | 9259231b8a4eebd81344a8f323d8737ef2c7f0f9 /src/nix | |
parent | 1fbaf367292a8eb57a120f74daacabccce622f2f (diff) |
Add "nix profile rollback" command
Diffstat (limited to 'src/nix')
-rw-r--r-- | src/nix/profile-rollback.md | 26 | ||||
-rw-r--r-- | src/nix/profile.cc | 33 |
2 files changed, 59 insertions, 0 deletions
diff --git a/src/nix/profile-rollback.md b/src/nix/profile-rollback.md new file mode 100644 index 000000000..fccdbb10e --- /dev/null +++ b/src/nix/profile-rollback.md @@ -0,0 +1,26 @@ +R""( + +# Examples + +* Roll back your default profile to the previous version: + + ```console + # nix profile rollback + switching from generation 519 to 518 + ``` + +* Switch your default profile to version 510: + + ```console + # nix profile rollback --to 510 + switching from generation 518 to 510 + ``` + +# Description + +This command switches a profile to the most recent version older +than the currently active version, or if `--to` *N* is given, to +version *N* of the profile. To see the available versions of a +profile, use `nix profile history`. + +)"" diff --git a/src/nix/profile.cc b/src/nix/profile.cc index 8cef6d0b6..4c4a9bff4 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -543,6 +543,38 @@ struct CmdProfileHistory : virtual StoreCommand, EvalCommand, MixDefaultProfile } }; +struct CmdProfileRollback : virtual StoreCommand, MixDefaultProfile, MixDryRun +{ + std::optional<GenerationNumber> version; + + CmdProfileRollback() + { + addFlag({ + .longName = "to", + .description = "The profile version to roll back to.", + .labels = {"version"}, + .handler = {&version}, + }); + } + + std::string description() override + { + return "roll back to the previous version or a specified version of this profile"; + } + + std::string doc() override + { + return + #include "profile-rollback.md" + ; + } + + void run(ref<Store> store) override + { + switchGeneration(*profile, version, dryRun); + } +}; + struct CmdProfile : NixMultiCommand { CmdProfile() @@ -553,6 +585,7 @@ struct CmdProfile : NixMultiCommand {"list", []() { return make_ref<CmdProfileList>(); }}, {"diff-closures", []() { return make_ref<CmdProfileDiffClosures>(); }}, {"history", []() { return make_ref<CmdProfileHistory>(); }}, + {"rollback", []() { return make_ref<CmdProfileRollback>(); }}, }) { } |