Skip to content

Commit

Permalink
Merge branch 'master' into new-store-settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericson2314 committed Jul 22, 2024
2 parents 40ebe0f + 40f80e1 commit dd6c7f0
Show file tree
Hide file tree
Showing 19 changed files with 116 additions and 31 deletions.
20 changes: 15 additions & 5 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@
in
"-D${prefix}:${rest}";
havePerl = stdenv.buildPlatform == stdenv.hostPlatform && stdenv.hostPlatform.isUnix;
ignoreCrossFile = flags: builtins.filter (flag: !(lib.strings.hasInfix "cross-file" flag)) flags;
in {
pname = "shell-for-" + attrs.pname;

Expand Down Expand Up @@ -309,10 +310,12 @@
};

mesonFlags =
map (transformFlag "libutil") pkgs.nixComponents.nix-util.mesonFlags
++ map (transformFlag "libstore") pkgs.nixComponents.nix-store.mesonFlags
++ map (transformFlag "libfetchers") pkgs.nixComponents.nix-fetchers.mesonFlags
++ lib.optionals havePerl (map (transformFlag "perl") pkgs.nixComponents.nix-perl-bindings.mesonFlags)
map (transformFlag "libutil") (ignoreCrossFile pkgs.nixComponents.nix-util.mesonFlags)
++ map (transformFlag "libstore") (ignoreCrossFile pkgs.nixComponents.nix-store.mesonFlags)
++ map (transformFlag "libfetchers") (ignoreCrossFile pkgs.nixComponents.nix-fetchers.mesonFlags)
++ lib.optionals havePerl (map (transformFlag "perl") (ignoreCrossFile pkgs.nixComponents.nix-perl-bindings.mesonFlags))
++ map (transformFlag "libexpr") (ignoreCrossFile pkgs.nixComponents.nix-expr.mesonFlags)
++ map (transformFlag "libcmd") (ignoreCrossFile pkgs.nixComponents.nix-cmd.mesonFlags)
;

