From 817562e6946fa44c253beb76a36d85b55fd9c14d Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 14 Sep 2021 19:05:28 +0200 Subject: Add "nix profile rollback" command --- src/nix/profile.cc | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/nix/profile.cc') 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 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) override + { + switchGeneration(*profile, version, dryRun); + } +}; + struct CmdProfile : NixMultiCommand { CmdProfile() @@ -553,6 +585,7 @@ struct CmdProfile : NixMultiCommand {"list", []() { return make_ref(); }}, {"diff-closures", []() { return make_ref(); }}, {"history", []() { return make_ref(); }}, + {"rollback", []() { return make_ref(); }}, }) { } -- cgit v1.2.3 From f359b9981ba3d81e33981018c4bcb83ab45830a3 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 14 Sep 2021 19:57:45 +0200 Subject: Generations -> profile versions --- src/nix/profile.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nix/profile.cc') diff --git a/src/nix/profile.cc b/src/nix/profile.cc index 4c4a9bff4..ab0e88fa1 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -559,7 +559,7 @@ struct CmdProfileRollback : virtual StoreCommand, MixDefaultProfile, MixDryRun std::string description() override { - return "roll back to the previous version or a specified version of this profile"; + return "roll back to the previous version or a specified version of a profile"; } std::string doc() override -- cgit v1.2.3 From 4b738fc7a922ff7b30135768ee4f469d784b5569 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 14 Sep 2021 20:35:12 +0200 Subject: Add 'nix profile wipe-history' command --- src/nix/profile.cc | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/nix/profile.cc') diff --git a/src/nix/profile.cc b/src/nix/profile.cc index ab0e88fa1..6d5fa5cd0 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -575,6 +575,44 @@ struct CmdProfileRollback : virtual StoreCommand, MixDefaultProfile, MixDryRun } }; +struct CmdProfileWipeHistory : virtual StoreCommand, MixDefaultProfile, MixDryRun +{ + std::optional minAge; + + CmdProfileWipeHistory() + { + addFlag({ + .longName = "older-than", + .description = + "Delete versions older than the specified age. *age* " + "must be in the format *N*`d`, where *N* denotes a number " + "of days.", + .labels = {"age"}, + .handler = {&minAge}, + }); + } + + std::string description() override + { + return "delete non-current versions of a profile"; + } + + std::string doc() override + { + return + #include "profile-wipe-history.md" + ; + } + + void run(ref store) override + { + if (minAge) + deleteGenerationsOlderThan(*profile, *minAge, dryRun); + else + deleteOldGenerations(*profile, dryRun); + } +}; + struct CmdProfile : NixMultiCommand { CmdProfile() @@ -586,6 +624,7 @@ struct CmdProfile : NixMultiCommand {"diff-closures", []() { return make_ref(); }}, {"history", []() { return make_ref(); }}, {"rollback", []() { return make_ref(); }}, + {"wipe-history", []() { return make_ref(); }}, }) { } -- cgit v1.2.3 From b41968f15a6393a55b5c7ff5fe7eac4e33d94357 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 14 Sep 2021 20:47:33 +0200 Subject: nix profile history: Show profile date --- src/nix/profile.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/nix/profile.cc') diff --git a/src/nix/profile.cc b/src/nix/profile.cc index 6d5fa5cd0..a1cb3fc76 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -12,6 +12,7 @@ #include #include +#include using namespace nix; @@ -528,10 +529,11 @@ struct CmdProfileHistory : virtual StoreCommand, EvalCommand, MixDefaultProfile if (!first) std::cout << "\n"; first = false; - if (prevGen) - std::cout << fmt("Version %d -> %d:\n", prevGen->first.number, gen.number); - else - std::cout << fmt("Version %d:\n", gen.number); + std::cout << fmt("Version %s%d" ANSI_NORMAL " (%s)%s:\n", + gen.number == curGen ? ANSI_GREEN : ANSI_BOLD, + gen.number, + std::put_time(std::gmtime(&gen.creationTime), "%Y-%m-%d"), + prevGen ? fmt(" <- %d", prevGen->first.number) : ""); ProfileManifest::printDiff( prevGen ? prevGen->second : ProfileManifest(), -- cgit v1.2.3