about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDaiderd Jordan <daiderd@gmail.com>2018-08-25T18·25+0200
committerDaiderd Jordan <daiderd@gmail.com>2018-08-25T18·25+0200
commit414397759a5390b54cee12c6834e6106bea12f5f (patch)
tree28dcee7531b34332310b78956d45eeb8395ed637
parentc651b7bdc996a18688c5e5dd5dd84eeeb8d3376d (diff)
upgrade-nix: add --dry-run
-rw-r--r--src/nix/upgrade-nix.cc21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/nix/upgrade-nix.cc b/src/nix/upgrade-nix.cc
index e23ae792369c..3417adb62c9f 100644
--- a/src/nix/upgrade-nix.cc
+++ b/src/nix/upgrade-nix.cc
@@ -1,4 +1,5 @@
 #include "command.hh"
+#include "common-args.hh"
 #include "store-api.hh"
 #include "download.hh"
 #include "eval.hh"
@@ -6,7 +7,7 @@
 
 using namespace nix;
 
-struct CmdUpgradeNix : StoreCommand
+struct CmdUpgradeNix : MixDryRun, StoreCommand
 {
     Path profileDir;
 
@@ -61,21 +62,25 @@ struct CmdUpgradeNix : StoreCommand
 
         {
             Activity act(*logger, lvlInfo, actUnknown, fmt("downloading '%s'...", storePath));
-            store->ensurePath(storePath);
+            if (!dryRun)
+                store->ensurePath(storePath);
         }
 
         {
             Activity act(*logger, lvlInfo, actUnknown, fmt("verifying that '%s' works...", storePath));
-            auto program = storePath + "/bin/nix-env";
-            auto s = runProgram(program, false, {"--version"});
-            if (s.find("Nix") == std::string::npos)
-                throw Error("could not verify that '%s' works", program);
+            if (!dryRun) {
+                auto program = storePath + "/bin/nix-env";
+                auto s = runProgram(program, false, {"--version"});
+                if (s.find("Nix") == std::string::npos)
+                    throw Error("could not verify that '%s' works", program);
+            }
         }
 
         {
             Activity act(*logger, lvlInfo, actUnknown, fmt("installing '%s' into profile '%s'...", storePath, profileDir));
-            runProgram(settings.nixBinDir + "/nix-env", false,
-                {"--profile", profileDir, "-i", storePath, "--no-sandbox"});
+            if (!dryRun)
+                runProgram(settings.nixBinDir + "/nix-env", false,
+                    {"--profile", profileDir, "-i", storePath, "--no-sandbox"});
         }
     }