Merge branch 'master' into debug-exploratory-PR

This commit is contained in:
Ben Burdette 2022-04-15 14:49:08 -06:00
commit 93b8d31508
24 changed files with 102 additions and 53 deletions

View file

@ -8,7 +8,7 @@ jobs:
if: github.repository_owner == 'NixOS' && github.event.pull_request.merged == true && (github.event_name != 'labeled' || startsWith('backport', github.event.label.name)) if: github.repository_owner == 'NixOS' && github.event.pull_request.merged == true && (github.event_name != 'labeled' || startsWith('backport', github.event.label.name))
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
with: with:
ref: ${{ github.event.pull_request.head.sha }} ref: ${{ github.event.pull_request.head.sha }}
# required to find all branches # required to find all branches

View file

@ -14,10 +14,10 @@ jobs:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
timeout-minutes: 60 timeout-minutes: 60
steps: steps:
- uses: actions/checkout@v2.4.0 - uses: actions/checkout@v3
with: with:
fetch-depth: 0 fetch-depth: 0
- uses: cachix/install-nix-action@v16 - uses: cachix/install-nix-action@v17
- run: echo CACHIX_NAME="$(echo $GITHUB_REPOSITORY-install-tests | tr "[A-Z]/" "[a-z]-")" >> $GITHUB_ENV - run: echo CACHIX_NAME="$(echo $GITHUB_REPOSITORY-install-tests | tr "[A-Z]/" "[a-z]-")" >> $GITHUB_ENV
- uses: cachix/cachix-action@v10 - uses: cachix/cachix-action@v10
if: needs.check_cachix.outputs.secret == 'true' if: needs.check_cachix.outputs.secret == 'true'
@ -46,11 +46,11 @@ jobs:
outputs: outputs:
installerURL: ${{ steps.prepare-installer.outputs.installerURL }} installerURL: ${{ steps.prepare-installer.outputs.installerURL }}
steps: steps:
- uses: actions/checkout@v2.4.0 - uses: actions/checkout@v3
with: with:
fetch-depth: 0 fetch-depth: 0
- run: echo CACHIX_NAME="$(echo $GITHUB_REPOSITORY-install-tests | tr "[A-Z]/" "[a-z]-")" >> $GITHUB_ENV - run: echo CACHIX_NAME="$(echo $GITHUB_REPOSITORY-install-tests | tr "[A-Z]/" "[a-z]-")" >> $GITHUB_ENV
- uses: cachix/install-nix-action@v16 - uses: cachix/install-nix-action@v17
- uses: cachix/cachix-action@v10 - uses: cachix/cachix-action@v10
with: with:
name: '${{ env.CACHIX_NAME }}' name: '${{ env.CACHIX_NAME }}'
@ -67,9 +67,9 @@ jobs:
os: [ubuntu-latest, macos-latest] os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v2.4.0 - uses: actions/checkout@v3
- run: echo CACHIX_NAME="$(echo $GITHUB_REPOSITORY-install-tests | tr "[A-Z]/" "[a-z]-")" >> $GITHUB_ENV - run: echo CACHIX_NAME="$(echo $GITHUB_REPOSITORY-install-tests | tr "[A-Z]/" "[a-z]-")" >> $GITHUB_ENV
- uses: cachix/install-nix-action@v16 - uses: cachix/install-nix-action@v17
with: with:
install_url: '${{needs.installer.outputs.installerURL}}' install_url: '${{needs.installer.outputs.installerURL}}'
install_options: "--tarball-url-prefix https://${{ env.CACHIX_NAME }}.cachix.org/serve" install_options: "--tarball-url-prefix https://${{ env.CACHIX_NAME }}.cachix.org/serve"
@ -83,10 +83,10 @@ jobs:
needs.check_cachix.outputs.secret == 'true' needs.check_cachix.outputs.secret == 'true'
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2.4.0 - uses: actions/checkout@v3
with: with:
fetch-depth: 0 fetch-depth: 0
- uses: cachix/install-nix-action@v16 - uses: cachix/install-nix-action@v17
- run: echo CACHIX_NAME="$(echo $GITHUB_REPOSITORY-install-tests | tr "[A-Z]/" "[a-z]-")" >> $GITHUB_ENV - run: echo CACHIX_NAME="$(echo $GITHUB_REPOSITORY-install-tests | tr "[A-Z]/" "[a-z]-")" >> $GITHUB_ENV
- run: echo NIX_VERSION="$(nix-instantiate --eval -E '(import ./default.nix).defaultPackage.${builtins.currentSystem}.version' | tr -d \")" >> $GITHUB_ENV - run: echo NIX_VERSION="$(nix-instantiate --eval -E '(import ./default.nix).defaultPackage.${builtins.currentSystem}.version' | tr -d \")" >> $GITHUB_ENV
- uses: cachix/cachix-action@v10 - uses: cachix/cachix-action@v10

