diff options
30 files changed, 203 insertions, 86 deletions
diff --git a/doc/manual/book.toml b/doc/manual/book.toml index 1030f96bb..27c6c4637 100644 --- a/doc/manual/book.toml +++ b/doc/manual/book.toml @@ -11,6 +11,10 @@ additional-js = ["redirects.js"] # to just submit a Gerrit CL by the web for trivial stuff. edit-url-template = "https://github.com/lix-project/lix/tree/main/doc/manual/{path}" git-repository-url = "https://git.lix.systems/lix-project/lix" +# Folding by default would prevent things like "Ctrl+F for nix-env" from working +# trivially, but the user should be able to fold if they want to. +fold.enable = true +fold.level = 30 # Handles replacing @docroot@ with a path to ./src relative to that markdown file, # {{#include handlebars}}, and the @generated@ syntax used within these. it mostly 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/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 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/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 05503ae98..6251b28ba 100644 --- a/package.nix +++ b/package.nix @@ -85,6 +85,7 @@ let inherit (__forDefaults) canRunInstalled; inherit (lib) fileset; + inherit (stdenv) hostPlatform buildPlatform; version = lib.fileContents ./.version + versionSuffix; @@ -143,6 +144,7 @@ let ./meson.options ./meson ./scripts/meson.build + ./subprojects ]); functionalTestFiles = fileset.unions [ @@ -187,23 +189,23 @@ stdenv.mkDerivation (finalAttrs: { dontBuild = false; mesonFlags = - lib.optionals stdenv.hostPlatform.isLinux [ + lib.optionals hostPlatform.isLinux [ # You'd think meson could just find this in PATH, but busybox is in buildInputs, # which don't actually get added to PATH. And buildInputs is correct over # nativeBuildInputs since this should be a busybox executable on the host. "-Dsandbox-shell=${lib.getExe' busybox-sandbox-shell "busybox"}" ] - ++ lib.optional stdenv.hostPlatform.isStatic "-Denable-embedded-sandbox-shell=true" + ++ lib.optional hostPlatform.isStatic "-Denable-embedded-sandbox-shell=true" ++ lib.optional (finalAttrs.dontBuild) "-Denable-build=false" ++ [ # mesonConfigurePhase automatically passes -Dauto_features=enabled, # so we must explicitly enable or disable features that we are not passing # dependencies for. (lib.mesonEnable "internal-api-docs" internalApiDocs) - (lib.mesonBool "enable-tests" finalAttrs.doCheck) + (lib.mesonBool "enable-tests" finalAttrs.finalPackage.doCheck) (lib.mesonBool "enable-docs" canRunInstalled) ] - ++ lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) "--cross-file=${mesonCrossFile}"; + ++ lib.optional (hostPlatform != buildPlatform) "--cross-file=${mesonCrossFile}"; # We only include CMake so that Meson can locate toml11, which only ships CMake dependency metadata. dontUseCmakeConfigure = true; @@ -231,7 +233,7 @@ stdenv.mkDerivation (finalAttrs: { jq lsof ] - ++ lib.optional stdenv.hostPlatform.isLinux util-linuxMinimal + ++ lib.optional hostPlatform.isLinux util-linuxMinimal ++ lib.optional (!officialRelease && buildUnreleasedNotes) build-release-notes ++ lib.optional internalApiDocs doxygen; @@ -251,14 +253,14 @@ stdenv.mkDerivation (finalAttrs: { toml11 lix-doc ] - ++ lib.optionals stdenv.hostPlatform.isLinux [ + ++ lib.optionals hostPlatform.isLinux [ libseccomp busybox-sandbox-shell ] ++ lib.optional internalApiDocs rapidcheck - ++ lib.optional stdenv.hostPlatform.isx86_64 libcpuid + ++ lib.optional hostPlatform.isx86_64 libcpuid # There have been issues building these dependencies - ++ lib.optional (stdenv.hostPlatform == stdenv.buildPlatform) aws-sdk-cpp-nix + ++ lib.optional (hostPlatform.canExecute buildPlatform) aws-sdk-cpp-nix ++ lib.optionals (finalAttrs.dontBuild) maybePropagatedInputs; checkInputs = [ @@ -278,18 +280,18 @@ stdenv.mkDerivation (finalAttrs: { }; preConfigure = - lib.optionalString (!finalAttrs.dontBuild && !stdenv.hostPlatform.isStatic) '' + lib.optionalString (!finalAttrs.dontBuild && !hostPlatform.isStatic) '' # Copy libboost_context so we don't get all of Boost in our closure. # https://github.com/NixOS/nixpkgs/issues/45462 mkdir -p $out/lib cp -pd ${boost}/lib/{libboost_context*,libboost_thread*,libboost_system*} $out/lib rm -f $out/lib/*.a '' - + lib.optionalString (!finalAttrs.dontBuild && stdenv.hostPlatform.isLinux) '' + + lib.optionalString (!finalAttrs.dontBuild && hostPlatform.isLinux && !hostPlatform.isStatic) '' chmod u+w $out/lib/*.so.* patchelf --set-rpath $out/lib:${stdenv.cc.cc.lib}/lib $out/lib/libboost_thread.so.* '' - + lib.optionalString (!finalAttrs.dontBuild && stdenv.hostPlatform.isDarwin) '' + + lib.optionalString (!finalAttrs.dontBuild && hostPlatform.isDarwin) '' for LIB in $out/lib/*.dylib; do chmod u+w $LIB install_name_tool -id $LIB $LIB @@ -333,7 +335,7 @@ stdenv.mkDerivation (finalAttrs: { mkdir -p $doc/nix-support echo "doc manual $doc/share/doc/nix/manual" >> $doc/nix-support/hydra-build-products '' - + lib.optionalString stdenv.hostPlatform.isStatic '' + + lib.optionalString hostPlatform.isStatic '' mkdir -p $out/nix-support echo "file binary-dist $out/bin/nix" >> $out/nix-support/hydra-build-products '' @@ -364,12 +366,12 @@ stdenv.mkDerivation (finalAttrs: { runHook postInstallCheck ''; - separateDebugInfo = !stdenv.hostPlatform.isStatic && !finalAttrs.dontBuild; + separateDebugInfo = !hostPlatform.isStatic && !finalAttrs.dontBuild; strictDeps = true; # strictoverflow is disabled because we trap on signed overflow instead - hardeningDisable = [ "strictoverflow" ] ++ lib.optional stdenv.hostPlatform.isStatic "pie"; + hardeningDisable = [ "strictoverflow" ] ++ lib.optional hostPlatform.isStatic "pie"; meta = { mainProgram = "nix"; @@ -398,7 +400,7 @@ stdenv.mkDerivation (finalAttrs: { contribNotice, }: let - glibcFix = lib.optionalAttrs (stdenv.buildPlatform.isLinux && glibcLocales != null) { + glibcFix = lib.optionalAttrs (buildPlatform.isLinux && glibcLocales != null) { # Required to make non-NixOS Linux not complain about missing locale files during configure in a dev shell LOCALE_ARCHIVE = "${lib.getLib pkgs.glibcLocales}/lib/locale/locale-archive"; }; @@ -416,13 +418,19 @@ stdenv.mkDerivation (finalAttrs: { name = "lix-shell-env"; - inputsFrom = [ finalAttrs ]; + # finalPackage is necessary to propagate stuff that is set by mkDerivation itself, + # like doCheck. + inputsFrom = [ finalAttrs.finalPackage ]; # For Meson to find Boost. env = finalAttrs.env; + # I guess this is necessary because mesonFlags to mkDerivation doesn't propagate in inputsFrom, + # which only propagates stuff set in hooks? idk. + inherit (finalAttrs) mesonFlags; + packages = - lib.optional (stdenv.cc.isClang && stdenv.hostPlatform == stdenv.buildPlatform) clang-tools_llvm + lib.optional (stdenv.cc.isClang && hostPlatform == buildPlatform) clang-tools_llvm ++ [ just nixfmt @@ -435,37 +443,41 @@ stdenv.mkDerivation (finalAttrs: { llvmPackages.clang-unwrapped.dev ] ++ lib.optional (pre-commit-checks ? enabledPackages) pre-commit-checks.enabledPackages - ++ lib.optional (lib.meta.availableOn stdenv.buildPlatform clangbuildanalyzer) clangbuildanalyzer + ++ lib.optional (lib.meta.availableOn buildPlatform clangbuildanalyzer) clangbuildanalyzer ++ finalAttrs.checkInputs; shellHook = '' # don't re-run the hook in (other) nested nix-shells - if [[ $name != lix-shell-env ]]; then - return; - fi - - PATH=$prefix/bin:$PATH - unset PYTHONPATH - export MANPATH=$out/share/man:$MANPATH - - # Make bash completion work. - XDG_DATA_DIRS+=:$out/share - - ${lib.optionalString (pre-commit-checks ? shellHook) pre-commit-checks.shellHook} - # Allow `touch .nocontribmsg` to turn this notice off. - if ! [[ -f .nocontribmsg ]]; then - cat ${contribNotice} - fi - - # Install the Gerrit commit-msg hook. - # (git common dir is the main .git, including for worktrees) - if gitcommondir=$(git rev-parse --git-common-dir 2>/dev/null) && [[ ! -f "$gitcommondir/hooks/commit-msg" ]]; then - echo 'Installing Gerrit commit-msg hook (adds Change-Id to commit messages)' >&2 - mkdir -p "$gitcommondir/hooks" - curl -s -Lo "$gitcommondir/hooks/commit-msg" https://gerrit.lix.systems/tools/hooks/commit-msg - chmod u+x "$gitcommondir/hooks/commit-msg" - fi - unset gitcommondir + function lixShellHook() { + if [[ $name != lix-shell-env ]]; then + return; + fi + + PATH=$prefix/bin:$PATH + unset PYTHONPATH + export MANPATH=$out/share/man:$MANPATH + + # Make bash completion work. + XDG_DATA_DIRS+=:$out/share + + ${lib.optionalString (pre-commit-checks ? shellHook) pre-commit-checks.shellHook} + # Allow `touch .nocontribmsg` to turn this notice off. + if ! [[ -f .nocontribmsg ]]; then + cat ${contribNotice} + fi + + # Install the Gerrit commit-msg hook. + # (git common dir is the main .git, including for worktrees) + if gitcommondir=$(git rev-parse --git-common-dir 2>/dev/null) && [[ ! -f "$gitcommondir/hooks/commit-msg" ]]; then + echo 'Installing Gerrit commit-msg hook (adds Change-Id to commit messages)' >&2 + mkdir -p "$gitcommondir/hooks" + curl -s -Lo "$gitcommondir/hooks/commit-msg" https://gerrit.lix.systems/tools/hooks/commit-msg + chmod u+x "$gitcommondir/hooks/commit-msg" + fi + unset gitcommondir + } + + lixShellHook ''; } ); 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 <algorithm> #include <chrono> #include <iostream> +#include <sstream> #include <cstring> #include <optional> #include <unistd.h> @@ -29,7 +30,6 @@ #include <sys/resource.h> #include <fstream> #include <functional> -#include <iostream> #include <sys/resource.h> #include <nlohmann/json.hpp> 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 <boost/lexical_cast.hpp> - #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<int64_t>(yytext); - } catch (const boost::bad_lexical_cast &) { + std::optional<int64_t> numMay = string2Int<int64_t>(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 <cstdlib> +#include <sstream> 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 <algorithm> #include <cstring> +#include <sstream> #include <regex> #include <dlfcn.h> 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 <limits> #include <span> #include <unordered_set> +#include <sstream> #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 <atomic> #include <map> #include <thread> +#include <sstream> #include <iostream> #include <chrono> 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 <future> #include <regex> #include <fstream> +#include <sstream> #include <nlohmann/json.hpp> 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 <sstream> + namespace nix::daemon { Sink & operator << (Sink & sink, const Logger::Fields & fields) 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); } } } 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<float>(tokens[fieldIndex]); + const auto result = string2Float<float>(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/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/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 <math.h> #ifdef __APPLE__ # include <mach-o/dyld.h> 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 <dirent.h> #include <unistd.h> -#include <boost/lexical_cast.hpp> - #include <functional> #include <optional> 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 <atomic> +#include <sstream> #include <nlohmann/json.hpp> 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 <unistd.h> #include <signal.h> -#include <boost/lexical_cast.hpp> - #include <functional> #include <map> #include <optional> 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 <boost/lexical_cast.hpp> +#include <stdint.h> namespace nix { @@ -89,6 +91,43 @@ std::string Rewriter::operator()(std::string s) return s; } +template<class N> +std::optional<N> string2Int(const std::string_view s) +{ + if (s.substr(0, 1) == "-" && !std::numeric_limits<N>::is_signed) + return std::nullopt; + try { + return boost::lexical_cast<N>(s.data(), s.size()); + } catch (const boost::bad_lexical_cast &) { + return std::nullopt; + } +} + +// Explicitly instantiated in one place for faster compilation +template std::optional<unsigned char> string2Int<unsigned char>(const std::string_view s); +template std::optional<unsigned short> string2Int<unsigned short>(const std::string_view s); +template std::optional<unsigned int> string2Int<unsigned int>(const std::string_view s); +template std::optional<unsigned long> string2Int<unsigned long>(const std::string_view s); +template std::optional<unsigned long long> string2Int<unsigned long long>(const std::string_view s); +template std::optional<signed char> string2Int<signed char>(const std::string_view s); +template std::optional<signed short> string2Int<signed short>(const std::string_view s); +template std::optional<signed int> string2Int<signed int>(const std::string_view s); +template std::optional<signed long> string2Int<signed long>(const std::string_view s); +template std::optional<signed long long> string2Int<signed long long>(const std::string_view s); + +template<class N> +std::optional<N> string2Float(const std::string_view s) +{ + try { + return boost::lexical_cast<N>(s.data(), s.size()); + } catch (const boost::bad_lexical_cast &) { + return std::nullopt; + } +} + +template std::optional<double> string2Float<double>(const std::string_view s); +template std::optional<float> string2Float<float>(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 <boost/lexical_cast.hpp> #include <vector> namespace nix { @@ -130,16 +129,7 @@ inline std::string rewriteStrings(std::string s, const StringMap & rewrites) * Parse a string into an integer. */ template<class N> -std::optional<N> string2Int(const std::string_view s) -{ - if (s.substr(0, 1) == "-" && !std::numeric_limits<N>::is_signed) - return std::nullopt; - try { - return boost::lexical_cast<N>(s.data(), s.size()); - } catch (const boost::bad_lexical_cast &) { - return std::nullopt; - } -} +std::optional<N> 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<class N> -std::optional<N> string2Float(const std::string_view s) -{ - try { - return boost::lexical_cast<N>(s.data(), s.size()); - } catch (const boost::bad_lexical_cast &) { - return std::nullopt; - } -} +std::optional<N> string2Float(const std::string_view s); /** 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) 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 <limits> +#include <limits> +#include <sstream> 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 <iterator> #include <memory> +#include <sstream> #include <nlohmann/json.hpp> #include <algorithm> 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') 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 ]] |