Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into lazy-trees-post-s…
Browse files Browse the repository at this point in the history
…ettings
  • Loading branch information
Ericson2314 committed Jul 12, 2024
2 parents 0d3a157 + 6c5d2a1 commit 750ba9f
Show file tree
Hide file tree
Showing 135 changed files with 1,141 additions and 522 deletions.
20 changes: 0 additions & 20 deletions .github/workflows/hydra_status.yml

This file was deleted.

7 changes: 7 additions & 0 deletions build-utils-meson/generate-header/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
bash = find_program('bash', native: true)

gen_header = generator(
bash,
arguments : [ '-c', '{ echo \'R"__NIX_STR(\' && cat @INPUT@ && echo \')__NIX_STR"\'; } > "$1"', '_ignored_argv0', '@OUTPUT@' ],
output : '@[email protected]',
)
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
1 change: 0 additions & 1 deletion maintainers/flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,6 @@
''^misc/bash/completion\.sh$''
''^misc/fish/completion\.fish$''
''^misc/zsh/completion\.zsh$''
''^scripts/check-hydra-status\.sh$''
''^scripts/create-darwin-volume\.sh$''
''^scripts/install-darwin-multi-user\.sh$''
''^scripts/install-multi-user\.sh$''
Expand Down
6 changes: 5 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ project('nix-dev-shell', 'cpp',
subproject_dir : 'src',
)

# Internal Libraries
subproject('libutil')
subproject('libstore')
subproject('libfetchers')
Expand All @@ -14,11 +15,14 @@ subproject('libflake')
subproject('libmain')
subproject('libcmd')

# Executables
subproject('nix')

# Docs
subproject('internal-api-docs')
subproject('external-api-docs')

# C wrappers
# External C wrapper libraries
subproject('libutil-c')
subproject('libstore-c')
subproject('libexpr-c')
Expand Down
3 changes: 3 additions & 0 deletions packaging/components.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ in

nix-cmd = callPackage ../src/libcmd/package.nix { };

# Will replace `nix` once the old build system is gone.
nix-ng = callPackage ../src/nix/package.nix { };

nix-internal-api-docs = callPackage ../src/internal-api-docs/package.nix { };
nix-external-api-docs = callPackage ../src/external-api-docs/package.nix { };

Expand Down
1 change: 1 addition & 0 deletions packaging/hydra.nix
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ let
"nix-flake-tests"
"nix-main"
"nix-cmd"
"nix-ng"
];
in
{
Expand Down
33 changes: 0 additions & 33 deletions scripts/check-hydra-status.sh

This file was deleted.

2 changes: 1 addition & 1 deletion src/libcmd/command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,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 [accessor, _] = flakeRef.resolve(store).lazyFetch(store);
return SourcePath(accessor);
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 [accessor, _] = flakeRef.resolve(state.store).lazyFetch(state.store);
return SourcePath(accessor);
}
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
5 changes: 2 additions & 3 deletions src/libcmd/installable-flake.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
///@file

#include "common-eval-args.hh"
#include "installable-value.hh"