nativeBuildInputs = attrs.nativeBuildInputs or []
Expand All @@ -322,9 +325,16 @@
++ lib.optionals havePerl pkgs.nixComponents.nix-perl-bindings.nativeBuildInputs
++ pkgs.nixComponents.nix-internal-api-docs.nativeBuildInputs
++ pkgs.nixComponents.nix-external-api-docs.nativeBuildInputs
++ lib.optional
(!stdenv.buildPlatform.canExecute stdenv.hostPlatform
# Hack around https://github.com/nixos/nixpkgs/commit/bf7ad8cfbfa102a90463433e2c5027573b462479
&& !(stdenv.hostPlatform.isWindows && stdenv.buildPlatform.isDarwin)
&& stdenv.hostPlatform.emulatorAvailable pkgs.buildPackages
&& lib.meta.availableOn stdenv.buildPlatform (stdenv.hostPlatform.emulator pkgs.buildPackages))
pkgs.buildPackages.mesonEmulatorHook
++ [
pkgs.buildPackages.cmake
pkgs.shellcheck
pkgs.buildPackages.shellcheck
modular.pre-commit.settings.package
(pkgs.writeScriptBin "pre-commit-hooks-install"
modular.pre-commit.settings.installationScript)
Expand Down
2 changes: 1 addition & 1 deletion maintainers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ The team meets twice a week (times are denoted in the [Europe/Amsterdam](https:/
- mark it as draft if it is blocked on the contributor
- escalate it back to the team by moving it to To discuss, and leaving a comment as to why the issue needs to be discussed again.

- Work meeting: [Mondays 13:00-15:00 Europe/Amsterdam](https://www.google.com/calendar/event?eid=Ym52NDdzYnRic2NzcDcybjZiNDhpNzhpa3NfMjAyNDA1MTNUMTIwMDAwWiBiOW81MmZvYnFqYWs4b3E4bGZraGczdDBxZ0Bn)
- Work meeting: [Mondays 14:00-16:00 Europe/Amsterdam](https://www.google.com/calendar/event?eid=Ym52NDdzYnRic2NzcDcybjZiNDhpNzhpa3NfMjAyNDA1MTNUMTIwMDAwWiBiOW81MmZvYnFqYWs4b3E4bGZraGczdDBxZ0Bn)

1. Code review on pull requests from [In review](#in-review).
2. Other chores and tasks.
Expand Down
4 changes: 3 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ subproject('libexpr-c')
subproject('libmain-c')

# Language Bindings
subproject('perl')
if not meson.is_cross_build()
subproject('perl')
endif

# Testing
subproject('nix-util-test-support')
Expand Down
12 changes: 6 additions & 6 deletions src/libexpr-c/nix_api_expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
#include "nix_api_util.h"
#include "nix_api_util_internal.h"

#ifdef HAVE_BOEHMGC
#include <mutex>
#define GC_INCLUDE_NEW 1
#include "gc_cpp.h"
#if HAVE_BOEHMGC
# include <mutex>
# define GC_INCLUDE_NEW 1
# include "gc_cpp.h"
#endif

nix_err nix_libexpr_init(nix_c_context * context)
Expand Down Expand Up @@ -131,7 +131,7 @@ void nix_state_free(EvalState * state)
delete state;
}

#ifdef HAVE_BOEHMGC
#if HAVE_BOEHMGC
std::unordered_map<
const void *,
unsigned int,
Expand Down Expand Up @@ -207,7 +207,7 @@ nix_err nix_value_decref(nix_c_context * context, nix_value *x)

void nix_gc_register_finalizer(void * obj, void * cd, void (*finalizer)(void * obj, void * cd))
{
#ifdef HAVE_BOEHMGC
#if HAVE_BOEHMGC
GC_REGISTER_FINALIZER(obj, finalizer, cd, 0, 0);
#endif
}
4 changes: 2 additions & 2 deletions src/libexpr-c/nix_api_external.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include <nlohmann/json.hpp>

#ifdef HAVE_BOEHMGC
#if HAVE_BOEHMGC
# include "gc/gc.h"
# define GC_INCLUDE_NEW 1
# include "gc_cpp.h"
Expand Down Expand Up @@ -174,7 +174,7 @@ ExternalValue * nix_create_external_value(nix_c_context * context, NixCExternalV
context->last_err_code = NIX_OK;
try {
auto ret = new
#ifdef HAVE_BOEHMGC
#if HAVE_BOEHMGC
(GC)
#endif
NixCExternalValue(*desc, v);
Expand Down
4 changes: 2 additions & 2 deletions src/libexpr-c/nix_api_value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "nix_api_value.h"
#include "value/context.hh"

#ifdef HAVE_BOEHMGC
#if HAVE_BOEHMGC
# include "gc/gc.h"
# define GC_INCLUDE_NEW 1
# include "gc_cpp.h"
Expand Down Expand Up @@ -131,7 +131,7 @@ PrimOp * nix_alloc_primop(
try {
using namespace std::placeholders;
auto p = new
#ifdef HAVE_BOEHMGC
#if HAVE_BOEHMGC
(GC)
#endif
nix::PrimOp{
Expand Down
12 changes: 12 additions & 0 deletions src/libexpr/eval-gc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ static inline void initGCReal()
there. */
GC_set_no_dls(1);

/* Enable perf measurements. This is just a setting; not much of a
start of something. */
GC_start_performance_measurement();

GC_INIT();

GC_set_oom_fn(oomHandler);
Expand Down Expand Up @@ -205,6 +209,7 @@ static inline void initGCReal()
#endif

static bool gcInitialised = false;
static GC_word gcCyclesAfterInit = 0;

void initGC()
{
Expand All @@ -216,11 +221,18 @@ void initGC()
#endif

gcInitialised = true;
gcCyclesAfterInit = GC_get_gc_no();
}

void assertGCInitialized()
{
assert(gcInitialised);
}

size_t getGCCycles()
{
assertGCInitialized();
return GC_get_gc_no() - gcCyclesAfterInit;
}

} // namespace nix
7 changes: 7 additions & 0 deletions src/libexpr/eval-gc.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once
///@file

#include <cstddef>

namespace nix {

/**
Expand All @@ -13,4 +15,9 @@ void initGC();
*/
void assertGCInitialized();

/**
* The number of GC cycles since initGC().
*/
size_t getGCCycles();

}
13 changes: 13 additions & 0 deletions src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2610,6 +2610,11 @@ void EvalState::printStatistics()
#if HAVE_BOEHMGC
GC_word heapSize, totalBytes;
GC_get_heap_usage_safe(&heapSize, 0, 0, 0, &totalBytes);
double gcFullOnlyTime = ({
auto ms = GC_get_full_gc_total_time();
ms * 0.001;
});
auto gcCycles = getGCCycles();
#endif

auto outPath = getEnv("NIX_SHOW_STATS_PATH").value_or("-");
Expand All @@ -2620,6 +2625,13 @@ void EvalState::printStatistics()
#ifndef _WIN32 // TODO implement
topObj["cpuTime"] = cpuTime;
#endif
topObj["time"] = {
{"cpu", cpuTime},
#ifdef HAVE_BOEHMGC
{GC_is_incremental_mode() ? "gcNonIncremental" : "gc", gcFullOnlyTime},
{GC_is_incremental_mode() ? "gcNonIncrementalFraction" : "gcFraction", gcFullOnlyTime / cpuTime},
#endif
};
topObj["envs"] = {
{"number", nrEnvs},
{"elements", nrValuesInEnvs},
Expand Down Expand Up @@ -2661,6 +2673,7 @@ void EvalState::printStatistics()
topObj["gc"] = {
{"heapSize", heapSize},
{"totalBytes", totalBytes},
{"cycles", gcCycles},
};
#endif

Expand Down
12 changes: 11 additions & 1 deletion src/libexpr/primops/fetchTree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,19 @@ static void prim_fetchurl(EvalState & state, const PosIdx pos, Value * * args, V

static RegisterPrimOp primop_fetchurl({
.name = "__fetchurl",
.args = {"url"},
.args = {"arg"},
.doc = R"(
Download the specified URL and return the path of the downloaded file.
`arg` can be either a string denoting the URL, or an attribute set with the following attributes:
- `url`
The URL of the file to download.
- `name` (default: the last path component of the URL)
A name for the file in the store. This can be useful if the URL has any
characters that are invalid for the store.
Not available in [restricted evaluation mode](@docroot@/command-ref/conf-file.md#conf-restrict-eval).
)",
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/build/drv-output-substitution-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Goal::Co DrvOutputSubstitutionGoal::init()
#ifndef _WIN32
outPipe->readSide.get()
#else
&outPipe
&*outPipe
#endif
}, true, false);

Expand Down
3 changes: 3 additions & 0 deletions src/libstore/globals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -304,18 +304,21 @@ template<> void BaseSetting<SandboxMode>::convertToArg(Args & args, const std::s
{
args.addFlag({
.longName = name,
.aliases = aliases,
.description = "Enable sandboxing.",
.category = category,
.handler = {[this]() { override(smEnabled); }}
});
args.addFlag({
.longName = "no-" + name,
.aliases = aliases,
.description = "Disable sandboxing.",
.category = category,
.handler = {[this]() { override(smDisabled); }}
});
args.addFlag({
.longName = "relaxed-" + name,
.aliases = aliases,
.description = "Enable sandboxing, but allow builds to disable it.",
.category = category,
.handler = {[this]() { override(smRelaxed); }}
Expand Down
2 changes: 2 additions & 0 deletions src/libutil/config-impl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ void BaseSetting<T>::convertToArg(Args & args, const std::string & category)
{
args.addFlag({
.longName = name,
.aliases = aliases,
.description = fmt("Set the `%s` setting.", name),
.category = category,
.labels = {"value"},
Expand All @@ -91,6 +92,7 @@ void BaseSetting<T>::convertToArg(Args & args, const std::string & category)
if (isAppendable())
args.addFlag({
.longName = "extra-" + name,
.aliases = aliases,
.description = fmt("Append to the `%s` setting.", name),
.category = category,
.labels = {"value"},
Expand Down
2 changes: 2 additions & 0 deletions src/libutil/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,15 @@ template<> void BaseSetting<bool>::convertToArg(Args & args, const std::string &
{
args.addFlag({
.longName = name,
.aliases = aliases,
.description = fmt("Enable the `%s` setting.", name),
.category = category,
.handler = {[this] { override(true); }},
.experimentalFeature = experimentalFeature,
});
args.addFlag({
.longName = "no-" + name,
.aliases = aliases,
.description = fmt("Disable the `%s` setting.", name),
.category = category,
.handler = {[this] { override(false); }},
Expand Down
6 changes: 5 additions & 1 deletion src/libutil/file-system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,11 @@ void deletePath(const fs::path & path)

void createDir(const Path & path, mode_t mode)
{
if (mkdir(path.c_str(), mode) == -1)
if (mkdir(path.c_str()
#ifndef _WIN32
, mode
#endif
) == -1)
throw SysError("creating directory '%1%'", path);
}

Expand Down
4 changes: 2 additions & 2 deletions src/libutil/fs-sink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void RestoreSink::createRegularFile(const CanonPath & path, std::function<void(C
RestoreRegularFile crf;
crf.fd =
#ifdef _WIN32
CreateFileW(path.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)
CreateFileW(p.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)
#else
open(p.c_str(), O_CREAT | O_EXCL | O_WRONLY | O_CLOEXEC, 0666)
#endif
Expand Down Expand Up @@ -145,7 +145,7 @@ void RestoreRegularFile::operator () (std::string_view data)
void RestoreSink::createSymlink(const CanonPath & path, const std::string & target)
{
auto p = append(dstPath, path);
nix::createSymlink(target, p);
nix::createSymlink(target, p.string());
}


Expand Down
22 changes: 13 additions & 9 deletions src/nix/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,17 @@ nix_sources = files(
'store-info.cc',
'store-repair.cc',
'store.cc',
'unix/daemon.cc',
'upgrade-nix.cc',
'verify.cc',
'why-depends.cc',
)

if host_machine.system() != 'windows'
nix_sources += files(
'unix/daemon.cc',
)
endif

nix_sources += [
gen_header.process('doc/manual/generate-manpage.nix'),
gen_header.process('doc/manual/generate-settings.nix'),
Expand All @@ -104,12 +109,6 @@ nix_sources += [
gen_header.process('help-stores.md'),
]

if host_machine.system() != 'windows'
nix_sources += files(
'unix/daemon.cc',
)
endif

# The rest of the subdirectories aren't separate components,
# just source files in another directory, so we process them here.

Expand Down Expand Up @@ -146,9 +145,7 @@ nix_store_sources = files(
# Hurray for Meson list flattening!
sources = [
nix_sources,
build_remote_sources,
nix_build_sources,
nix_channel_sources,
unpack_channel_gen,
nix_collect_garbage_sources,
nix_copy_closure_sources,
Expand All @@ -158,6 +155,13 @@ sources = [
nix_store_sources,
]

if host_machine.system() != 'windows'
sources += [
build_remote_sources,
nix_channel_sources,
]
endif

include_dirs = [include_directories('.')]

this_exe = executable(
Expand Down
Loading

0 comments on commit dd6c7f0

Please sign in to comment.