Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into pluggable-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
edolstra committed Jul 16, 2024
2 parents 3aabfef + 9c6678d commit 65e1b59
Show file tree
Hide file tree
Showing 223 changed files with 3,302 additions and 1,279 deletions.
5 changes: 4 additions & 1 deletion doc/manual/generate-manpage.nix
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,12 @@ let
storeInfo = commandInfo.stores;
inherit inlineHTML;
};
hasInfix = infix: content:
builtins.stringLength content != builtins.stringLength (replaceStrings [ infix ] [ "" ] content);
in
optionalString (details ? doc) (
if match ".*@store-types@.*" details.doc != null
# An alternate implementation with builtins.match stack overflowed on some systems.
if hasInfix "@store-types@" details.doc
then help-stores
else details.doc
);
Expand Down
53 changes: 53 additions & 0 deletions doc/manual/rl-next/repl-doc-renders-doc-comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
synopsis: "`nix-repl`'s `:doc` shows documentation comments"
significance: significant
issues:
- 3904
- 10771
prs:
- 1652
- 9054
- 11072
---

`nix repl` has a `:doc` command that previously only rendered documentation for internally defined functions.
This feature has been extended to also render function documentation comments, in accordance with [RFC 145].

Example:

```
nix-repl> :doc lib.toFunction
Function toFunction
… defined at /home/user/h/nixpkgs/lib/trivial.nix:1072:5
Turns any non-callable values into constant functions. Returns
callable values as is.
Inputs
v
: Any value
Examples
:::{.example}
## lib.trivial.toFunction usage example
| nix-repl> lib.toFunction 1 2
| 1
|
| nix-repl> lib.toFunction (x: x + 1) 2
| 3
:::
```

Known limitations:
- It does not render documentation for "formals", such as `{ /** the value to return */ x, ... }: x`.
- Some extensions to markdown are not yet supported, as you can see in the example above.

We'd like to acknowledge Yingchi Long for proposing a proof of concept for this functionality in [#9054](https://github.com/NixOS/nix/pull/9054), as well as @sternenseemann and Johannes Kirschbauer for their contributions, proposals, and their work on [RFC 145].

[RFC 145]: https://github.com/NixOS/rfcs/pull/145
2 changes: 1 addition & 1 deletion doc/manual/src/contributing/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ A environment variables that Google Test accepts are also worth knowing:
Putting the two together, one might run
```bash
GTEST_BREIF=1 GTEST_FILTER='ErrorTraceTest.*' meson test nix-expr-tests -v
GTEST_BRIEF=1 GTEST_FILTER='ErrorTraceTest.*' meson test nix-expr-tests -v
```
for short but comprensive output.
Expand Down
2 changes: 1 addition & 1 deletion maintainers/flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
''^src/libstore/common-protocol-impl\.hh$''
''^src/libstore/common-protocol\.cc$''
''^src/libstore/common-protocol\.hh$''
''^src/libstore/common-ssh-store-config\.hh$''
''^src/libstore/content-address\.cc$''
''^src/libstore/content-address\.hh$''
''^src/libstore/daemon\.cc$''
Expand Down Expand Up @@ -215,7 +216,6 @@
''^src/libstore/serve-protocol\.hh$''
''^src/libstore/sqlite\.cc$''
''^src/libstore/sqlite\.hh$''
''^src/libstore/ssh-store-config\.hh$''
''^src/libstore/ssh-store\.cc$''
''^src/libstore/ssh\.cc$''
''^src/libstore/ssh\.hh$''
Expand Down
17 changes: 17 additions & 0 deletions packaging/dependencies.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,28 @@
versionSuffix,
}:

let
prevStdenv = stdenv;
in

let
inherit (pkgs) lib;

root = ../.;

stdenv = if prevStdenv.isDarwin && prevStdenv.isx86_64
then darwinStdenv
else prevStdenv;

# Fix the following error with the default x86_64-darwin SDK:
#
# error: aligned allocation function of type 'void *(std::size_t, std::align_val_t)' is only available on macOS 10.13 or newer
#
# Despite the use of the 10.13 deployment target here, the aligned
# allocation function Clang uses with this setting actually works
# all the way back to 10.6.
darwinStdenv = pkgs.overrideSDK prevStdenv { darwinMinVersion = "10.13"; };

# Nixpkgs implements this by returning a subpath into the fetched Nix sources.
resolvePath = p: p;

Expand Down
1 change: 1 addition & 0 deletions src/build-remote/build-remote.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "serialise.hh"
#include "build-result.hh"
#include "store-api.hh"
#include "strings.hh"
#include "derivations.hh"
#include "local-store.hh"
#include "legacy.hh"
Expand Down
43 changes: 19 additions & 24 deletions src/libcmd/built-path.cc
Original file line number Diff line number Diff line change
@@ -1,37 +1,32 @@
#include "built-path.hh"
#include "derivations.hh"
#include "store-api.hh"
#include "comparator.hh"

#include <nlohmann/json.hpp>

#include <optional>

