Compare commits

..
Author SHA1 Message Date
John Ericson bec4da9e26 NarCache improvements
- Separate implementation, abstract implements

- `NarCache` work in constant memory

  This is using `RestoreSink` to dedup some write-side IO, but I am not
  so sure that is a good idea. We'll continue reworking it.

- Use pathlocks to avoid download storms

- Use `Descriptor`-based logic, not `pathExists` to avoid symlink races
  if anything is deleted.
2026-01-26 15:30:09 -05:00
130 changed files with 721 additions and 1220 deletions

No files matched your search

-2
View File
@@ -1,7 +1,5 @@
# Default meson build dir
/build
# Meson creates this file too
src/.wraplock
# /tests/functional/
/tests/functional/common/subst-vars.sh
Generated
+5 -5
View File
@@ -63,15 +63,15 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1769089682,
"narHash": "sha256-Xu+7iYcAuOvsI2wdkUcIEmkqEJbvvE6n7qR9QNjJyP4=",
"rev": "078d69f03934859a181e81ba987c2bb033eebfc5",
"lastModified": 1763948260,
"narHash": "sha256-zZk7fn2ARAqmLwaYTpxBJmj81KIdz11NiWt7ydHHD/M=",
"rev": "1c8ba8d3f7634acac4a2094eef7c32ad9106532c",
"type": "tarball",
"url": "https://releases.nixos.org/nixos/25.11/nixos-25.11.4506.078d69f03934/nixexprs.tar.xz"
"url": "https://releases.nixos.org/nixos/25.05/nixos-25.05.813095.1c8ba8d3f763/nixexprs.tar.xz"
},
"original": {
"type": "tarball",
"url": "https://channels.nixos.org/nixos-25.11/nixexprs.tar.xz"
"url": "https://channels.nixos.org/nixos-25.05/nixexprs.tar.xz"
}
},
"nixpkgs-23-11": {
+1 -1
View File
@@ -1,7 +1,7 @@
{
description = "The purely functional package manager";
inputs.nixpkgs.url = "https://channels.nixos.org/nixos-25.11/nixexprs.tar.xz";
inputs.nixpkgs.url = "https://channels.nixos.org/nixos-25.05/nixexprs.tar.xz";
inputs.nixpkgs-regression.url = "github:NixOS/nixpkgs/215d4d0fd80ca5163643b03a33fde804a29cc1e2";
inputs.nixpkgs-23-11.url = "github:NixOS/nixpkgs/a62e6edd6d5e1fa0329b8653c801147986f8d446";
+2 -9
View File
@@ -88,23 +88,16 @@
''^tests/functional/lang/eval-fail-path-slash\.nix$''
''^tests/functional/lang/eval-fail-toJSON-non-utf-8\.nix$''
''^tests/functional/lang/eval-fail-set\.nix$''
# Language tests, don't churn the formatting of strings
''^tests/functional/lang/eval-fail-fromTOML-overflow\.nix$''
''^tests/functional/lang/eval-fail-fromTOML-underflow\.nix$''
''^tests/functional/lang/eval-fail-bad-string-interpolation-3\.nix$''
''^tests/functional/lang/eval-fail-bad-string-interpolation-4\.nix$''
''^tests/functional/lang/eval-okay-regex-match2\.nix$''
];
};
clang-format = {
enable = true;
# https://github.com/cachix/git-hooks.nix/pull/532
package = pkgs.llvmPackages_21.clang-tools;
package = pkgs.llvmPackages_latest.clang-tools;
excludes = [
# We don't want to format test data
# ''tests/(?!nixos/).*\.nix''
"^src/[^/]*-tests/data/.*$"
''^src/[^/]*-tests/data/.*$''
# Don't format vendored code
''^doc/manual/redirects\.js$''
@@ -1,7 +1,7 @@
# Clang gets grumpy about missing libasan symbols if -shared-libasan is not
# passed when building shared libs, at least on Linux
if cxx.get_id() == 'clang' and ('address' in get_option('b_sanitize') or 'undefined' in get_option(
'b_sanitize',
'b_sanitize',
))
add_project_link_arguments('-shared-libasan', language : 'cpp')
endif
+2 -4
View File
@@ -155,14 +155,12 @@ let
];
};
mesonBuildLayer = finalAttrs: prevAttrs: rec {
mesonBuildLayer = finalAttrs: prevAttrs: {
nativeBuildInputs = prevAttrs.nativeBuildInputs or [ ] ++ [
pkg-config
];
separateDebugInfo = !stdenv.hostPlatform.isStatic;
# needed by separateDebugInfo
# SEE: https://github.com/NixOS/nixpkgs/pull/394674/commits/a4d355342976e9e9823fb94f133bc43ebec9da5b
__structuredAttrs = separateDebugInfo;
hardeningDisable = lib.optional stdenv.hostPlatform.isStatic "pie";
};
mesonLibraryLayer = finalAttrs: prevAttrs: {
+26 -6
View File
@@ -30,13 +30,33 @@ scope: {
NIX_CFLAGS_COMPILE = "-DINITIAL_MARK_STACK_SIZE=1048576";
});
curl = pkgs.curl.override {
http3Support = !pkgs.stdenv.hostPlatform.isWindows;
};
lowdown = pkgs.lowdown.overrideAttrs (prevAttrs: rec {
version = "2.0.2";
src = pkgs.fetchurl {
url = "https://kristaps.bsd.lv/lowdown/snapshots/lowdown-${version}.tar.gz";
hash = "sha512-cfzhuF4EnGmLJf5EGSIbWqJItY3npbRSALm+GarZ7SMU7Hr1xw0gtBFMpOdi5PBar4TgtvbnG4oRPh+COINGlA==";
};
nativeBuildInputs = prevAttrs.nativeBuildInputs ++ [ pkgs.buildPackages.bmake ];
postInstall =
lib.replaceStrings [ "lowdown.so.1" "lowdown.1.dylib" ] [ "lowdown.so.2" "lowdown.2.dylib" ]
(prevAttrs.postInstall or "");
patches = [ ];
});
libblake3 = pkgs.libblake3.override {
useTBB = !(stdenv.hostPlatform.isWindows || stdenv.hostPlatform.isStatic);
};
# TODO: Remove this when https://github.com/NixOS/nixpkgs/pull/442682 is included in a stable release
toml11 =
if lib.versionAtLeast pkgs.toml11.version "4.4.0" then
pkgs.toml11
else
pkgs.toml11.overrideAttrs rec {
version = "4.4.0";
src = pkgs.fetchFromGitHub {
owner = "ToruNiina";
repo = "toml11";
tag = "v${version}";
hash = "sha256-sgWKYxNT22nw376ttGsTdg0AMzOwp8QH3E8mx0BZJTQ=";
};
};
# TODO Hack until https://github.com/NixOS/nixpkgs/issues/45462 is fixed.
boost =
-1
View File
@@ -38,7 +38,6 @@ escape_systemd_env() {
create_systemd_proxy_env() {
vars="http_proxy https_proxy ftp_proxy all_proxy no_proxy HTTP_PROXY HTTPS_PROXY FTP_PROXY ALL_PROXY NO_PROXY"
for v in $vars; do
# shellcheck disable=SC2268
if [ "x${!v:-}" != "x" ]; then
echo "Environment=${v}=$(escape_systemd_env "${!v}")"
fi
+2 -2
View File
@@ -43,7 +43,7 @@ RC_GTEST_FIXTURE_PROP(
auto * v = state.allocValue();
state.mkOutputString(*v, b, std::nullopt, mockXpSettings);
auto d = state.coerceToSingleDerivedPath(noPos, *v, "", mockXpSettings, true);
auto [d, _] = state.coerceToSingleDerivedPathUnchecked(noPos, *v, "", mockXpSettings);
RC_ASSERT(SingleDerivedPath{b} == d);
}
@@ -57,7 +57,7 @@ RC_GTEST_FIXTURE_PROP(
auto * v = state.allocValue();
state.mkOutputString(*v, b, outPath, mockXpSettings);
auto d = state.coerceToSingleDerivedPath(noPos, *v, "", mockXpSettings, true);
auto [d, _] = state.coerceToSingleDerivedPathUnchecked(noPos, *v, "", mockXpSettings);
RC_ASSERT(SingleDerivedPath{b} == d);
}
+55 -139
View File
@@ -2406,8 +2406,7 @@ BackedStringView EvalState::coerceToString(
std::string_view errorCtx,
bool coerceMore,
bool copyToStore,
bool canonicalizePath,
bool strict)
bool canonicalizePath)
{
auto _level = addCallDepth(pos);
@@ -2434,28 +2433,14 @@ BackedStringView EvalState::coerceToString(
auto maybeString = tryAttrsToString(pos, v, context, coerceMore, copyToStore);
if (maybeString)
return std::move(*maybeString);
auto outPathAttr = v.attrs()->get(s.outPath);
if (!outPathAttr) {
auto i = v.attrs()->get(s.outPath);
if (!i) {
error<TypeError>(
"cannot coerce %1% to a string: %2%", showType(v), ValuePrinter(*this, v, errorPrintOptions))
.withTrace(pos, errorCtx)
.debugThrow();
}
try {
auto derivedPath = coerceToSingleDerivedPath(pos, v, errorCtx);
auto result = mkSingleDerivedPathStringRaw(derivedPath);
context.insert(
std::visit([](auto && o) -> NixStringContextElem { return std::move(o); }, std::move(derivedPath)));
return result;
} catch (Error & e) {
if (strict)
throw;
auto info = e.info();
info.msg = HintFmt("in a future version of Nix this will be an error: %s", Uncolored(info.msg.str()));
logWarning(info);
return coerceToString(
pos, *outPathAttr->value, context, errorCtx, coerceMore, copyToStore, canonicalizePath, strict);
}
return coerceToString(pos, *i->value, context, errorCtx, coerceMore, copyToStore, canonicalizePath);
}
if (v.type() == nExternal) {
@@ -2493,8 +2478,7 @@ BackedStringView EvalState::coerceToString(
"while evaluating one element of the list",
coerceMore,
copyToStore,
canonicalizePath,
strict);
canonicalizePath);
} catch (Error & e) {
e.addTrace(positions[pos], errorCtx);
throw;
@@ -2581,131 +2565,63 @@ EvalState::coerceToStorePath(const PosIdx pos, Value & v, NixStringContext & con
error<EvalError>("path '%1%' is not in the Nix store", path).withTrace(pos, errorCtx).debugThrow();
}
SingleDerivedPath EvalState::coerceToSingleDerivedPath(
const PosIdx pos,
Value & v,
std::string_view errorCtx,
const ExperimentalFeatureSettings & xpSettings,
bool skipStringValidation)
std::pair<SingleDerivedPath, std::string_view> EvalState::coerceToSingleDerivedPathUnchecked(
const PosIdx pos, Value & v, std::string_view errorCtx, const ExperimentalFeatureSettings & xpSettings)
{
forceValue(v, pos);
NixStringContext context;
auto s = forceString(v, context, pos, errorCtx, xpSettings);
auto csize = context.size();
if (csize != 1)
error<EvalError>("string '%s' has %d entries in its context. It should only have exactly one entry", s, csize)
.withTrace(pos, errorCtx)
.debugThrow();
auto derivedPath = std::visit(
overloaded{
[&](NixStringContextElem::Opaque && o) -> SingleDerivedPath { return std::move(o); },
[&](NixStringContextElem::DrvDeep &&) -> SingleDerivedPath {
error<EvalError>(
"string '%s' has a context which refers to a complete source and binary closure. This is not supported at this time",
s)
.withTrace(pos, errorCtx)
.debugThrow();
},
[&](NixStringContextElem::Built && b) -> SingleDerivedPath { return std::move(b); },
},
((NixStringContextElem &&) *context.begin()).raw);
return {
std::move(derivedPath),
std::move(s),
};
}
switch (v.type()) {
case nAttrs: {
if (!isDerivation(v)) {
error<TypeError>(
"cannot coerce a set that is not a package to a single derived path: %1%",
ValuePrinter(*this, v, errorPrintOptions))
.withTrace(pos, errorCtx)
.debugThrow();
}
auto outPathAttr = v.attrs()->get(s.outPath);
if (!outPathAttr) {
error<TypeError>(
"cannot coerce %1% to a single derived path: no 'outPath' attribute: %2%",
showType(v),
ValuePrinter(*this, v, errorPrintOptions))
.withTrace(pos, errorCtx)
.debugThrow();
}
auto outPathDerivedPath =
coerceToSingleDerivedPath(pos, *outPathAttr->value, errorCtx, xpSettings, skipStringValidation);
auto drvPathAttr = v.attrs()->get(s.drvPath);
if (drvPathAttr) {
auto drvPathDerivedPath =
coerceToSingleDerivedPath(pos, *drvPathAttr->value, errorCtx, xpSettings, skipStringValidation);
std::visit(
overloaded{
[&](const SingleDerivedPath::Built & built) {
if (*built.drvPath != drvPathDerivedPath) {
error<EvalError>(
"relative outPath '%s' does not refer to drvPath '%s'",
outPathDerivedPath.to_string(*store),
drvPathDerivedPath.to_string(*store))
.withTrace(pos, errorCtx)
.debugThrow();
}
},
[&](const SingleDerivedPath::Opaque &) {
error<EvalError>(
"relative outPath '%s' does not refer to drvPath '%s'",
outPathDerivedPath.to_string(*store),
drvPathDerivedPath.to_string(*store))
.withTrace(pos, errorCtx)
.debugThrow();
},
},
outPathDerivedPath.raw());
}
return outPathDerivedPath;
}
case nString: {
auto s = v.string_view();
NixStringContext context;
copyContext(v, context, xpSettings);
auto csize = context.size();
if (csize != 1)
error<EvalError>(
"string '%s' has %d entries in its context. It should only have exactly one entry", s, csize)
.withTrace(pos, errorCtx)
.debugThrow();
auto derivedPath = std::visit(
SingleDerivedPath EvalState::coerceToSingleDerivedPath(const PosIdx pos, Value & v, std::string_view errorCtx)
{
auto [derivedPath, s_] = coerceToSingleDerivedPathUnchecked(pos, v, errorCtx);
auto s = s_;
auto sExpected = mkSingleDerivedPathStringRaw(derivedPath);
if (s != sExpected) {
/* `std::visit` is used here just to provide a more precise
error message. */
std::visit(
overloaded{
[&](NixStringContextElem::Opaque && o) -> SingleDerivedPath { return std::move(o); },
[&](NixStringContextElem::DrvDeep &&) -> SingleDerivedPath {
error<EvalError>(
"string '%s' has a context which refers to a complete source and binary closure. This is not "
"supported at this time",
s)
[&](const SingleDerivedPath::Opaque & o) {
error<EvalError>("path string '%s' has context with the different path '%s'", s, sExpected)
.withTrace(pos, errorCtx)
.debugThrow();
},
[&](NixStringContextElem::Built && b) -> SingleDerivedPath { return std::move(b); },
},
((NixStringContextElem &&) *context.begin()).raw);
if (!skipStringValidation) {
auto sExpected = mkSingleDerivedPathStringRaw(derivedPath);
if (s != sExpected) {
/* `std::visit` is used here just to provide a more precise
error message. */
std::visit(
overloaded{
[&](const SingleDerivedPath::Opaque & o) {
error<EvalError>("path string '%s' has context with the different path '%s'", s, sExpected)
.withTrace(pos, errorCtx)
.debugThrow();
},
[&](const SingleDerivedPath::Built & b) {
error<EvalError>(
"string '%s' has context with the output '%s' from derivation '%s', but the string is "
"not the right placeholder for this derivation output. It should be '%s'",
s,
b.output,
b.drvPath->to_string(*store),
sExpected)
.withTrace(pos, errorCtx)
.debugThrow();
}},
derivedPath.raw());
}
}
return derivedPath;
}
default:
error<TypeError>(
"cannot coerce %1% to a single derived path: %2%", showType(v), ValuePrinter(*this, v, errorPrintOptions))
.withTrace(pos, errorCtx)
.debugThrow();
[&](const SingleDerivedPath::Built & b) {
error<EvalError>(
"string '%s' has context with the output '%s' from derivation '%s', but the string is not the right placeholder for this derivation output. It should be '%s'",
s,
b.output,
b.drvPath->to_string(*store),
sExpected)
.withTrace(pos, errorCtx)
.debugThrow();
}},
derivedPath.raw());
}
return derivedPath;
}
// NOTE: This implementation must match eqValues!
+25 -99
View File
@@ -1,6 +1,5 @@
#include "nix/expr/get-drvs.hh"
#include "nix/expr/eval-inline.hh"
#include "nix/store/derived-path.hh"
#include "nix/store/derivations.hh"
#include "nix/store/store-api.hh"
#include "nix/store/path-with-outputs.hh"
@@ -22,13 +21,13 @@ PackageInfo::PackageInfo(EvalState & state, ref<Store> store, const std::string
, attrs(nullptr)
, attrPath("")
{
auto [drvStorePath, selectedOutputs] = parsePathWithOutputs(*store, drvPathWithOutputs);
auto [drvPath, selectedOutputs] = parsePathWithOutputs(*store, drvPathWithOutputs);
this->drvPath = {{Path{SingleDerivedPath::Opaque{drvStorePath}, drvStorePath}}};
this->drvPath = drvPath;
auto drv = store->derivationFromPath(drvStorePath);
auto drv = store->derivationFromPath(drvPath);
name = drvStorePath.name();
name = drvPath.name();
if (selectedOutputs.size() > 1)
throw Error("building more than one derivation output is not supported, in '%s'", drvPathWithOutputs);
@@ -37,18 +36,10 @@ PackageInfo::PackageInfo(EvalState & state, ref<Store> store, const std::string
auto i = drv.outputs.find(outputName);
if (i == drv.outputs.end())
throw Error("derivation '%s' does not have output '%s'", store->printStorePath(drvStorePath), outputName);
auto & [outputName_, output] = *i;
throw Error("derivation '%s' does not have output '%s'", store->printStorePath(drvPath), outputName);
auto & [outputName, output] = *i;
auto outStorePath = output.path(*store, drv.name, outputName_);
if (outStorePath) {
outPath = Path{SingleDerivedPath::Opaque{*outStorePath}, *outStorePath};
} else {
// CA derivation with unknown output path
outPath = Path{
SingleDerivedPath::Built{makeConstantStorePathRef(drvStorePath), outputName_},
std::nullopt};
}
outPath = {output.path(*store, drv.name, outputName)};
}
std::string PackageInfo::queryName() const
@@ -73,60 +64,26 @@ std::string PackageInfo::querySystem() const
return system;
}
std::optional<PackageInfo::Path> PackageInfo::queryDrvPathFlexible() const
std::optional<StorePath> PackageInfo::queryDrvPath() const
{
if (!drvPath && attrs) {
auto i = attrs->get(state->s.drvPath);
if (i) {
Value v;
v.mkAttrs(const_cast<Bindings *>(attrs));
std::optional<SingleDerivedPath> outPathDerivedPath;
if (auto i = attrs->get(state->s.drvPath)) {
NixStringContext context;
auto found = state->coerceToStorePath(
i->pos, *i->value, context, "while evaluating the 'drvPath' attribute of a derivation");
try {
// Validate derivation structure
outPathDerivedPath = state->coerceToSingleDerivedPath(
noPos, v, "while evaluating the derivation");
found.requireDerivation();
} catch (Error & e) {
auto info = e.info();
info.msg = HintFmt("in a future version of Nix this will be an error: %s", Uncolored(info.msg.str()));
logWarning(info);
}
if (outPathDerivedPath) {
// Validation passed. Now get drvPath.
auto drvPathDerivedPath = state->coerceToSingleDerivedPath(
i->pos, *i->value, "while evaluating the 'drvPath' attribute of a derivation");
if (auto * opaque = std::get_if<SingleDerivedPath::Opaque>(&drvPathDerivedPath.raw())) {
opaque->path.requireDerivation();
drvPath = {{Path{std::move(drvPathDerivedPath), opaque->path}}};
} else {
// Dynamic derivation - drvPath is itself a derivation output
drvPath = {{Path{std::move(drvPathDerivedPath), std::nullopt}}};
}
} else {
// Fall back to old behavior
NixStringContext context;
auto found = state->coerceToStorePath(
i->pos, *i->value, context, "while evaluating the 'drvPath' attribute of a derivation");
try {
found.requireDerivation();
} catch (Error & e) {
e.addTrace(state->positions[i->pos], "while evaluating the 'drvPath' attribute of a derivation");
throw;
}
drvPath = {{Path{SingleDerivedPath::Opaque{found}, std::move(found)}}};
e.addTrace(state->positions[i->pos], "while evaluating the 'drvPath' attribute of a derivation");
throw;
}
drvPath = {std::move(found)};
} else
drvPath = {std::nullopt};
}
return drvPath.value_or(std::nullopt);
}
std::optional<StorePath> PackageInfo::queryDrvPath() const
{
if (auto path = queryDrvPathFlexible())
return path->storePath;
return std::nullopt;
}
StorePath PackageInfo::requireDrvPath() const
{
if (auto drvPath = queryDrvPath())
@@ -134,49 +91,18 @@ StorePath PackageInfo::requireDrvPath() const
throw Error("derivation does not contain a 'drvPath' attribute");
}
PackageInfo::Path PackageInfo::queryOutPathFlexible() const
{
if (!outPath && attrs) {
Value v;
v.mkAttrs(const_cast<Bindings *>(attrs));
std::optional<SingleDerivedPath> derivedPath;
try {
derivedPath = state->coerceToSingleDerivedPath(
noPos, v, "while evaluating the derivation");
} catch (Error & e) {
auto info = e.info();
info.msg = HintFmt("in a future version of Nix this will be an error: %s", Uncolored(info.msg.str()));
logWarning(info);
}
if (derivedPath) {
if (auto * opaque = std::get_if<SingleDerivedPath::Opaque>(&derivedPath->raw())) {
outPath = Path{std::move(*derivedPath), opaque->path};
} else {
// Built path - no concrete output path available (placeholder)
outPath = Path{std::move(*derivedPath), std::nullopt};
}
} else {
// Fall back to old behavior
auto i = attrs->get(state->s.outPath);
NixStringContext context;
if (i) {
auto path = state->coerceToStorePath(
i->pos, *i->value, context, "while evaluating the output path of a derivation");
outPath = Path{SingleDerivedPath::Opaque{path}, std::move(path)};
}
}
}
if (!outPath)
throw Error("derivation does not have an 'outPath' attribute");
return *outPath;
}
StorePath PackageInfo::queryOutPath() const
{
auto path = queryOutPathFlexible();
if (!path.storePath)
if (!outPath && attrs) {
auto i = attrs->get(state->s.outPath);
NixStringContext context;
if (i)
outPath = state->coerceToStorePath(
i->pos, *i->value, context, "while evaluating the output path of a derivation");
}
if (!outPath)
throw UnimplementedError("CA derivations are not yet supported");
return *path.storePath;
return *outPath;
}
PackageInfo::Outputs PackageInfo::queryOutputs(bool withPaths, bool onlyOutputsToInstall)
+21 -28
View File
@@ -715,9 +715,6 @@ public:
* string. If `coerceMore` is set, also converts nulls, integers,
* booleans and lists to a string. If `copyToStore` is set,
* referenced paths are copied to the Nix store as a side effect.
* If `strict` is set, ensures that when coercing an attrset with
* both `outPath` and `drvPath`, the string context for `outPath`
* agrees with the `drvPath` attribute.
*/
BackedStringView coerceToString(
const PosIdx pos,
@@ -726,8 +723,7 @@ public:
std::string_view errorCtx,
bool coerceMore = false,
bool copyToStore = true,
bool canonicalizePath = true,
bool strict = false);
bool canonicalizePath = true);
StorePath copyPathToStore(NixStringContext & context, const SourcePath & path);
@@ -746,33 +742,30 @@ public:
StorePath coerceToStorePath(const PosIdx pos, Value & v, NixStringContext & context, std::string_view errorCtx);
/**
* Coerce to `SingleDerivedPath`.
*
* For strings: must be either a literal store path or a
* placeholder (see `DownstreamPlaceholder`). The string context
* must be exactly one element, which is either a
* `NixStringContextElem::Opaque` or `NixStringContextElem::Built`.
* (`NixStringContextElem::DrvDeep` is not permitted). The string
* is parsed based on the context --- the context is the source of
* truth, and ultimately tells us what we want, and then we ensure
* the string corresponds to it.
*
* For attrsets: must have an `outPath` attribute which is
* recursively coerced. If a `drvPath` attribute is present, it is
* also coerced and validated to agree with the `outPath` context.
*
* @param xpSettings Stop-gap to avoid globals during unit tests.
*
* @param skipStringValidation Skip validating that the string
* matches the expected placeholder for the context. This is
* exposed for unit testing only to avoid store IO.
* Part of `coerceToSingleDerivedPath()` without any store IO which is exposed for unit testing only.
*/
SingleDerivedPath coerceToSingleDerivedPath(
std::pair<SingleDerivedPath, std::string_view> coerceToSingleDerivedPathUnchecked(
const PosIdx pos,
Value & v,
std::string_view errorCtx,
const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings,
bool skipStringValidation = false);
const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
/**
* Coerce to `SingleDerivedPath`.
*
* Must be a string which is either a literal store path or a
* "placeholder (see `DownstreamPlaceholder`).
*
* Even more importantly, the string context must be exactly one
* element, which is either a `NixStringContextElem::Opaque` or
* `NixStringContextElem::Built`. (`NixStringContextEleme::DrvDeep`
* is not permitted).
*
* The string is parsed based on the context --- the context is the
* source of truth, and ultimately tells us what we want, and then
* we ensure the string corresponds to it.
*/
SingleDerivedPath coerceToSingleDerivedPath(const PosIdx pos, Value & v, std::string_view errorCtx);
#if NIX_USE_BOEHMGC
/** A GC root for the baseEnv reference. */
+4 -20
View File
@@ -2,7 +2,6 @@
///@file
#include "nix/expr/eval.hh"
#include "nix/store/derived-path.hh"
#include "nix/store/path.hh"
#include <string>
@@ -21,23 +20,10 @@ public:
private:
EvalState * state;
struct Path {
/**
* Underlying semantic path, valid in CA and IA cases.
*/
SingleDerivedPath derivedPath;
/**
* If we don't need a placeholder, we'll have a real store path, which we can remember here.
* For CA derivations using placeholders, this will be std::nullopt.
*/
std::optional<StorePath> storePath;
};
mutable std::string name;
mutable std::string system;
mutable std::optional<std::optional<Path>> drvPath;
mutable std::optional<Path> outPath;
mutable std::optional<std::optional<StorePath>> drvPath;
mutable std::optional<StorePath> outPath;
mutable std::string outputName;
Outputs outputs;
@@ -66,10 +52,8 @@ public:
std::string queryName() const;
std::string querySystem() const;
std::optional<StorePath> queryDrvPath() const;
std::optional<Path> queryDrvPathFlexible() const;
StorePath requireDrvPath() const;
StorePath queryOutPath() const;
Path queryOutPathFlexible() const;
std::string queryOutputName() const;
/**
* Return the unordered map of output names to (optional) output paths.
@@ -97,12 +81,12 @@ public:
void setDrvPath(StorePath path)
{
drvPath = {{Path{SingleDerivedPath::Opaque{path}, std::move(path)}}};
drvPath = {{std::move(path)}};
}
void setOutPath(StorePath path)
{
outPath = Path{SingleDerivedPath::Opaque{path}, std::move(path)};
outPath = {{std::move(path)}};
}
void setFailed()
+2 -2
View File
@@ -533,8 +533,8 @@ inline constexpr bool useBitPackedValueStorage = (ptrSize == 8) && (__STDCPP_DEF
* Packs discriminator bits into the pointer alignment niches.
*/
template<std::size_t ptrSize>
class alignas(16)
ValueStorage<ptrSize, std::enable_if_t<detail::useBitPackedValueStorage<ptrSize>>> : public detail::ValueBase
class alignas(16) ValueStorage<ptrSize, std::enable_if_t<detail::useBitPackedValueStorage<ptrSize>>>
: public detail::ValueBase
{
/* Needs a dependent type name in order for member functions (and
* potentially ill-formed bit casts) to be SFINAE'd out.
+13 -36
View File
@@ -3,7 +3,7 @@
%define api.namespace { ::nix::parser }
%define api.parser.class { BisonParser }
%locations
%define parse.error detailed
%define parse.error verbose
%defines
/* %no-lines */
%parse-param { void * scanner }
@@ -140,41 +140,18 @@ static Expr * makeCall(Exprs & exprs, PosIdx pos, Expr * fn, Expr * arg) {
%type <Expr *> path_start
%type <ToBeStringyExpr> string_parts string_attr
%type <StringToken> attr
%token <StringToken> ID "identifier"
%token <StringToken> STR "string"
%token <StringToken> IND_STR "indented string"
%token <NixInt> INT_LIT "integer"
%token <NixFloat> FLOAT_LIT "floating-point literal"
%token <StringToken> PATH "path"
%token <StringToken> HPATH "'~/…' path"
%token <StringToken> SPATH "'<…>' path"
%token <StringToken> PATH_END "end of path"
%token <StringToken> URI "URI"
%token IF "'if'"
%token THEN "'then'"
%token ELSE "'else'"
%token ASSERT "'assert'"
%token WITH "'with'"
%token LET "'let'"
%token IN_KW "'in'"
%token REC "'rec'"
%token INHERIT "'inherit'"
%token EQ "'=='"
%token NEQ "'!='"
%token LEQ "'<='"
%token GEQ "'>='"
%token UPDATE "'//'"
%token CONCAT "'++'"
%token AND "'&&'"
%token OR "'||'"
%token IMPL "'->'"
%token OR_KW "'or'"
%token PIPE_FROM "'<|'"
%token PIPE_INTO "'|>'"
%token DOLLAR_CURLY "'${'"
%token IND_STRING_OPEN "start of an indented string"
%token IND_STRING_CLOSE "end of an indented string"
%token ELLIPSIS "'...'"
%token <StringToken> ID
%token <StringToken> STR IND_STR
%token <NixInt> INT_LIT
%token <NixFloat> FLOAT_LIT
%token <StringToken> PATH HPATH SPATH PATH_END
%token <StringToken> URI
%token IF THEN ELSE ASSERT WITH LET IN_KW REC INHERIT EQ NEQ AND OR IMPL OR_KW
%token PIPE_FROM PIPE_INTO /* <| and |> */
%token DOLLAR_CURLY /* == ${ */
%token IND_STRING_OPEN IND_STRING_CLOSE
%token ELLIPSIS
%right IMPL
%left OR
+7 -7
View File
@@ -37,7 +37,7 @@ namespace {
// old version of git, which will ignore unrecognized `-c` options.
const std::string gitInitialBranch = "__nix_dummy_branch";
bool isCacheFileWithinTtl(time_t now, const PosixStat & st)
bool isCacheFileWithinTtl(time_t now, const struct stat & st)
{
return st.st_mtime + static_cast<time_t>(settings.tarballTtl) > now;
}
@@ -113,11 +113,11 @@ std::optional<std::string> readHeadCached(const std::string & actualUrl, bool sh
std::filesystem::path headRefFile = cacheDir / "HEAD";
time_t now = time(0);
auto st = maybeStat(headRefFile);
struct stat st;
std::optional<std::string> cachedRef;
if (st) {
if (stat(headRefFile.string().c_str(), &st) == 0) {
cachedRef = readHead(cacheDir);
if (cachedRef != std::nullopt && *cachedRef != gitInitialBranch && isCacheFileWithinTtl(now, *st)) {
if (cachedRef != std::nullopt && *cachedRef != gitInitialBranch && isCacheFileWithinTtl(now, st)) {
debug("using cached HEAD ref '%s' for repo '%s'", *cachedRef, actualUrl);
return cachedRef;
}
@@ -819,10 +819,10 @@ struct GitInputScheme : InputScheme
if (getAllRefsAttr(input)) {
doFetch = true;
} else {
/* If the local ref is older than 'tarball-ttl' seconds, do a
/* If the local ref is older than ‘tarball-ttl’ seconds, do a
git fetch to update the local ref to the remote ref. */
auto st = maybeStat(localRefFile);
doFetch = !st || !isCacheFileWithinTtl(now, *st);
struct stat st;
doFetch = stat(localRefFile.string().c_str(), &st) != 0 || !isCacheFileWithinTtl(now, st);
}
}
+1 -2
View File
@@ -177,8 +177,7 @@ static DownloadTarballResult downloadTarball_(
the entire file to disk so libarchive can access it
in random-access mode. */
auto [fdTemp, path] = createTempFile("nix-zipfile");
cleanupTemp.cancel();
cleanupTemp = {path};
cleanupTemp.reset(path);
debug("downloading '%s' into '%s'...", url, path);
{
FdSink sink(fdTemp.get());
+1 -1
View File
@@ -562,7 +562,7 @@ ref<SourceAccessor> BinaryCacheStore::getFSAccessor(bool requireValidPath)
std::shared_ptr<SourceAccessor> BinaryCacheStore::getFSAccessor(const StorePath & storePath, bool requireValidPath)
{
return getRemoteFSAccessor(requireValidPath)->accessObject(storePath);
return static_cast<ref<SourceAccessor>>(getRemoteFSAccessor(requireValidPath)->accessObject(storePath));
}
void BinaryCacheStore::addSignatures(const StorePath & storePath, const std::set<Signature> & sigs)
+16 -13
View File
@@ -396,22 +396,13 @@ Goal::Co DerivationBuildingGoal::tryToBuild(StorePathSet inputPaths)
if (useHook) {
co_return buildWithHook(
std::move(inputPaths), std::move(initialOutputs), std::move(drvOptions), std::move(outputLocks));
} else if (auto * localStoreP = dynamic_cast<LocalStore *>(&worker.store)) {
} else {
co_return buildLocally(
*localStoreP,
std::move(inputPaths),
std::move(initialOutputs),
std::move(drvOptions),
std::move(outputLocks),
externalBuilder);
} else {
throw Error(
R"(
Unable to build with a primary store that isn't a local store;
either pass a different '--store' or enable remote builds.
For more information check 'man nix.conf' and search for '/machines'.
)");
}
}
@@ -620,7 +611,6 @@ Goal::Co DerivationBuildingGoal::buildWithHook(
}
Goal::Co DerivationBuildingGoal::buildLocally(
LocalStore & localStore,
StorePathSet inputPaths,
std::map<std::string, InitialOutput> initialOutputs,
DerivationOptions<StorePath> drvOptions,
@@ -629,6 +619,16 @@ Goal::Co DerivationBuildingGoal::buildLocally(
{
co_await yield();
if (!dynamic_cast<LocalStore *>(&worker.store)) {
throw Error(
R"(
Unable to build with a primary store that isn't a local store;
either pass a different '--store' or enable remote builds.
For more information check 'man nix.conf' and search for '/machines'.
)");
}
#ifdef _WIN32 // TODO enable `DerivationBuilder` on Windows
throw UnimplementedError("building derivations is not yet implemented on Windows");
#else
@@ -708,6 +708,9 @@ Goal::Co DerivationBuildingGoal::buildLocally(
}
};
auto * localStoreP = dynamic_cast<LocalStore *>(&worker.store);
assert(localStoreP);
decltype(DerivationBuilderParams::defaultPathsInChroot) defaultPathsInChroot = settings.sandboxPaths.get();
DesugaredEnv desugaredEnv;
@@ -753,12 +756,12 @@ Goal::Co DerivationBuildingGoal::buildLocally(
already be created, so we don't need to create it again. */
builder = externalBuilder
? makeExternalDerivationBuilder(
localStore,
*localStoreP,
std::make_unique<DerivationBuildingGoalCallbacks>(*this, openLogFile, closeLogFile),
std::move(params),
*externalBuilder)
: makeDerivationBuilder(
localStore,
*localStoreP,
std::make_unique<DerivationBuildingGoalCallbacks>(*this, openLogFile, closeLogFile),
std::move(params));
}
+10 -5
View File
@@ -50,12 +50,17 @@ static void createLinks(State & state, const Path & srcDir, const Path & dstDir,
auto srcFile = (std::filesystem::path{srcDir} / name).string();
auto dstFile = (std::filesystem::path{dstDir} / name).string();
auto srcStOpt = maybeStat(srcFile.c_str());
if (!srcStOpt) {
warn("skipping dangling symlink '%s'", dstFile);
continue;
struct stat srcSt;
try {
if (stat(srcFile.c_str(), &srcSt) == -1)
throw SysError("getting status of '%1%'", srcFile);
} catch (SystemError & e) {
if (e.is(std::errc::no_such_file_or_directory) || e.is(std::errc::not_a_directory)) {
warn("skipping dangling symlink '%s'", dstFile);
continue;
}
throw;
}
auto & srcSt = *srcStOpt;
/* The files below are special-cased to that they don't show
* up in user profiles, either because they are useless, or
-47
View File
@@ -111,51 +111,4 @@ void CommonProto::Serialise<Signature>::write(
conn.to << sig.to_string();
}
/**
* Mapping from protocol wire values to BuildResultStatus.
*
* The array index is the wire value.
* Note: HashMismatch is not in the protocol; it gets converted
* to OutputRejected before serialization.
*/
constexpr static BuildResultStatus buildResultStatusTable[] = {
BuildResultSuccessStatus::Built, // 0
BuildResultSuccessStatus::Substituted, // 1
BuildResultSuccessStatus::AlreadyValid, // 2
BuildResultFailureStatus::PermanentFailure, // 3
BuildResultFailureStatus::InputRejected, // 4
BuildResultFailureStatus::OutputRejected, // 5
BuildResultFailureStatus::TransientFailure, // 6
BuildResultFailureStatus::CachedFailure, // 7
BuildResultFailureStatus::TimedOut, // 8
BuildResultFailureStatus::MiscFailure, // 9
BuildResultFailureStatus::DependencyFailed, // 10
BuildResultFailureStatus::LogLimitExceeded, // 11
BuildResultFailureStatus::NotDeterministic, // 12
BuildResultSuccessStatus::ResolvesToAlreadyValid, // 13
BuildResultFailureStatus::NoSubstituters, // 14
};
BuildResultStatus
CommonProto::Serialise<BuildResultStatus>::read(const StoreDirConfig & store, CommonProto::ReadConn conn)
{
auto rawStatus = readNum<uint8_t>(conn.from);
if (rawStatus >= std::size(buildResultStatusTable))
throw Error("Invalid BuildResult status %d from remote", rawStatus);
return buildResultStatusTable[rawStatus];
}
void CommonProto::Serialise<BuildResultStatus>::write(
const StoreDirConfig & store, CommonProto::WriteConn conn, const BuildResultStatus & status)
{
for (auto && [wire, val] : enumerate(buildResultStatusTable))
if (val == status) {
conn.to << uint8_t(wire);
return;
}
unreachable();
}
} // namespace nix
+6 -3
View File
@@ -7,7 +7,6 @@
#include "nix/util/signals.hh"
#include "nix/util/serialise.hh"
#include "nix/util/util.hh"
#include "nix/util/file-system.hh"
#include "nix/store/posix-fs-canonicalise.hh"
#include "store-config-private.hh"
@@ -69,7 +68,9 @@ void LocalStore::createTempRootsFile()
/* Check whether the garbage collector didn't get in our
way. */
auto st = nix::fstat(fromDescriptorReadOnly(fdTempRoots->get()));
struct stat st;
if (fstat(fromDescriptorReadOnly(fdTempRoots->get()), &st) == -1)
throw SysError("statting '%1%'", fnTempRoots);
if (st.st_size == 0)
break;
@@ -900,7 +901,9 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
accounting. */
}
auto st = stat(linksDir);
struct stat st;
if (stat(linksDir.c_str(), &st) == -1)
throw SysError("statting '%1%'", linksDir);
int64_t overhead =
#ifdef _WIN32
0
+47 -45
View File
@@ -11,52 +11,24 @@
namespace nix {
/**
* Names must be disjoint with `BuildResultFailureStatus`.
*
* @note Prefer using `BuildResult::Success::Status`, this name is just
* for sake of forward declarations.
*/
enum struct BuildResultSuccessStatus : uint8_t {
Built,
Substituted,
AlreadyValid,
ResolvesToAlreadyValid,
};
/**
* Names must be disjoint with `BuildResultSuccessStatus`.
*
* @note Prefer using `BuildResult::Failure::Status`, this name is just
* for sake of forward declarations.
*/
enum struct BuildResultFailureStatus : uint8_t {
PermanentFailure,
InputRejected,
OutputRejected,
/// possibly transient
TransientFailure,
/// no longer used
CachedFailure,
TimedOut,
MiscFailure,
DependencyFailed,
LogLimitExceeded,
NotDeterministic,
NoSubstituters,
/// A certain type of `OutputRejected`. The protocols do not yet
/// know about this one, so change it back to `OutputRejected`
/// before serialization.
HashMismatch,
};
struct BuildResult
{
struct Success
{
using Status = enum BuildResultSuccessStatus;
using enum Status;
Status status;
/**
* @note This is directly used in the nix-store --serve protocol.
* That means we need to worry about compatibility across versions.
* Therefore, don't remove status codes, and only add new status
* codes at the end of the list.
*
* Must be disjoint with `Failure::Status`.
*/
enum Status : uint8_t {
Built = 0,
Substituted = 1,
AlreadyValid = 2,
ResolvesToAlreadyValid = 13,
} status;
/**
* For derivations, a mapping from the names of the wanted outputs
@@ -66,13 +38,43 @@ struct BuildResult
bool operator==(const BuildResult::Success &) const noexcept;
std::strong_ordering operator<=>(const BuildResult::Success &) const noexcept;
static bool statusIs(uint8_t status)
{
return status == Built || status == Substituted || status == AlreadyValid
|| status == ResolvesToAlreadyValid;
}
};
struct Failure
{
using Status = enum BuildResultFailureStatus;
using enum Status;
Status status = MiscFailure;
/**
* @note This is directly used in the nix-store --serve protocol.
* That means we need to worry about compatibility across versions.
* Therefore, don't remove status codes, and only add new status
* codes at the end of the list.
*
* Must be disjoint with `Success::Status`.
*/
enum Status : uint8_t {
PermanentFailure = 3,
InputRejected = 4,
OutputRejected = 5,
/// possibly transient
TransientFailure = 6,
/// no longer used
CachedFailure = 7,
TimedOut = 8,
MiscFailure = 9,
DependencyFailed = 10,
LogLimitExceeded = 11,
NotDeterministic = 12,
NoSubstituters = 14,
/// A certain type of `OutputRejected`. The protocols do not yet
/// know about this one, so change it back to `OutputRejected`
/// before serialization.
HashMismatch = 15,
} status = MiscFailure;
/**
* Information about the error if the build failed.
@@ -2,10 +2,10 @@
///@file
#include "nix/store/derivations.hh"
#include "nix/store/local-store.hh"
#include "nix/store/parsed-derivations.hh"
#include "nix/store/derivation-options.hh"
#include "nix/store/build/derivation-building-misc.hh"
#include "nix/store/outputs-spec.hh"
#include "nix/store/store-api.hh"
#include "nix/store/pathlocks.hh"
#include "nix/store/build/goal.hh"
@@ -75,7 +75,6 @@ private:
DerivationOptions<StorePath> drvOptions,
PathLocks outputLocks);
Co buildLocally(
LocalStore & localStore,
StorePathSet inputPaths,
std::map<std::string, InitialOutput> initialOutputs,
DerivationOptions<StorePath> drvOptions,
@@ -3,8 +3,6 @@
#include "nix/util/serialise.hh"
#include <variant>
namespace nix {
struct StoreDirConfig;
@@ -16,8 +14,6 @@ struct ContentAddress;
struct DrvOutput;
struct Realisation;
struct Signature;
enum struct BuildResultSuccessStatus : uint8_t;
enum struct BuildResultFailureStatus : uint8_t;
/**
* Shared serializers between the worker protocol, serve protocol, and a
@@ -90,6 +86,7 @@ DECLARE_COMMON_SERIALISER(std::tuple<Ts...>);
template<typename K, typename V>
DECLARE_COMMON_SERIALISER(std::map<K COMMA_ V>);
#undef COMMA_
/**
* These use the empty string for the null case, relying on the fact
@@ -110,14 +107,4 @@ DECLARE_COMMON_SERIALISER(std::optional<StorePath>);
template<>
DECLARE_COMMON_SERIALISER(std::optional<ContentAddress>);
/**
* The success and failure codes never overlay in enum tag values in the wire formats
*/
using BuildResultStatus = std::variant<BuildResultSuccessStatus, BuildResultFailureStatus>;
template<>
DECLARE_COMMON_SERIALISER(BuildResultStatus);
#undef COMMA_
} // namespace nix
+32 -12
View File
@@ -735,6 +735,29 @@ public:
duplicate files.
)"};
Setting<bool> envKeepDerivations{
this,
false,
"keep-env-derivations",
R"(
If `false` (default), derivations are not stored in Nix user
environments. That is, the derivations of any build-time-only
dependencies may be garbage-collected.
If `true`, when you add a Nix derivation to a user environment, the
path of the derivation is stored in the user environment. Thus, the
derivation isn't garbage-collected until the user environment
generation is deleted (`nix-env --delete-generations`). To prevent
build-time-only dependencies from being collected, you should also
turn on `keep-outputs`.
The difference between this option and `keep-derivations` is that
this one is “sticky”: it applies to any user environment created
while this option was enabled, while `keep-derivations` only applies
at the moment the garbage collector is run.
)",
{"env-keep-derivations"}};
Setting<SandboxMode> sandboxMode{
this,
#ifdef __linux__
@@ -883,8 +906,6 @@ public:
line.
)"};
private:
OptionalPathSetting diffHook{
this,
std::nullopt,
@@ -917,16 +938,6 @@ private:
configuration file, and cannot be passed at the command line.
)"};
public:
const Path * getDiffHook() const
{
if (!runDiffHook.get()) {
return nullptr;
}
return get(diffHook.get());
}
Setting<Strings> trustedPublicKeys{
this,
{"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="},
@@ -1400,6 +1411,15 @@ public:
true, // document default
Xp::ConfigurableImpureEnv};
Setting<std::string> upgradeNixStorePathUrl{
this,
"https://github.com/NixOS/nixpkgs/raw/master/nixos/modules/installer/tools/nix-fallback-paths.nix",
"upgrade-nix-store-path-url",
R"(
Used by `nix upgrade-nix`, the URL of the file that contains the
store paths of the latest Nix release.
)"};
Setting<uint64_t> warnLargePathThreshold{
this,
0,
@@ -0,0 +1,20 @@
#pragma once
///@file
#include "nix/util/nar-cache.hh"
#include <filesystem>
#include <memory>
namespace nix {
/**
* Create a NAR cache with local disk storage.
*
* Uses file locks to ensure only one process downloads a NAR at a time.
*
* @param cacheDir Directory to store cached NAR files
*/
std::unique_ptr<NarCache> makeLocalNarCache(std::filesystem::path cacheDir);
} // namespace nix
@@ -50,6 +50,7 @@ headers = [ config_pub_h ] + files(
'length-prefixed-protocol-helper.hh',
'local-binary-cache-store.hh',
'local-fs-store.hh',
'local-nar-cache.hh',
'local-overlay-store.hh',
'local-store.hh',
'log-store.hh',
@@ -19,7 +19,7 @@ class RemoteFSAccessor : public SourceAccessor
*/
std::map<std::string, Hash, std::less<>> narHashes;
NarCache narCache;
std::unique_ptr<NarCache> narCache;
bool requireValidPath;
@@ -32,7 +32,7 @@ public:
/**
* @return nullptr if the store does not contain any object at that path.
*/
std::shared_ptr<SourceAccessor> accessObject(const StorePath & path);
ref<NarAccessor> accessObject(const StorePath & path);
RemoteFSAccessor(
ref<Store> store, bool requireValidPath = true, std::optional<std::filesystem::path> cacheDir = {});
+7 -6
View File
@@ -3,7 +3,6 @@
#include "nix/util/archive.hh"
#include "nix/util/pool.hh"
#include "nix/store/remote-store.hh"
#include "nix/store/common-protocol.hh"
#include "nix/store/serve-protocol.hh"
#include "nix/store/serve-protocol-connection.hh"
#include "nix/store/serve-protocol-impl.hh"
@@ -244,11 +243,13 @@ void LegacySSHStore::buildPaths(
conn->to.flush();
auto status = CommonProto::Serialise<BuildResultStatus>::read(*this, {conn->from});
if (auto * failure = std::get_if<BuildResultFailureStatus>(&status)) {
std::string errorMsg;
conn->from >> errorMsg;
throw BuildError(*failure, std::move(errorMsg));
auto status = readInt(conn->from);
if (!BuildResult::Success::statusIs(status)) {
BuildResult::Failure failure{
.status = (BuildResult::Failure::Status) status,
};
conn->from >> failure.errorMsg;
throw Error(failure.status, std::move(failure.errorMsg));
}
}
+134
View File
@@ -0,0 +1,134 @@
#include "nix/util/nar-cache.hh"
#include "nix/util/file-system.hh"
#include "nix/util/file-descriptor.hh"
#include "nix/util/fs-sink.hh"
#include "nix/store/pathlocks.hh"
#include <nlohmann/json.hpp>
#include <optional>
namespace nix {
namespace {
/**
* NAR cache with local disk storage (private implementation).
*
* Uses file locks to ensure only one process downloads a NAR at a time.
*/
class LocalNarCache : public NarCache
{
RestoreSink cacheSink;
public:
LocalNarCache(std::filesystem::path cacheDir)
: cacheSink(false)
{
createDirs(cacheDir);
cacheSink.dstPath = std::move(cacheDir);
}
ref<NarAccessor> getOrInsert(const Hash & narHash, std::function<void(Sink &)> populate) override;
};
} // anonymous namespace
ref<NarAccessor> LocalNarCache::getOrInsert(const Hash & narHash, std::function<void(Sink &)> populate)
{
// Check in-memory cache first
if (auto * accessor = get(nars, narHash))
return *accessor;
auto cacheAccessor = [&](ref<NarAccessor> accessor) {
nars.emplace(narHash, accessor);
return accessor;
};
auto makeCacheFile = [&](const std::string & ext) -> CanonPath {
return {narHash.to_string(HashFormat::Nix32, false) + "." + ext};
};
auto cacheFile = makeCacheFile("nar");
auto listingFile = makeCacheFile("ls");
auto lockFile = makeCacheFile("lock");
auto cacheFilePath = cacheSink.dstPath / cacheFile.rel();
auto lockFilePath = cacheSink.dstPath / lockFile.rel();
auto listingFilePath = cacheSink.dstPath / listingFile.rel();
// Helper to try loading from cache files using FD operations to avoid race conditions
auto tryLoadFromCache = [&]() -> std::optional<ref<NarAccessor>> {
try {
// Try to open cache file - will throw if doesn't exist
AutoCloseFD cacheFD = openFileReadonly(cacheFilePath);
// Try lazy accessor with listing file first
try {
AutoCloseFD listingFD = openFileReadonly(listingFilePath);
auto listingContent = readFile(listingFD.get());
return cacheAccessor(makeLazyNarAccessor(
nlohmann::json::parse(listingContent).template get<NarListing>(),
seekableGetNarBytes(cacheFilePath)));
} catch (SystemError &) {
// Listing file missing or invalid, fall back to full NAR
}
// Fall back to reading full NAR
auto narContent = readFile(cacheFD.get());
return cacheAccessor(makeNarAccessor(std::move(narContent)));
} catch (SystemError &) {
// Cache file doesn't exist or can't be opened
return std::nullopt;
}
};
// Check if already cached (before acquiring lock)
if (auto accessor = tryLoadFromCache())
return *accessor;
// Acquire lock to ensure only one process downloads this NAR
AutoCloseFD lockFD = openLockFile(lockFilePath, true);
FdLock lock(lockFD.get(), ltWrite, true, "waiting for NAR cache lock");
// Check again after acquiring lock (another process might have just finished)
if (auto accessor = tryLoadFromCache())
return *accessor;
// Download and cache the NAR
NarListing listing;
try {
/* FIXME: do this asynchronously. */
cacheSink.createRegularFile(cacheFile, [&](CreateRegularFileSink & fileSink) {
auto source = sinkToSource([&](Sink & parseSink) {
TeeSink teeSink{fileSink, parseSink};
populate(teeSink);
});
listing = parseNarListing(*source);
});
} catch (...) {
ignoreExceptionExceptInterrupt();
StringSink narSink;
populate(narSink);
return cacheAccessor(makeNarAccessor(std::move(narSink.s)));
}
try {
cacheSink.createRegularFile(listingFile, [&](CreateRegularFileSink & sink) {
auto s = nlohmann::json(listing).dump();
StringSource source{s};
source.drainInto(sink);
});
} catch (...) {
ignoreExceptionExceptInterrupt();
}
return cacheAccessor(makeLazyNarAccessor(std::move(listing), seekableGetNarBytes(cacheFilePath)));
}
std::unique_ptr<NarCache> makeLocalNarCache(std::filesystem::path cacheDir)
{
return std::make_unique<LocalNarCache>(std::move(cacheDir));
}
} // namespace nix
+5 -3
View File
@@ -167,7 +167,9 @@ LocalStore::LocalStore(ref<const Config> config)
printError(
"warning: the group '%1%' specified in 'build-users-group' does not exist", settings.buildUsersGroup);
else if (!config->readOnly) {
auto st = stat(config->realStoreDir.get());
struct stat st;
if (stat(config->realStoreDir.get().c_str(), &st))
throw SysError("getting attributes of path '%1%'", config->realStoreDir);
if (st.st_uid != 0 || st.st_gid != gr->gr_gid || (st.st_mode & ~S_IFMT) != perm) {
if (chown(config->realStoreDir.get().c_str(), 0, gr->gr_gid) == -1)
@@ -197,8 +199,8 @@ LocalStore::LocalStore(ref<const Config> config)
needed, we reserve some dummy space that we can free just
before doing a garbage collection. */
try {
auto st = maybeStat(reservedPath);
if (!st || st->st_size != gcSettings.reservedSize) {
struct stat st;
if (stat(reservedPath.c_str(), &st) == -1 || st.st_size != gcSettings.reservedSize) {
AutoCloseFD fd = toDescriptor(open(
reservedPath.c_str(),
O_WRONLY | O_CREAT
+1
View File
@@ -315,6 +315,7 @@ sources = files(
'legacy-ssh-store.cc',
'local-binary-cache-store.cc',
'local-fs-store.cc',
'local-nar-cache.cc',
'local-overlay-store.cc',
'local-store.cc',
'log-store.cc',
+2 -2
View File
@@ -169,7 +169,7 @@ void LocalStore::optimisePath_(
/* Maybe delete the link, if it has been corrupted. */
if (std::filesystem::exists(std::filesystem::symlink_status(linkPath))) {
auto stLink = lstat(linkPath);
auto stLink = lstat(linkPath.string());
if (st.st_size != stLink.st_size || (repair && hash != ({
hashPath(
makeFSSourceAccessor(linkPath),
@@ -215,7 +215,7 @@ void LocalStore::optimisePath_(
/* Yes! We've seen a file with the same contents. Replace the
current file with a hard link to that file. */
auto stLink = lstat(linkPath);
auto stLink = lstat(linkPath.string());
if (st.st_ino == stLink.st_ino) {
debug("%1% is already linked to %2%", PathFmt(path), PathFmt(linkPath));
+2 -2
View File
@@ -15,7 +15,7 @@ namespace nix {
const time_t mtimeStore = 1; /* 1 second into the epoch */
static void canonicaliseTimestampAndPermissions(const Path & path, const PosixStat & st)
static void canonicaliseTimestampAndPermissions(const Path & path, const struct stat & st)
{
if (!S_ISLNK(st.st_mode)) {
@@ -30,7 +30,7 @@ static void canonicaliseTimestampAndPermissions(const Path & path, const PosixSt
#ifndef _WIN32 // TODO implement
if (st.st_mtime != mtimeStore) {
PosixStat st2 = st;
struct stat st2 = st;
st2.st_mtime = mtimeStore, setWriteTime(path, st2);
}
#endif
+5 -4
View File
@@ -1,11 +1,12 @@
#include "nix/store/remote-fs-accessor.hh"
#include "nix/store/local-nar-cache.hh"
namespace nix {
RemoteFSAccessor::RemoteFSAccessor(
ref<Store> store, bool requireValidPath, std::optional<std::filesystem::path> cacheDir)
: store(store)
, narCache(cacheDir)
, narCache(cacheDir ? makeLocalNarCache(*cacheDir) : makeMemoryNarCache())
, requireValidPath(requireValidPath)
{
}
@@ -18,11 +19,11 @@ std::pair<ref<SourceAccessor>, CanonPath> RemoteFSAccessor::fetch(const CanonPat
return {ref{accessObject(storePath)}, CanonPath{restPath}};
}
std::shared_ptr<SourceAccessor> RemoteFSAccessor::accessObject(const StorePath & storePath)
ref<NarAccessor> RemoteFSAccessor::accessObject(const StorePath & storePath)
{
// Check if we already have the NAR hash for this store path
if (auto * narHash = get(narHashes, storePath.hashPart()))
return narCache.getOrInsert(*narHash, [&](Sink & sink) { store->narFromPath(storePath, sink); });
return narCache->getOrInsert(*narHash, [&](Sink & sink) { store->narFromPath(storePath, sink); });
// Query the path info to get the NAR hash
auto info = store->queryPathInfo(storePath);
@@ -31,7 +32,7 @@ std::shared_ptr<SourceAccessor> RemoteFSAccessor::accessObject(const StorePath &
narHashes.emplace(storePath.hashPart(), info->narHash);
// Get or create the NAR accessor
return narCache.getOrInsert(info->narHash, [&](Sink & sink) { store->narFromPath(storePath, sink); });
return narCache->getOrInsert(info->narHash, [&](Sink & sink) { store->narFromPath(storePath, sink); });
}
std::optional<SourceAccessor::Stat> RemoteFSAccessor::maybeLstat(const CanonPath & path)
+1 -1
View File
@@ -841,7 +841,7 @@ ref<SourceAccessor> RemoteStore::getFSAccessor(bool requireValidPath)
std::shared_ptr<SourceAccessor> RemoteStore::getFSAccessor(const StorePath & path, bool requireValidPath)
{
return getRemoteFSAccessor(requireValidPath)->accessObject(path);
return static_cast<ref<SourceAccessor>>(getRemoteFSAccessor(requireValidPath)->accessObject(path));
}
void RemoteStore::ConnectionHandle::withFramedSink(std::function<void(Sink & sink)> fun)
+13 -19
View File
@@ -2,7 +2,6 @@
#include "nix/store/path-with-outputs.hh"
#include "nix/store/store-api.hh"
#include "nix/store/build-result.hh"
#include "nix/store/common-protocol.hh"
#include "nix/store/serve-protocol.hh"
#include "nix/store/serve-protocol-impl.hh"
#include "nix/util/archive.hh"
@@ -16,35 +15,30 @@ namespace nix {
BuildResult ServeProto::Serialise<BuildResult>::read(const StoreDirConfig & store, ServeProto::ReadConn conn)
{
BuildResult res;
BuildResult status;
BuildResult::Success success;
BuildResult::Failure failure;
auto status = ServeProto::Serialise<BuildResultStatus>::read(store, {conn.from});
auto rawStatus = readInt(conn.from);
conn.from >> failure.errorMsg;
if (GET_PROTOCOL_MINOR(conn.version) >= 3)
conn.from >> res.timesBuilt >> failure.isNonDeterministic >> res.startTime >> res.stopTime;
conn.from >> status.timesBuilt >> failure.isNonDeterministic >> status.startTime >> status.stopTime;
if (GET_PROTOCOL_MINOR(conn.version) >= 6) {
auto builtOutputs = ServeProto::Serialise<DrvOutputs>::read(store, conn);
for (auto && [output, realisation] : builtOutputs)
success.builtOutputs.insert_or_assign(std::move(output.outputName), std::move(realisation));
}
res.inner = std::visit(
overloaded{
[&](BuildResult::Success::Status s) -> decltype(res.inner) {
success.status = s;
return std::move(success);
},
[&](BuildResult::Failure::Status s) -> decltype(res.inner) {
failure.status = s;
return std::move(failure);
},
},
status);
if (BuildResult::Success::statusIs(rawStatus)) {
success.status = static_cast<BuildResult::Success::Status>(rawStatus);
status.inner = std::move(success);
} else {
failure.status = static_cast<BuildResult::Failure::Status>(rawStatus);
status.inner = std::move(failure);
}
return res;
return status;
}
void ServeProto::Serialise<BuildResult>::write(
@@ -69,11 +63,11 @@ void ServeProto::Serialise<BuildResult>::write(
std::visit(
overloaded{
[&](const BuildResult::Failure & failure) {
ServeProto::write(store, {conn.to}, BuildResultStatus{failure.status});
conn.to << failure.status;
common(failure.errorMsg, failure.isNonDeterministic, decltype(BuildResult::Success::builtOutputs){});
},
[&](const BuildResult::Success & success) {
ServeProto::write(store, {conn.to}, BuildResultStatus{success.status});
conn.to << success.status;
common(/*errorMsg=*/"", /*isNonDeterministic=*/false, success.builtOutputs);
},
},
+33 -34
View File
@@ -439,8 +439,7 @@ private:
StorePath makeFallbackPath(OutputNameView outputName);
};
static void handleDiffHook(
const Path & diffHook,
void handleDiffHook(
uid_t uid,
uid_t gid,
const std::filesystem::path & tryA,
@@ -448,25 +447,29 @@ static void handleDiffHook(
const std::filesystem::path & drvPath,
const std::filesystem::path & tmpDir)
{
try {
auto diffRes = runProgram(
RunOptions{
.program = diffHook,
.lookupPath = true,
.args = {tryA, tryB, drvPath, tmpDir},
.uid = uid,
.gid = gid,
.chdir = "/"});
if (!statusOk(diffRes.first))
throw ExecError(diffRes.first, "diff-hook program '%1%' %2%", diffHook, statusToString(diffRes.first));
auto & diffHookOpt = settings.diffHook.get();
if (diffHookOpt && settings.runDiffHook) {
auto & diffHook = *diffHookOpt;
try {
auto diffRes = runProgram(
RunOptions{
.program = diffHook,
.lookupPath = true,
.args = {tryA, tryB, drvPath, tmpDir},
.uid = uid,
.gid = gid,
.chdir = "/"});
if (!statusOk(diffRes.first))
throw ExecError(diffRes.first, "diff-hook program '%1%' %2%", diffHook, statusToString(diffRes.first));
if (diffRes.second != "")
printError(chomp(diffRes.second));
} catch (Error & error) {
ErrorInfo ei = error.info();
// FIXME: wrap errors.
ei.msg = HintFmt("diff hook execution failed: %s", ei.msg.str());
logError(ei);
if (diffRes.second != "")
printError(chomp(diffRes.second));
} catch (Error & error) {
ErrorInfo ei = error.info();
// FIXME: wrap errors.
ei.msg = HintFmt("diff hook execution failed: %s", ei.msg.str());
logError(ei);
}
}
}
@@ -1409,7 +1412,7 @@ SingleDrvOutputs DerivationBuilderImpl::registerOutputs()
scratchOutputsInverse.insert_or_assign(path, outputName);
std::map<std::string, std::variant<AlreadyRegistered, PerhapsNeedToRegister>> outputReferencesIfUnregistered;
std::map<std::string, PosixStat> outputStats;
std::map<std::string, struct stat> outputStats;
for (auto & [outputName, _] : drv.outputs) {
auto scratchOutput = get(scratchOutputs, outputName);
assert(scratchOutput);
@@ -1438,7 +1441,7 @@ SingleDrvOutputs DerivationBuilderImpl::registerOutputs()
store.printStorePath(drvPath),
outputName,
PathFmt(actualPath));
PosixStat & st = *optSt;
struct stat & st = *optSt;
#ifndef __CYGWIN__
/* Check that the output is not group or world writable, as
@@ -1782,22 +1785,18 @@ SingleDrvOutputs DerivationBuilderImpl::registerOutputs()
if (store.isValidPath(newInfo.path)) {
ValidPathInfo oldInfo(*store.queryPathInfo(newInfo.path));
if (newInfo.narHash != oldInfo.narHash) {
auto * diffHook = settings.getDiffHook();
if (diffHook || settings.keepFailed) {
if (settings.runDiffHook || settings.keepFailed) {
auto dst = store.toRealPath(finalDestPath + ".check");
deletePath(dst);
movePath(actualPath, dst);
if (diffHook) {
handleDiffHook(
*diffHook,
buildUser ? buildUser->getUID() : getuid(),
buildUser ? buildUser->getGID() : getgid(),
finalDestPath,
dst,
store.printStorePath(drvPath),
tmpDir);
}
handleDiffHook(
buildUser ? buildUser->getUID() : getuid(),
buildUser ? buildUser->getGID() : getgid(),
finalDestPath,
dst,
store.printStorePath(drvPath),
tmpDir);
throw NotDeterministic(
"derivation '%s' may not be deterministic: output '%s' differs from '%s'",
+3 -2
View File
@@ -1,5 +1,4 @@
#include "nix/store/pathlocks.hh"
#include "nix/util/file-system.hh"
#include "nix/util/util.hh"
#include "nix/util/sync.hh"
#include "nix/util/signals.hh"
@@ -111,7 +110,9 @@ bool PathLocks::lockPaths(const std::set<std::filesystem::path> & paths, const s
/* Check that the lock file hasn't become stale (i.e.,
hasn't been unlinked). */
auto st = nix::fstat(fd.get());
struct stat st;
if (fstat(fd.get(), &st) == -1)
throw SysError("statting lock file %1%", PathFmt(lockPath));
if (st.st_size != 0)
/* This lock file has been unlinked, so we're holding
a lock on a deleted file. This means that other
+10 -16
View File
@@ -3,7 +3,6 @@
#include "nix/store/store-api.hh"
#include "nix/store/gc-store.hh"
#include "nix/store/build-result.hh"
#include "nix/store/common-protocol.hh"
#include "nix/store/worker-protocol.hh"
#include "nix/store/worker-protocol-impl.hh"
#include "nix/util/archive.hh"
@@ -210,7 +209,7 @@ BuildResult WorkerProto::Serialise<BuildResult>::read(const StoreDirConfig & sto
BuildResult::Success success;
BuildResult::Failure failure;
auto status = WorkerProto::Serialise<BuildResultStatus>::read(store, {conn.from});
auto rawStatus = readInt(conn.from);
conn.from >> failure.errorMsg;
if (GET_PROTOCOL_MINOR(conn.version) >= 29) {
@@ -226,18 +225,13 @@ BuildResult WorkerProto::Serialise<BuildResult>::read(const StoreDirConfig & sto
success.builtOutputs.insert_or_assign(std::move(output.outputName), std::move(realisation));
}
res.inner = std::visit(
overloaded{
[&](BuildResult::Success::Status s) -> decltype(res.inner) {
success.status = s;
return std::move(success);
},
[&](BuildResult::Failure::Status s) -> decltype(res.inner) {
failure.status = s;
return std::move(failure);
},
},
status);
if (BuildResult::Success::statusIs(rawStatus)) {
success.status = static_cast<BuildResult::Success::Status>(rawStatus);
res.inner = std::move(success);
} else {
failure.status = static_cast<BuildResult::Failure::Status>(rawStatus);
res.inner = std::move(failure);
}
return res;
}
@@ -269,11 +263,11 @@ void WorkerProto::Serialise<BuildResult>::write(
std::visit(
overloaded{
[&](const BuildResult::Failure & failure) {
WorkerProto::write(store, {conn.to}, BuildResultStatus{failure.status});
conn.to << failure.status;
common(failure.errorMsg, failure.isNonDeterministic, decltype(BuildResult::Success::builtOutputs){});
},
[&](const BuildResult::Success & success) {
WorkerProto::write(store, {conn.to}, BuildResultStatus{success.status});
conn.to << success.status;
common(/*errorMsg=*/"", /*isNonDeterministic=*/false, success.builtOutputs);
},
},
+41 -76
View File
@@ -193,71 +193,40 @@ bool isDirOrInDir(const std::filesystem::path & path, const std::filesystem::pat
return path == dir || isInDir(path, dir);
}
struct stat stat(const Path & path)
{
struct stat st;
if (stat(path.c_str(), &st))
throw SysError("getting status of '%1%'", path);
return st;
}
#ifdef _WIN32
# define STAT _wstat64
# define LSTAT _wstat64
#else
# define STAT stat
# define LSTAT lstat
#endif
PosixStat stat(const std::filesystem::path & path)
{
PosixStat st;
if (STAT(path.c_str(), &st))
throw SysError("getting status of %s", PathFmt(path));
return st;
}
PosixStat lstat(const std::filesystem::path & path)
{
PosixStat st;
if (LSTAT(path.c_str(), &st))
throw SysError("getting status of %s", PathFmt(path));
return st;
}
PosixStat fstat(int fd)
{
PosixStat st;
if (
#ifdef _WIN32
_fstat64
#else
::fstat
# define STAT lstat
#endif
(fd, &st))
throw SysError("getting status of fd %d", fd);
struct stat lstat(const Path & path)
{
struct stat st;
if (STAT(path.c_str(), &st))
throw SysError("getting status of '%1%'", path);
return st;
}
std::optional<PosixStat> maybeStat(const std::filesystem::path & path)
std::optional<struct stat> maybeLstat(const Path & path)
{
std::optional<PosixStat> st{std::in_place};
std::optional<struct stat> st{std::in_place};
if (STAT(path.c_str(), &*st)) {
if (errno == ENOENT || errno == ENOTDIR)
st.reset();
else
throw SysError("getting status of %s", PathFmt(path));
throw SysError("getting status of '%s'", path);
}
return st;
}
std::optional<PosixStat> maybeLstat(const std::filesystem::path & path)
{
std::optional<PosixStat> st{std::in_place};
if (LSTAT(path.c_str(), &*st)) {
if (errno == ENOENT || errno == ENOTDIR)
st.reset();
else
throw SysError("getting status of %s", PathFmt(path));
}
return st;
}
#undef STAT
#undef LSTAT
bool pathExists(const std::filesystem::path & path)
{
return maybeLstat(path.string()).has_value();
@@ -479,31 +448,33 @@ AutoDelete::AutoDelete(const std::filesystem::path & p, bool recursive)
this->recursive = recursive;
}
void AutoDelete::deletePath()
{
if (del) {
if (recursive)
nix::deletePath(_path);
else
std::filesystem::remove(_path);
cancel();
}
}
AutoDelete::~AutoDelete()
{
try {
deletePath();
if (del) {
if (recursive)
deletePath(_path);
else {
std::filesystem::remove(_path);
}
}
} catch (...) {
ignoreExceptionInDestructor();
}
}
void AutoDelete::cancel() noexcept
void AutoDelete::cancel()
{
del = false;
}
void AutoDelete::reset(const std::filesystem::path & p, bool recursive)
{
_path = p;
this->recursive = recursive;
del = true;
}
//////////////////////////////////////////////////////////////////////
#ifdef __FreeBSD__
@@ -512,7 +483,7 @@ AutoUnmount::AutoUnmount()
{
}
AutoUnmount::AutoUnmount(const std::filesystem::path & p)
AutoUnmount::AutoUnmount(Path & p)
: path(p)
, del(true)
{
@@ -521,26 +492,20 @@ AutoUnmount::AutoUnmount(const std::filesystem::path & p)
AutoUnmount::~AutoUnmount()
{
try {
unmount();
if (del) {
if (unmount(path.c_str(), 0) < 0) {
throw SysError("Failed to unmount path %1%", path);
}
}
} catch (...) {
ignoreExceptionInDestructor();
}
}
void AutoUnmount::cancel() noexcept
void AutoUnmount::cancel()
{
del = false;
}
void AutoUnmount::unmount()
{
if (del) {
if (::unmount(path.c_str(), 0) < 0) {
throw SysError("Failed to unmount path %1%", PathFmt(path));
}
}
cancel();
}
#endif
//////////////////////////////////////////////////////////////////////
@@ -676,7 +641,7 @@ void replaceSymlink(const std::filesystem::path & target, const std::filesystem:
}
}
void setWriteTime(const std::filesystem::path & path, const PosixStat & st)
void setWriteTime(const std::filesystem::path & path, const struct stat & st)
{
setWriteTime(path, st.st_atime, st.st_mtime, S_ISLNK(st.st_mode));
}
+18 -14
View File
@@ -11,35 +11,39 @@
namespace nix {
AutoRemoveJail::AutoRemoveJail() = default;
AutoRemoveJail::AutoRemoveJail(int jid)
: jid(jid)
AutoRemoveJail::AutoRemoveJail()
: del{false}
{
}
void AutoRemoveJail::remove()
AutoRemoveJail::AutoRemoveJail(int jid)
: jid(jid)
, del(true)
{
if (jid != INVALID_JAIL) {
if (jail_remove(jid) < 0) {
throw SysError("Failed to remove jail %1%", jid);
}
}
cancel();
}
AutoRemoveJail::~AutoRemoveJail()
{
try {
remove();
if (del) {
if (jail_remove(jid) < 0) {
throw SysError("Failed to remove jail %1%", jid);
}
}
} catch (...) {
ignoreExceptionInDestructor();
}
}
void AutoRemoveJail::cancel() noexcept
void AutoRemoveJail::cancel()
{
jid = INVALID_JAIL;
del = false;
}
void AutoRemoveJail::reset(int j)
{
del = true;
jid = j;
}
//////////////////////////////////////////////////////////////////////
@@ -7,51 +7,32 @@ namespace nix {
class AutoRemoveJail
{
static constexpr int INVALID_JAIL = -1;
int jid = INVALID_JAIL;
int jid;
bool del;
public:
AutoRemoveJail() = default;
AutoRemoveJail(int jid);
AutoRemoveJail(const AutoRemoveJail &) = delete;
AutoRemoveJail & operator=(const AutoRemoveJail &) = delete;
AutoRemoveJail(AutoRemoveJail && other) noexcept
: jid(other.jid)
, del(other.del)
{
other.cancel();
}
AutoRemoveJail & operator=(AutoRemoveJail && other) noexcept
{
swap(*this, other);
jid = other.jid;
del = other.del;
other.cancel();
return *this;
}
friend void swap(AutoRemoveJail & lhs, AutoRemoveJail & rhs) noexcept
{
using std::swap;
swap(lhs.jid, rhs.jid);
}
operator int() const
{
return jid;
}
AutoRemoveJail();
~AutoRemoveJail();
/**
* Remove the jail and cancel this `AutoRemoveJail`, so jail removal is not
* attempted a second time by the destructor.
*
* The destructor calls this ignoring any exception.
*/
void remove();
/**
* Cancel the jail removal.
*/
void cancel() noexcept;
void cancel();
void reset(int j);
};
} // namespace nix
+3 -1
View File
@@ -189,7 +189,9 @@ void RestoreRegularFile::isExecutable()
// Windows doesn't have a notion of executable file permissions we
// care about here, right?
#ifndef _WIN32
auto st = nix::fstat(fd.get());
struct stat st;
if (fstat(fd.get(), &st) == -1)
throw SysError("fstat");
if (fchmod(fd.get(), st.st_mode | (S_IXUSR | S_IXGRP | S_IXOTH)) == -1)
throw SysError("fchmod");
#endif
+13 -73
View File
@@ -15,7 +15,6 @@
#include <unistd.h>
#ifdef _WIN32
# include <windef.h>
# include <wchar.h>
#endif
#include <functional>
@@ -111,35 +110,16 @@ bool isInDir(const std::filesystem::path & path, const std::filesystem::path & d
*/
bool isDirOrInDir(const std::filesystem::path & path, const std::filesystem::path & dir);
/**
* `struct stat` is not 64-bit everywhere on Windows.
*/
using PosixStat =
#ifdef _WIN32
struct ::__stat64
#else
struct ::stat
#endif
;
/**
* Get status of `path`.
*/
PosixStat lstat(const std::filesystem::path & path);
/**
* Get status of `path` following symlinks.
*/
PosixStat stat(const std::filesystem::path & path);
/**
* Get status of an open file descriptor.
*/
PosixStat fstat(int fd);
struct stat stat(const Path & path);
struct stat lstat(const Path & path);
/**
* `lstat` the given path if it exists.
* @return std::nullopt if the path doesn't exist, or an optional containing the result of `lstat` otherwise
*/
std::optional<PosixStat> maybeLstat(const std::filesystem::path & path);
std::optional<PosixStat> maybeStat(const std::filesystem::path & path);
std::optional<struct stat> maybeLstat(const Path & path);
/**
* @return true iff the given path exists.
@@ -280,9 +260,9 @@ void setWriteTime(
std::optional<bool> isSymlink = std::nullopt);
/**
* Convenience wrapper that takes all arguments from the `PosixStat`.
* Convenience wrapper that takes all arguments from the `struct stat`.
*/
void setWriteTime(const std::filesystem::path & path, const PosixStat & st);
void setWriteTime(const std::filesystem::path & path, const struct stat & st);
/**
* Create a symlink.
@@ -336,37 +316,15 @@ public:
x.del = false;
}
AutoDelete & operator=(AutoDelete && x) noexcept
{
swap(*this, x);
return *this;
}
friend void swap(AutoDelete & lhs, AutoDelete & rhs) noexcept
{
using std::swap;
swap(lhs._path, rhs._path);
swap(lhs.del, rhs.del);
swap(lhs.recursive, rhs.recursive);
}
AutoDelete(const std::filesystem::path & p, bool recursive = true);
AutoDelete(const AutoDelete &) = delete;
AutoDelete & operator=(AutoDelete &&) = delete;
AutoDelete & operator=(const AutoDelete &) = delete;
~AutoDelete();
/**
* Delete the file the path points to, and cancel this `AutoDelete`,
* so deletion is not attempted a second time by the destructor.
*
* The destructor calls this, but ignoring any exception.
*/
void deletePath();
void cancel();
/**
* Cancel the pending deletion
*/
void cancel() noexcept;
void reset(const std::filesystem::path & p, bool recursive = true);
const std::filesystem::path & path() const
{
@@ -546,11 +504,11 @@ private:
#ifdef __FreeBSD__
class AutoUnmount
{
std::filesystem::path path;
Path path;
bool del;
public:
AutoUnmount();
AutoUnmount(const std::filesystem::path &);
AutoUnmount(Path &);
AutoUnmount(const AutoUnmount &) = delete;
AutoUnmount(AutoUnmount && other) noexcept
@@ -561,31 +519,13 @@ public:
AutoUnmount & operator=(AutoUnmount && other) noexcept
{
swap(*this, other);
path = std::move(other.path);
del = std::exchange(other.del, false);
return *this;
}
friend void swap(AutoUnmount & lhs, AutoUnmount & rhs) noexcept
{
using std::swap;
swap(lhs.path, rhs.path);
swap(lhs.del, rhs.del);
}
~AutoUnmount();
/**
* Cancel the unmounting
*/
void cancel() noexcept;
/**
* Unmount the mountpoint right away (if it exists), resetting the
* `AutoUnmount`
*
* The destructor calls this, but ignoring any exception.
*/
void unmount();
void cancel();
};
#endif
+12 -15
View File
@@ -3,45 +3,42 @@
#include "nix/util/hash.hh"
#include "nix/util/nar-accessor.hh"
#include "nix/util/ref.hh"
#include "nix/util/source-accessor.hh"
#include <filesystem>
#include <functional>
#include <map>
#include <optional>
#include <memory>
namespace nix {
/**
* A cache for NAR accessors with optional disk caching.
* Abstract cache for NAR accessors.
*/
class NarCache
{
/**
* Optional directory for caching NARs and listings on disk.
*/
std::optional<std::filesystem::path> cacheDir;
protected:
/**
* Map from NAR hash to NAR accessor.
*/
std::map<Hash, ref<SourceAccessor>> nars;
std::map<Hash, ref<NarAccessor>> nars;
public:
/**
* Create a NAR cache with an optional cache directory for disk storage.
*/
NarCache(std::optional<std::filesystem::path> cacheDir = {});
virtual ~NarCache() = default;
/**
* Lookup or create a NAR accessor, optionally using disk cache.
* Lookup or create a NAR accessor.
*
* @param narHash The NAR hash to use as cache key
* @param populate Function called with a Sink to populate the NAR if not cached
* @return The cached or newly created accessor
*/
ref<SourceAccessor> getOrInsert(const Hash & narHash, std::function<void(Sink &)> populate);
virtual ref<NarAccessor> getOrInsert(const Hash & narHash, std::function<void(Sink &)> populate) = 0;
};
/**
* Create an in-memory only NAR cache.
*/
std::unique_ptr<NarCache> makeMemoryNarCache();
} // namespace nix
@@ -87,7 +87,7 @@ private:
*/
void assertNoSymlinks(CanonPath path);
std::optional<PosixStat> cachedLstat(const CanonPath & path);
std::optional<struct stat> cachedLstat(const CanonPath & path);
std::filesystem::path makeAbsPath(const CanonPath & path);
};
+22 -70
View File
@@ -1,84 +1,36 @@
#include "nix/util/nar-cache.hh"
#include "nix/util/file-system.hh"
#include <nlohmann/json.hpp>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
namespace nix {
NarCache::NarCache(std::optional<std::filesystem::path> cacheDir_)
: cacheDir(std::move(cacheDir_))
{
if (cacheDir)
createDirs(*cacheDir);
}
namespace {
ref<SourceAccessor> NarCache::getOrInsert(const Hash & narHash, std::function<void(Sink &)> populate)
/**
* In-memory only NAR cache (private implementation).
*/
class MemoryNarCache : public NarCache
{
public:
ref<NarAccessor> getOrInsert(const Hash & narHash, std::function<void(Sink &)> populate) override;
};
} // anonymous namespace
ref<NarAccessor> MemoryNarCache::getOrInsert(const Hash & narHash, std::function<void(Sink &)> populate)
{
// Check in-memory cache first
if (auto * accessor = get(nars, narHash))
return *accessor;
auto cacheAccessor = [&](ref<SourceAccessor> accessor) {
nars.emplace(narHash, accessor);
return accessor;
};
StringSink sink;
populate(sink);
auto accessor = makeNarAccessor(std::move(sink.s));
nars.emplace(narHash, accessor);
return accessor;
}
auto getNar = [&]() {
StringSink sink;
populate(sink);
return std::move(sink.s);
};
if (cacheDir) {
auto makeCacheFile = [&](const std::string & ext) {
auto res = *cacheDir / narHash.to_string(HashFormat::Nix32, false);
res += ".";
res += ext;
return res;
};
auto cacheFile = makeCacheFile("nar");
auto listingFile = makeCacheFile("ls");
if (nix::pathExists(cacheFile)) {
try {
return cacheAccessor(makeLazyNarAccessor(
nlohmann::json::parse(nix::readFile(listingFile)).template get<NarListing>(),
seekableGetNarBytes(cacheFile)));
} catch (SystemError &) {
}
try {
return cacheAccessor(makeNarAccessor(nix::readFile(cacheFile)));
} catch (SystemError &) {
}
}
auto nar = getNar();
try {
/* FIXME: do this asynchronously. */
writeFile(cacheFile, nar);
} catch (...) {
ignoreExceptionExceptInterrupt();
}
auto narAccessor = makeNarAccessor(std::move(nar));
try {
nlohmann::json j = narAccessor->getListing();
writeFile(listingFile, j.dump());
} catch (...) {
ignoreExceptionExceptInterrupt();
}
return cacheAccessor(narAccessor);
}
return cacheAccessor(makeNarAccessor(getNar()));
std::unique_ptr<NarCache> makeMemoryNarCache()
{
return std::make_unique<MemoryNarCache>();
}
} // namespace nix
+5 -3
View File
@@ -55,7 +55,9 @@ void PosixSourceAccessor::readFile(const CanonPath & path, Sink & sink, std::fun
if (!fd)
throw SysError("opening file '%1%'", ap.string());
auto st = nix::fstat(fromDescriptorReadOnly(fd.get()));
struct stat st;
if (fstat(fromDescriptorReadOnly(fd.get()), &st) == -1)
throw SysError("statting file");
sizeCallback(st.st_size);
@@ -85,9 +87,9 @@ bool PosixSourceAccessor::pathExists(const CanonPath & path)
return nix::pathExists(makeAbsPath(path).string());
}
std::optional<PosixStat> PosixSourceAccessor::cachedLstat(const CanonPath & path)
std::optional<struct stat> PosixSourceAccessor::cachedLstat(const CanonPath & path)
{
using Cache = boost::concurrent_flat_map<Path, std::optional<PosixStat>>;
using Cache = boost::concurrent_flat_map<Path, std::optional<struct stat>>;
static Cache cache;
// Note: we convert std::filesystem::path to Path because the
+4 -1
View File
@@ -51,7 +51,10 @@ void pollFD(int fd, int events)
std::string readFile(int fd)
{
auto st = nix::fstat(fd);
struct stat st;
if (fstat(fd, &st) == -1)
throw SysError("statting file");
return drainFD(fd, true, st.st_size);
}
+4 -4
View File
@@ -70,15 +70,15 @@ void setWriteTime(
};
# if HAVE_LUTIMES
if (lutimes(path.c_str(), times) == -1)
throw SysError("changing modification time of %s", PathFmt{path});
throw SysError("changing modification time of %s", path);
# else
bool isSymlink = optIsSymlink ? *optIsSymlink : std::filesystem::is_symlink(path);
if (!isSymlink) {
if (utimes(path.c_str(), times) == -1)
throw SysError("changing modification time of %s (not a symlink)", PathFmt{path});
throw SysError("changing modification time of %s (not a symlink)", path);
} else {
throw Error("Cannot change modification time of symlink %s", PathFmt{path});
throw Error("Cannot change modification time of symlink %s", path);
}
# endif
#endif
@@ -110,7 +110,7 @@ static void _deletePath(
std::string name(path.filename());
assert(name != "." && name != ".." && !name.empty());
PosixStat st;
struct stat st;
if (fstatat(parentfd, name.c_str(), &st, AT_SYMLINK_NOFOLLOW) == -1) {
if (errno == ENOENT)
return;
+12 -10
View File
@@ -35,16 +35,18 @@ std::filesystem::path getHome()
auto homeDir = getEnv("HOME");
if (homeDir) {
// Only use $HOME if doesn't exist or is owned by the current user.
try {
auto st = maybeStat(homeDir->c_str());
if (st && st->st_uid != geteuid())
unownedUserHomeDir.swap(homeDir);
} catch (SysError & e) {
warn(
"couldn't stat $HOME ('%s') for reason other than not existing, falling back to the one defined in the 'passwd' file: %s",
*homeDir,
e.what());
homeDir.reset();
struct stat st;
int result = stat(homeDir->c_str(), &st);
if (result != 0) {
if (errno != ENOENT) {
warn(
"couldn't stat $HOME ('%s') for reason other than not existing ('%d'), falling back to the one defined in the 'passwd' file",
*homeDir,
errno);
homeDir.reset();
}
} else if (st.st_uid != geteuid()) {
unownedUserHomeDir.swap(homeDir);
}
}
if (!homeDir) {
+4 -4
View File
@@ -374,6 +374,10 @@ void mainWrapped(int argc, char ** argv)
}
#endif
initNix();
initGC();
flakeSettings.configureEvalSettings(evalSettings);
/* Set the build hook location
For builds we perform a self-invocation, so Nix has to be
@@ -386,10 +390,6 @@ void mainWrapped(int argc, char ** argv)
"__build-remote",
});
initNix();
initGC();
flakeSettings.configureEvalSettings(evalSettings);
#ifdef __linux__
if (isRootUser()) {
try {
+1 -1
View File
@@ -163,7 +163,7 @@ static void update(const StringSet & channelNames)
runProgram(getNixBin("nix-env").string(), false, envArgs);
// Make the channels appear in nix-env.
PosixStat st;
struct stat st;
if (lstat(nixDefExpr.c_str(), &st) == 0) {
if (S_ISLNK(st.st_mode))
// old-skool ~/.nix-defexpr
+4 -38
View File
@@ -5,7 +5,6 @@
#include "nix/expr/eval.hh"
#include "nix/expr/get-drvs.hh"
#include "nix/store/globals.hh"
#include "nix/util/config-global.hh"
#include "nix/store/names.hh"
#include "nix/store/profiles.hh"
#include "nix/store/path-with-outputs.hh"
@@ -35,39 +34,6 @@
using namespace nix;
using std::cout;
/**
* Settings related to Nix user environments.
*/
struct EnvSettings : Config
{
Setting<bool> keepDerivations{
this,
false,
"keep-env-derivations",
R"(
If `false` (default), derivations are not stored in Nix user
environments. That is, the derivations of any build-time-only
dependencies may be garbage-collected.
If `true`, when you add a Nix derivation to a user environment, the
path of the derivation is stored in the user environment. Thus, the
derivation isn't garbage-collected until the user environment
generation is deleted (`nix-env --delete-generations`). To prevent
build-time-only dependencies from being collected, you should also
turn on `keep-outputs`.
The difference between this option and `keep-derivations` is that
this one is "sticky": it applies to any user environment created
while this option was enabled, while `keep-derivations` only applies
at the moment the garbage collector is run.
)",
{"env-keep-derivations"}};
};
EnvSettings envSettings;
static GlobalConfig::Register rSettings(&envSettings);
typedef enum { srcNixExprDrvs, srcNixExprs, srcStorePaths, srcProfile, srcAttrPath, srcUnknown } InstallSourceType;
struct InstallSourceInfo
@@ -580,7 +546,7 @@ installDerivations(Globals & globals, const Strings & args, const Path & profile
if (globals.dryRun)
return;
if (createUserEnv(*globals.state, allElems, profile, envSettings.keepDerivations, lockToken))
if (createUserEnv(*globals.state, allElems, profile, settings.envKeepDerivations, lockToken))
break;
}
}
@@ -691,7 +657,7 @@ static void upgradeDerivations(Globals & globals, const Strings & args, UpgradeT
if (globals.dryRun)
return;
if (createUserEnv(*globals.state, newElems, globals.profile, envSettings.keepDerivations, lockToken))
if (createUserEnv(*globals.state, newElems, globals.profile, settings.envKeepDerivations, lockToken))
break;
}
}
@@ -750,7 +716,7 @@ static void opSetFlag(Globals & globals, Strings opFlags, Strings opArgs)
checkSelectorUse(selectors);
/* Write the new user environment. */
if (createUserEnv(*globals.state, installedElems, globals.profile, envSettings.keepDerivations, lockToken))
if (createUserEnv(*globals.state, installedElems, globals.profile, settings.envKeepDerivations, lockToken))
break;
}
}
@@ -833,7 +799,7 @@ static void uninstallDerivations(Globals & globals, Strings & selectors, Path &
if (globals.dryRun)
return;
if (createUserEnv(*globals.state, workingElems, profile, envSettings.keepDerivations, lockToken))
if (createUserEnv(*globals.state, workingElems, profile, settings.envKeepDerivations, lockToken))
break;
}
}
+11 -4
View File
@@ -15,7 +15,6 @@
#include "nix/store/globals.hh"
#include "nix/store/path-with-outputs.hh"
#include "nix/store/export-import.hh"
#include "nix/util/strings.hh"
#include "man-pages.hh"
@@ -536,9 +535,17 @@ static void opPrintEnv(Strings opFlags, Strings opArgs)
for (auto & i : drv.env)
logger->cout("export %1%; %1%=%2%\n", i.first, escapeShellArgAlways(i.second));
/* Also output the arguments. */
std::string argsStr = concatStringsSep(" ", drv.args);
cout << "export _args; _args=" << escapeShellArgAlways(argsStr) << "\n";
/* Also output the arguments. This doesn't preserve whitespace in
arguments. */
cout << "export _args; _args='";
bool first = true;
for (auto & i : drv.args) {
if (!first)
cout << ' ';
first = false;
cout << escapeShellArgAlways(i);
}
cout << "'\n";
}
static void opReadLog(Strings opFlags, Strings opArgs)
+2 -25
View File
@@ -9,33 +9,10 @@
#include "nix/store/names.hh"
#include "nix/util/executable-path.hh"
#include "nix/store/globals.hh"
#include "nix/util/config-global.hh"
#include "self-exe.hh"
using namespace nix;
/**
* Settings related to upgrading Nix itself.
*/
struct UpgradeSettings : Config
{
/**
* The URL of the file that contains the store paths of the latest Nix release.
*/
Setting<std::string> storePathUrl{
this,
"https://github.com/NixOS/nixpkgs/raw/master/nixos/modules/installer/tools/nix-fallback-paths.nix",
"upgrade-nix-store-path-url",
R"(
Used by `nix upgrade-nix`, the URL of the file that contains the
store paths of the latest Nix release.
)"};
};
UpgradeSettings upgradeSettings;
static GlobalConfig::Register rSettings(&upgradeSettings);
struct CmdUpgradeNix : MixDryRun, StoreCommand
{
std::filesystem::path profileDir;
@@ -54,7 +31,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand
.longName = "nix-store-paths-url",
.description = "The URL of the file that contains the store paths of the latest Nix release.",
.labels = {"url"},
.handler = {&(std::string &) upgradeSettings.storePathUrl},
.handler = {&(std::string &) settings.upgradeNixStorePathUrl},
});
}
@@ -179,7 +156,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand
Activity act(*logger, lvlInfo, actUnknown, "querying latest Nix version");
// FIXME: use nixos.org?
auto req = FileTransferRequest(parseURL(upgradeSettings.storePathUrl.get()));
auto req = FileTransferRequest(parseURL(settings.upgradeNixStorePathUrl.get()));
auto res = getFileTransfer()->download(req);
auto state = std::make_unique<EvalState>(LookupPath{}, store, fetchSettings, evalSettings);
+2 -2
View File
@@ -47,8 +47,6 @@ perl.pkgs.toPerlModule (
nix-store
bzip2
libsodium
perlPackages.DBI
perlPackages.DBDSQLite
];
# `perlPackages.Test2Harness` is marked broken for Darwin
@@ -66,6 +64,8 @@ perl.pkgs.toPerlModule (
'';
mesonFlags = [
(lib.mesonOption "dbi_path" "${perlPackages.DBI}/${perl.libPrefix}")
(lib.mesonOption "dbd_sqlite_path" "${perlPackages.DBDSQLite}/${perl.libPrefix}")
(lib.mesonEnable "tests" finalAttrs.finalPackage.doCheck)
];
+1 -4
View File
@@ -191,10 +191,7 @@ test "$status" = 1
# Precise number of errors depends on daemon version / goal refactorings
(( "$(<<<"$out" grep -cE '^error:')" >= 2 ))
if isDaemonNewer "2.31"; then
<<<"$out" grepQuiet -E "error: Cannot build '.*-x4\\.drv'"
<<<"$out" grepQuiet -E "Reason: 1 dependency failed."
elif isDaemonNewer "2.29pre"; then
if isDaemonNewer "2.29pre"; then
<<<"$out" grepQuiet -E "error: Cannot build '.*-x4\\.drv'"
<<<"$out" grepQuiet -E "Reason: 1 dependency failed."
<<<"$out" grepQuiet -E "Build failed due to failed dependency"
+4 -4
View File
@@ -42,7 +42,7 @@ buildViaSubstitute () {
nix build -f issue-13247.nix "$1" --no-link --max-jobs 0 --substituters "$cache" --no-require-sigs --offline --substitute
}
# Substitute just the first output
# Substitue just the first output
buildViaSubstitute use-a-more-outputs^first
# Should only fetch the output we asked for
@@ -52,10 +52,10 @@ buildViaSubstitute use-a-more-outputs^first
delete
# Failure with 2.33 encountered in CI
requireDaemonNewerThan "2.34pre"
# Failure with 2.28 encountered in CI
requireDaemonNewerThan "2.29"
# Substitute just the first output
# Substitue just the first output
#
# This derivation is the same after normalization, so we should get
# early cut-off, and thus a chance to download just the output we want
-3
View File
@@ -64,9 +64,6 @@ unset XDG_CONFIG_HOME
unset XDG_CONFIG_DIRS
unset XDG_CACHE_HOME
unset GIT_DIR
# Isolate tests from host git config (signing, url rewrites, etc.)
export GIT_CONFIG_SYSTEM=/dev/null
export GIT_CONFIG_GLOBAL=/dev/null
export IMPURE_VAR1=foo
export IMPURE_VAR2=bar
@@ -41,8 +41,5 @@ out=$(nix build --impure --no-link --expr '
builtins.outputOf failingProducer.outPath "out"
' 2>&1) || true
# Store layer needs bugfix
requireDaemonNewerThan "2.34pre"
# The error message must NOT be empty - it should mention the failed derivation
echo "$out" | grepQuiet "failed to obtain derivation of"
+3 -5
View File
@@ -18,11 +18,9 @@ rm -rf "${rootRepo}" "${subRepo}" "$TEST_HOME"/.cache/nix
# submodule is intentionally local and it's all trusted, so we
# disable this restriction. Setting it per repo is not sufficient, as
# the repo-local config does not apply to the commands run from
# outside the repos by Nix. We use environment variables to avoid
# attempting to write to a read-only system git config.
export GIT_CONFIG_COUNT=1
export GIT_CONFIG_KEY_0=protocol.file.allow
export GIT_CONFIG_VALUE_0=always
# outside the repos by Nix.
export XDG_CONFIG_HOME=$TEST_HOME/.config
git config --global protocol.file.allow always
addGitContent() {
echo "lorem ipsum" > "$1"/content
@@ -21,9 +21,8 @@ clearStore
# Submodules can't be fetched locally by default.
# See fetchGitSubmodules.sh
export GIT_CONFIG_COUNT=1
export GIT_CONFIG_KEY_0=protocol.file.allow
export GIT_CONFIG_VALUE_0=always
export XDG_CONFIG_HOME=$TEST_HOME/.config
git config --global protocol.file.allow always
rootRepo=$TEST_ROOT/rootRepo
@@ -1,4 +0,0 @@
warning:
… while evaluating the first argument passed to builtins.toPath
warning: in a future version of Nix this will be an error: cannot coerce a set that is not a package to a single derived path: { outPath = «thunk»; }
@@ -1 +0,0 @@
warning: in a future version of Nix this will be an error: derivation '/nix/store/y1s2fiq89v2h9vkb38w508ir20dwv6v2-test.drv' is not valid
@@ -1,5 +0,0 @@
error: syntax error, unexpected '&&'
at «stdin»:1:1:
1| && true
| ^
2|
@@ -1 +0,0 @@
&& true
@@ -1,5 +0,0 @@
error: syntax error, unexpected 'assert', expecting identifier or 'or' or '${' or '"'
at «stdin»:1:3:
1| a.assert
| ^
2|
@@ -1 +0,0 @@
a.assert
@@ -1,5 +0,0 @@
error: syntax error, unexpected '++'
at «stdin»:1:1:
1| ++ []
| ^
2|
@@ -1 +0,0 @@
++ []
@@ -1,5 +0,0 @@
error: syntax error, unexpected '...', expecting '.' or '='
at «stdin»:1:5:
1| { a ... }
| ^
2|
@@ -1 +0,0 @@
{ a ... }
@@ -1,5 +0,0 @@
error: syntax error, unexpected 'else', expecting 'then'
at «stdin»:1:6:
1| if 1 else
| ^
2|
@@ -1 +0,0 @@
if 1 else
@@ -1,5 +0,0 @@
error: syntax error, unexpected '=='
at «stdin»:1:1:
1| == 1
| ^
2|
@@ -1 +0,0 @@
== 1
@@ -1,5 +0,0 @@
error: syntax error, unexpected floating-point literal, expecting 'inherit'
at «stdin»:1:3:
1| { 1.5 = x; }
| ^
2|
@@ -1 +0,0 @@
{ 1.5 = x; }
@@ -1,5 +0,0 @@
error: syntax error, unexpected '>='
at «stdin»:1:1:
1| >= 1
| ^
2|
@@ -1 +0,0 @@
>= 1
@@ -1,5 +0,0 @@
error: syntax error, unexpected '~/…' path, expecting identifier or 'or' or '${' or '"'
at «stdin»:1:3:
1| a.~/foo
| ^
2|
@@ -1 +0,0 @@
a.~/foo
@@ -1,5 +0,0 @@
error: syntax error, unexpected 'if', expecting identifier or 'or' or '${' or '"'
at «stdin»:1:3:
1| a.if
| ^
2|
@@ -1 +0,0 @@
a.if
@@ -1,5 +0,0 @@
error: syntax error, unexpected '->'
at «stdin»:1:1:
1| -> x
| ^
2|
@@ -1 +0,0 @@
-> x
@@ -1,5 +0,0 @@
error: syntax error, unexpected 'in', expecting identifier or 'or' or '${' or '"'
at «stdin»:1:3:
1| a.in
| ^
2|
@@ -1 +0,0 @@
a.in
@@ -1,5 +0,0 @@
error: syntax error, unexpected start of an indented string, expecting identifier or 'or' or '${' or '"'
at «stdin»:1:3:
1| a.''
| ^
2|
@@ -1 +0,0 @@
a.''
@@ -1,5 +0,0 @@
error: syntax error, unexpected 'inherit', expecting identifier or 'or' or '${' or '"'
at «stdin»:1:3:
1| a.inherit
| ^
2|
@@ -1 +0,0 @@
a.inherit
@@ -1,5 +0,0 @@
error: syntax error, unexpected integer, expecting 'inherit'
at «stdin»:1:3:
1| { 1 = x; }
| ^
2|
@@ -1 +0,0 @@
{ 1 = x; }
@@ -1,5 +0,0 @@
error: syntax error, unexpected '<='
at «stdin»:1:1:
1| <= 1
| ^
2|
@@ -1 +0,0 @@
<= 1
@@ -1,5 +0,0 @@
error: syntax error, unexpected 'let', expecting identifier or 'or' or '${' or '"'
at «stdin»:1:3:
1| a.let
| ^
2|
Loaded 100 of 130 files, more files were not shown because too many files have changed in this diff. Show more