View file

@ -9,7 +9,7 @@ jobs:
if: github.repository_owner == 'NixOS' if: github.repository_owner == 'NixOS'
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2.4.0 - uses: actions/checkout@v3
with: with:
fetch-depth: 0 fetch-depth: 0
- run: bash scripts/check-hydra-status.sh - run: bash scripts/check-hydra-status.sh

View file

@ -423,6 +423,18 @@ EOF
fi fi
done done
if [ "$(uname -s)" = "Linux" ] && [ ! -e /run/systemd/system ]; then
warning <<EOF
We did not detect systemd on your system. With a multi-user install
without systemd you will have to manually configure your init system to
launch the Nix daemon after installation.
EOF
if ! ui_confirm "Do you want to proceed with a multi-user installation?"; then
failure <<EOF
You have aborted the installation.
EOF
fi
fi
} }
setup_report() { setup_report() {

View file

@ -87,11 +87,12 @@ struct SourceExprCommand : virtual Args, MixFlakeOptions
{ {
std::optional<Path> file; std::optional<Path> file;
std::optional<std::string> expr; std::optional<std::string> expr;
bool readOnlyMode = false;
// FIXME: move this; not all commands (e.g. 'nix run') use it. // FIXME: move this; not all commands (e.g. 'nix run') use it.
OperateOn operateOn = OperateOn::Output; OperateOn operateOn = OperateOn::Output;
SourceExprCommand(); SourceExprCommand(bool supportReadOnlyMode = false);
std::vector<std::shared_ptr<Installable>> parseInstallables( std::vector<std::shared_ptr<Installable>> parseInstallables(
ref<Store> store, std::vector<std::string> ss); ref<Store> store, std::vector<std::string> ss);
@ -130,7 +131,7 @@ struct InstallableCommand : virtual Args, SourceExprCommand
{ {
std::shared_ptr<Installable> installable; std::shared_ptr<Installable> installable;
InstallableCommand(); InstallableCommand(bool supportReadOnlyMode = false);
void prepare() override; void prepare() override;

View file

@ -1,3 +1,4 @@
#include "globals.hh"
#include "installables.hh" #include "installables.hh"
#include "command.hh" #include "command.hh"
#include "attr-path.hh" #include "attr-path.hh"
@ -129,7 +130,7 @@ MixFlakeOptions::MixFlakeOptions()
}); });
} }
SourceExprCommand::SourceExprCommand() SourceExprCommand::SourceExprCommand(bool supportReadOnlyMode)
{ {
addFlag({ addFlag({
.longName = "file", .longName = "file",
@ -157,6 +158,17 @@ SourceExprCommand::SourceExprCommand()
.category = installablesCategory, .category = installablesCategory,
.handler = {&operateOn, OperateOn::Derivation}, .handler = {&operateOn, OperateOn::Derivation},
}); });
if (supportReadOnlyMode) {
addFlag({
.longName = "read-only",
.description =
"Do not instantiate each evaluated derivation. "
"This improves performance, but can cause errors when accessing "
"store paths of derivations during evaluation.",
.handler = {&readOnlyMode, true},
});
}
} }
Strings SourceExprCommand::getDefaultFlakeAttrPaths() Strings SourceExprCommand::getDefaultFlakeAttrPaths()
@ -687,6 +699,10 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
{ {
std::vector<std::shared_ptr<Installable>> result; std::vector<std::shared_ptr<Installable>> result;
if (readOnlyMode) {
settings.readOnlyMode = true;
}
if (file || expr) { if (file || expr) {
if (file && expr) if (file && expr)
throw UsageError("'--file' and '--expr' are exclusive"); throw UsageError("'--file' and '--expr' are exclusive");
@ -954,7 +970,7 @@ InstallablesCommand::InstallablesCommand()
void InstallablesCommand::prepare() void InstallablesCommand::prepare()
{ {
if (_installables.empty() && useDefaultInstallables()) if (_installables.empty() && useDefaultInstallables())
// FIXME: commands like "nix install" should not have a // FIXME: commands like "nix profile install" should not have a
// default, probably. // default, probably.
_installables.push_back("."); _installables.push_back(".");
installables = parseInstallables(getStore(), _installables); installables = parseInstallables(getStore(), _installables);
@ -970,7 +986,8 @@ std::optional<FlakeRef> InstallablesCommand::getFlakeRefForCompletion()
return parseFlakeRef(_installables.front(), absPath(".")); return parseFlakeRef(_installables.front(), absPath("."));
} }
InstallableCommand::InstallableCommand() InstallableCommand::InstallableCommand(bool supportReadOnlyMode)
: SourceExprCommand(supportReadOnlyMode)
{ {
expectArgs({ expectArgs({
.label = "installable", .label = "installable",

View file

@ -238,9 +238,18 @@ std::optional<std::string> Input::getRef() const
std::optional<Hash> Input::getRev() const std::optional<Hash> Input::getRev() const
{ {
if (auto s = maybeGetStrAttr(attrs, "rev")) std::optional<Hash> hash = {};
return Hash::parseAny(*s, htSHA1);
return {}; if (auto s = maybeGetStrAttr(attrs, "rev")) {
try {
hash = Hash::parseAnyPrefixed(*s);
} catch (BadHash &e) {
// Default to sha1 for backwards compatibility with existing flakes
hash = Hash::parseAny(*s, htSHA1);
}
}
return hash;
} }
std::optional<uint64_t> Input::getRevCount() const std::optional<uint64_t> Input::getRevCount() const

View file

@ -28,9 +28,7 @@ static std::string readHead(const Path & path)
static bool isNotDotGitDirectory(const Path & path) static bool isNotDotGitDirectory(const Path & path)
{ {
static const std::regex gitDirRegex("^(?:.*/)?\\.git$"); return baseNameOf(path) != ".git";
return not std::regex_match(path, gitDirRegex);
} }
struct GitInputScheme : InputScheme struct GitInputScheme : InputScheme
@ -189,8 +187,16 @@ struct GitInputScheme : InputScheme
if (submodules) cacheType += "-submodules"; if (submodules) cacheType += "-submodules";
if (allRefs) cacheType += "-all-refs"; if (allRefs) cacheType += "-all-refs";
auto checkHashType = [&](const std::optional<Hash> & hash)
{
if (hash.has_value() && !(hash->type == htSHA1 || hash->type == htSHA256))
throw Error("Hash '%s' is not supported by Git. Supported types are sha1 and sha256.", hash->to_string(Base16, true));
};
auto getLockedAttrs = [&]() auto getLockedAttrs = [&]()
{ {
checkHashType(input.getRev());
return Attrs({ return Attrs({
{"type", cacheType}, {"type", cacheType},
{"name", name}, {"name", name},

View file

@ -178,9 +178,11 @@ struct MercurialInputScheme : InputScheme
auto files = tokenizeString<std::set<std::string>>( auto files = tokenizeString<std::set<std::string>>(
runHg({ "status", "-R", actualUrl, "--clean", "--modified", "--added", "--no-status", "--print0" }), "\0"s); runHg({ "status", "-R", actualUrl, "--clean", "--modified", "--added", "--no-status", "--print0" }), "\0"s);
Path actualPath(absPath(actualUrl));
PathFilter filter = [&](const Path & p) -> bool { PathFilter filter = [&](const Path & p) -> bool {
assert(hasPrefix(p, actualUrl)); assert(hasPrefix(p, actualPath));
std::string file(p, actualUrl.size() + 1); std::string file(p, actualPath.size() + 1);
auto st = lstat(p); auto st = lstat(p);
@ -193,7 +195,7 @@ struct MercurialInputScheme : InputScheme
return files.count(file); return files.count(file);
}; };
auto storePath = store->addToStore(input.getName(), actualUrl, FileIngestionMethod::Recursive, htSHA256, filter); auto storePath = store->addToStore(input.getName(), actualPath, FileIngestionMethod::Recursive, htSHA256, filter);
return {std::move(storePath), input}; return {std::move(storePath), input};
} }
@ -201,8 +203,17 @@ struct MercurialInputScheme : InputScheme
if (!input.getRef()) input.attrs.insert_or_assign("ref", "default"); if (!input.getRef()) input.attrs.insert_or_assign("ref", "default");
auto checkHashType = [&](const std::optional<Hash> & hash)
{
if (hash.has_value() && hash->type != htSHA1)
throw Error("Hash '%s' is not supported by Mercurial. Only sha1 is supported.", hash->to_string(Base16, true));
};
auto getLockedAttrs = [&]() auto getLockedAttrs = [&]()
{ {
checkHashType(input.getRev());
return Attrs({ return Attrs({
{"type", "hg"}, {"type", "hg"},
{"name", name}, {"name", name},

View file

@ -31,6 +31,8 @@ struct BuildResult
ResolvesToAlreadyValid, ResolvesToAlreadyValid,
NoSubstituters, NoSubstituters,
} status = MiscFailure; } status = MiscFailure;
// FIXME: include entire ErrorInfo object.
std::string errorMsg; std::string errorMsg;
std::string toString() const { std::string toString() const {

View file

@ -1371,8 +1371,7 @@ void DerivationGoal::done(
{ {
buildResult.status = status; buildResult.status = status;
if (ex) if (ex)
// FIXME: strip: "error: " buildResult.errorMsg = fmt("%s", normaltxt(ex->info().msg));
buildResult.errorMsg = ex->what();
if (buildResult.status == BuildResult::TimedOut) if (buildResult.status == BuildResult::TimedOut)
worker.timedOut = true; worker.timedOut = true;
if (buildResult.status == BuildResult::PermanentFailure) if (buildResult.status == BuildResult::PermanentFailure)

View file

@ -704,6 +704,9 @@ void LocalDerivationGoal::startBuilder()
/* Run the builder. */ /* Run the builder. */
printMsg(lvlChatty, "executing builder '%1%'", drv->builder); printMsg(lvlChatty, "executing builder '%1%'", drv->builder);
printMsg(lvlChatty, "using builder args '%1%'", concatStringsSep(" ", drv->args));
for (auto & i : drv->env)
printMsg(lvlVomit, "setting builder env variable '%1%'='%2%'", i.first, i.second);
/* Create the log file. */ /* Create the log file. */
Path logFile = openLogFile(); Path logFile = openLogFile();

View file

@ -123,8 +123,6 @@ public:
template<typename... Args> template<typename... Args>
FileTransferError(FileTransfer::Error error, std::optional<std::string> response, const Args & ... args); FileTransferError(FileTransfer::Error error, std::optional<std::string> response, const Args & ... args);
virtual const char* sname() const override { return "FileTransferError"; }
}; };
bool isUri(std::string_view s); bool isUri(std::string_view s);

View file

@ -215,7 +215,6 @@ void handleSQLiteBusy(const SQLiteBusy & e)
if (now > lastWarned + 10) { if (now > lastWarned + 10) {
lastWarned = now; lastWarned = now;
logWarning({ logWarning({
.name = "Sqlite busy",
.msg = hintfmt(e.what()) .msg = hintfmt(e.what())
}); });
} }

View file

@ -21,12 +21,9 @@ const std::string & BaseError::calcWhat() const
if (what_.has_value()) if (what_.has_value())
return *what_; return *what_;
else { else {
err.name = sname();
std::ostringstream oss; std::ostringstream oss;
showErrorInfo(oss, err, loggerSettings.showTrace); showErrorInfo(oss, err, loggerSettings.showTrace);
what_ = oss.str(); what_ = oss.str();
return *what_; return *what_;
} }
} }

View file

@ -118,7 +118,6 @@ struct Trace {
struct ErrorInfo { struct ErrorInfo {
Verbosity level; Verbosity level;
std::string name; // FIXME: rename
hintformat msg; hintformat msg;
std::optional<ErrPos> errPos; std::optional<ErrPos> errPos;
std::list<Trace> traces; std::list<Trace> traces;
@ -171,8 +170,6 @@ public:
: err(e) : err(e)
{ } { }
virtual const char* sname() const { return "BaseError"; }
#ifdef EXCEPTION_NEEDS_THROW_SPEC #ifdef EXCEPTION_NEEDS_THROW_SPEC
~BaseError() throw () { }; ~BaseError() throw () { };
const char * what() const throw () { return calcWhat().c_str(); } const char * what() const throw () { return calcWhat().c_str(); }
@ -199,7 +196,6 @@ public:
{ \ { \
public: \ public: \
using superClass::superClass; \ using superClass::superClass; \
virtual const char* sname() const override { return #newClass; } \
} }
MakeError(Error, BaseError); MakeError(Error, BaseError);
@ -219,8 +215,6 @@ public:
auto hf = hintfmt(args...); auto hf = hintfmt(args...);
err.msg = hintfmt("%1%: %2%", normaltxt(hf.str()), strerror(errNo)); err.msg = hintfmt("%1%: %2%", normaltxt(hf.str()), strerror(errNo));
} }
virtual const char* sname() const override { return "SysError"; }
}; };
} }

View file

@ -49,10 +49,6 @@ public:
ExperimentalFeature missingFeature; ExperimentalFeature missingFeature;
MissingExperimentalFeature(ExperimentalFeature); MissingExperimentalFeature(ExperimentalFeature);
virtual const char * sname() const override
{
return "MissingExperimentalFeature";
}
}; };
} }

View file

@ -155,7 +155,7 @@ static std::pair<std::optional<HashType>, bool> getParsedTypeAndSRI(std::string_
{ {
bool isSRI = false; bool isSRI = false;
// Parse the has type before the separater, if there was one. // Parse the hash type before the separator, if there was one.
std::optional<HashType> optParsedType; std::optional<HashType> optParsedType;
{ {
auto hashRaw = splitPrefixTo(rest, ':'); auto hashRaw = splitPrefixTo(rest, ':');

View file

@ -93,13 +93,11 @@ public:
std::string gitRev() const std::string gitRev() const
{ {
assert(type == htSHA1);
return to_string(Base16, false); return to_string(Base16, false);
} }
std::string gitShortRev() const std::string gitShortRev() const
{ {
assert(type == htSHA1);
return std::string(to_string(Base16, false), 0, 7); return std::string(to_string(Base16, false), 0, 7);
} }

View file

@ -357,7 +357,7 @@ Sink & operator << (Sink & sink, const Error & ex)
sink sink
<< "Error" << "Error"
<< info.level << info.level
<< info.name << "Error" // removed
<< info.msg.str() << info.msg.str()
<< 0 // FIXME: info.errPos << 0 // FIXME: info.errPos
<< info.traces.size(); << info.traces.size();
@ -426,11 +426,10 @@ Error readError(Source & source)
auto type = readString(source); auto type = readString(source);
assert(type == "Error"); assert(type == "Error");
auto level = (Verbosity) readInt(source); auto level = (Verbosity) readInt(source);
auto name = readString(source); auto name = readString(source); // removed
auto msg = readString(source); auto msg = readString(source);
ErrorInfo info { ErrorInfo info {
.level = level, .level = level,
.name = name,
.msg = hintformat(std::move(format("%s") % msg)), .msg = hintformat(std::move(format("%s") % msg)),
}; };
auto havePos = readNum<size_t>(source); auto havePos = readNum<size_t>(source);

View file

@ -178,7 +178,7 @@ namespace nix {
} }
TEST(parseURL, parseFileURLWithQueryAndFragment) { TEST(parseURL, parseFileURLWithQueryAndFragment) {
auto s = "file:///none/of/your/business"; auto s = "file:///none/of//your/business";
auto parsed = parseURL(s); auto parsed = parseURL(s);
ParsedURL expected { ParsedURL expected {
@ -186,7 +186,7 @@ namespace nix {
.base = "", .base = "",
.scheme = "file", .scheme = "file",
.authority = "", .authority = "",
.path = "/none/of/your/business", .path = "/none/of//your/business",
.query = (StringMap) { }, .query = (StringMap) { },
.fragment = "", .fragment = "",
}; };

View file

@ -18,7 +18,7 @@ const static std::string userRegex = "(?:(?:" + unreservedRegex + "|" + pctEncod
const static std::string authorityRegex = "(?:" + userRegex + "@)?" + hostRegex + "(?::[0-9]+)?"; const static std::string authorityRegex = "(?:" + userRegex + "@)?" + hostRegex + "(?::[0-9]+)?";
const static std::string pcharRegex = "(?:" + unreservedRegex + "|" + pctEncoded + "|" + subdelimsRegex + "|[:@])"; const static std::string pcharRegex = "(?:" + unreservedRegex + "|" + pctEncoded + "|" + subdelimsRegex + "|[:@])";
const static std::string queryRegex = "(?:" + pcharRegex + "|[/? \"])*"; const static std::string queryRegex = "(?:" + pcharRegex + "|[/? \"])*";
const static std::string segmentRegex = "(?:" + pcharRegex + "+)"; const static std::string segmentRegex = "(?:" + pcharRegex + "*)";
const static std::string absPathRegex = "(?:(?:/" + segmentRegex + ")*/?)"; const static std::string absPathRegex = "(?:(?:/" + segmentRegex + ")*/?)";
const static std::string pathRegex = "(?:" + segmentRegex + "(?:/" + segmentRegex + ")*/?)"; const static std::string pathRegex = "(?:" + segmentRegex + "(?:/" + segmentRegex + ")*/?)";

View file

@ -16,7 +16,7 @@ struct CmdEval : MixJSON, InstallableCommand
std::optional<std::string> apply; std::optional<std::string> apply;
std::optional<Path> writeTo; std::optional<Path> writeTo;
CmdEval() CmdEval() : InstallableCommand(true /* supportReadOnlyMode */)
{ {
addFlag({ addFlag({
.longName = "raw", .longName = "raw",

View file

@ -7,7 +7,9 @@ fi
clearStore clearStore
repo=$TEST_ROOT/hg # Intentionally not in a canonical form
# See https://github.com/NixOS/nix/issues/6195
repo=$TEST_ROOT/./hg
rm -rf $repo ${repo}-tmp $TEST_HOME/.cache/nix rm -rf $repo ${repo}-tmp $TEST_HOME/.cache/nix
@ -28,6 +30,12 @@ echo world > $repo/hello
hg commit --cwd $repo -m 'Bla2' hg commit --cwd $repo -m 'Bla2'
rev2=$(hg log --cwd $repo -r tip --template '{node}') rev2=$(hg log --cwd $repo -r tip --template '{node}')
# Fetch an unclean branch.
echo unclean > $repo/hello
path=$(nix eval --impure --raw --expr "(builtins.fetchMercurial file://$repo).outPath")
[[ $(cat $path/hello) = unclean ]]
hg revert --cwd $repo --all
# Fetch the default branch. # Fetch the default branch.
path=$(nix eval --impure --raw --expr "(builtins.fetchMercurial file://$repo).outPath") path=$(nix eval --impure --raw --expr "(builtins.fetchMercurial file://$repo).outPath")
[[ $(cat $path/hello) = world ]] [[ $(cat $path/hello) = world ]]