namespace nix {
Expand Down Expand Up @@ -52,8 +53,6 @@ struct InstallableFlake : InstallableValue

std::vector<std::string> getActualAttrPaths();

Value * getFlakeOutputs(EvalState & state, const flake::LockedFlake & lockedFlake);

DerivedPathsWithInfo toDerivedPaths() override;

std::pair<Value *, PosIdx> toValue(EvalState & state) override;
Expand All @@ -80,7 +79,7 @@ struct InstallableFlake : InstallableValue
*/
static inline FlakeRef defaultNixpkgsFlakeRef()
{
return FlakeRef::fromAttrs({{"type","indirect"}, {"id", "nixpkgs"}});
return FlakeRef::fromAttrs(fetchSettings, {{"type","indirect"}, {"id", "nixpkgs"}});
}

ref<eval_cache::EvalCache> openEvalCache(
Expand Down
23 changes: 14 additions & 9 deletions src/libcmd/installables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ MixFlakeOptions::MixFlakeOptions()
lockFlags.writeLockFile = false;
lockFlags.inputOverrides.insert_or_assign(
flake::parseInputPath(inputPath),
parseFlakeRef(flakeRef, absPath(getCommandBaseDir()), true));
parseFlakeRef(fetchSettings, flakeRef, absPath(getCommandBaseDir()), true));
}},
.completer = {[&](AddCompletions & completions, size_t n, std::string_view prefix) {
if (n == 0) {
Expand Down Expand Up @@ -170,14 +170,15 @@ MixFlakeOptions::MixFlakeOptions()
.handler = {[&](std::string flakeRef) {
auto evalState = getEvalState();
auto flake = flake::lockFlake(
flakeSettings,
*evalState,
parseFlakeRef(flakeRef, absPath(getCommandBaseDir())),
parseFlakeRef(fetchSettings, flakeRef, absPath(getCommandBaseDir())),
{ .writeLockFile = false });
for (auto & [inputName, input] : flake.lockFile.root->inputs) {
auto input2 = flake.lockFile.findInput({inputName}); // resolve 'follows' nodes
if (auto input3 = std::dynamic_pointer_cast<const flake::LockedNode>(input2)) {
overrideRegistry(
fetchers::Input::fromAttrs({{"type","indirect"}, {"id", inputName}}),
fetchers::Input::fromAttrs(fetchSettings, {{"type","indirect"}, {"id", inputName}}),
input3->lockedRef.input,
{});
}
Expand Down Expand Up @@ -289,10 +290,10 @@ void SourceExprCommand::completeInstallable(AddCompletions & completions, std::s

if (v2.type() == nAttrs) {
for (auto & i : *v2.attrs()) {
std::string name = state->symbols[i.name];
std::string_view name = state->symbols[i.name];
if (name.find(searchWord) == 0) {
if (prefix_ == "")
completions.add(name);
completions.add(std::string(name));
else
completions.add(prefix_ + "." + name);
}
Expand Down Expand Up @@ -338,10 +339,11 @@ void completeFlakeRefWithFragment(
auto flakeRefS = std::string(prefix.substr(0, hash));

// TODO: ideally this would use the command base directory instead of assuming ".".
auto flakeRef = parseFlakeRef(expandTilde(flakeRefS), absPath("."));
auto flakeRef = parseFlakeRef(fetchSettings, expandTilde(flakeRefS), absPath("."));

auto evalCache = openEvalCache(*evalState,
std::make_shared<flake::LockedFlake>(lockFlake(*evalState, flakeRef, lockFlags)));
std::make_shared<flake::LockedFlake>(lockFlake(
flakeSettings, *evalState, flakeRef, lockFlags)));

auto root = evalCache->getRoot();

Expand Down Expand Up @@ -403,7 +405,7 @@ void completeFlakeRef(AddCompletions & completions, ref<Store> store, std::strin
Args::completeDir(completions, 0, prefix);

/* Look for registry entries that match the prefix. */
for (auto & registry : fetchers::getRegistries(store)) {
for (auto & registry : fetchers::getRegistries(fetchSettings, store)) {
for (auto & entry : registry->entries) {
auto from = entry.from.to_string();
if (!hasPrefix(prefix, "flake:") && hasPrefix(from, "flake:")) {
Expand Down Expand Up @@ -534,7 +536,8 @@ Installables SourceExprCommand::parseInstallables(
}

try {
auto [flakeRef, fragment] = parseFlakeRefWithFragment(std::string { prefix }, absPath(getCommandBaseDir()));
auto [flakeRef, fragment] = parseFlakeRefWithFragment(
fetchSettings, std::string { prefix }, absPath(getCommandBaseDir()));
result.push_back(make_ref<InstallableFlake>(
this,
getEvalState(),
Expand Down Expand Up @@ -851,6 +854,7 @@ std::vector<FlakeRef> RawInstallablesCommand::getFlakeRefsForCompletion()
std::vector<FlakeRef> res;
for (auto i : rawInstallables)
res.push_back(parseFlakeRefWithFragment(
fetchSettings,
expandTilde(i),
absPath(getCommandBaseDir())).first);
return res;
Expand All @@ -873,6 +877,7 @@ std::vector<FlakeRef> InstallableCommand::getFlakeRefsForCompletion()
{
return {
parseFlakeRefWithFragment(
fetchSettings,
expandTilde(_installable),
absPath(getCommandBaseDir())).first
};
Expand Down
1 change: 1 addition & 0 deletions src/libcmd/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ add_project_arguments(
'-include', 'config-util.hh',
'-include', 'config-store.hh',
# '-include', 'config-fetchers.h',
'-include', 'config-expr.hh',
'-include', 'config-main.hh',
'-include', 'config-cmd.hh',
language : 'cpp',
Expand Down
Loading

0 comments on commit 750ba9f

Please sign in to comment.