From 26b3a1b9ce526b14d92666695c2b712b2d025d15 Mon Sep 17 00:00:00 2001 From: Jade Lovelace Date: Wed, 29 May 2024 15:56:32 -0700 Subject: [PATCH 1/7] unix-domain-socket.cc: add comment explaining why bindConnectProcHelper We reviewed this code a while ago, and we neglected to get a comment in saying why it's Like This at the time. Let's fix that, since it is code that looks very absurd at first glance. Change-Id: Ib67b49605ef9ef1c84ecda1db16be74fc9105398 --- src/libutil/unix-domain-socket.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/libutil/unix-domain-socket.cc b/src/libutil/unix-domain-socket.cc index a9a2a415a..a6e46ca50 100644 --- a/src/libutil/unix-domain-socket.cc +++ b/src/libutil/unix-domain-socket.cc @@ -37,6 +37,17 @@ AutoCloseFD createUnixDomainSocket(const Path & path, mode_t mode) return fdSocket; } +/** + * Workaround for the max length of Unix socket names being between 102 + * (darwin) and 108 (Linux), which is extremely short. This limitation is + * caused by historical restrictions on sizeof(struct sockaddr): + * https://unix.stackexchange.com/a/367012. + * + * Our solution here is to start a process inheriting the socket, chdir into + * the directory of the socket, then connect with just the filename. This is + * rather silly but it works around working directory being process-wide state, + * and is as clearly sound as possible. + */ static void bindConnectProcHelper( std::string_view operationName, auto && operation, int fd, const std::string & path) From 031d92411637904a8ed759dc80bc474213dd4fa9 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Tue, 14 May 2024 12:13:40 -0700 Subject: [PATCH 2/7] libutil/args: warn on unknown settings after parsing all flags Upstream change: https://github.com/NixOS/nix/pull/10701 Change-Id: Icf271df57ec529dd8c64667d1ef9f6dbf02d33d3 --- doc/manual/change-authors.yml | 4 +++ .../rl-next/fix-silent-unknown-options.md | 30 +++++++++++++++++++ src/libutil/args.cc | 8 +---- tests/functional/eval.sh | 4 +++ tests/functional/misc.sh | 9 ++++++ 5 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 doc/manual/rl-next/fix-silent-unknown-options.md diff --git a/doc/manual/change-authors.yml b/doc/manual/change-authors.yml index 98a135397..c56f588ca 100644 --- a/doc/manual/change-authors.yml +++ b/doc/manual/change-authors.yml @@ -36,6 +36,10 @@ artemist: display_name: Artemis Tosini forgejo: artemist +cole-h: + display_name: Cole Helbling + github: cole-h + edolstra: display_name: Eelco Dolstra github: edolstra diff --git a/doc/manual/rl-next/fix-silent-unknown-options.md b/doc/manual/rl-next/fix-silent-unknown-options.md new file mode 100644 index 000000000..679cc26e8 --- /dev/null +++ b/doc/manual/rl-next/fix-silent-unknown-options.md @@ -0,0 +1,30 @@ +--- +synopsis: Warn on unknown settings anywhere in the command line +prs: 10701 +credits: [cole-h] +category: Improvements +--- + +All `nix` commands will now properly warn when an unknown option is specified anywhere in the command line. + +Before: + +```console +$ nix-instantiate --option foobar baz --expr '{}' +warning: unknown setting 'foobar' +$ nix-instantiate '{}' --option foobar baz --expr +$ nix eval --expr '{}' --option foobar baz +{ } +``` + +After: + +```console +$ nix-instantiate --option foobar baz --expr '{}' +warning: unknown setting 'foobar' +$ nix-instantiate '{}' --option foobar baz --expr +warning: unknown setting 'foobar' +$ nix eval --expr '{}' --option foobar baz +warning: unknown setting 'foobar' +{ } +``` diff --git a/src/libutil/args.cc b/src/libutil/args.cc index 4983e49af..655b3e82f 100644 --- a/src/libutil/args.cc +++ b/src/libutil/args.cc @@ -93,7 +93,6 @@ void RootArgs::parseCmdline(const Strings & _cmdline) verbosity = lvlError; } - bool argsSeen = false; for (auto pos = cmdline.begin(); pos != cmdline.end(); ) { auto arg = *pos; @@ -122,10 +121,6 @@ void RootArgs::parseCmdline(const Strings & _cmdline) throw UsageError("unrecognised flag '%1%'", arg); } else { - if (!argsSeen) { - argsSeen = true; - initialFlagsProcessed(); - } pos = rewriteArgs(cmdline, pos); pendingArgs.push_back(*pos++); if (processArgs(pendingArgs, false)) @@ -135,8 +130,7 @@ void RootArgs::parseCmdline(const Strings & _cmdline) processArgs(pendingArgs, true); - if (!argsSeen) - initialFlagsProcessed(); + initialFlagsProcessed(); /* Now that we are done parsing, make sure that any experimental * feature required by the flags is enabled */ diff --git a/tests/functional/eval.sh b/tests/functional/eval.sh index 2b34caddb..9c125b569 100644 --- a/tests/functional/eval.sh +++ b/tests/functional/eval.sh @@ -51,3 +51,7 @@ mkdir -p $TEST_ROOT/xyzzy $TEST_ROOT/foo ln -sfn ../xyzzy $TEST_ROOT/foo/bar printf 123 > $TEST_ROOT/xyzzy/default.nix [[ $(nix eval --impure --expr "import $TEST_ROOT/foo/bar") = 123 ]] + +# Test that unknown settings are warned about +out="$(expectStderr 0 nix eval --option foobar baz --expr '""' --raw)" +[[ "$(echo "$out" | grep foobar | wc -l)" = 1 ]] diff --git a/tests/functional/misc.sh b/tests/functional/misc.sh index af96d20bd..d4379b7ce 100644 --- a/tests/functional/misc.sh +++ b/tests/functional/misc.sh @@ -30,3 +30,12 @@ expectStderr 1 nix-instantiate --eval -E '[]' -A 'x' | grepQuiet "should be a se expectStderr 1 nix-instantiate --eval -E '{}' -A '1' | grepQuiet "should be a list" expectStderr 1 nix-instantiate --eval -E '{}' -A '.' | grepQuiet "empty attribute name" expectStderr 1 nix-instantiate --eval -E '[]' -A '1' | grepQuiet "out of range" + +# Unknown setting warning +# NOTE(cole-h): behavior is different depending on the order, which is why we test an unknown option +# before and after the `'{}'`! +out="$(expectStderr 0 nix-instantiate --option foobar baz --expr '{}')" +[[ "$(echo "$out" | grep foobar | wc -l)" = 1 ]] + +out="$(expectStderr 0 nix-instantiate '{}' --option foobar baz --expr )" +[[ "$(echo "$out" | grep foobar | wc -l)" = 1 ]] From 285bc67318e2ee4b69b13eb0b8e7b202fc287c51 Mon Sep 17 00:00:00 2001 From: Jade Lovelace Date: Wed, 29 May 2024 20:41:22 -0700 Subject: [PATCH 3/7] =?UTF-8?q?tests/filetransfer:=20re=C3=ABnable=20on=20?= =?UTF-8?q?Darwin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since we put __darwinAllowLocalNetworking in our derivation in I752b81c85ebeaab4e582ac01c239d69d65580f37, this stuff will just work fine. I checked our derivation works on the darwin community builder. Change-Id: I40e3a801d6bb38efede79af4aded65c1e1f57cec --- tests/unit/libstore/filetransfer.cc | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/tests/unit/libstore/filetransfer.cc b/tests/unit/libstore/filetransfer.cc index 0e5c0965e..b74d01516 100644 --- a/tests/unit/libstore/filetransfer.cc +++ b/tests/unit/libstore/filetransfer.cc @@ -13,14 +13,6 @@ #include #include -// local server tests don't work on darwin without some incantations -// the horrors do not want to look up. contributions welcome though! -#if __APPLE__ -#define NOT_ON_DARWIN(n) DISABLED_##n -#else -#define NOT_ON_DARWIN(n) n -#endif - using namespace std::chrono_literals; namespace { @@ -150,7 +142,7 @@ TEST(FileTransfer, exceptionAbortsDownload) } } -TEST(FileTransfer, NOT_ON_DARWIN(reportsSetupErrors)) +TEST(FileTransfer, reportsSetupErrors) { auto [port, srv] = serveHTTP("404 not found", "", [] { return ""; }); auto ft = makeFileTransfer(); @@ -159,7 +151,7 @@ TEST(FileTransfer, NOT_ON_DARWIN(reportsSetupErrors)) FileTransferError); } -TEST(FileTransfer, NOT_ON_DARWIN(reportsTransferError)) +TEST(FileTransfer, reportsTransferError) { auto [port, srv] = serveHTTP("200 ok", "content-length: 100\r\n", [] { std::this_thread::sleep_for(10ms); @@ -171,7 +163,7 @@ TEST(FileTransfer, NOT_ON_DARWIN(reportsTransferError)) ASSERT_THROW(ft->download(req), FileTransferError); } -TEST(FileTransfer, NOT_ON_DARWIN(handlesContentEncoding)) +TEST(FileTransfer, handlesContentEncoding) { std::string original = "Test data string"; std::string compressed = compress("gzip", original); From 7575db522e9008685c4009423398f6900a16bcce Mon Sep 17 00:00:00 2001 From: Jade Lovelace Date: Wed, 29 May 2024 21:12:34 -0700 Subject: [PATCH 4/7] Remove 100s of CPU time (10%) from build times (1465s -> 1302s) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I saw that boost/lexical_cast was costing about 100s in CPU time on our compiles. We can fix this trivially by doing explicit template instantiation in exactly one place and eliminating all other includes of it, which is a code improvement anyway by hiding the boost. Before: ``` lix/lix2 » ClangBuildAnalyzer --analyze buildtimeold.bin Analyzing build trace from 'buildtimeold.bin'... **** Time summary: Compilation (551 times): Parsing (frontend): 1465.3 s Codegen & opts (backend): 1110.9 s **** Expensive headers: 178153 ms: ../src/libcmd/installable-value.hh (included 52 times, avg 3426 ms), included via: 40x: command.hh 5x: command-installable-value.hh 3x: installable-flake.hh 2x: 2x: installable-attr-path.hh 176217 ms: ../src/libutil/error.hh (included 246 times, avg 716 ms), included via: 36x: command.hh installable-value.hh installables.hh derived-path.hh config.hh experimental-features.hh 12x: globals.hh config.hh experimental-features.hh 11x: file-system.hh file-descriptor.hh 6x: serialise.hh strings.hh 6x: 6x: archive.hh serialise.hh strings.hh ... 173243 ms: ../src/libstore/store-api.hh (included 152 times, avg 1139 ms), included via: 55x: 39x: command.hh installable-value.hh installables.hh 7x: libexpr.hh 4x: local-store.hh 4x: command-installable-value.hh installable-value.hh installables.hh 3x: binary-cache-store.hh ... 170482 ms: ../src/libutil/serialise.hh (included 201 times, avg 848 ms), included via: 37x: command.hh installable-value.hh installables.hh built-path.hh realisation.hh hash.hh 14x: store-api.hh nar-info.hh hash.hh 11x: 7x: primops.hh eval.hh attr-set.hh nixexpr.hh value.hh source-path.hh archive.hh 7x: libexpr.hh value.hh source-path.hh archive.hh 6x: fetchers.hh hash.hh ... 169397 ms: ../src/libcmd/installables.hh (included 53 times, avg 3196 ms), included via: 40x: command.hh installable-value.hh 5x: command-installable-value.hh installable-value.hh 3x: installable-flake.hh installable-value.hh 2x: 1x: installable-derived-path.hh 1x: installable-value.hh ... 159740 ms: ../src/libutil/strings.hh (included 221 times, avg 722 ms), included via: 37x: command.hh installable-value.hh installables.hh built-path.hh realisation.hh hash.hh serialise.hh 19x: 14x: store-api.hh nar-info.hh hash.hh serialise.hh 11x: serialise.hh 7x: primops.hh eval.hh attr-set.hh nixexpr.hh value.hh source-path.hh archive.hh serialise.hh 7x: libexpr.hh value.hh source-path.hh archive.hh serialise.hh ... 156796 ms: ../src/libcmd/command.hh (included 51 times, avg 3074 ms), included via: 42x: 7x: command-installable-value.hh 2x: installable-attr-path.hh 150392 ms: ../src/libutil/types.hh (included 251 times, avg 599 ms), included via: 36x: command.hh installable-value.hh installables.hh path.hh 11x: file-system.hh 10x: globals.hh 6x: fetchers.hh 6x: serialise.hh strings.hh error.hh 5x: archive.hh ... 133101 ms: /nix/store/644b90j1vms44nr18yw3520pzkrg4dd1-boost-1.81.0-dev/include/boost/lexical_cast.hpp (included 226 times, avg 588 ms), included via : 37x: command.hh installable-value.hh installables.hh built-path.hh realisation.hh hash.hh serialise.hh strings.hh 19x: file-system.hh 11x: store-api.hh nar-info.hh hash.hh serialise.hh strings.hh 7x: primops.hh eval.hh attr-set.hh nixexpr.hh value.hh source-path.hh archive.hh serialise.hh strings.hh 7x: libexpr.hh value.hh source-path.hh archive.hh serialise.hh strings.hh 6x: eval.hh attr-set.hh nixexpr.hh value.hh source-path.hh archive.hh serialise.hh strings.hh ... 132887 ms: /nix/store/h2abv2l8irqj942i5rq9wbrj42kbsh5y-gcc-12.3.0/include/c++/12.3.0/memory (included 262 times, avg 507 ms), included via: 36x: command.hh installable-value.hh installables.hh path.hh types.hh ref.hh 16x: gtest.h 11x: file-system.hh types.hh ref.hh 10x: globals.hh types.hh ref.hh 10x: json.hpp 6x: serialise.hh ... done in 0.6s. ``` After: ``` lix/lix2 » maintainers/buildtime_report.sh build Processing all files and saving to '/home/jade/lix/lix2/maintainers/../buildtime.bin'... done in 0.6s. Run 'ClangBuildAnalyzer --analyze /home/jade/lix/lix2/maintainers/../buildtime.bin' to analyze it. Analyzing build trace from '/home/jade/lix/lix2/maintainers/../buildtime.bin'... **** Time summary: Compilation (551 times): Parsing (frontend): 1302.1 s Codegen & opts (backend): 956.3 s **** Expensive headers: 178145 ms: ../src/libutil/error.hh (included 246 times, avg 724 ms), included via: 36x: command.hh installable-value.hh installables.hh derived-path.hh config.hh experimental-features.hh 12x: globals.hh config.hh experimental-features.hh 11x: file-system.hh file-descriptor.hh 6x: 6x: serialise.hh strings.hh 6x: fetchers.hh hash.hh serialise.hh strings.hh ... 154043 ms: ../src/libcmd/installable-value.hh (included 52 times, avg 2962 ms), included via: 40x: command.hh 5x: command-installable-value.hh 3x: installable-flake.hh 2x: 2x: installable-attr-path.hh 153593 ms: ../src/libstore/store-api.hh (included 152 times, avg 1010 ms), included via: 55x: 39x: command.hh installable-value.hh installables.hh 7x: libexpr.hh 4x: local-store.hh 4x: command-installable-value.hh installable-value.hh installables.hh 3x: binary-cache-store.hh ... 149948 ms: ../src/libutil/types.hh (included 251 times, avg 597 ms), included via: 36x: command.hh installable-value.hh installables.hh path.hh 11x: file-system.hh 10x: globals.hh 6x: fetchers.hh 6x: serialise.hh strings.hh error.hh 5x: archive.hh ... 144560 ms: ../src/libcmd/installables.hh (included 53 times, avg 2727 ms), included via: 40x: command.hh installable-value.hh 5x: command-installable-value.hh installable-value.hh 3x: installable-flake.hh installable-value.hh 2x: 1x: installable-value.hh 1x: installable-derived-path.hh ... 136585 ms: ../src/libcmd/command.hh (included 51 times, avg 2678 ms), included via: 42x: 7x: command-installable-value.hh 2x: installable-attr-path.hh 133394 ms: /nix/store/h2abv2l8irqj942i5rq9wbrj42kbsh5y-gcc-12.3.0/include/c++/12.3.0/memory (included 262 times, avg 509 ms), included via: 36x: command.hh installable-value.hh installables.hh path.hh types.hh ref.hh 16x: gtest.h 11x: file-system.hh types.hh ref.hh 10x: globals.hh types.hh ref.hh 10x: json.hpp 6x: serialise.hh ... 89315 ms: ../src/libstore/derived-path.hh (included 178 times, avg 501 ms), included via: 37x: command.hh installable-value.hh installables.hh 25x: store-api.hh realisation.hh 7x: primops.hh eval.hh attr-set.hh nixexpr.hh value.hh context.hh 6x: eval.hh attr-set.hh nixexpr.hh value.hh context.hh 6x: libexpr.hh value.hh context.hh 6x: shared.hh ... 87347 ms: /nix/store/h2abv2l8irqj942i5rq9wbrj42kbsh5y-gcc-12.3.0/include/c++/12.3.0/ostream (included 273 times, avg 319 ms), included via: 35x: command.hh installable-value.hh installables.hh path.hh types.hh ref.hh memory unique_ptr.h 12x: regex sstream istream 10x: file-system.hh types.hh ref.hh memory unique_ptr.h 10x: gtest.h memory unique_ptr.h 10x: globals.hh types.hh ref.hh memory unique_ptr.h 6x: fetchers.hh types.hh ref.hh memory unique_ptr.h ... 85249 ms: ../src/libutil/config.hh (included 213 times, avg 400 ms), included via: 37x: command.hh installable-value.hh installables.hh derived-path.hh 20x: globals.hh 20x: logging.hh 16x: store-api.hh logging.hh 6x: 6x: eval.hh attr-set.hh nixexpr.hh value.hh context.hh derived-path.hh ... done in 0.5s. ``` Change-Id: I27f0a2d566db17832cd9be935f12efe7f95b92d0 --- src/libexpr/eval.cc | 2 +- src/libexpr/lexer.l | 10 +++--- src/libexpr/nixexpr.cc | 1 + src/libexpr/primops.cc | 1 + src/libexpr/print.cc | 1 + src/libmain/progress-bar.cc | 1 + src/libstore/binary-cache-store.cc | 1 + src/libstore/build/local-derivation-goal.cc | 5 ++- src/libstore/daemon.cc | 2 ++ src/libstore/machines.cc | 2 +- src/libutil/current-process.cc | 1 + src/libutil/file-system.hh | 2 -- src/libutil/logging.cc | 1 + src/libutil/processes.hh | 2 -- src/libutil/strings.cc | 39 +++++++++++++++++++++ src/libutil/strings.hh | 21 ++--------- src/nix-env/user-env.cc | 3 +- src/nix/develop.cc | 1 + 18 files changed, 64 insertions(+), 32 deletions(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index c9a624eeb..c72b69af2 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -29,7 +30,6 @@ #include #include #include -#include #include #include diff --git a/src/libexpr/lexer.l b/src/libexpr/lexer.l index 1780f5cb9..1c1cdd673 100644 --- a/src/libexpr/lexer.l +++ b/src/libexpr/lexer.l @@ -26,10 +26,9 @@ #pragma clang diagnostic ignored "-Wimplicit-fallthrough" #endif -#include - #include "nixexpr.hh" #include "parser-tab.hh" +#include "strings.hh" using namespace nix; @@ -132,9 +131,10 @@ or { return OR_KW; } {ID} { yylval->id = {yytext, (size_t) yyleng}; return ID; } {INT} { errno = 0; - try { - yylval->n = boost::lexical_cast(yytext); - } catch (const boost::bad_lexical_cast &) { + std::optional numMay = string2Int(yytext); + if (numMay.has_value()) { + yylval->n = *numMay; + } else { throw ParseError(ErrorInfo{ .msg = HintFmt("invalid integer '%1%'", yytext), .pos = state->positions[CUR_POS], diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index 6a1aa8f35..664872882 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -6,6 +6,7 @@ #include "escape-string.hh" #include +#include namespace nix { diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index f8ce90ac1..3cc2659fb 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -25,6 +25,7 @@ #include #include +#include #include #include diff --git a/src/libexpr/print.cc b/src/libexpr/print.cc index c56b0e72e..e387a09fb 100644 --- a/src/libexpr/print.cc +++ b/src/libexpr/print.cc @@ -1,6 +1,7 @@ #include #include #include +#include #include "escape-string.hh" #include "print.hh" diff --git a/src/libmain/progress-bar.cc b/src/libmain/progress-bar.cc index 11b2fe800..d83b09cd4 100644 --- a/src/libmain/progress-bar.cc +++ b/src/libmain/progress-bar.cc @@ -7,6 +7,7 @@ #include #include #include +#include #include #include diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc index e9413cf99..ea643fd31 100644 --- a/src/libstore/binary-cache-store.cc +++ b/src/libstore/binary-cache-store.cc @@ -16,6 +16,7 @@ #include #include #include +#include #include diff --git a/src/libstore/build/local-derivation-goal.cc b/src/libstore/build/local-derivation-goal.cc index 479b4ffeb..99468d420 100644 --- a/src/libstore/build/local-derivation-goal.cc +++ b/src/libstore/build/local-derivation-goal.cc @@ -64,10 +64,13 @@ extern "C" int sandbox_init_with_parameters(const char *profile, uint64_t flags, namespace nix { +namespace { /** * The system for which Nix is compiled. */ -constexpr std::string_view nativeSystem = SYSTEM; +[[gnu::unused]] +constexpr const std::string_view nativeSystem = SYSTEM; +} void handleDiffHook( uid_t uid, uid_t gid, diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc index 420fc8bfe..641910bd7 100644 --- a/src/libstore/daemon.cc +++ b/src/libstore/daemon.cc @@ -14,6 +14,8 @@ #include "derivations.hh" #include "args.hh" +#include + namespace nix::daemon { Sink & operator << (Sink & sink, const Logger::Fields & fields) diff --git a/src/libstore/machines.cc b/src/libstore/machines.cc index cdd1e1c2c..833482815 100644 --- a/src/libstore/machines.cc +++ b/src/libstore/machines.cc @@ -140,7 +140,7 @@ static Machine parseBuilderLine(const std::string & line) }; auto parseFloatField = [&](size_t fieldIndex) { - const auto result = string2Int(tokens[fieldIndex]); + const auto result = string2Float(tokens[fieldIndex]); if (!result) { throw FormatError("bad machine specification: failed to convert column #%lu in a row: '%s' to 'float'", fieldIndex, line); } diff --git a/src/libutil/current-process.cc b/src/libutil/current-process.cc index c64dd1e0d..3c037c33f 100644 --- a/src/libutil/current-process.cc +++ b/src/libutil/current-process.cc @@ -5,6 +5,7 @@ #include "namespaces.hh" #include "signals.hh" #include "strings.hh" +#include #ifdef __APPLE__ # include diff --git a/src/libutil/file-system.hh b/src/libutil/file-system.hh index b9b753980..6c1923d55 100644 --- a/src/libutil/file-system.hh +++ b/src/libutil/file-system.hh @@ -13,8 +13,6 @@ #include #include -#include - #include #include diff --git a/src/libutil/logging.cc b/src/libutil/logging.cc index febbfdb55..b01bb4dd4 100644 --- a/src/libutil/logging.cc +++ b/src/libutil/logging.cc @@ -6,6 +6,7 @@ #include "terminal.hh" #include +#include #include namespace nix { diff --git a/src/libutil/processes.hh b/src/libutil/processes.hh index 91a4edfd2..b84fc7c4b 100644 --- a/src/libutil/processes.hh +++ b/src/libutil/processes.hh @@ -10,8 +10,6 @@ #include #include -#include - #include #include #include diff --git a/src/libutil/strings.cc b/src/libutil/strings.cc index 9cb319cce..947478481 100644 --- a/src/libutil/strings.cc +++ b/src/libutil/strings.cc @@ -1,4 +1,6 @@ #include "strings.hh" +#include +#include namespace nix { @@ -89,6 +91,43 @@ std::string Rewriter::operator()(std::string s) return s; } +template +std::optional string2Int(const std::string_view s) +{ + if (s.substr(0, 1) == "-" && !std::numeric_limits::is_signed) + return std::nullopt; + try { + return boost::lexical_cast(s.data(), s.size()); + } catch (const boost::bad_lexical_cast &) { + return std::nullopt; + } +} + +// Explicitly instantiated in one place for faster compilation +template std::optional string2Int(const std::string_view s); +template std::optional string2Int(const std::string_view s); +template std::optional string2Int(const std::string_view s); +template std::optional string2Int(const std::string_view s); +template std::optional string2Int(const std::string_view s); +template std::optional string2Int(const std::string_view s); +template std::optional string2Int(const std::string_view s); +template std::optional string2Int(const std::string_view s); +template std::optional string2Int(const std::string_view s); +template std::optional string2Int(const std::string_view s); + +template +std::optional string2Float(const std::string_view s) +{ + try { + return boost::lexical_cast(s.data(), s.size()); + } catch (const boost::bad_lexical_cast &) { + return std::nullopt; + } +} + +template std::optional string2Float(const std::string_view s); +template std::optional string2Float(const std::string_view s); + std::string toLower(const std::string & s) { diff --git a/src/libutil/strings.hh b/src/libutil/strings.hh index daeb5be50..03dff8160 100644 --- a/src/libutil/strings.hh +++ b/src/libutil/strings.hh @@ -4,7 +4,6 @@ #include "error.hh" #include "types.hh" -#include #include namespace nix { @@ -130,16 +129,7 @@ inline std::string rewriteStrings(std::string s, const StringMap & rewrites) * Parse a string into an integer. */ template -std::optional string2Int(const std::string_view s) -{ - if (s.substr(0, 1) == "-" && !std::numeric_limits::is_signed) - return std::nullopt; - try { - return boost::lexical_cast(s.data(), s.size()); - } catch (const boost::bad_lexical_cast &) { - return std::nullopt; - } -} +std::optional string2Int(const std::string_view s); /** * Like string2Int(), but support an optional suffix 'K', 'M', 'G' or @@ -169,14 +159,7 @@ N string2IntWithUnitPrefix(std::string_view s) * Parse a string into a float. */ template -std::optional string2Float(const std::string_view s) -{ - try { - return boost::lexical_cast(s.data(), s.size()); - } catch (const boost::bad_lexical_cast &) { - return std::nullopt; - } -} +std::optional string2Float(const std::string_view s); /** diff --git a/src/nix-env/user-env.cc b/src/nix-env/user-env.cc index 530039ac6..f5dbd06ca 100644 --- a/src/nix-env/user-env.cc +++ b/src/nix-env/user-env.cc @@ -9,8 +9,9 @@ #include "eval-inline.hh" #include "profiles.hh" #include "print-ambiguous.hh" -#include +#include +#include namespace nix { diff --git a/src/nix/develop.cc b/src/nix/develop.cc index cd32bb20a..90bdf3bed 100644 --- a/src/nix/develop.cc +++ b/src/nix/develop.cc @@ -11,6 +11,7 @@ #include #include +#include #include #include From 647579367827d2db54ad773ecb30ebb1782fa578 Mon Sep 17 00:00:00 2001 From: Qyriad Date: Thu, 30 May 2024 00:40:25 -0600 Subject: [PATCH 5/7] build: fix static aws-cpp-sdk Change-Id: I310830951106f194f6960a6b2d52b5081a7f6156 --- meson.build | 4 ++-- package.nix | 3 ++- subprojects/aws_sdk/meson.build | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 subprojects/aws_sdk/meson.build diff --git a/meson.build b/meson.build index 16cf80cf4..9db764f00 100644 --- a/meson.build +++ b/meson.build @@ -203,7 +203,7 @@ openssl = dependency('libcrypto', 'openssl', required : true) deps += openssl aws_sdk = dependency('aws-cpp-sdk-core', required : false) -aws_sdk_transfer = dependency('aws-cpp-sdk-transfer', required : aws_sdk.found()) +aws_sdk_transfer = dependency('aws-cpp-sdk-transfer', required : aws_sdk.found(), fallback : ['aws_sdk', 'aws_cpp_sdk_transfer_dep']) if aws_sdk.found() # The AWS pkg-config adds -std=c++11. # https://github.com/aws/aws-sdk-cpp/issues/2673 @@ -230,7 +230,7 @@ if aws_sdk.found() ) endif -aws_s3 = dependency('aws-cpp-sdk-s3', required : false) +aws_s3 = dependency('aws-cpp-sdk-s3', required : aws_sdk.found(), fallback : ['aws_sdk', 'aws_cpp_sdk_s3_dep']) if aws_s3.found() # The AWS pkg-config adds -std=c++11. # https://github.com/aws/aws-sdk-cpp/issues/2673 diff --git a/package.nix b/package.nix index cc5902a91..6251b28ba 100644 --- a/package.nix +++ b/package.nix @@ -144,6 +144,7 @@ let ./meson.options ./meson ./scripts/meson.build + ./subprojects ]); functionalTestFiles = fileset.unions [ @@ -259,7 +260,7 @@ stdenv.mkDerivation (finalAttrs: { ++ lib.optional internalApiDocs rapidcheck ++ lib.optional hostPlatform.isx86_64 libcpuid # There have been issues building these dependencies - ++ lib.optional (hostPlatform == buildPlatform) aws-sdk-cpp-nix + ++ lib.optional (hostPlatform.canExecute buildPlatform) aws-sdk-cpp-nix ++ lib.optionals (finalAttrs.dontBuild) maybePropagatedInputs; checkInputs = [ diff --git a/subprojects/aws_sdk/meson.build b/subprojects/aws_sdk/meson.build new file mode 100644 index 000000000..8685f8f41 --- /dev/null +++ b/subprojects/aws_sdk/meson.build @@ -0,0 +1,15 @@ +project('aws-sdk', 'cpp') + +# dependency() uses Meson's internal logic and generally relies on pkg-config or CMake, +# but Meson can also use the project's compiler to find a library in the compiler's search +# path. Not in the dependency() function, though. You have to use compiler.find_library(), +# and Meson doesn't have a way to tell dependency() to simply fallback to find_library(). +# It *does* however allow dependency() to fallback to a variable defined in a subproject, +# Hence: this file. + +# For some reason, these specific components of the AWS C++ SDK aren't found by CMake when +# compiling statically, and `pkgsStatic.aws-sdk-cpp` doesn't even have a pkg-config at all. + +cxx = meson.get_compiler('cpp') +aws_cpp_sdk_transfer_dep = cxx.find_library('aws-cpp-sdk-transfer') +aws_cpp_sdk_s3_dep = cxx.find_library('aws-cpp-sdk-s3') From da95bf8c82dbb9808bc2f80d3b3cf62ef7afea13 Mon Sep 17 00:00:00 2001 From: K900 Date: Thu, 30 May 2024 16:34:28 +0300 Subject: [PATCH 6/7] libstore/filetransfer: remove debug print foo. Change-Id: I7d7db22f68046d2ecf3b594b4ee6fd9c9dac4be1 --- src/libstore/filetransfer.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc index 76da8e415..fd341b2f0 100644 --- a/src/libstore/filetransfer.cc +++ b/src/libstore/filetransfer.cc @@ -196,7 +196,6 @@ struct curlFileTransfer : public FileTransfer result.immutableUrl = match.str(1); else debug("got invalid link header '%s'", value); - warn("foo %s", value); } } } From 6abac7aacc29cce6aab359ba74212a0729dbaa1e Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Wed, 29 May 2024 22:28:47 +0200 Subject: [PATCH 7/7] release-notes: add missing credits/category to consistent-nix-build entry Change-Id: I737422a2ff9d66be30cc432f8c1ddba9b1e71f4f --- doc/manual/rl-next/consistent-nix-build.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/manual/rl-next/consistent-nix-build.md b/doc/manual/rl-next/consistent-nix-build.md index d5929dc8e..7e9fb5f49 100644 --- a/doc/manual/rl-next/consistent-nix-build.md +++ b/doc/manual/rl-next/consistent-nix-build.md @@ -1,5 +1,8 @@ --- synopsis: Show all FOD errors with `nix build --keep-going` +credits: [ma27] +category: Improvements +cls: [1108] --- `nix build --keep-going` now behaves consistently with `nix-build --keep-going`. This means