Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nix
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 64ec087f582c
Choose a base ref
...
head repository: NixOS/nix
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 09dde33c1912
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Jun 25, 2019

  1. Add "warning" verbosity level

    This ensures that "nix" shows warnings. Previously these were hidden
    because they were at "info" level.
    
    (cherry picked from commit 615a9d0)
    edolstra committed Jun 25, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    5600b07 View commit details
  2. Automatically use --no-net if there are no network interfaces

    (cherry picked from commit 04a5976)
    edolstra committed Jun 25, 2019
    Copy the full SHA
    09dde33 View commit details
Showing with 59 additions and 13 deletions.
  1. +0 −11 src/libmain/common-args.cc
  2. +2 −1 src/libutil/logging.cc
  3. +1 −0 src/libutil/logging.hh
  4. +56 −1 src/nix/main.cc
11 changes: 0 additions & 11 deletions src/libmain/common-args.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "common-args.hh"
#include "globals.hh"
#include "download.hh"

namespace nix {

@@ -45,16 +44,6 @@ MixCommonArgs::MixCommonArgs(const string & programName)
settings.set("max-jobs", s);
});

mkFlag()
.longName("no-net")
.description("disable substituters and consider all previously downloaded files up-to-date")
.handler([]() {
settings.useSubstitutes = false;
settings.tarballTtl = std::numeric_limits<unsigned int>::max();
downloadSettings.tries = 0;
downloadSettings.connectTimeout = 1;
});

std::string cat = "config";
globalConfig.convertToArgs(*this, cat);

3 changes: 2 additions & 1 deletion src/libutil/logging.cc
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ Logger * logger = makeDefaultLogger();

void Logger::warn(const std::string & msg)
{
log(lvlInfo, ANSI_RED "warning:" ANSI_NORMAL " " + msg);
log(lvlWarn, ANSI_RED "warning:" ANSI_NORMAL " " + msg);
}

class SimpleLogger : public Logger
@@ -46,6 +46,7 @@ class SimpleLogger : public Logger
char c;
switch (lvl) {
case lvlError: c = '3'; break;
case lvlWarn: c = '4'; break;
case lvlInfo: c = '5'; break;
case lvlTalkative: case lvlChatty: c = '6'; break;
default: c = '7';
1 change: 1 addition & 0 deletions src/libutil/logging.hh
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ namespace nix {

typedef enum {
lvlError = 0,
lvlWarn,
lvlInfo,
lvlTalkative,
lvlChatty,
57 changes: 56 additions & 1 deletion src/nix/main.cc
Original file line number Diff line number Diff line change
@@ -8,19 +8,52 @@
#include "shared.hh"
#include "store-api.hh"
#include "progress-bar.hh"
#include "download.hh"
#include "finally.hh"

#include <sys/types.h>
#include <sys/socket.h>
#include <ifaddrs.h>
#include <netdb.h>

extern std::string chrootHelperName;

void chrootHelper(int argc, char * * argv);

namespace nix {

/* Check if we have a non-loopback/link-local network interface. */
static bool haveInternet()
{
struct ifaddrs * addrs;

if (getifaddrs(&addrs))
return true;

Finally free([&]() { freeifaddrs(addrs); });

for (auto i = addrs; i; i = i->ifa_next) {
if (!i->ifa_addr) continue;
if (i->ifa_addr->sa_family == AF_INET) {
if (ntohl(((sockaddr_in *) i->ifa_addr)->sin_addr.s_addr) != INADDR_LOOPBACK) {
return true;
}
} else if (i->ifa_addr->sa_family == AF_INET6) {
if (!IN6_IS_ADDR_LOOPBACK(((sockaddr_in6 *) i->ifa_addr)->sin6_addr.s6_addr) &&
!IN6_IS_ADDR_LINKLOCAL(((sockaddr_in6 *) i->ifa_addr)->sin6_addr.s6_addr))
return true;
}
}

return false;
}

std::string programPath;

struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
{
bool printBuildLogs = false;
bool useNet = true;

NixArgs() : MultiCommand(*RegisterCommand::commands), MixCommonArgs("nix")
{
@@ -53,6 +86,11 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
.longName("version")
.description("show version information")
.handler([&]() { printVersion(programName); });

mkFlag()
.longName("no-net")
.description("disable substituters and consider all previously downloaded files up-to-date")
.handler([&]() { useNet = false; });
}

void printFlags(std::ostream & out) override
@@ -93,7 +131,7 @@ void mainWrapped(int argc, char * * argv)
if (legacy) return legacy(argc, argv);
}

verbosity = lvlError;
verbosity = lvlWarn;
settings.verboseBuild = false;

NixArgs args;
@@ -108,6 +146,23 @@ void mainWrapped(int argc, char * * argv)

startProgressBar(args.printBuildLogs);

if (args.useNet && !haveInternet()) {
warn("you don't have Internet access; disabling some network-dependent features");
args.useNet = false;
}

if (!args.useNet) {
// FIXME: should check for command line overrides only.
if (!settings.useSubstitutes.overriden)
settings.useSubstitutes = false;
if (!settings.tarballTtl.overriden)
settings.tarballTtl = std::numeric_limits<unsigned int>::max();
if (!downloadSettings.tries.overriden)
downloadSettings.tries = 0;
if (!downloadSettings.connectTimeout.overriden)
downloadSettings.connectTimeout = 1;
}

args.command->prepare();
args.command->run();
}