namespace nix {

#define CMP_ONE(CHILD_TYPE, MY_TYPE, FIELD, COMPARATOR) \
bool MY_TYPE ::operator COMPARATOR (const MY_TYPE & other) const \
{ \
const MY_TYPE* me = this; \
auto fields1 = std::tie(*me->drvPath, me->FIELD); \
me = &other; \
auto fields2 = std::tie(*me->drvPath, me->FIELD); \
return fields1 COMPARATOR fields2; \
}
#define CMP(CHILD_TYPE, MY_TYPE, FIELD) \
CMP_ONE(CHILD_TYPE, MY_TYPE, FIELD, ==) \
CMP_ONE(CHILD_TYPE, MY_TYPE, FIELD, !=) \
CMP_ONE(CHILD_TYPE, MY_TYPE, FIELD, <)

#define FIELD_TYPE std::pair<std::string, StorePath>
CMP(SingleBuiltPath, SingleBuiltPathBuilt, output)
#undef FIELD_TYPE

#define FIELD_TYPE std::map<std::string, StorePath>
CMP(SingleBuiltPath, BuiltPathBuilt, outputs)
#undef FIELD_TYPE

#undef CMP
#undef CMP_ONE
// Custom implementation to avoid `ref` ptr equality
GENERATE_CMP_EXT(
,
std::strong_ordering,
SingleBuiltPathBuilt,
*me->drvPath,
me->output);

// Custom implementation to avoid `ref` ptr equality

// TODO no `GENERATE_CMP_EXT` because no `std::set::operator<=>` on
// Darwin, per header.
GENERATE_EQUAL(
,
BuiltPathBuilt ::,
BuiltPathBuilt,
*me->drvPath,
me->outputs);

StorePath SingleBuiltPath::outPath() const
{
Expand Down
16 changes: 13 additions & 3 deletions src/libcmd/built-path.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ struct SingleBuiltPathBuilt {
static SingleBuiltPathBuilt parse(const StoreDirConfig & store, std::string_view, std::string_view);
nlohmann::json toJSON(const StoreDirConfig & store) const;

DECLARE_CMP(SingleBuiltPathBuilt);
bool operator ==(const SingleBuiltPathBuilt &) const noexcept;
std::strong_ordering operator <=>(const SingleBuiltPathBuilt &) const noexcept;
};

using _SingleBuiltPathRaw = std::variant<
Expand All @@ -33,6 +34,9 @@ struct SingleBuiltPath : _SingleBuiltPathRaw {
using Opaque = DerivedPathOpaque;
using Built = SingleBuiltPathBuilt;

bool operator == (const SingleBuiltPath &) const = default;
auto operator <=> (const SingleBuiltPath &) const = default;

inline const Raw & raw() const {
return static_cast<const Raw &>(*this);
}
Expand All @@ -59,11 +63,13 @@ struct BuiltPathBuilt {
ref<SingleBuiltPath> drvPath;
std::map<std::string, StorePath> outputs;

bool operator == (const BuiltPathBuilt &) const noexcept;
// TODO libc++ 16 (used by darwin) missing `std::map::operator <=>`, can't do yet.
//std::strong_ordering operator <=> (const BuiltPathBuilt &) const noexcept;

std::string to_string(const StoreDirConfig & store) const;
static BuiltPathBuilt parse(const StoreDirConfig & store, std::string_view, std::string_view);
nlohmann::json toJSON(const StoreDirConfig & store) const;

DECLARE_CMP(BuiltPathBuilt);
};

using _BuiltPathRaw = std::variant<
Expand All @@ -82,6 +88,10 @@ struct BuiltPath : _BuiltPathRaw {
using Opaque = DerivedPathOpaque;
using Built = BuiltPathBuilt;

bool operator == (const BuiltPath &) const = default;
// TODO libc++ 16 (used by darwin) missing `std::map::operator <=>`, can't do yet.
//auto operator <=> (const BuiltPath &) const = default;

inline const Raw & raw() const {
return static_cast<const Raw &>(*this);
}
Expand Down
7 changes: 4 additions & 3 deletions src/libcmd/command.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <nlohmann/json.hpp>

#include "command.hh"
#include "markdown.hh"
#include "store-api.hh"
Expand All @@ -6,8 +8,7 @@
#include "nixexpr.hh"
#include "profiles.hh"
#include "repl.hh"

#include <nlohmann/json.hpp>
#include "strings.hh"

extern char * * environ __attribute__((weak));

Expand Down Expand Up @@ -132,7 +133,7 @@ ref<EvalState> EvalCommand::getEvalState()
#else
std::make_shared<EvalState>(
#endif
lookupPath, getEvalStore(), evalSettings, getStore())
lookupPath, getEvalStore(), fetchSettings, evalSettings, getStore())
;

evalState->repair = repair;
Expand Down
20 changes: 16 additions & 4 deletions src/libcmd/common-eval-args.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "fetch-settings.hh"
#include "eval-settings.hh"
#include "common-eval-args.hh"
#include "shared.hh"
Expand All @@ -7,6 +8,7 @@
#include "fetchers.hh"
#include "registry.hh"
#include "flake/flakeref.hh"
#include "flake/settings.hh"
#include "store-api.hh"
#include "command.hh"
#include "tarball.hh"
Expand All @@ -16,6 +18,10 @@

namespace nix {

fetchers::Settings fetchSettings;

static GlobalConfig::Register rFetchSettings(&fetchSettings);

EvalSettings evalSettings {
settings.readOnlyMode,
{
Expand All @@ -24,7 +30,7 @@ EvalSettings evalSettings {
[](ref<Store> store, std::string_view rest) {
experimentalFeatureSettings.require(Xp::Flakes);
// FIXME `parseFlakeRef` should take a `std::string_view`.
auto flakeRef = parseFlakeRef(std::string { rest }, {}, true, false);
auto flakeRef = parseFlakeRef(fetchSettings, std::string { rest }, {}, true, false);
debug("fetching flake search path element '%s''", rest);
auto storePath = flakeRef.resolve(store).fetchTree(store).first;
return store->toRealPath(storePath);
Expand All @@ -35,6 +41,12 @@ EvalSettings evalSettings {

static GlobalConfig::Register rEvalSettings(&evalSettings);


flake::Settings flakeSettings;

static GlobalConfig::Register rFlakeSettings(&flakeSettings);


CompatibilitySettings compatibilitySettings {};

static GlobalConfig::Register rCompatibilitySettings(&compatibilitySettings);
Expand Down Expand Up @@ -171,8 +183,8 @@ MixEvalArgs::MixEvalArgs()
.category = category,
.labels = {"original-ref", "resolved-ref"},
.handler = {[&](std::string _from, std::string _to) {
auto from = parseFlakeRef(_from, absPath("."));
auto to = parseFlakeRef(_to, absPath("."));
auto from = parseFlakeRef(fetchSettings, _from, absPath("."));
auto to = parseFlakeRef(fetchSettings, _to, absPath("."));
fetchers::Attrs extraAttrs;
if (to.subdir != "") extraAttrs["dir"] = to.subdir;
fetchers::overrideRegistry(from.input, to.input, extraAttrs);
Expand Down Expand Up @@ -230,7 +242,7 @@ SourcePath lookupFileArg(EvalState & state, std::string_view s, const Path * bas

else if (hasPrefix(s, "flake:")) {
experimentalFeatureSettings.require(Xp::Flakes);
auto flakeRef = parseFlakeRef(std::string(s.substr(6)), {}, true, false);
auto flakeRef = parseFlakeRef(fetchSettings, std::string(s.substr(6)), {}, true, false);
auto storePath = flakeRef.resolve(state.store).fetchTree(state.store).first;
return state.rootPath(CanonPath(state.store->toRealPath(storePath)));
}
Expand Down
15 changes: 15 additions & 0 deletions src/libcmd/common-eval-args.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,32 @@
namespace nix {

class Store;

namespace fetchers { struct Settings; }

class EvalState;
struct EvalSettings;
struct CompatibilitySettings;
class Bindings;
struct SourcePath;

namespace flake { struct Settings; }

/**
* @todo Get rid of global setttings variables
*/
extern fetchers::Settings fetchSettings;

/**
* @todo Get rid of global setttings variables
*/
extern EvalSettings evalSettings;

/**
* @todo Get rid of global setttings variables
*/
extern flake::Settings flakeSettings;

/**
* Settings that control behaviors that have changed since Nix 2.3.
*/
Expand Down
17 changes: 2 additions & 15 deletions src/libcmd/installable-flake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,6 @@ std::vector<std::string> InstallableFlake::getActualAttrPaths()
return res;
}

Value * InstallableFlake::getFlakeOutputs(EvalState & state, const flake::LockedFlake & lockedFlake)
{
auto vFlake = state.allocValue();

callFlake(state, lockedFlake, *vFlake);

auto aOutputs = vFlake->attrs()->get(state.symbols.create("outputs"));
assert(aOutputs);

state.forceValue(*aOutputs->value, aOutputs->value->determinePos(noPos));

return aOutputs->value;
}

static std::string showAttrPaths(const std::vector<std::string> & paths)
{
std::string s;
Expand Down Expand Up @@ -210,7 +196,8 @@ std::shared_ptr<flake::LockedFlake> InstallableFlake::getLockedFlake() const
flake::LockFlags lockFlagsApplyConfig = lockFlags;
// FIXME why this side effect?
lockFlagsApplyConfig.applyNixConfig = true;
_lockedFlake = std::make_shared<flake::LockedFlake>(lockFlake(*state, flakeRef, lockFlagsApplyConfig));
_lockedFlake = std::make_shared<flake::LockedFlake>(lockFlake(
flakeSettings, *state, flakeRef, lockFlagsApplyConfig));
}
return _lockedFlake;
}
Expand Down
Loading

0 comments on commit 65e1b59

Please sign in to comment.