Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
adcbf3e19a |
No files matched your search
@@ -13,7 +13,6 @@ project(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Internal Libraries
|
# Internal Libraries
|
||||||
subproject('libcmarkcpp')
|
|
||||||
subproject('libutil')
|
subproject('libutil')
|
||||||
subproject('libstore')
|
subproject('libstore')
|
||||||
subproject('libfetchers')
|
subproject('libfetchers')
|
||||||
|
|||||||
@@ -269,8 +269,6 @@ pkgs.nixComponents2.nix-util.overrideAttrs (
|
|||||||
CXX_LD = "mold";
|
CXX_LD = "mold";
|
||||||
};
|
};
|
||||||
|
|
||||||
dontUseCmakeConfigure = true;
|
|
||||||
|
|
||||||
mesonFlags =
|
mesonFlags =
|
||||||
map (transformFlag "libutil") (ignoreCrossFile pkgs.nixComponents2.nix-util.mesonFlags)
|
map (transformFlag "libutil") (ignoreCrossFile pkgs.nixComponents2.nix-util.mesonFlags)
|
||||||
++ map (transformFlag "libstore") (ignoreCrossFile pkgs.nixComponents2.nix-store.mesonFlags)
|
++ map (transformFlag "libstore") (ignoreCrossFile pkgs.nixComponents2.nix-store.mesonFlags)
|
||||||
|
|||||||
@@ -174,6 +174,24 @@ rec {
|
|||||||
|
|
||||||
buildNoTests = forAllSystems (system: nixpkgsFor.${system}.native.nixComponents2.nix-cli);
|
buildNoTests = forAllSystems (system: nixpkgsFor.${system}.native.nixComponents2.nix-cli);
|
||||||
|
|
||||||
|
# Toggles some settings for better coverage. Windows needs these
|
||||||
|
# library combinations, and Debian build Nix with GNU readline too.
|
||||||
|
buildReadlineNoMarkdown =
|
||||||
|
let
|
||||||
|
components = forAllSystems (
|
||||||
|
system:
|
||||||
|
nixpkgsFor.${system}.native.nixComponents2.overrideScope (
|
||||||
|
self: super: {
|
||||||
|
nix-cmd = super.nix-cmd.override {
|
||||||
|
enableMarkdown = false;
|
||||||
|
readlineFlavor = "readline";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
in
|
||||||
|
forAllPackages (pkgName: forAllSystems (system: components.${system}.${pkgName}));
|
||||||
|
|
||||||
# Perl bindings for various platforms.
|
# Perl bindings for various platforms.
|
||||||
perlBindings = forAllSystems (system: nixpkgsFor.${system}.native.nixComponents2.nix-perl-bindings);
|
perlBindings = forAllSystems (system: nixpkgsFor.${system}.native.nixComponents2.nix-perl-bindings);
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
Copyright (c) 2008, Natacha Porté
|
|
||||||
Copyright (c) 2011, Vicent Martí
|
|
||||||
Copyright (c) 2014, Xavier Mendez, Devin Torres and the Hoedown authors
|
|
||||||
Copyright (c) 2016--2023, Kristaps Dzonsons
|
|
||||||
Copyright (c) 2025, Obsidian Systems
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any purpose
|
|
||||||
with or without fee is hereby granted, provided that the above copyright notice
|
|
||||||
and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
||||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
||||||
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
||||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
||||||
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
||||||
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
|
||||||
THIS SOFTWARE.
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
# libcmarkcpp
|
|
||||||
|
|
||||||
A C++ terminal renderer for CommonMark documents.
|
|
||||||
|
|
||||||
## Overview
|
|
||||||
|
|
||||||
libcmarkcpp provides a terminal renderer for CommonMark (Markdown) documents using the cmark library. It renders formatted, colored output suitable for display in ANSI-capable terminals.
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
- ANSI color styling and text formatting (bold, italic, underline)
|
|
||||||
- Intelligent text wrapping and indentation
|
|
||||||
- Support for:
|
|
||||||
- Headers with hierarchical styling
|
|
||||||
- Lists (ordered and unordered)
|
|
||||||
- Code blocks (fenced and indented)
|
|
||||||
- Blockquotes
|
|
||||||
- Links with OSC8 hyperlink support
|
|
||||||
- Inline code, bold, and italic
|
|
||||||
- Horizontal rules
|
|
||||||
- Images
|
|
||||||
- Terminal width detection and adaptive wrapping
|
|
||||||
- Configurable margins, padding, and styling options
|
|
||||||
|
|
||||||
## Origin
|
|
||||||
|
|
||||||
This library is a C++ port of the terminal renderer from [lowdown](https://github.com/kristapsdz/lowdown) by Kristaps Dzonsons, adapted to work with the [cmark](https://github.com/commonmark/cmark) CommonMark implementation.
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
ISC License (same as lowdown)
|
|
||||||
|
|
||||||
## Dependencies
|
|
||||||
|
|
||||||
- cmark >= 0.31.0
|
|
||||||
- C++20 compiler
|
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1,89 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
/**
|
|
||||||
* @file cmark-cpp.hh
|
|
||||||
* @brief C++ wrappers for the cmark CommonMark library
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <cmark.h>
|
|
||||||
#include <memory>
|
|
||||||
#include <string_view>
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
namespace cmark {
|
|
||||||
|
|
||||||
using Node = struct cmark_node;
|
|
||||||
using NodeType = cmark_node_type;
|
|
||||||
using ListType = cmark_list_type;
|
|
||||||
|
|
||||||
using Iter = struct cmark_iter;
|
|
||||||
|
|
||||||
struct Deleter
|
|
||||||
{
|
|
||||||
void operator()(Node * ptr)
|
|
||||||
{
|
|
||||||
cmark_node_free(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator()(Iter * ptr)
|
|
||||||
{
|
|
||||||
cmark_iter_free(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator()(char * ptr)
|
|
||||||
{
|
|
||||||
free(ptr);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
using UniquePtr = std::unique_ptr<Node, Deleter>;
|
|
||||||
|
|
||||||
static inline void parse_document(Node & root, std::string_view s, int options)
|
|
||||||
{
|
|
||||||
cmark_parser * parser = cmark_parser_new_with_mem_into_root(options, cmark_get_default_mem_allocator(), &root);
|
|
||||||
cmark_parser_feed(parser, s.data(), s.size());
|
|
||||||
(void) cmark_parser_finish(parser);
|
|
||||||
cmark_parser_free(parser);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline UniquePtr<Node> parse_document(std::string_view s, int options)
|
|
||||||
{
|
|
||||||
return UniquePtr<Node>{cmark_parse_document(s.data(), s.size(), options)};
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline std::unique_ptr<char, Deleter> render_commonmark(Node & root, int options, int width)
|
|
||||||
{
|
|
||||||
return std::unique_ptr<char, Deleter>{cmark_render_commonmark(&root, options, width)};
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline std::unique_ptr<char, Deleter> render_xml(Node & root, int options)
|
|
||||||
{
|
|
||||||
return std::unique_ptr<char, Deleter>{cmark_render_xml(&root, options)};
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline UniquePtr<Node> node_new(NodeType type)
|
|
||||||
{
|
|
||||||
return UniquePtr<Node>{cmark_node_new(type)};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The parent takes ownership
|
|
||||||
*/
|
|
||||||
static inline Node & node_append_child(Node & node, UniquePtr<Node> child)
|
|
||||||
{
|
|
||||||
auto status = (bool) cmark_node_append_child(&node, &*child);
|
|
||||||
assert(status);
|
|
||||||
return *child.release();
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool node_set_literal(Node & node, const char * content)
|
|
||||||
{
|
|
||||||
return (bool) cmark_node_set_literal(&node, content);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool node_set_list_type(Node & node, ListType type)
|
|
||||||
{
|
|
||||||
return (bool) cmark_node_set_list_type(&node, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace cmark
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
///@file
|
|
||||||
|
|
||||||
#include "cmark-cpp.hh"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace cmark {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Terminal rendering options
|
|
||||||
*/
|
|
||||||
struct TerminalOptions
|
|
||||||
{
|
|
||||||
/** Terminal width in columns */
|
|
||||||
size_t cols = 80;
|
|
||||||
|
|
||||||
/** Content width (0 = auto, max 80 or cols) */
|
|
||||||
size_t width = 0;
|
|
||||||
|
|
||||||
/** Horizontal margin (left padding) */
|
|
||||||
size_t hmargin = 0;
|
|
||||||
|
|
||||||
/** Horizontal padding (additional left padding) */
|
|
||||||
size_t hpadding = 4;
|
|
||||||
|
|
||||||
/** Vertical margin (blank lines before/after) */
|
|
||||||
size_t vmargin = 0;
|
|
||||||
|
|
||||||
/** Center content */
|
|
||||||
bool centre = false;
|
|
||||||
|
|
||||||
/** Disable ANSI escape sequences */
|
|
||||||
bool noAnsi = false;
|
|
||||||
|
|
||||||
/** Disable ANSI colors only */
|
|
||||||
bool noColor = false;
|
|
||||||
|
|
||||||
/** Don't show any link URLs */
|
|
||||||
bool noLink = false;
|
|
||||||
|
|
||||||
/** Don't show relative link URLs */
|
|
||||||
bool noRelLink = false;
|
|
||||||
|
|
||||||
/** Shorten long URLs */
|
|
||||||
bool shortLink = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Style attributes for terminal output
|
|
||||||
*/
|
|
||||||
struct Style
|
|
||||||
{
|
|
||||||
bool italic = false;
|
|
||||||
bool strike = false;
|
|
||||||
bool bold = false;
|
|
||||||
bool under = false;
|
|
||||||
size_t bcolour = 0; // Background color (ANSI code)
|
|
||||||
size_t colour = 0; // Foreground color (ANSI code)
|
|
||||||
int override = 0; // Override flags
|
|
||||||
|
|
||||||
static constexpr int OVERRIDE_UNDER = 0x01;
|
|
||||||
static constexpr int OVERRIDE_BOLD = 0x02;
|
|
||||||
|
|
||||||
bool hasStyle() const
|
|
||||||
{
|
|
||||||
return colour || bold || italic || under || strike || bcolour || override;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Terminal renderer for CommonMark documents
|
|
||||||
*
|
|
||||||
* Renders a CMark AST to ANSI terminal output with styling, wrapping,
|
|
||||||
* and proper indentation.
|
|
||||||
*/
|
|
||||||
class TerminalRenderer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Create a new terminal renderer with the given options
|
|
||||||
*/
|
|
||||||
explicit TerminalRenderer(const TerminalOptions & opts = TerminalOptions{});
|
|
||||||
|
|
||||||
~TerminalRenderer();
|
|
||||||
|
|
||||||
// Non-copyable
|
|
||||||
TerminalRenderer(const TerminalRenderer &) = delete;
|
|
||||||
TerminalRenderer & operator=(const TerminalRenderer &) = delete;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render a CMark node tree to a string
|
|
||||||
*/
|
|
||||||
std::string render(cmark::Node & root);
|
|
||||||
|
|
||||||
private:
|
|
||||||
struct Impl;
|
|
||||||
std::unique_ptr<Impl> impl;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convenience function to render a CMark document to terminal output
|
|
||||||
*/
|
|
||||||
std::string renderTerminal(cmark::Node & root, const TerminalOptions & opts = TerminalOptions{});
|
|
||||||
|
|
||||||
} // namespace cmark
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
project(
|
|
||||||
'cmark-cpp',
|
|
||||||
'cpp',
|
|
||||||
version : '0.1',
|
|
||||||
default_options : [
|
|
||||||
'cpp_std=c++20',
|
|
||||||
'warning_level=1',
|
|
||||||
],
|
|
||||||
meson_version : '>= 1.1',
|
|
||||||
license : 'ISC',
|
|
||||||
)
|
|
||||||
|
|
||||||
cxx = meson.get_compiler('cpp')
|
|
||||||
|
|
||||||
# CMark dependency
|
|
||||||
cmark = dependency('libcmark', required : true)
|
|
||||||
|
|
||||||
sources = files(
|
|
||||||
'cmark-terminal.cc',
|
|
||||||
)
|
|
||||||
|
|
||||||
headers = files(
|
|
||||||
'include/cmark/cmark-cpp.hh',
|
|
||||||
'include/cmark/cmark-terminal.hh',
|
|
||||||
)
|
|
||||||
|
|
||||||
include_dirs = include_directories('include')
|
|
||||||
|
|
||||||
libcmarkcpp = library(
|
|
||||||
'cmarkcpp',
|
|
||||||
sources,
|
|
||||||
dependencies : cmark,
|
|
||||||
include_directories : include_dirs,
|
|
||||||
install : true,
|
|
||||||
version : meson.project_version(),
|
|
||||||
)
|
|
||||||
|
|
||||||
install_headers(headers, subdir : 'cmark')
|
|
||||||
|
|
||||||
# Make this available as a dependency for meson projects
|
|
||||||
meson.override_dependency(
|
|
||||||
'cmark-cpp',
|
|
||||||
declare_dependency(
|
|
||||||
include_directories : include_dirs,
|
|
||||||
link_with : libcmarkcpp,
|
|
||||||
dependencies : cmark,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
# Pkg-config file
|
|
||||||
pkg = import('pkgconfig')
|
|
||||||
pkg.generate(
|
|
||||||
libcmarkcpp,
|
|
||||||
name : 'cmark-cpp',
|
|
||||||
description : 'C++ terminal renderer for CommonMark',
|
|
||||||
url : 'https://github.com/NixOS/nix',
|
|
||||||
)
|
|
||||||
@@ -34,7 +34,7 @@ EvalSettings evalSettings{
|
|||||||
auto flakeRef = parseFlakeRef(fetchSettings, std::string{rest}, {}, true, false);
|
auto flakeRef = parseFlakeRef(fetchSettings, std::string{rest}, {}, true, false);
|
||||||
debug("fetching flake search path element '%s''", rest);
|
debug("fetching flake search path element '%s''", rest);
|
||||||
auto [accessor, lockedRef] =
|
auto [accessor, lockedRef] =
|
||||||
flakeRef.resolve(fetchSettings, *state.store).lazyFetch(fetchSettings, *state.store);
|
flakeRef.resolve(fetchSettings, state.store).lazyFetch(fetchSettings, state.store);
|
||||||
auto storePath = nix::fetchToStore(
|
auto storePath = nix::fetchToStore(
|
||||||
state.fetchSettings,
|
state.fetchSettings,
|
||||||
*state.store,
|
*state.store,
|
||||||
@@ -180,7 +180,7 @@ Bindings * MixEvalArgs::getAutoArgs(EvalState & state)
|
|||||||
SourcePath lookupFileArg(EvalState & state, std::string_view s, const Path * baseDir)
|
SourcePath lookupFileArg(EvalState & state, std::string_view s, const Path * baseDir)
|
||||||
{
|
{
|
||||||
if (EvalSettings::isPseudoUrl(s)) {
|
if (EvalSettings::isPseudoUrl(s)) {
|
||||||
auto accessor = fetchers::downloadTarball(*state.store, state.fetchSettings, EvalSettings::resolvePseudoUrl(s));
|
auto accessor = fetchers::downloadTarball(state.store, state.fetchSettings, EvalSettings::resolvePseudoUrl(s));
|
||||||
auto storePath = fetchToStore(state.fetchSettings, *state.store, SourcePath(accessor), FetchMode::Copy);
|
auto storePath = fetchToStore(state.fetchSettings, *state.store, SourcePath(accessor), FetchMode::Copy);
|
||||||
return state.storePath(storePath);
|
return state.storePath(storePath);
|
||||||
}
|
}
|
||||||
@@ -188,8 +188,7 @@ SourcePath lookupFileArg(EvalState & state, std::string_view s, const Path * bas
|
|||||||
else if (hasPrefix(s, "flake:")) {
|
else if (hasPrefix(s, "flake:")) {
|
||||||
experimentalFeatureSettings.require(Xp::Flakes);
|
experimentalFeatureSettings.require(Xp::Flakes);
|
||||||
auto flakeRef = parseFlakeRef(fetchSettings, std::string(s.substr(6)), {}, true, false);
|
auto flakeRef = parseFlakeRef(fetchSettings, std::string(s.substr(6)), {}, true, false);
|
||||||
auto [accessor, lockedRef] =
|
auto [accessor, lockedRef] = flakeRef.resolve(fetchSettings, state.store).lazyFetch(fetchSettings, state.store);
|
||||||
flakeRef.resolve(fetchSettings, *state.store).lazyFetch(fetchSettings, *state.store);
|
|
||||||
auto storePath = nix::fetchToStore(
|
auto storePath = nix::fetchToStore(
|
||||||
state.fetchSettings, *state.store, SourcePath(accessor), FetchMode::Copy, lockedRef.input.getName());
|
state.fetchSettings, *state.store, SourcePath(accessor), FetchMode::Copy, lockedRef.input.getName());
|
||||||
state.allowPath(storePath);
|
state.allowPath(storePath);
|
||||||
|
|||||||
@@ -410,7 +410,7 @@ void completeFlakeRef(AddCompletions & completions, ref<Store> store, std::strin
|
|||||||
Args::completeDir(completions, 0, prefix);
|
Args::completeDir(completions, 0, prefix);
|
||||||
|
|
||||||
/* Look for registry entries that match the prefix. */
|
/* Look for registry entries that match the prefix. */
|
||||||
for (auto & registry : fetchers::getRegistries(fetchSettings, *store)) {
|
for (auto & registry : fetchers::getRegistries(fetchSettings, store)) {
|
||||||
for (auto & entry : registry->entries) {
|
for (auto & entry : registry->entries) {
|
||||||
auto from = entry.from.to_string();
|
auto from = entry.from.to_string();
|
||||||
if (!hasPrefix(prefix, "flake:") && hasPrefix(from, "flake:")) {
|
if (!hasPrefix(prefix, "flake:") && hasPrefix(from, "flake:")) {
|
||||||
|
|||||||
+66
-18
@@ -1,38 +1,79 @@
|
|||||||
#include "nix/cmd/markdown.hh"
|
#include "nix/cmd/markdown.hh"
|
||||||
#include "nix/util/environment-variables.hh"
|
#include "nix/util/environment-variables.hh"
|
||||||
#include "nix/util/error.hh"
|
#include "nix/util/error.hh"
|
||||||
|
#include "nix/util/finally.hh"
|
||||||
#include "nix/util/terminal.hh"
|
#include "nix/util/terminal.hh"
|
||||||
|
|
||||||
#include <cmark/cmark-cpp.hh>
|
#include "cmd-config-private.hh"
|
||||||
#include <cmark/cmark-terminal.hh>
|
|
||||||
|
#if HAVE_LOWDOWN
|
||||||
|
# include <sys/queue.h>
|
||||||
|
# include <lowdown.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
#if HAVE_LOWDOWN
|
||||||
static std::string doRenderMarkdownToTerminal(std::string_view markdown)
|
static std::string doRenderMarkdownToTerminal(std::string_view markdown)
|
||||||
{
|
{
|
||||||
int windowWidth = getWindowSize().second;
|
int windowWidth = getWindowSize().second;
|
||||||
|
|
||||||
// Set up terminal rendering options
|
# if HAVE_LOWDOWN_1_4
|
||||||
::cmark::TerminalOptions opts;
|
struct lowdown_opts_term opts_term{
|
||||||
opts.cols = std::max(windowWidth - 5, 60);
|
.cols = (size_t) std::max(windowWidth - 5, 60),
|
||||||
opts.hmargin = 0;
|
.hmargin = 0,
|
||||||
opts.vmargin = 0;
|
.vmargin = 0,
|
||||||
opts.noRelLink = true; // Skip rendering relative links
|
};
|
||||||
|
# endif
|
||||||
|
struct lowdown_opts opts{
|
||||||
|
.type = LOWDOWN_TERM,
|
||||||
|
# if HAVE_LOWDOWN_1_4
|
||||||
|
.term = opts_term,
|
||||||
|
# endif
|
||||||
|
.maxdepth = 20,
|
||||||
|
# if !HAVE_LOWDOWN_1_4
|
||||||
|
.cols = (size_t) std::max(windowWidth - 5, 60),
|
||||||
|
.hmargin = 0,
|
||||||
|
.vmargin = 0,
|
||||||
|
# endif
|
||||||
|
.feat = LOWDOWN_COMMONMARK | LOWDOWN_FENCED | LOWDOWN_DEFLIST | LOWDOWN_TABLES,
|
||||||
|
.oflags =
|
||||||
|
# if HAVE_LOWDOWN_1_4
|
||||||
|
LOWDOWN_TERM_NORELLINK // To render full links while skipping relative ones
|
||||||
|
# else
|
||||||
|
LOWDOWN_TERM_NOLINK
|
||||||
|
# endif
|
||||||
|
};
|
||||||
|
|
||||||
if (!isTTY())
|
if (!isTTY())
|
||||||
opts.noAnsi = true;
|
opts.oflags |= LOWDOWN_TERM_NOANSI;
|
||||||
|
|
||||||
// Parse the markdown document
|
auto doc = lowdown_doc_new(&opts);
|
||||||
auto doc = ::cmark::parse_document(markdown, CMARK_OPT_DEFAULT);
|
|
||||||
if (!doc)
|
if (!doc)
|
||||||
throw Error("cannot parse Markdown document");
|
throw Error("cannot allocate Markdown document");
|
||||||
|
Finally freeDoc([&]() { lowdown_doc_free(doc); });
|
||||||
|
|
||||||
try {
|
size_t maxn = 0;
|
||||||
// Render to terminal
|
auto node = lowdown_doc_parse(doc, &maxn, markdown.data(), markdown.size(), nullptr);
|
||||||
return ::cmark::renderTerminal(*doc, opts);
|
if (!node)
|
||||||
} catch (const std::exception & e) {
|
throw Error("cannot parse Markdown document");
|
||||||
throw Error("error rendering Markdown: %s", e.what());
|
Finally freeNode([&]() { lowdown_node_free(node); });
|
||||||
}
|
|
||||||
|
auto renderer = lowdown_term_new(&opts);
|
||||||
|
if (!renderer)
|
||||||
|
throw Error("cannot allocate Markdown renderer");
|
||||||
|
Finally freeRenderer([&]() { lowdown_term_free(renderer); });
|
||||||
|
|
||||||
|
auto buf = lowdown_buf_new(16384);
|
||||||
|
if (!buf)
|
||||||
|
throw Error("cannot allocate Markdown output buffer");
|
||||||
|
Finally freeBuffer([&]() { lowdown_buf_free(buf); });
|
||||||
|
|
||||||
|
int rndr_res = lowdown_term_rndr(buf, renderer, node);
|
||||||
|
if (!rndr_res)
|
||||||
|
throw Error("allocation error while rendering Markdown");
|
||||||
|
|
||||||
|
return std::string(buf->data, buf->size);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string renderMarkdownToTerminal(std::string_view markdown)
|
std::string renderMarkdownToTerminal(std::string_view markdown)
|
||||||
@@ -43,4 +84,11 @@ std::string renderMarkdownToTerminal(std::string_view markdown)
|
|||||||
return doRenderMarkdownToTerminal(markdown);
|
return doRenderMarkdownToTerminal(markdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
std::string renderMarkdownToTerminal(std::string_view markdown)
|
||||||
|
{
|
||||||
|
return std::string(markdown);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace nix
|
} // namespace nix
|
||||||
+13
-1
@@ -26,13 +26,25 @@ deps_public_maybe_subproject = [
|
|||||||
dependency('nix-expr'),
|
dependency('nix-expr'),
|
||||||
dependency('nix-flake'),
|
dependency('nix-flake'),
|
||||||
dependency('nix-main'),
|
dependency('nix-main'),
|
||||||
dependency('cmark-cpp'),
|
|
||||||
]
|
]
|
||||||
subdir('nix-meson-build-support/subprojects')
|
subdir('nix-meson-build-support/subprojects')
|
||||||
|
|
||||||
nlohmann_json = dependency('nlohmann_json', version : '>= 3.9')
|
nlohmann_json = dependency('nlohmann_json', version : '>= 3.9')
|
||||||
deps_public += nlohmann_json
|
deps_public += nlohmann_json
|
||||||
|
|
||||||
|
lowdown = dependency(
|
||||||
|
'lowdown',
|
||||||
|
version : '>= 0.9.0',
|
||||||
|
required : get_option('markdown'),
|
||||||
|
)
|
||||||
|
deps_private += lowdown
|
||||||
|
configdata.set('HAVE_LOWDOWN', lowdown.found().to_int())
|
||||||
|
# The API changed slightly around terminal initialization.
|
||||||
|
configdata.set(
|
||||||
|
'HAVE_LOWDOWN_1_4',
|
||||||
|
lowdown.version().version_compare('>= 1.4.0').to_int(),
|
||||||
|
)
|
||||||
|
|
||||||
readline_flavor = get_option('readline-flavor')
|
readline_flavor = get_option('readline-flavor')
|
||||||
if readline_flavor == 'editline'
|
if readline_flavor == 'editline'
|
||||||
editline = dependency('libeditline', 'editline', version : '>=1.14')
|
editline = dependency('libeditline', 'editline', version : '>=1.14')
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
# vim: filetype=meson
|
# vim: filetype=meson
|
||||||
|
|
||||||
|
option(
|
||||||
|
'markdown',
|
||||||
|
type : 'feature',
|
||||||
|
description : 'Enable Markdown rendering in the Nix binary (requires lowdown)',
|
||||||
|
)
|
||||||
|
|
||||||
option(
|
option(
|
||||||
'readline-flavor',
|
'readline-flavor',
|
||||||
type : 'combo',
|
type : 'combo',
|
||||||
|
|||||||
@@ -11,12 +11,16 @@
|
|||||||
nix-main,
|
nix-main,
|
||||||
editline,
|
editline,
|
||||||
readline,
|
readline,
|
||||||
|
lowdown,
|
||||||
nlohmann_json,
|
nlohmann_json,
|
||||||
|
|
||||||
# Configuration Options
|
# Configuration Options
|
||||||
|
|
||||||
version,
|
version,
|
||||||
|
|
||||||
|
# Whether to enable Markdown rendering in the Nix binary.
|
||||||
|
enableMarkdown ? !stdenv.hostPlatform.isWindows,
|
||||||
|
|
||||||
# Which interactive line editor library to use for Nix's repl.
|
# Which interactive line editor library to use for Nix's repl.
|
||||||
#
|
#
|
||||||
# Currently supported choices are:
|
# Currently supported choices are:
|
||||||
@@ -49,7 +53,8 @@ mkMesonLibrary (finalAttrs: {
|
|||||||
|
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
({ inherit editline readline; }.${readlineFlavor})
|
({ inherit editline readline; }.${readlineFlavor})
|
||||||
];
|
]
|
||||||
|
++ lib.optional enableMarkdown lowdown;
|
||||||
|
|
||||||
propagatedBuildInputs = [
|
propagatedBuildInputs = [
|
||||||
nix-util
|
nix-util
|
||||||
@@ -62,6 +67,7 @@ mkMesonLibrary (finalAttrs: {
|
|||||||
];
|
];
|
||||||
|
|
||||||
mesonFlags = [
|
mesonFlags = [
|
||||||
|
(lib.mesonEnable "markdown" enableMarkdown)
|
||||||
(lib.mesonOption "readline-flavor" readlineFlavor)
|
(lib.mesonOption "readline-flavor" readlineFlavor)
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -739,7 +739,7 @@ void NixRepl::loadFlake(const std::string & flakeRefS)
|
|||||||
|
|
||||||
auto flakeRef = parseFlakeRef(fetchSettings, flakeRefS, cwd.string(), true);
|
auto flakeRef = parseFlakeRef(fetchSettings, flakeRefS, cwd.string(), true);
|
||||||
if (evalSettings.pureEval && !flakeRef.input.isLocked(fetchSettings))
|
if (evalSettings.pureEval && !flakeRef.input.isLocked(fetchSettings))
|
||||||
throw Error("cannot use ':load-flake' on unlocked flake reference '%s' (use --impure to override)", flakeRefS);
|
throw Error("cannot use ':load-flake' on locked flake reference '%s' (use --impure to override)", flakeRefS);
|
||||||
|
|
||||||
Value v;
|
Value v;
|
||||||
|
|
||||||
|
|||||||
+13
-13
@@ -205,7 +205,7 @@ bool Value::isTrivial() const
|
|||||||
{
|
{
|
||||||
return !isa<tApp, tPrimOpApp>()
|
return !isa<tApp, tPrimOpApp>()
|
||||||
&& (!isa<tThunk>()
|
&& (!isa<tThunk>()
|
||||||
|| (dynamic_cast<ExprAttrs *>(thunk().expr) && ((ExprAttrs *) thunk().expr)->dynamicAttrs->empty())
|
|| (dynamic_cast<ExprAttrs *>(thunk().expr) && ((ExprAttrs *) thunk().expr)->dynamicAttrs.empty())
|
||||||
|| dynamic_cast<ExprLambda *>(thunk().expr) || dynamic_cast<ExprList *>(thunk().expr));
|
|| dynamic_cast<ExprLambda *>(thunk().expr) || dynamic_cast<ExprList *>(thunk().expr));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1226,26 +1226,26 @@ Env * ExprAttrs::buildInheritFromEnv(EvalState & state, Env & up)
|
|||||||
|
|
||||||
void ExprAttrs::eval(EvalState & state, Env & env, Value & v)
|
void ExprAttrs::eval(EvalState & state, Env & env, Value & v)
|
||||||
{
|
{
|
||||||
auto bindings = state.buildBindings(attrs->size() + dynamicAttrs->size());
|
auto bindings = state.buildBindings(attrs.size() + dynamicAttrs.size());
|
||||||
auto dynamicEnv = &env;
|
auto dynamicEnv = &env;
|
||||||
bool sort = false;
|
bool sort = false;
|
||||||
|
|
||||||
if (recursive) {
|
if (recursive) {
|
||||||
/* Create a new environment that contains the attributes in
|
/* Create a new environment that contains the attributes in
|
||||||
this `rec'. */
|
this `rec'. */
|
||||||
Env & env2(state.mem.allocEnv(attrs->size()));
|
Env & env2(state.mem.allocEnv(attrs.size()));
|
||||||
env2.up = &env;
|
env2.up = &env;
|
||||||
dynamicEnv = &env2;
|
dynamicEnv = &env2;
|
||||||
Env * inheritEnv = inheritFromExprs ? buildInheritFromEnv(state, env2) : nullptr;
|
Env * inheritEnv = inheritFromExprs ? buildInheritFromEnv(state, env2) : nullptr;
|
||||||
|
|
||||||
AttrDefs::iterator overrides = attrs->find(state.s.overrides);
|
AttrDefs::iterator overrides = attrs.find(state.s.overrides);
|
||||||
bool hasOverrides = overrides != attrs->end();
|
bool hasOverrides = overrides != attrs.end();
|
||||||
|
|
||||||
/* The recursive attributes are evaluated in the new
|
/* The recursive attributes are evaluated in the new
|
||||||
environment, while the inherited attributes are evaluated
|
environment, while the inherited attributes are evaluated
|
||||||
in the original environment. */
|
in the original environment. */
|
||||||
Displacement displ = 0;
|
Displacement displ = 0;
|
||||||
for (auto & i : *attrs) {
|
for (auto & i : attrs) {
|
||||||
Value * vAttr;
|
Value * vAttr;
|
||||||
if (hasOverrides && i.second.kind != AttrDef::Kind::Inherited) {
|
if (hasOverrides && i.second.kind != AttrDef::Kind::Inherited) {
|
||||||
vAttr = state.allocValue();
|
vAttr = state.allocValue();
|
||||||
@@ -1272,8 +1272,8 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v)
|
|||||||
"while evaluating the `__overrides` attribute");
|
"while evaluating the `__overrides` attribute");
|
||||||
bindings.grow(state.buildBindings(bindings.capacity() + vOverrides->attrs()->size()));
|
bindings.grow(state.buildBindings(bindings.capacity() + vOverrides->attrs()->size()));
|
||||||
for (auto & i : *vOverrides->attrs()) {
|
for (auto & i : *vOverrides->attrs()) {
|
||||||
AttrDefs::iterator j = attrs->find(i.name);
|
AttrDefs::iterator j = attrs.find(i.name);
|
||||||
if (j != attrs->end()) {
|
if (j != attrs.end()) {
|
||||||
(*bindings.bindings)[j->second.displ] = i;
|
(*bindings.bindings)[j->second.displ] = i;
|
||||||
env2.values[j->second.displ] = i.value;
|
env2.values[j->second.displ] = i.value;
|
||||||
} else
|
} else
|
||||||
@@ -1285,13 +1285,13 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v)
|
|||||||
|
|
||||||
else {
|
else {
|
||||||
Env * inheritEnv = inheritFromExprs ? buildInheritFromEnv(state, env) : nullptr;
|
Env * inheritEnv = inheritFromExprs ? buildInheritFromEnv(state, env) : nullptr;
|
||||||
for (auto & i : *attrs)
|
for (auto & i : attrs)
|
||||||
bindings.insert(
|
bindings.insert(
|
||||||
i.first, i.second.e->maybeThunk(state, *i.second.chooseByKind(&env, &env, inheritEnv)), i.second.pos);
|
i.first, i.second.e->maybeThunk(state, *i.second.chooseByKind(&env, &env, inheritEnv)), i.second.pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Dynamic attrs apply *after* rec and __overrides. */
|
/* Dynamic attrs apply *after* rec and __overrides. */
|
||||||
for (auto & i : *dynamicAttrs) {
|
for (auto & i : dynamicAttrs) {
|
||||||
Value nameVal;
|
Value nameVal;
|
||||||
i.nameExpr->eval(state, *dynamicEnv, nameVal);
|
i.nameExpr->eval(state, *dynamicEnv, nameVal);
|
||||||
state.forceValue(nameVal, i.pos);
|
state.forceValue(nameVal, i.pos);
|
||||||
@@ -1325,7 +1325,7 @@ void ExprLet::eval(EvalState & state, Env & env, Value & v)
|
|||||||
{
|
{
|
||||||
/* Create a new environment that contains the attributes in this
|
/* Create a new environment that contains the attributes in this
|
||||||
`let'. */
|
`let'. */
|
||||||
Env & env2(state.mem.allocEnv(attrs->attrs->size()));
|
Env & env2(state.mem.allocEnv(attrs->attrs.size()));
|
||||||
env2.up = &env;
|
env2.up = &env;
|
||||||
|
|
||||||
Env * inheritEnv = attrs->inheritFromExprs ? attrs->buildInheritFromEnv(state, env2) : nullptr;
|
Env * inheritEnv = attrs->inheritFromExprs ? attrs->buildInheritFromEnv(state, env2) : nullptr;
|
||||||
@@ -1334,7 +1334,7 @@ void ExprLet::eval(EvalState & state, Env & env, Value & v)
|
|||||||
while the inherited attributes are evaluated in the original
|
while the inherited attributes are evaluated in the original
|
||||||
environment. */
|
environment. */
|
||||||
Displacement displ = 0;
|
Displacement displ = 0;
|
||||||
for (auto & i : *attrs->attrs) {
|
for (auto & i : attrs->attrs) {
|
||||||
env2.values[displ++] = i.second.e->maybeThunk(state, *i.second.chooseByKind(&env2, &env, inheritEnv));
|
env2.values[displ++] = i.second.e->maybeThunk(state, *i.second.chooseByKind(&env2, &env, inheritEnv));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3190,7 +3190,7 @@ std::optional<SourcePath> EvalState::resolveLookupPathPath(const LookupPath::Pat
|
|||||||
|
|
||||||
if (EvalSettings::isPseudoUrl(value)) {
|
if (EvalSettings::isPseudoUrl(value)) {
|
||||||
try {
|
try {
|
||||||
auto accessor = fetchers::downloadTarball(*store, fetchSettings, EvalSettings::resolvePseudoUrl(value));
|
auto accessor = fetchers::downloadTarball(store, fetchSettings, EvalSettings::resolvePseudoUrl(value));
|
||||||
auto storePath = fetchToStore(fetchSettings, *store, SourcePath(accessor), FetchMode::Copy);
|
auto storePath = fetchToStore(fetchSettings, *store, SourcePath(accessor), FetchMode::Copy);
|
||||||
return finish(this->storePath(storePath));
|
return finish(this->storePath(storePath));
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
|
|||||||
@@ -395,13 +395,9 @@ struct ExprAttrs : Expr
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::pmr::map<Symbol, AttrDef> AttrDefs;
|
typedef std::map<Symbol, AttrDef> AttrDefs;
|
||||||
/**
|
AttrDefs attrs;
|
||||||
* attrs will never be null. we use std::optional so that we can call emplace() to re-initialize the value with a
|
std::unique_ptr<std::vector<Expr *>> inheritFromExprs;
|
||||||
* new pmr::map using a different allocator (move assignment will copy into the old allocator)
|
|
||||||
*/
|
|
||||||
std::optional<AttrDefs> attrs;
|
|
||||||
std::unique_ptr<std::pmr::vector<Expr *>> inheritFromExprs;
|
|
||||||
|
|
||||||
struct DynamicAttrDef
|
struct DynamicAttrDef
|
||||||
{
|
{
|
||||||
@@ -413,20 +409,13 @@ struct ExprAttrs : Expr
|
|||||||
, pos(pos) {};
|
, pos(pos) {};
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::pmr::vector<DynamicAttrDef> DynamicAttrDefs;
|
typedef std::vector<DynamicAttrDef> DynamicAttrDefs;
|
||||||
/**
|
DynamicAttrDefs dynamicAttrs;
|
||||||
* dynamicAttrs will never be null. See comment on AttrDefs above.
|
|
||||||
*/
|
|
||||||
std::optional<DynamicAttrDefs> dynamicAttrs;
|
|
||||||
ExprAttrs(const PosIdx & pos)
|
ExprAttrs(const PosIdx & pos)
|
||||||
: recursive(false)
|
: recursive(false)
|
||||||
, pos(pos)
|
, pos(pos) {};
|
||||||
, attrs(AttrDefs{})
|
|
||||||
, dynamicAttrs(DynamicAttrDefs{}) {};
|
|
||||||
ExprAttrs()
|
ExprAttrs()
|
||||||
: recursive(false)
|
: recursive(false) {};
|
||||||
, attrs(AttrDefs{})
|
|
||||||
, dynamicAttrs(DynamicAttrDefs{}) {};
|
|
||||||
|
|
||||||
PosIdx getPos() const override
|
PosIdx getPos() const override
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -126,8 +126,8 @@ inline void ParserState::addAttr(
|
|||||||
for (i = attrPath.begin(); i + 1 < attrPath.end(); i++) {
|
for (i = attrPath.begin(); i + 1 < attrPath.end(); i++) {
|
||||||
ExprAttrs * nested;
|
ExprAttrs * nested;
|
||||||
if (i->symbol) {
|
if (i->symbol) {
|
||||||
ExprAttrs::AttrDefs::iterator j = attrs->attrs->find(i->symbol);
|
ExprAttrs::AttrDefs::iterator j = attrs->attrs.find(i->symbol);
|
||||||
if (j != attrs->attrs->end()) {
|
if (j != attrs->attrs.end()) {
|
||||||
nested = dynamic_cast<ExprAttrs *>(j->second.e);
|
nested = dynamic_cast<ExprAttrs *>(j->second.e);
|
||||||
if (!nested) {
|
if (!nested) {
|
||||||
attrPath.erase(i + 1, attrPath.end());
|
attrPath.erase(i + 1, attrPath.end());
|
||||||
@@ -135,11 +135,11 @@ inline void ParserState::addAttr(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
nested = exprs.add<ExprAttrs>();
|
nested = exprs.add<ExprAttrs>();
|
||||||
(*attrs->attrs)[i->symbol] = ExprAttrs::AttrDef(nested, pos);
|
attrs->attrs[i->symbol] = ExprAttrs::AttrDef(nested, pos);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
nested = exprs.add<ExprAttrs>();
|
nested = exprs.add<ExprAttrs>();
|
||||||
attrs->dynamicAttrs->push_back(ExprAttrs::DynamicAttrDef(i->expr, nested, pos));
|
attrs->dynamicAttrs.push_back(ExprAttrs::DynamicAttrDef(i->expr, nested, pos));
|
||||||
}
|
}
|
||||||
attrs = nested;
|
attrs = nested;
|
||||||
}
|
}
|
||||||
@@ -148,7 +148,7 @@ inline void ParserState::addAttr(
|
|||||||
if (i->symbol) {
|
if (i->symbol) {
|
||||||
addAttr(attrs, attrPath, i->symbol, ExprAttrs::AttrDef(e, pos));
|
addAttr(attrs, attrPath, i->symbol, ExprAttrs::AttrDef(e, pos));
|
||||||
} else {
|
} else {
|
||||||
attrs->dynamicAttrs->push_back(ExprAttrs::DynamicAttrDef(i->expr, e, pos));
|
attrs->dynamicAttrs.push_back(ExprAttrs::DynamicAttrDef(i->expr, e, pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto it = lexerState.positionToDocComment.find(pos);
|
auto it = lexerState.positionToDocComment.find(pos);
|
||||||
@@ -165,8 +165,8 @@ inline void ParserState::addAttr(
|
|||||||
inline void
|
inline void
|
||||||
ParserState::addAttr(ExprAttrs * attrs, AttrPath & attrPath, const Symbol & symbol, ExprAttrs::AttrDef && def)
|
ParserState::addAttr(ExprAttrs * attrs, AttrPath & attrPath, const Symbol & symbol, ExprAttrs::AttrDef && def)
|
||||||
{
|
{
|
||||||
ExprAttrs::AttrDefs::iterator j = attrs->attrs->find(symbol);
|
ExprAttrs::AttrDefs::iterator j = attrs->attrs.find(symbol);
|
||||||
if (j != attrs->attrs->end()) {
|
if (j != attrs->attrs.end()) {
|
||||||
// This attr path is already defined. However, if both
|
// This attr path is already defined. However, if both
|
||||||
// e and the expr pointed by the attr path are two attribute sets,
|
// e and the expr pointed by the attr path are two attribute sets,
|
||||||
// we want to merge them.
|
// we want to merge them.
|
||||||
@@ -181,8 +181,8 @@ ParserState::addAttr(ExprAttrs * attrs, AttrPath & attrPath, const Symbol & symb
|
|||||||
// See https://github.com/NixOS/nix/issues/9020.
|
// See https://github.com/NixOS/nix/issues/9020.
|
||||||
if (jAttrs && ae) {
|
if (jAttrs && ae) {
|
||||||
if (ae->inheritFromExprs && !jAttrs->inheritFromExprs)
|
if (ae->inheritFromExprs && !jAttrs->inheritFromExprs)
|
||||||
jAttrs->inheritFromExprs = std::make_unique<std::pmr::vector<Expr *>>();
|
jAttrs->inheritFromExprs = std::make_unique<std::vector<Expr *>>();
|
||||||
for (auto & ad : *ae->attrs) {
|
for (auto & ad : ae->attrs) {
|
||||||
if (ad.second.kind == ExprAttrs::AttrDef::Kind::InheritedFrom) {
|
if (ad.second.kind == ExprAttrs::AttrDef::Kind::InheritedFrom) {
|
||||||
auto & sel = dynamic_cast<ExprSelect &>(*ad.second.e);
|
auto & sel = dynamic_cast<ExprSelect &>(*ad.second.e);
|
||||||
auto & from = dynamic_cast<ExprInheritFrom &>(*sel.e);
|
auto & from = dynamic_cast<ExprInheritFrom &>(*sel.e);
|
||||||
@@ -192,12 +192,12 @@ ParserState::addAttr(ExprAttrs * attrs, AttrPath & attrPath, const Symbol & symb
|
|||||||
addAttr(jAttrs, attrPath, ad.first, std::move(ad.second));
|
addAttr(jAttrs, attrPath, ad.first, std::move(ad.second));
|
||||||
attrPath.pop_back();
|
attrPath.pop_back();
|
||||||
}
|
}
|
||||||
ae->attrs->clear();
|
ae->attrs.clear();
|
||||||
jAttrs->dynamicAttrs->insert(
|
jAttrs->dynamicAttrs.insert(
|
||||||
jAttrs->dynamicAttrs->end(),
|
jAttrs->dynamicAttrs.end(),
|
||||||
std::make_move_iterator(ae->dynamicAttrs->begin()),
|
std::make_move_iterator(ae->dynamicAttrs.begin()),
|
||||||
std::make_move_iterator(ae->dynamicAttrs->end()));
|
std::make_move_iterator(ae->dynamicAttrs.end()));
|
||||||
ae->dynamicAttrs->clear();
|
ae->dynamicAttrs.clear();
|
||||||
if (ae->inheritFromExprs) {
|
if (ae->inheritFromExprs) {
|
||||||
jAttrs->inheritFromExprs->insert(
|
jAttrs->inheritFromExprs->insert(
|
||||||
jAttrs->inheritFromExprs->end(),
|
jAttrs->inheritFromExprs->end(),
|
||||||
@@ -210,7 +210,7 @@ ParserState::addAttr(ExprAttrs * attrs, AttrPath & attrPath, const Symbol & symb
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// This attr path is not defined. Let's create it.
|
// This attr path is not defined. Let's create it.
|
||||||
attrs->attrs->emplace(symbol, def);
|
attrs->attrs.emplace(symbol, def);
|
||||||
def.e->setName(symbol);
|
def.e->setName(symbol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ deps_public_maybe_subproject = [
|
|||||||
dependency('nix-util'),
|
dependency('nix-util'),
|
||||||
dependency('nix-store'),
|
dependency('nix-store'),
|
||||||
dependency('nix-fetchers'),
|
dependency('nix-fetchers'),
|
||||||
dependency('cmark-cpp'),
|
|
||||||
]
|
]
|
||||||
subdir('nix-meson-build-support/subprojects')
|
subdir('nix-meson-build-support/subprojects')
|
||||||
subdir('nix-meson-build-support/big-objs')
|
subdir('nix-meson-build-support/big-objs')
|
||||||
|
|||||||
+12
-23
@@ -74,9 +74,9 @@ void ExprOpHasAttr::show(const SymbolTable & symbols, std::ostream & str) const
|
|||||||
|
|
||||||
void ExprAttrs::showBindings(const SymbolTable & symbols, std::ostream & str) const
|
void ExprAttrs::showBindings(const SymbolTable & symbols, std::ostream & str) const
|
||||||
{
|
{
|
||||||
typedef const AttrDefs::value_type * Attr;
|
typedef const decltype(attrs)::value_type * Attr;
|
||||||
std::vector<Attr> sorted;
|
std::vector<Attr> sorted;
|
||||||
for (auto & i : *attrs)
|
for (auto & i : attrs)
|
||||||
sorted.push_back(&i);
|
sorted.push_back(&i);
|
||||||
std::sort(sorted.begin(), sorted.end(), [&](Attr a, Attr b) {
|
std::sort(sorted.begin(), sorted.end(), [&](Attr a, Attr b) {
|
||||||
std::string_view sa = symbols[a->first], sb = symbols[b->first];
|
std::string_view sa = symbols[a->first], sb = symbols[b->first];
|
||||||
@@ -122,7 +122,7 @@ void ExprAttrs::showBindings(const SymbolTable & symbols, std::ostream & str) co
|
|||||||
str << "; ";
|
str << "; ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (auto & i : *dynamicAttrs) {
|
for (auto & i : dynamicAttrs) {
|
||||||
str << "\"${";
|
str << "\"${";
|
||||||
i.nameExpr->show(symbols, str);
|
i.nameExpr->show(symbols, str);
|
||||||
str << "}\" = ";
|
str << "}\" = ";
|
||||||
@@ -401,26 +401,15 @@ ExprAttrs::bindInheritSources(EvalState & es, const std::shared_ptr<const Static
|
|||||||
|
|
||||||
void ExprAttrs::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
void ExprAttrs::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
||||||
{
|
{
|
||||||
// Move storage into the Exprs arena
|
|
||||||
{
|
|
||||||
auto arena = es.mem.exprs.alloc;
|
|
||||||
AttrDefs newAttrs{std::move(*attrs), arena};
|
|
||||||
attrs.emplace(std::move(newAttrs), arena);
|
|
||||||
DynamicAttrDefs newDynamicAttrs{std::move(*dynamicAttrs), arena};
|
|
||||||
dynamicAttrs.emplace(std::move(newDynamicAttrs), arena);
|
|
||||||
if (inheritFromExprs)
|
|
||||||
inheritFromExprs = std::make_unique<std::pmr::vector<Expr *>>(std::move(*inheritFromExprs), arena);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (es.debugRepl)
|
if (es.debugRepl)
|
||||||
es.exprEnvs.insert(std::make_pair(this, env));
|
es.exprEnvs.insert(std::make_pair(this, env));
|
||||||
|
|
||||||
if (recursive) {
|
if (recursive) {
|
||||||
auto newEnv = [&]() -> std::shared_ptr<const StaticEnv> {
|
auto newEnv = [&]() -> std::shared_ptr<const StaticEnv> {
|
||||||
auto newEnv = std::make_shared<StaticEnv>(nullptr, env, attrs->size());
|
auto newEnv = std::make_shared<StaticEnv>(nullptr, env, attrs.size());
|
||||||
|
|
||||||
Displacement displ = 0;
|
Displacement displ = 0;
|
||||||
for (auto & i : *attrs)
|
for (auto & i : attrs)
|
||||||
newEnv->vars.emplace_back(i.first, i.second.displ = displ++);
|
newEnv->vars.emplace_back(i.first, i.second.displ = displ++);
|
||||||
return newEnv;
|
return newEnv;
|
||||||
}();
|
}();
|
||||||
@@ -428,20 +417,20 @@ void ExprAttrs::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv>
|
|||||||
// No need to sort newEnv since attrs is in sorted order.
|
// No need to sort newEnv since attrs is in sorted order.
|
||||||
|
|
||||||
auto inheritFromEnv = bindInheritSources(es, newEnv);
|
auto inheritFromEnv = bindInheritSources(es, newEnv);
|
||||||
for (auto & i : *attrs)
|
for (auto & i : attrs)
|
||||||
i.second.e->bindVars(es, i.second.chooseByKind(newEnv, env, inheritFromEnv));
|
i.second.e->bindVars(es, i.second.chooseByKind(newEnv, env, inheritFromEnv));
|
||||||
|
|
||||||
for (auto & i : *dynamicAttrs) {
|
for (auto & i : dynamicAttrs) {
|
||||||
i.nameExpr->bindVars(es, newEnv);
|
i.nameExpr->bindVars(es, newEnv);
|
||||||
i.valueExpr->bindVars(es, newEnv);
|
i.valueExpr->bindVars(es, newEnv);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
auto inheritFromEnv = bindInheritSources(es, env);
|
auto inheritFromEnv = bindInheritSources(es, env);
|
||||||
|
|
||||||
for (auto & i : *attrs)
|
for (auto & i : attrs)
|
||||||
i.second.e->bindVars(es, i.second.chooseByKind(env, env, inheritFromEnv));
|
i.second.e->bindVars(es, i.second.chooseByKind(env, env, inheritFromEnv));
|
||||||
|
|
||||||
for (auto & i : *dynamicAttrs) {
|
for (auto & i : dynamicAttrs) {
|
||||||
i.nameExpr->bindVars(es, env);
|
i.nameExpr->bindVars(es, env);
|
||||||
i.valueExpr->bindVars(es, env);
|
i.valueExpr->bindVars(es, env);
|
||||||
}
|
}
|
||||||
@@ -497,10 +486,10 @@ void ExprCall::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> &
|
|||||||
void ExprLet::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
void ExprLet::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
||||||
{
|
{
|
||||||
auto newEnv = [&]() -> std::shared_ptr<const StaticEnv> {
|
auto newEnv = [&]() -> std::shared_ptr<const StaticEnv> {
|
||||||
auto newEnv = std::make_shared<StaticEnv>(nullptr, env, attrs->attrs->size());
|
auto newEnv = std::make_shared<StaticEnv>(nullptr, env, attrs->attrs.size());
|
||||||
|
|
||||||
Displacement displ = 0;
|
Displacement displ = 0;
|
||||||
for (auto & i : *attrs->attrs)
|
for (auto & i : attrs->attrs)
|
||||||
newEnv->vars.emplace_back(i.first, i.second.displ = displ++);
|
newEnv->vars.emplace_back(i.first, i.second.displ = displ++);
|
||||||
return newEnv;
|
return newEnv;
|
||||||
}();
|
}();
|
||||||
@@ -508,7 +497,7 @@ void ExprLet::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> &
|
|||||||
// No need to sort newEnv since attrs->attrs is in sorted order.
|
// No need to sort newEnv since attrs->attrs is in sorted order.
|
||||||
|
|
||||||
auto inheritFromEnv = attrs->bindInheritSources(es, newEnv);
|
auto inheritFromEnv = attrs->bindInheritSources(es, newEnv);
|
||||||
for (auto & i : *attrs->attrs)
|
for (auto & i : attrs->attrs)
|
||||||
i.second.e->bindVars(es, i.second.chooseByKind(newEnv, env, inheritFromEnv));
|
i.second.e->bindVars(es, i.second.chooseByKind(newEnv, env, inheritFromEnv));
|
||||||
|
|
||||||
if (es.debugRepl)
|
if (es.debugRepl)
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ expr_function
|
|||||||
| WITH expr ';' expr_function
|
| WITH expr ';' expr_function
|
||||||
{ $$ = state->exprs.add<ExprWith>(CUR_POS, $2, $4); }
|
{ $$ = state->exprs.add<ExprWith>(CUR_POS, $2, $4); }
|
||||||
| LET binds IN_KW expr_function
|
| LET binds IN_KW expr_function
|
||||||
{ if (!$2->dynamicAttrs->empty())
|
{ if (!$2->dynamicAttrs.empty())
|
||||||
throw ParseError({
|
throw ParseError({
|
||||||
.msg = HintFmt("dynamic attributes not allowed in let"),
|
.msg = HintFmt("dynamic attributes not allowed in let"),
|
||||||
.pos = state->positions[CUR_POS]
|
.pos = state->positions[CUR_POS]
|
||||||
@@ -413,9 +413,9 @@ binds1
|
|||||||
| binds[accum] INHERIT attrs ';'
|
| binds[accum] INHERIT attrs ';'
|
||||||
{ $$ = $accum;
|
{ $$ = $accum;
|
||||||
for (auto & [i, iPos] : $attrs) {
|
for (auto & [i, iPos] : $attrs) {
|
||||||
if ($accum->attrs->find(i.symbol) != $accum->attrs->end())
|
if ($accum->attrs.find(i.symbol) != $accum->attrs.end())
|
||||||
state->dupAttr(i.symbol, iPos, (*$accum->attrs)[i.symbol].pos);
|
state->dupAttr(i.symbol, iPos, $accum->attrs[i.symbol].pos);
|
||||||
$accum->attrs->emplace(
|
$accum->attrs.emplace(
|
||||||
i.symbol,
|
i.symbol,
|
||||||
ExprAttrs::AttrDef(state->exprs.add<ExprVar>(iPos, i.symbol), iPos, ExprAttrs::AttrDef::Kind::Inherited));
|
ExprAttrs::AttrDef(state->exprs.add<ExprVar>(iPos, i.symbol), iPos, ExprAttrs::AttrDef::Kind::Inherited));
|
||||||
}
|
}
|
||||||
@@ -423,13 +423,13 @@ binds1
|
|||||||
| binds[accum] INHERIT '(' expr ')' attrs ';'
|
| binds[accum] INHERIT '(' expr ')' attrs ';'
|
||||||
{ $$ = $accum;
|
{ $$ = $accum;
|
||||||
if (!$accum->inheritFromExprs)
|
if (!$accum->inheritFromExprs)
|
||||||
$accum->inheritFromExprs = std::make_unique<std::pmr::vector<Expr *>>();
|
$accum->inheritFromExprs = std::make_unique<std::vector<Expr *>>();
|
||||||
$accum->inheritFromExprs->push_back($expr);
|
$accum->inheritFromExprs->push_back($expr);
|
||||||
auto from = state->exprs.add<ExprInheritFrom>(state->at(@expr), $accum->inheritFromExprs->size() - 1);
|
auto from = state->exprs.add<ExprInheritFrom>(state->at(@expr), $accum->inheritFromExprs->size() - 1);
|
||||||
for (auto & [i, iPos] : $attrs) {
|
for (auto & [i, iPos] : $attrs) {
|
||||||
if ($accum->attrs->find(i.symbol) != $accum->attrs->end())
|
if ($accum->attrs.find(i.symbol) != $accum->attrs.end())
|
||||||
state->dupAttr(i.symbol, iPos, (*$accum->attrs)[i.symbol].pos);
|
state->dupAttr(i.symbol, iPos, $accum->attrs[i.symbol].pos);
|
||||||
$accum->attrs->emplace(
|
$accum->attrs.emplace(
|
||||||
i.symbol,
|
i.symbol,
|
||||||
ExprAttrs::AttrDef(
|
ExprAttrs::AttrDef(
|
||||||
state->exprs.add<ExprSelect>(state->exprs.alloc, iPos, from, i.symbol),
|
state->exprs.add<ExprSelect>(state->exprs.alloc, iPos, from, i.symbol),
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ static void prim_fetchMercurial(EvalState & state, const PosIdx pos, Value ** ar
|
|||||||
attrs.insert_or_assign("rev", rev->gitRev());
|
attrs.insert_or_assign("rev", rev->gitRev());
|
||||||
auto input = fetchers::Input::fromAttrs(state.fetchSettings, std::move(attrs));
|
auto input = fetchers::Input::fromAttrs(state.fetchSettings, std::move(attrs));
|
||||||
|
|
||||||
auto [storePath, input2] = input.fetchToStore(state.fetchSettings, *state.store);
|
auto [storePath, input2] = input.fetchToStore(state.fetchSettings, state.store);
|
||||||
|
|
||||||
auto attrs2 = state.buildBindings(8);
|
auto attrs2 = state.buildBindings(8);
|
||||||
state.mkStorePathString(storePath, attrs2.alloc(state.s.outPath));
|
state.mkStorePathString(storePath, attrs2.alloc(state.s.outPath));
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
#include "nix/fetchers/registry.hh"
|
#include "nix/fetchers/registry.hh"
|
||||||
#include "nix/fetchers/tarball.hh"
|
#include "nix/fetchers/tarball.hh"
|
||||||
#include "nix/util/url.hh"
|
#include "nix/util/url.hh"
|
||||||
#include "nix/util/cmark-cpp.hh"
|
|
||||||
#include "nix/expr/value-to-json.hh"
|
#include "nix/expr/value-to-json.hh"
|
||||||
#include "nix/fetchers/fetch-to-store.hh"
|
#include "nix/fetchers/fetch-to-store.hh"
|
||||||
#include "nix/fetchers/input-cache.hh"
|
#include "nix/fetchers/input-cache.hh"
|
||||||
@@ -195,7 +194,7 @@ static void fetchTree(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!state.settings.pureEval && !input.isDirect() && experimentalFeatureSettings.isEnabled(Xp::Flakes))
|
if (!state.settings.pureEval && !input.isDirect() && experimentalFeatureSettings.isEnabled(Xp::Flakes))
|
||||||
input = lookupInRegistries(state.fetchSettings, *state.store, input, fetchers::UseRegistries::Limited).first;
|
input = lookupInRegistries(state.fetchSettings, state.store, input, fetchers::UseRegistries::Limited).first;
|
||||||
|
|
||||||
if (state.settings.pureEval && !input.isLocked(state.fetchSettings)) {
|
if (state.settings.pureEval && !input.isLocked(state.fetchSettings)) {
|
||||||
if (input.getNarHash())
|
if (input.getNarHash())
|
||||||
@@ -221,7 +220,7 @@ static void fetchTree(
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto cachedInput =
|
auto cachedInput =
|
||||||
state.inputCache->getAccessor(state.fetchSettings, *state.store, input, fetchers::UseRegistries::No);
|
state.inputCache->getAccessor(state.fetchSettings, state.store, input, fetchers::UseRegistries::No);
|
||||||
|
|
||||||
auto storePath = state.mountInput(cachedInput.lockedInput, input, cachedInput.accessor);
|
auto storePath = state.mountInput(cachedInput.lockedInput, input, cachedInput.accessor);
|
||||||
|
|
||||||
@@ -237,14 +236,7 @@ static RegisterPrimOp primop_fetchTree({
|
|||||||
.name = "fetchTree",
|
.name = "fetchTree",
|
||||||
.args = {"input"},
|
.args = {"input"},
|
||||||
.doc = []() -> std::string {
|
.doc = []() -> std::string {
|
||||||
using namespace cmark;
|
std::string doc = stripIndentation(R"(
|
||||||
|
|
||||||
// Stores strings referenced by AST. Deallocate after rendering.
|
|
||||||
std::vector<std::string> textArena;
|
|
||||||
|
|
||||||
auto root = node_new(CMARK_NODE_DOCUMENT);
|
|
||||||
|
|
||||||
auto & before = textArena.emplace_back(stripIndentation(R"(
|
|
||||||
Fetch a file system tree or a plain file using one of the supported backends and return an attribute set with:
|
Fetch a file system tree or a plain file using one of the supported backends and return an attribute set with:
|
||||||
|
|
||||||
- the resulting fixed-output [store path](@docroot@/store/store-path.md)
|
- the resulting fixed-output [store path](@docroot@/store/store-path.md)
|
||||||
@@ -284,45 +276,38 @@ static RegisterPrimOp primop_fetchTree({
|
|||||||
<!-- TODO: It would be soooo much more predictable to work with (and
|
<!-- TODO: It would be soooo much more predictable to work with (and
|
||||||
document) if `fetchTree` was a curried call with the first parameter for
|
document) if `fetchTree` was a curried call with the first parameter for
|
||||||
`type` or an attribute like `builtins.fetchTree.git`! -->
|
`type` or an attribute like `builtins.fetchTree.git`! -->
|
||||||
)"));
|
)");
|
||||||
parse_document(*root, before, CMARK_OPT_DEFAULT);
|
|
||||||
|
|
||||||
auto & schemes = node_append_child(*root, node_new(CMARK_NODE_LIST));
|
auto indentString = [](std::string const & str, std::string const & indent) {
|
||||||
|
std::string result;
|
||||||
|
std::istringstream stream(str);
|
||||||
|
std::string line;
|
||||||
|
bool first = true;
|
||||||
|
while (std::getline(stream, line)) {
|
||||||
|
if (!first)
|
||||||
|
result += "\n";
|
||||||
|
result += indent + line;
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
for (const auto & [schemeName, scheme] : fetchers::getAllInputSchemes()) {
|
for (const auto & [schemeName, scheme] : fetchers::getAllInputSchemes()) {
|
||||||
auto & s = node_append_child(schemes, node_new(CMARK_NODE_ITEM));
|
doc += "\n- `" + quoteString(schemeName, '"') + "`\n\n";
|
||||||
{
|
doc += indentString(scheme->schemeDescription(), " ");
|
||||||
auto & name_p = node_append_child(s, node_new(CMARK_NODE_PARAGRAPH));
|
if (!doc.empty() && doc.back() != '\n')
|
||||||
auto & name = node_append_child(name_p, node_new(CMARK_NODE_CODE));
|
doc += "\n";
|
||||||
auto & name_t = textArena.emplace_back(quoteString(schemeName, '"'));
|
|
||||||
node_set_literal(name, name_t.c_str());
|
|
||||||
}
|
|
||||||
parse_document(s, scheme->schemeDescription(), CMARK_OPT_DEFAULT);
|
|
||||||
|
|
||||||
auto & attrs = node_append_child(s, node_new(CMARK_NODE_LIST));
|
|
||||||
for (const auto & [attrName, attribute] : scheme->allowedAttrs()) {
|
for (const auto & [attrName, attribute] : scheme->allowedAttrs()) {
|
||||||
auto & a = node_append_child(attrs, node_new(CMARK_NODE_ITEM));
|
doc += "\n - `" + attrName + "` (" + attribute.type + ", "
|
||||||
{
|
+ (attribute.required ? "required" : "optional") + ")\n\n";
|
||||||
auto & name_info = node_append_child(a, node_new(CMARK_NODE_PARAGRAPH));
|
doc += indentString(stripIndentation(attribute.doc), " ");
|
||||||
{
|
if (!doc.empty() && doc.back() != '\n')
|
||||||
auto & name = node_append_child(name_info, node_new(CMARK_NODE_CODE));
|
doc += "\n";
|
||||||
auto & name_t = textArena.emplace_back(attrName);
|
|
||||||
node_set_literal(name, name_t.c_str());
|
|
||||||
}
|
|
||||||
auto & info = node_append_child(name_info, node_new(CMARK_NODE_TEXT));
|
|
||||||
auto & header = textArena.emplace_back(
|
|
||||||
std::string{} + " (" + attribute.type + ", " + (attribute.required ? "required" : "optional")
|
|
||||||
+ ")");
|
|
||||||
node_set_literal(info, header.c_str());
|
|
||||||
}
|
|
||||||
{
|
|
||||||
auto & doc = textArena.emplace_back(stripIndentation(attribute.doc));
|
|
||||||
parse_document(a, doc, CMARK_OPT_DEFAULT);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto & after = textArena.emplace_back(stripIndentation(R"(
|
doc += "\n" + stripIndentation(R"(
|
||||||
The following input types are still subject to change:
|
The following input types are still subject to change:
|
||||||
|
|
||||||
- `"path"`
|
- `"path"`
|
||||||
@@ -367,12 +352,9 @@ static RegisterPrimOp primop_fetchTree({
|
|||||||
> ```nix
|
> ```nix
|
||||||
> builtins.fetchTree "github:NixOS/nixpkgs/ae2e6b3958682513d28f7d633734571fb18285dd"
|
> builtins.fetchTree "github:NixOS/nixpkgs/ae2e6b3958682513d28f7d633734571fb18285dd"
|
||||||
> ```
|
> ```
|
||||||
)"));
|
)");
|
||||||
parse_document(*root, after, CMARK_OPT_DEFAULT);
|
|
||||||
|
|
||||||
auto p = render_commonmark(*root, CMARK_OPT_DEFAULT, 0);
|
return doc;
|
||||||
assert(p);
|
|
||||||
return {&*p};
|
|
||||||
}(),
|
}(),
|
||||||
.fun = prim_fetchTree,
|
.fun = prim_fetchTree,
|
||||||
.experimentalFeature = Xp::FetchTree,
|
.experimentalFeature = Xp::FetchTree,
|
||||||
@@ -498,10 +480,10 @@ static void fetch(
|
|||||||
auto storePath = unpack ? fetchToStore(
|
auto storePath = unpack ? fetchToStore(
|
||||||
state.fetchSettings,
|
state.fetchSettings,
|
||||||
*state.store,
|
*state.store,
|
||||||
fetchers::downloadTarball(*state.store, state.fetchSettings, *url),
|
fetchers::downloadTarball(state.store, state.fetchSettings, *url),
|
||||||
FetchMode::Copy,
|
FetchMode::Copy,
|
||||||
name)
|
name)
|
||||||
: fetchers::downloadFile(*state.store, state.fetchSettings, *url, name).storePath;
|
: fetchers::downloadFile(state.store, state.fetchSettings, *url, name).storePath;
|
||||||
|
|
||||||
if (expectedHash) {
|
if (expectedHash) {
|
||||||
auto hash = unpack ? state.store->queryPathInfo(storePath)->narHash
|
auto hash = unpack ? state.store->queryPathInfo(storePath)->narHash
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ TEST_F(GitTest, submodulePeriodSupport)
|
|||||||
{"ref", "main"},
|
{"ref", "main"},
|
||||||
});
|
});
|
||||||
|
|
||||||
auto [accessor, i] = input.getAccessor(settings, *store);
|
auto [accessor, i] = input.getAccessor(settings, store);
|
||||||
|
|
||||||
ASSERT_EQ(accessor->readFile(CanonPath("deps/sub/lib.txt")), "hello from submodule\n");
|
ASSERT_EQ(accessor->readFile(CanonPath("deps/sub/lib.txt")), "hello from submodule\n");
|
||||||
}
|
}
|
||||||
+15
-26
@@ -6,7 +6,6 @@
|
|||||||
#include "nix/fetchers/fetch-settings.hh"
|
#include "nix/fetchers/fetch-settings.hh"
|
||||||
#include "nix/fetchers/fetch-to-store.hh"
|
#include "nix/fetchers/fetch-to-store.hh"
|
||||||
#include "nix/util/url.hh"
|
#include "nix/util/url.hh"
|
||||||
#include "nix/util/archive.hh"
|
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
@@ -111,7 +110,7 @@ Input Input::fromAttrs(const Settings & settings, Attrs && attrs)
|
|||||||
return std::move(*res);
|
return std::move(*res);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::string> Input::getFingerprint(Store & store) const
|
std::optional<std::string> Input::getFingerprint(ref<Store> store) const
|
||||||
{
|
{
|
||||||
if (!scheme)
|
if (!scheme)
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
@@ -190,7 +189,7 @@ bool Input::contains(const Input & other) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: remove
|
// FIXME: remove
|
||||||
std::pair<StorePath, Input> Input::fetchToStore(const Settings & settings, Store & store) const
|
std::pair<StorePath, Input> Input::fetchToStore(const Settings & settings, ref<Store> store) const
|
||||||
{
|
{
|
||||||
if (!scheme)
|
if (!scheme)
|
||||||
throw Error("cannot fetch unsupported input '%s'", attrsToJSON(toAttrs()));
|
throw Error("cannot fetch unsupported input '%s'", attrsToJSON(toAttrs()));
|
||||||
@@ -200,9 +199,9 @@ std::pair<StorePath, Input> Input::fetchToStore(const Settings & settings, Store
|
|||||||
auto [accessor, result] = getAccessorUnchecked(settings, store);
|
auto [accessor, result] = getAccessorUnchecked(settings, store);
|
||||||
|
|
||||||
auto storePath =
|
auto storePath =
|
||||||
nix::fetchToStore(settings, store, SourcePath(accessor), FetchMode::Copy, result.getName());
|
nix::fetchToStore(settings, *store, SourcePath(accessor), FetchMode::Copy, result.getName());
|
||||||
|
|
||||||
auto narHash = store.queryPathInfo(storePath)->narHash;
|
auto narHash = store->queryPathInfo(storePath)->narHash;
|
||||||
result.attrs.insert_or_assign("narHash", narHash.to_string(HashFormat::SRI, true));
|
result.attrs.insert_or_assign("narHash", narHash.to_string(HashFormat::SRI, true));
|
||||||
|
|
||||||
result.attrs.insert_or_assign("__final", Explicit<bool>(true));
|
result.attrs.insert_or_assign("__final", Explicit<bool>(true));
|
||||||
@@ -289,7 +288,7 @@ void Input::checkLocks(Input specified, Input & result)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<ref<SourceAccessor>, Input> Input::getAccessor(const Settings & settings, Store & store) const
|
std::pair<ref<SourceAccessor>, Input> Input::getAccessor(const Settings & settings, ref<Store> store) const
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
auto [accessor, result] = getAccessorUnchecked(settings, store);
|
auto [accessor, result] = getAccessorUnchecked(settings, store);
|
||||||
@@ -305,7 +304,7 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessor(const Settings & settin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(const Settings & settings, Store & store) const
|
std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(const Settings & settings, ref<Store> store) const
|
||||||
{
|
{
|
||||||
// FIXME: cache the accessor
|
// FIXME: cache the accessor
|
||||||
|
|
||||||
@@ -325,13 +324,13 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(const Settings
|
|||||||
*/
|
*/
|
||||||
if (isFinal() && getNarHash()) {
|
if (isFinal() && getNarHash()) {
|
||||||
try {
|
try {
|
||||||
auto storePath = computeStorePath(store);
|
auto storePath = computeStorePath(*store);
|
||||||
|
|
||||||
store.ensurePath(storePath);
|
store->ensurePath(storePath);
|
||||||
|
|
||||||
debug("using substituted/cached input '%s' in '%s'", to_string(), store.printStorePath(storePath));
|
debug("using substituted/cached input '%s' in '%s'", to_string(), store->printStorePath(storePath));
|
||||||
|
|
||||||
auto accessor = store.requireStoreObjectAccessor(storePath);
|
auto accessor = store->requireStoreObjectAccessor(storePath);
|
||||||
|
|
||||||
accessor->fingerprint = getFingerprint(store);
|
accessor->fingerprint = getFingerprint(store);
|
||||||
|
|
||||||
@@ -341,7 +340,7 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(const Settings
|
|||||||
if (accessor->fingerprint) {
|
if (accessor->fingerprint) {
|
||||||
ContentAddressMethod method = ContentAddressMethod::Raw::NixArchive;
|
ContentAddressMethod method = ContentAddressMethod::Raw::NixArchive;
|
||||||
auto cacheKey = makeFetchToStoreCacheKey(getName(), *accessor->fingerprint, method, "/");
|
auto cacheKey = makeFetchToStoreCacheKey(getName(), *accessor->fingerprint, method, "/");
|
||||||
settings.getCache()->upsert(cacheKey, store, {}, storePath);
|
settings.getCache()->upsert(cacheKey, *store, {}, storePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
accessor->setPathDisplay("«" + to_string() + "»");
|
accessor->setPathDisplay("«" + to_string() + "»");
|
||||||
@@ -369,10 +368,10 @@ Input Input::applyOverrides(std::optional<std::string> ref, std::optional<Hash>
|
|||||||
return scheme->applyOverrides(*this, ref, rev);
|
return scheme->applyOverrides(*this, ref, rev);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Input::clone(const Settings & settings, Store & store, const std::filesystem::path & destDir) const
|
void Input::clone(const Settings & settings, const Path & destDir) const
|
||||||
{
|
{
|
||||||
assert(scheme);
|
assert(scheme);
|
||||||
scheme->clone(settings, store, *this, destDir);
|
scheme->clone(settings, *this, destDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::filesystem::path> Input::getSourcePath() const
|
std::optional<std::filesystem::path> Input::getSourcePath() const
|
||||||
@@ -485,19 +484,9 @@ void InputScheme::putFile(
|
|||||||
throw Error("input '%s' does not support modifying file '%s'", input.to_string(), path);
|
throw Error("input '%s' does not support modifying file '%s'", input.to_string(), path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputScheme::clone(
|
void InputScheme::clone(const Settings & settings, const Input & input, const Path & destDir) const
|
||||||
const Settings & settings, Store & store, const Input & input, const std::filesystem::path & destDir) const
|
|
||||||
{
|
{
|
||||||
if (std::filesystem::exists(destDir))
|
throw Error("do not know how to clone input '%s'", input.to_string());
|
||||||
throw Error("cannot clone into existing path %s", destDir);
|
|
||||||
|
|
||||||
auto [accessor, input2] = getAccessor(settings, store, input);
|
|
||||||
|
|
||||||
Activity act(*logger, lvlTalkative, actUnknown, fmt("copying '%s' to %s...", input2.to_string(), destDir));
|
|
||||||
|
|
||||||
auto source = sinkToSource([&](Sink & sink) { accessor->dumpPath(CanonPath::root, sink); });
|
|
||||||
|
|
||||||
restorePath(destDir, *source);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<ExperimentalFeature> InputScheme::experimentalFeature() const
|
std::optional<ExperimentalFeature> InputScheme::experimentalFeature() const
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ std::vector<nlohmann::json> Fetch::fetchUrls(const std::vector<Pointer> & pointe
|
|||||||
auto url = api.endpoint + "/objects/batch";
|
auto url = api.endpoint + "/objects/batch";
|
||||||
const auto & authHeader = api.authHeader;
|
const auto & authHeader = api.authHeader;
|
||||||
FileTransferRequest request(parseURL(url));
|
FileTransferRequest request(parseURL(url));
|
||||||
request.method = HttpMethod::Post;
|
request.method = HttpMethod::POST;
|
||||||
Headers headers;
|
Headers headers;
|
||||||
if (authHeader.has_value())
|
if (authHeader.has_value())
|
||||||
headers.push_back({"Authorization", *authHeader});
|
headers.push_back({"Authorization", *authHeader});
|
||||||
|
|||||||
@@ -433,8 +433,7 @@ struct GitInputScheme : InputScheme
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clone(const Settings & settings, Store & store, const Input & input, const std::filesystem::path & destDir)
|
void clone(const Settings & settings, const Input & input, const Path & destDir) const override
|
||||||
const override
|
|
||||||
{
|
{
|
||||||
auto repoInfo = getRepoInfo(input);
|
auto repoInfo = getRepoInfo(input);
|
||||||
|
|
||||||
@@ -779,7 +778,7 @@ struct GitInputScheme : InputScheme
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::pair<ref<SourceAccessor>, Input>
|
std::pair<ref<SourceAccessor>, Input>
|
||||||
getAccessorFromCommit(const Settings & settings, Store & store, RepoInfo & repoInfo, Input && input) const
|
getAccessorFromCommit(const Settings & settings, ref<Store> store, RepoInfo & repoInfo, Input && input) const
|
||||||
{
|
{
|
||||||
assert(!repoInfo.workdirInfo.isDirty);
|
assert(!repoInfo.workdirInfo.isDirty);
|
||||||
|
|
||||||
@@ -953,7 +952,7 @@ struct GitInputScheme : InputScheme
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::pair<ref<SourceAccessor>, Input>
|
std::pair<ref<SourceAccessor>, Input>
|
||||||
getAccessorFromWorkdir(const Settings & settings, Store & store, RepoInfo & repoInfo, Input && input) const
|
getAccessorFromWorkdir(const Settings & settings, ref<Store> store, RepoInfo & repoInfo, Input && input) const
|
||||||
{
|
{
|
||||||
auto repoPath = repoInfo.getPath().value();
|
auto repoPath = repoInfo.getPath().value();
|
||||||
|
|
||||||
@@ -1037,7 +1036,7 @@ struct GitInputScheme : InputScheme
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::pair<ref<SourceAccessor>, Input>
|
std::pair<ref<SourceAccessor>, Input>
|
||||||
getAccessor(const Settings & settings, Store & store, const Input & _input) const override
|
getAccessor(const Settings & settings, ref<Store> store, const Input & _input) const override
|
||||||
{
|
{
|
||||||
Input input(_input);
|
Input input(_input);
|
||||||
|
|
||||||
@@ -1059,7 +1058,7 @@ struct GitInputScheme : InputScheme
|
|||||||
return {accessor, std::move(final)};
|
return {accessor, std::move(final)};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::string> getFingerprint(Store & store, const Input & input) const override
|
std::optional<std::string> getFingerprint(ref<Store> store, const Input & input) const override
|
||||||
{
|
{
|
||||||
auto makeFingerprint = [&](const Hash & rev) {
|
auto makeFingerprint = [&](const Hash & rev) {
|
||||||
return rev.gitRev() + (getSubmodulesAttr(input) ? ";s" : "") + (getExportIgnoreAttr(input) ? ";e" : "")
|
return rev.gitRev() + (getSubmodulesAttr(input) ? ";s" : "") + (getExportIgnoreAttr(input) ? ";e" : "")
|
||||||
|
|||||||
+17
-20
@@ -258,7 +258,7 @@ struct GitArchiveInputScheme : InputScheme
|
|||||||
std::optional<Hash> treeHash;
|
std::optional<Hash> treeHash;
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual RefInfo getRevFromRef(const Settings & settings, nix::Store & store, const Input & input) const = 0;
|
virtual RefInfo getRevFromRef(const Settings & settings, nix::ref<Store> store, const Input & input) const = 0;
|
||||||
|
|
||||||
virtual DownloadUrl getDownloadUrl(const Settings & settings, const Input & input) const = 0;
|
virtual DownloadUrl getDownloadUrl(const Settings & settings, const Input & input) const = 0;
|
||||||
|
|
||||||
@@ -268,7 +268,7 @@ struct GitArchiveInputScheme : InputScheme
|
|||||||
time_t lastModified;
|
time_t lastModified;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::pair<Input, TarballInfo> downloadArchive(const Settings & settings, Store & store, Input input) const
|
std::pair<Input, TarballInfo> downloadArchive(const Settings & settings, ref<Store> store, Input input) const
|
||||||
{
|
{
|
||||||
if (!maybeGetStrAttr(input.attrs, "ref"))
|
if (!maybeGetStrAttr(input.attrs, "ref"))
|
||||||
input.attrs.insert_or_assign("ref", "HEAD");
|
input.attrs.insert_or_assign("ref", "HEAD");
|
||||||
@@ -341,7 +341,7 @@ struct GitArchiveInputScheme : InputScheme
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::pair<ref<SourceAccessor>, Input>
|
std::pair<ref<SourceAccessor>, Input>
|
||||||
getAccessor(const Settings & settings, Store & store, const Input & _input) const override
|
getAccessor(const Settings & settings, ref<Store> store, const Input & _input) const override
|
||||||
{
|
{
|
||||||
auto [input, tarballInfo] = downloadArchive(settings, store, _input);
|
auto [input, tarballInfo] = downloadArchive(settings, store, _input);
|
||||||
|
|
||||||
@@ -370,7 +370,7 @@ struct GitArchiveInputScheme : InputScheme
|
|||||||
return Xp::Flakes;
|
return Xp::Flakes;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::string> getFingerprint(Store & store, const Input & input) const override
|
std::optional<std::string> getFingerprint(ref<Store> store, const Input & input) const override
|
||||||
{
|
{
|
||||||
if (auto rev = input.getRev())
|
if (auto rev = input.getRev())
|
||||||
return rev->gitRev();
|
return rev->gitRev();
|
||||||
@@ -418,7 +418,7 @@ struct GitHubInputScheme : GitArchiveInputScheme
|
|||||||
return getStrAttr(input.attrs, "repo");
|
return getStrAttr(input.attrs, "repo");
|
||||||
}
|
}
|
||||||
|
|
||||||
RefInfo getRevFromRef(const Settings & settings, nix::Store & store, const Input & input) const override
|
RefInfo getRevFromRef(const Settings & settings, nix::ref<Store> store, const Input & input) const override
|
||||||
{
|
{
|
||||||
auto host = getHost(input);
|
auto host = getHost(input);
|
||||||
auto url = fmt(
|
auto url = fmt(
|
||||||
@@ -432,7 +432,7 @@ struct GitHubInputScheme : GitArchiveInputScheme
|
|||||||
|
|
||||||
auto downloadResult = downloadFile(store, settings, url, "source", headers);
|
auto downloadResult = downloadFile(store, settings, url, "source", headers);
|
||||||
auto json = nlohmann::json::parse(
|
auto json = nlohmann::json::parse(
|
||||||
store.requireStoreObjectAccessor(downloadResult.storePath)->readFile(CanonPath::root));
|
store->requireStoreObjectAccessor(downloadResult.storePath)->readFile(CanonPath::root));
|
||||||
|
|
||||||
return RefInfo{
|
return RefInfo{
|
||||||
.rev = Hash::parseAny(std::string{json["sha"]}, HashAlgorithm::SHA1),
|
.rev = Hash::parseAny(std::string{json["sha"]}, HashAlgorithm::SHA1),
|
||||||
@@ -457,13 +457,12 @@ struct GitHubInputScheme : GitArchiveInputScheme
|
|||||||
return DownloadUrl{parseURL(url), headers};
|
return DownloadUrl{parseURL(url), headers};
|
||||||
}
|
}
|
||||||
|
|
||||||
void clone(const Settings & settings, Store & store, const Input & input, const std::filesystem::path & destDir)
|
void clone(const Settings & settings, const Input & input, const Path & destDir) const override
|
||||||
const override
|
|
||||||
{
|
{
|
||||||
auto host = getHost(input);
|
auto host = getHost(input);
|
||||||
Input::fromURL(settings, fmt("git+https://%s/%s/%s.git", host, getOwner(input), getRepo(input)))
|
Input::fromURL(settings, fmt("git+https://%s/%s/%s.git", host, getOwner(input), getRepo(input)))
|
||||||
.applyOverrides(input.getRef(), input.getRev())
|
.applyOverrides(input.getRef(), input.getRev())
|
||||||
.clone(settings, store, destDir);
|
.clone(settings, destDir);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -499,7 +498,7 @@ struct GitLabInputScheme : GitArchiveInputScheme
|
|||||||
return std::make_pair(token.substr(0, fldsplit), token.substr(fldsplit + 1));
|
return std::make_pair(token.substr(0, fldsplit), token.substr(fldsplit + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
RefInfo getRevFromRef(const Settings & settings, nix::Store & store, const Input & input) const override
|
RefInfo getRevFromRef(const Settings & settings, nix::ref<Store> store, const Input & input) const override
|
||||||
{
|
{
|
||||||
auto host = maybeGetStrAttr(input.attrs, "host").value_or("gitlab.com");
|
auto host = maybeGetStrAttr(input.attrs, "host").value_or("gitlab.com");
|
||||||
// See rate limiting note below
|
// See rate limiting note below
|
||||||
@@ -514,7 +513,7 @@ struct GitLabInputScheme : GitArchiveInputScheme
|
|||||||
|
|
||||||
auto downloadResult = downloadFile(store, settings, url, "source", headers);
|
auto downloadResult = downloadFile(store, settings, url, "source", headers);
|
||||||
auto json = nlohmann::json::parse(
|
auto json = nlohmann::json::parse(
|
||||||
store.requireStoreObjectAccessor(downloadResult.storePath)->readFile(CanonPath::root));
|
store->requireStoreObjectAccessor(downloadResult.storePath)->readFile(CanonPath::root));
|
||||||
|
|
||||||
if (json.is_array() && json.size() >= 1 && json[0]["id"] != nullptr) {
|
if (json.is_array() && json.size() >= 1 && json[0]["id"] != nullptr) {
|
||||||
return RefInfo{.rev = Hash::parseAny(std::string(json[0]["id"]), HashAlgorithm::SHA1)};
|
return RefInfo{.rev = Hash::parseAny(std::string(json[0]["id"]), HashAlgorithm::SHA1)};
|
||||||
@@ -545,8 +544,7 @@ struct GitLabInputScheme : GitArchiveInputScheme
|
|||||||
return DownloadUrl{parseURL(url), headers};
|
return DownloadUrl{parseURL(url), headers};
|
||||||
}
|
}
|
||||||
|
|
||||||
void clone(const Settings & settings, Store & store, const Input & input, const std::filesystem::path & destDir)
|
void clone(const Settings & settings, const Input & input, const Path & destDir) const override
|
||||||
const override
|
|
||||||
{
|
{
|
||||||
auto host = maybeGetStrAttr(input.attrs, "host").value_or("gitlab.com");
|
auto host = maybeGetStrAttr(input.attrs, "host").value_or("gitlab.com");
|
||||||
// FIXME: get username somewhere
|
// FIXME: get username somewhere
|
||||||
@@ -554,7 +552,7 @@ struct GitLabInputScheme : GitArchiveInputScheme
|
|||||||
settings,
|
settings,
|
||||||
fmt("git+https://%s/%s/%s.git", host, getStrAttr(input.attrs, "owner"), getStrAttr(input.attrs, "repo")))
|
fmt("git+https://%s/%s/%s.git", host, getStrAttr(input.attrs, "owner"), getStrAttr(input.attrs, "repo")))
|
||||||
.applyOverrides(input.getRef(), input.getRev())
|
.applyOverrides(input.getRef(), input.getRev())
|
||||||
.clone(settings, store, destDir);
|
.clone(settings, destDir);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -581,7 +579,7 @@ struct SourceHutInputScheme : GitArchiveInputScheme
|
|||||||
// Once it is implemented, however, should work as expected.
|
// Once it is implemented, however, should work as expected.
|
||||||
}
|
}
|
||||||
|
|
||||||
RefInfo getRevFromRef(const Settings & settings, nix::Store & store, const Input & input) const override
|
RefInfo getRevFromRef(const Settings & settings, nix::ref<Store> store, const Input & input) const override
|
||||||
{
|
{
|
||||||
// TODO: In the future, when the sourcehut graphql API is implemented for mercurial
|
// TODO: In the future, when the sourcehut graphql API is implemented for mercurial
|
||||||
// and with anonymous access, this method should use it instead.
|
// and with anonymous access, this method should use it instead.
|
||||||
@@ -597,7 +595,7 @@ struct SourceHutInputScheme : GitArchiveInputScheme
|
|||||||
std::string refUri;
|
std::string refUri;
|
||||||
if (ref == "HEAD") {
|
if (ref == "HEAD") {
|
||||||
auto downloadFileResult = downloadFile(store, settings, fmt("%s/HEAD", base_url), "source", headers);
|
auto downloadFileResult = downloadFile(store, settings, fmt("%s/HEAD", base_url), "source", headers);
|
||||||
auto contents = store.requireStoreObjectAccessor(downloadFileResult.storePath)->readFile(CanonPath::root);
|
auto contents = store->requireStoreObjectAccessor(downloadFileResult.storePath)->readFile(CanonPath::root);
|
||||||
|
|
||||||
auto remoteLine = git::parseLsRemoteLine(getLine(contents).first);
|
auto remoteLine = git::parseLsRemoteLine(getLine(contents).first);
|
||||||
if (!remoteLine) {
|
if (!remoteLine) {
|
||||||
@@ -610,7 +608,7 @@ struct SourceHutInputScheme : GitArchiveInputScheme
|
|||||||
std::regex refRegex(refUri);
|
std::regex refRegex(refUri);
|
||||||
|
|
||||||
auto downloadFileResult = downloadFile(store, settings, fmt("%s/info/refs", base_url), "source", headers);
|
auto downloadFileResult = downloadFile(store, settings, fmt("%s/info/refs", base_url), "source", headers);
|
||||||
auto contents = store.requireStoreObjectAccessor(downloadFileResult.storePath)->readFile(CanonPath::root);
|
auto contents = store->requireStoreObjectAccessor(downloadFileResult.storePath)->readFile(CanonPath::root);
|
||||||
std::istringstream is(contents);
|
std::istringstream is(contents);
|
||||||
|
|
||||||
std::string line;
|
std::string line;
|
||||||
@@ -641,15 +639,14 @@ struct SourceHutInputScheme : GitArchiveInputScheme
|
|||||||
return DownloadUrl{parseURL(url), headers};
|
return DownloadUrl{parseURL(url), headers};
|
||||||
}
|
}
|
||||||
|
|
||||||
void clone(const Settings & settings, Store & store, const Input & input, const std::filesystem::path & destDir)
|
void clone(const Settings & settings, const Input & input, const Path & destDir) const override
|
||||||
const override
|
|
||||||
{
|
{
|
||||||
auto host = maybeGetStrAttr(input.attrs, "host").value_or("git.sr.ht");
|
auto host = maybeGetStrAttr(input.attrs, "host").value_or("git.sr.ht");
|
||||||
Input::fromURL(
|
Input::fromURL(
|
||||||
settings,
|
settings,
|
||||||
fmt("git+https://%s/%s/%s", host, getStrAttr(input.attrs, "owner"), getStrAttr(input.attrs, "repo")))
|
fmt("git+https://%s/%s/%s", host, getStrAttr(input.attrs, "owner"), getStrAttr(input.attrs, "repo")))
|
||||||
.applyOverrides(input.getRef(), input.getRev())
|
.applyOverrides(input.getRef(), input.getRev())
|
||||||
.clone(settings, store, destDir);
|
.clone(settings, destDir);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ public:
|
|||||||
* Fetch the entire input into the Nix store, returning the
|
* Fetch the entire input into the Nix store, returning the
|
||||||
* location in the Nix store and the locked input.
|
* location in the Nix store and the locked input.
|
||||||
*/
|
*/
|
||||||
std::pair<StorePath, Input> fetchToStore(const Settings & settings, Store & store) const;
|
std::pair<StorePath, Input> fetchToStore(const Settings & settings, ref<Store> store) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check the locking attributes in `result` against
|
* Check the locking attributes in `result` against
|
||||||
@@ -133,17 +133,17 @@ public:
|
|||||||
* input without copying it to the store. Also return a possibly
|
* input without copying it to the store. Also return a possibly
|
||||||
* unlocked input.
|
* unlocked input.
|
||||||
*/
|
*/
|
||||||
std::pair<ref<SourceAccessor>, Input> getAccessor(const Settings & settings, Store & store) const;
|
std::pair<ref<SourceAccessor>, Input> getAccessor(const Settings & settings, ref<Store> store) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::pair<ref<SourceAccessor>, Input> getAccessorUnchecked(const Settings & settings, Store & store) const;
|
std::pair<ref<SourceAccessor>, Input> getAccessorUnchecked(const Settings & settings, ref<Store> store) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Input applyOverrides(std::optional<std::string> ref, std::optional<Hash> rev) const;
|
Input applyOverrides(std::optional<std::string> ref, std::optional<Hash> rev) const;
|
||||||
|
|
||||||
void clone(const Settings & settings, Store & store, const std::filesystem::path & destDir) const;
|
void clone(const Settings & settings, const Path & destDir) const;
|
||||||
|
|
||||||
std::optional<std::filesystem::path> getSourcePath() const;
|
std::optional<std::filesystem::path> getSourcePath() const;
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ public:
|
|||||||
*
|
*
|
||||||
* This is not a stable identifier between Nix versions, but not guaranteed to change either.
|
* This is not a stable identifier between Nix versions, but not guaranteed to change either.
|
||||||
*/
|
*/
|
||||||
std::optional<std::string> getFingerprint(Store & store) const;
|
std::optional<std::string> getFingerprint(ref<Store> store) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -229,8 +229,7 @@ struct InputScheme
|
|||||||
|
|
||||||
virtual Input applyOverrides(const Input & input, std::optional<std::string> ref, std::optional<Hash> rev) const;
|
virtual Input applyOverrides(const Input & input, std::optional<std::string> ref, std::optional<Hash> rev) const;
|
||||||
|
|
||||||
virtual void
|
virtual void clone(const Settings & settings, const Input & input, const Path & destDir) const;
|
||||||
clone(const Settings & settings, Store & store, const Input & input, const std::filesystem::path & destDir) const;
|
|
||||||
|
|
||||||
virtual std::optional<std::filesystem::path> getSourcePath(const Input & input) const;
|
virtual std::optional<std::filesystem::path> getSourcePath(const Input & input) const;
|
||||||
|
|
||||||
@@ -241,7 +240,7 @@ struct InputScheme
|
|||||||
std::optional<std::string> commitMsg) const;
|
std::optional<std::string> commitMsg) const;
|
||||||
|
|
||||||
virtual std::pair<ref<SourceAccessor>, Input>
|
virtual std::pair<ref<SourceAccessor>, Input>
|
||||||
getAccessor(const Settings & settings, Store & store, const Input & input) const = 0;
|
getAccessor(const Settings & settings, ref<Store> store, const Input & input) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is this `InputScheme` part of an experimental feature?
|
* Is this `InputScheme` part of an experimental feature?
|
||||||
@@ -253,7 +252,7 @@ struct InputScheme
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::optional<std::string> getFingerprint(Store & store, const Input & input) const
|
virtual std::optional<std::string> getFingerprint(ref<Store> store, const Input & input) const
|
||||||
{
|
{
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ struct InputCache
|
|||||||
};
|
};
|
||||||
|
|
||||||
CachedResult
|
CachedResult
|
||||||
getAccessor(const Settings & settings, Store & store, const Input & originalInput, UseRegistries useRegistries);
|
getAccessor(const Settings & settings, ref<Store> store, const Input & originalInput, UseRegistries useRegistries);
|
||||||
|
|
||||||
struct CachedInput
|
struct CachedInput
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ std::shared_ptr<Registry> getCustomRegistry(const Settings & settings, const Pat
|
|||||||
|
|
||||||
Path getUserRegistryPath();
|
Path getUserRegistryPath();
|
||||||
|
|
||||||
Registries getRegistries(const Settings & settings, Store & store);
|
Registries getRegistries(const Settings & settings, ref<Store> store);
|
||||||
|
|
||||||
void overrideRegistry(const Settings & settings, const Input & from, const Input & to, const Attrs & extraAttrs);
|
void overrideRegistry(const Settings & settings, const Input & from, const Input & to, const Attrs & extraAttrs);
|
||||||
|
|
||||||
@@ -72,6 +72,6 @@ enum class UseRegistries : int {
|
|||||||
* use the registries for which the filter function returns true.
|
* use the registries for which the filter function returns true.
|
||||||
*/
|
*/
|
||||||
std::pair<Input, Attrs>
|
std::pair<Input, Attrs>
|
||||||
lookupInRegistries(const Settings & settings, Store & store, const Input & input, UseRegistries useRegistries);
|
lookupInRegistries(const Settings & settings, ref<Store> store, const Input & input, UseRegistries useRegistries);
|
||||||
|
|
||||||
} // namespace nix::fetchers
|
} // namespace nix::fetchers
|
||||||
@@ -25,7 +25,7 @@ struct DownloadFileResult
|
|||||||
};
|
};
|
||||||
|
|
||||||
DownloadFileResult downloadFile(
|
DownloadFileResult downloadFile(
|
||||||
Store & store,
|
ref<Store> store,
|
||||||
const Settings & settings,
|
const Settings & settings,
|
||||||
const std::string & url,
|
const std::string & url,
|
||||||
const std::string & name,
|
const std::string & name,
|
||||||
@@ -43,6 +43,6 @@ struct DownloadTarballResult
|
|||||||
* Download and import a tarball into the Git cache. The result is the
|
* Download and import a tarball into the Git cache. The result is the
|
||||||
* Git tree hash of the root directory.
|
* Git tree hash of the root directory.
|
||||||
*/
|
*/
|
||||||
ref<SourceAccessor> downloadTarball(Store & store, const Settings & settings, const std::string & url);
|
ref<SourceAccessor> downloadTarball(ref<Store> store, const Settings & settings, const std::string & url);
|
||||||
|
|
||||||
} // namespace nix::fetchers
|
} // namespace nix::fetchers
|
||||||
@@ -126,7 +126,7 @@ struct IndirectInputScheme : InputScheme
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::pair<ref<SourceAccessor>, Input>
|
std::pair<ref<SourceAccessor>, Input>
|
||||||
getAccessor(const Settings & settings, Store & store, const Input & input) const override
|
getAccessor(const Settings & settings, ref<Store> store, const Input & input) const override
|
||||||
{
|
{
|
||||||
throw Error("indirect input '%s' cannot be fetched directly", input.to_string());
|
throw Error("indirect input '%s' cannot be fetched directly", input.to_string());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
namespace nix::fetchers {
|
namespace nix::fetchers {
|
||||||
|
|
||||||
InputCache::CachedResult InputCache::getAccessor(
|
InputCache::CachedResult InputCache::getAccessor(
|
||||||
const Settings & settings, Store & store, const Input & originalInput, UseRegistries useRegistries)
|
const Settings & settings, ref<Store> store, const Input & originalInput, UseRegistries useRegistries)
|
||||||
{
|
{
|
||||||
auto fetched = lookup(originalInput);
|
auto fetched = lookup(originalInput);
|
||||||
Input resolvedInput = originalInput;
|
Input resolvedInput = originalInput;
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ struct MercurialInputScheme : InputScheme
|
|||||||
return {isLocal, isLocal ? renderUrlPathEnsureLegal(url.path) : url.to_string()};
|
return {isLocal, isLocal ? renderUrlPathEnsureLegal(url.path) : url.to_string()};
|
||||||
}
|
}
|
||||||
|
|
||||||
StorePath fetchToStore(const Settings & settings, Store & store, Input & input) const
|
StorePath fetchToStore(const Settings & settings, ref<Store> store, Input & input) const
|
||||||
{
|
{
|
||||||
auto origRev = input.getRev();
|
auto origRev = input.getRev();
|
||||||
|
|
||||||
@@ -230,7 +230,7 @@ struct MercurialInputScheme : InputScheme
|
|||||||
return files.count(file);
|
return files.count(file);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto storePath = store.addToStore(
|
auto storePath = store->addToStore(
|
||||||
input.getName(),
|
input.getName(),
|
||||||
{getFSSourceAccessor(), CanonPath(actualPath)},
|
{getFSSourceAccessor(), CanonPath(actualPath)},
|
||||||
ContentAddressMethod::Raw::NixArchive,
|
ContentAddressMethod::Raw::NixArchive,
|
||||||
@@ -251,7 +251,7 @@ struct MercurialInputScheme : InputScheme
|
|||||||
"Hash '%s' is not supported by Mercurial. Only sha1 is supported.",
|
"Hash '%s' is not supported by Mercurial. Only sha1 is supported.",
|
||||||
rev.to_string(HashFormat::Base16, true));
|
rev.to_string(HashFormat::Base16, true));
|
||||||
|
|
||||||
return Cache::Key{"hgRev", {{"store", store.storeDir}, {"name", name}, {"rev", input.getRev()->gitRev()}}};
|
return Cache::Key{"hgRev", {{"store", store->storeDir}, {"name", name}, {"rev", input.getRev()->gitRev()}}};
|
||||||
};
|
};
|
||||||
|
|
||||||
auto makeResult = [&](const Attrs & infoAttrs, const StorePath & storePath) -> StorePath {
|
auto makeResult = [&](const Attrs & infoAttrs, const StorePath & storePath) -> StorePath {
|
||||||
@@ -271,7 +271,7 @@ struct MercurialInputScheme : InputScheme
|
|||||||
|
|
||||||
/* If we have a rev, check if we have a cached store path. */
|
/* If we have a rev, check if we have a cached store path. */
|
||||||
if (auto rev = input.getRev()) {
|
if (auto rev = input.getRev()) {
|
||||||
if (auto res = settings.getCache()->lookupStorePath(revInfoKey(*rev), store))
|
if (auto res = settings.getCache()->lookupStorePath(revInfoKey(*rev), *store))
|
||||||
return makeResult(res->value, res->storePath);
|
return makeResult(res->value, res->storePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,7 +325,7 @@ struct MercurialInputScheme : InputScheme
|
|||||||
|
|
||||||
/* Now that we have the rev, check the cache again for a
|
/* Now that we have the rev, check the cache again for a
|
||||||
cached store path. */
|
cached store path. */
|
||||||
if (auto res = settings.getCache()->lookupStorePath(revInfoKey(rev), store))
|
if (auto res = settings.getCache()->lookupStorePath(revInfoKey(rev), *store))
|
||||||
return makeResult(res->value, res->storePath);
|
return makeResult(res->value, res->storePath);
|
||||||
|
|
||||||
Path tmpDir = createTempDir();
|
Path tmpDir = createTempDir();
|
||||||
@@ -335,7 +335,7 @@ struct MercurialInputScheme : InputScheme
|
|||||||
|
|
||||||
deletePath(tmpDir + "/.hg_archival.txt");
|
deletePath(tmpDir + "/.hg_archival.txt");
|
||||||
|
|
||||||
auto storePath = store.addToStore(name, {getFSSourceAccessor(), CanonPath(tmpDir)});
|
auto storePath = store->addToStore(name, {getFSSourceAccessor(), CanonPath(tmpDir)});
|
||||||
|
|
||||||
Attrs infoAttrs({
|
Attrs infoAttrs({
|
||||||
{"revCount", (uint64_t) revCount},
|
{"revCount", (uint64_t) revCount},
|
||||||
@@ -344,18 +344,18 @@ struct MercurialInputScheme : InputScheme
|
|||||||
if (!origRev)
|
if (!origRev)
|
||||||
settings.getCache()->upsert(refToRevKey, {{"rev", rev.gitRev()}});
|
settings.getCache()->upsert(refToRevKey, {{"rev", rev.gitRev()}});
|
||||||
|
|
||||||
settings.getCache()->upsert(revInfoKey(rev), store, infoAttrs, storePath);
|
settings.getCache()->upsert(revInfoKey(rev), *store, infoAttrs, storePath);
|
||||||
|
|
||||||
return makeResult(infoAttrs, std::move(storePath));
|
return makeResult(infoAttrs, std::move(storePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<ref<SourceAccessor>, Input>
|
std::pair<ref<SourceAccessor>, Input>
|
||||||
getAccessor(const Settings & settings, Store & store, const Input & _input) const override
|
getAccessor(const Settings & settings, ref<Store> store, const Input & _input) const override
|
||||||
{
|
{
|
||||||
Input input(_input);
|
Input input(_input);
|
||||||
|
|
||||||
auto storePath = fetchToStore(settings, store, input);
|
auto storePath = fetchToStore(settings, store, input);
|
||||||
auto accessor = store.requireStoreObjectAccessor(storePath);
|
auto accessor = store->requireStoreObjectAccessor(storePath);
|
||||||
|
|
||||||
accessor->setPathDisplay("«" + input.to_string() + "»");
|
accessor->setPathDisplay("«" + input.to_string() + "»");
|
||||||
|
|
||||||
@@ -367,7 +367,7 @@ struct MercurialInputScheme : InputScheme
|
|||||||
return (bool) input.getRev();
|
return (bool) input.getRev();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::string> getFingerprint(Store & store, const Input & input) const override
|
std::optional<std::string> getFingerprint(ref<Store> store, const Input & input) const override
|
||||||
{
|
{
|
||||||
if (auto rev = input.getRev())
|
if (auto rev = input.getRev())
|
||||||
return rev->gitRev();
|
return rev->gitRev();
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ struct PathInputScheme : InputScheme
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::pair<ref<SourceAccessor>, Input>
|
std::pair<ref<SourceAccessor>, Input>
|
||||||
getAccessor(const Settings & settings, Store & store, const Input & _input) const override
|
getAccessor(const Settings & settings, ref<Store> store, const Input & _input) const override
|
||||||
{
|
{
|
||||||
Input input(_input);
|
Input input(_input);
|
||||||
auto path = getStrAttr(input.attrs, "path");
|
auto path = getStrAttr(input.attrs, "path");
|
||||||
@@ -147,31 +147,31 @@ struct PathInputScheme : InputScheme
|
|||||||
auto absPath = getAbsPath(input);
|
auto absPath = getAbsPath(input);
|
||||||
|
|
||||||
// FIXME: check whether access to 'path' is allowed.
|
// FIXME: check whether access to 'path' is allowed.
|
||||||
auto storePath = store.maybeParseStorePath(absPath.string());
|
auto storePath = store->maybeParseStorePath(absPath.string());
|
||||||
|
|
||||||
if (storePath)
|
if (storePath)
|
||||||
store.addTempRoot(*storePath);
|
store->addTempRoot(*storePath);
|
||||||
|
|
||||||
time_t mtime = 0;
|
time_t mtime = 0;
|
||||||
if (!storePath || storePath->name() != "source" || !store.isValidPath(*storePath)) {
|
if (!storePath || storePath->name() != "source" || !store->isValidPath(*storePath)) {
|
||||||
Activity act(*logger, lvlTalkative, actUnknown, fmt("copying %s to the store", absPath));
|
Activity act(*logger, lvlTalkative, actUnknown, fmt("copying %s to the store", absPath));
|
||||||
// FIXME: try to substitute storePath.
|
// FIXME: try to substitute storePath.
|
||||||
auto src = sinkToSource(
|
auto src = sinkToSource(
|
||||||
[&](Sink & sink) { mtime = dumpPathAndGetMtime(absPath.string(), sink, defaultPathFilter); });
|
[&](Sink & sink) { mtime = dumpPathAndGetMtime(absPath.string(), sink, defaultPathFilter); });
|
||||||
storePath = store.addToStoreFromDump(*src, "source");
|
storePath = store->addToStoreFromDump(*src, "source");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto accessor = store.requireStoreObjectAccessor(*storePath);
|
auto accessor = store->requireStoreObjectAccessor(*storePath);
|
||||||
|
|
||||||
// To prevent `fetchToStore()` copying the path again to Nix
|
// To prevent `fetchToStore()` copying the path again to Nix
|
||||||
// store, pre-create an entry in the fetcher cache.
|
// store, pre-create an entry in the fetcher cache.
|
||||||
auto info = store.queryPathInfo(*storePath);
|
auto info = store->queryPathInfo(*storePath);
|
||||||
accessor->fingerprint =
|
accessor->fingerprint =
|
||||||
fmt("path:%s", store.queryPathInfo(*storePath)->narHash.to_string(HashFormat::SRI, true));
|
fmt("path:%s", store->queryPathInfo(*storePath)->narHash.to_string(HashFormat::SRI, true));
|
||||||
settings.getCache()->upsert(
|
settings.getCache()->upsert(
|
||||||
makeFetchToStoreCacheKey(
|
makeFetchToStoreCacheKey(
|
||||||
input.getName(), *accessor->fingerprint, ContentAddressMethod::Raw::NixArchive, "/"),
|
input.getName(), *accessor->fingerprint, ContentAddressMethod::Raw::NixArchive, "/"),
|
||||||
store,
|
*store,
|
||||||
{},
|
{},
|
||||||
*storePath);
|
*storePath);
|
||||||
|
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ void overrideRegistry(const Settings & settings, const Input & from, const Input
|
|||||||
getFlagRegistry(settings)->add(from, to, extraAttrs);
|
getFlagRegistry(settings)->add(from, to, extraAttrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::shared_ptr<Registry> getGlobalRegistry(const Settings & settings, Store & store)
|
static std::shared_ptr<Registry> getGlobalRegistry(const Settings & settings, ref<Store> store)
|
||||||
{
|
{
|
||||||
static auto reg = [&]() {
|
static auto reg = [&]() {
|
||||||
auto path = settings.flakeRegistry.get();
|
auto path = settings.flakeRegistry.get();
|
||||||
@@ -149,9 +149,9 @@ static std::shared_ptr<Registry> getGlobalRegistry(const Settings & settings, St
|
|||||||
[&] -> SourcePath {
|
[&] -> SourcePath {
|
||||||
if (!isAbsolute(path)) {
|
if (!isAbsolute(path)) {
|
||||||
auto storePath = downloadFile(store, settings, path, "flake-registry.json").storePath;
|
auto storePath = downloadFile(store, settings, path, "flake-registry.json").storePath;
|
||||||
if (auto store2 = dynamic_cast<LocalFSStore *>(&store))
|
if (auto store2 = store.dynamic_pointer_cast<LocalFSStore>())
|
||||||
store2->addPermRoot(storePath, getCacheDir() + "/flake-registry.json");
|
store2->addPermRoot(storePath, getCacheDir() + "/flake-registry.json");
|
||||||
return {store.requireStoreObjectAccessor(storePath)};
|
return {store->requireStoreObjectAccessor(storePath)};
|
||||||
} else {
|
} else {
|
||||||
return SourcePath{getFSSourceAccessor(), CanonPath{path}}.resolveSymlinks();
|
return SourcePath{getFSSourceAccessor(), CanonPath{path}}.resolveSymlinks();
|
||||||
}
|
}
|
||||||
@@ -162,7 +162,7 @@ static std::shared_ptr<Registry> getGlobalRegistry(const Settings & settings, St
|
|||||||
return reg;
|
return reg;
|
||||||
}
|
}
|
||||||
|
|
||||||
Registries getRegistries(const Settings & settings, Store & store)
|
Registries getRegistries(const Settings & settings, ref<Store> store)
|
||||||
{
|
{
|
||||||
Registries registries;
|
Registries registries;
|
||||||
registries.push_back(getFlagRegistry(settings));
|
registries.push_back(getFlagRegistry(settings));
|
||||||
@@ -173,7 +173,7 @@ Registries getRegistries(const Settings & settings, Store & store)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::pair<Input, Attrs>
|
std::pair<Input, Attrs>
|
||||||
lookupInRegistries(const Settings & settings, Store & store, const Input & _input, UseRegistries useRegistries)
|
lookupInRegistries(const Settings & settings, ref<Store> store, const Input & _input, UseRegistries useRegistries)
|
||||||
{
|
{
|
||||||
Attrs extraAttrs;
|
Attrs extraAttrs;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|||||||
+11
-11
@@ -13,7 +13,7 @@
|
|||||||
namespace nix::fetchers {
|
namespace nix::fetchers {
|
||||||
|
|
||||||
DownloadFileResult downloadFile(
|
DownloadFileResult downloadFile(
|
||||||
Store & store,
|
ref<Store> store,
|
||||||
const Settings & settings,
|
const Settings & settings,
|
||||||
const std::string & url,
|
const std::string & url,
|
||||||
const std::string & name,
|
const std::string & name,
|
||||||
@@ -28,7 +28,7 @@ DownloadFileResult downloadFile(
|
|||||||
{"name", name},
|
{"name", name},
|
||||||
}}};
|
}}};
|
||||||
|
|
||||||
auto cached = settings.getCache()->lookupStorePath(key, store);
|
auto cached = settings.getCache()->lookupStorePath(key, *store);
|
||||||
|
|
||||||
auto useCached = [&]() -> DownloadFileResult {
|
auto useCached = [&]() -> DownloadFileResult {
|
||||||
return {
|
return {
|
||||||
@@ -74,7 +74,7 @@ DownloadFileResult downloadFile(
|
|||||||
dumpString(res.data, sink);
|
dumpString(res.data, sink);
|
||||||
auto hash = hashString(HashAlgorithm::SHA256, res.data);
|
auto hash = hashString(HashAlgorithm::SHA256, res.data);
|
||||||
auto info = ValidPathInfo::makeFromCA(
|
auto info = ValidPathInfo::makeFromCA(
|
||||||
store,
|
*store,
|
||||||
name,
|
name,
|
||||||
FixedOutputInfo{
|
FixedOutputInfo{
|
||||||
.method = FileIngestionMethod::Flat,
|
.method = FileIngestionMethod::Flat,
|
||||||
@@ -84,7 +84,7 @@ DownloadFileResult downloadFile(
|
|||||||
hashString(HashAlgorithm::SHA256, sink.s));
|
hashString(HashAlgorithm::SHA256, sink.s));
|
||||||
info.narSize = sink.s.size();
|
info.narSize = sink.s.size();
|
||||||
auto source = StringSource{sink.s};
|
auto source = StringSource{sink.s};
|
||||||
store.addToStore(info, source, NoRepair, NoCheckSigs);
|
store->addToStore(info, source, NoRepair, NoCheckSigs);
|
||||||
storePath = std::move(info.path);
|
storePath = std::move(info.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ DownloadFileResult downloadFile(
|
|||||||
key.second.insert_or_assign("url", url);
|
key.second.insert_or_assign("url", url);
|
||||||
assert(!res.urls.empty());
|
assert(!res.urls.empty());
|
||||||
infoAttrs.insert_or_assign("url", *res.urls.rbegin());
|
infoAttrs.insert_or_assign("url", *res.urls.rbegin());
|
||||||
settings.getCache()->upsert(key, store, infoAttrs, *storePath);
|
settings.getCache()->upsert(key, *store, infoAttrs, *storePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -214,7 +214,7 @@ static DownloadTarballResult downloadTarball_(
|
|||||||
return attrsToResult(infoAttrs);
|
return attrsToResult(infoAttrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
ref<SourceAccessor> downloadTarball(Store & store, const Settings & settings, const std::string & url)
|
ref<SourceAccessor> downloadTarball(ref<Store> store, const Settings & settings, const std::string & url)
|
||||||
{
|
{
|
||||||
/* Go through Input::getAccessor() to ensure that the resulting
|
/* Go through Input::getAccessor() to ensure that the resulting
|
||||||
accessor has a fingerprint. */
|
accessor has a fingerprint. */
|
||||||
@@ -414,7 +414,7 @@ struct FileInputScheme : CurlInputScheme
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::pair<ref<SourceAccessor>, Input>
|
std::pair<ref<SourceAccessor>, Input>
|
||||||
getAccessor(const Settings & settings, Store & store, const Input & _input) const override
|
getAccessor(const Settings & settings, ref<Store> store, const Input & _input) const override
|
||||||
{
|
{
|
||||||
auto input(_input);
|
auto input(_input);
|
||||||
|
|
||||||
@@ -424,10 +424,10 @@ struct FileInputScheme : CurlInputScheme
|
|||||||
tarballs. */
|
tarballs. */
|
||||||
auto file = downloadFile(store, settings, getStrAttr(input.attrs, "url"), input.getName());
|
auto file = downloadFile(store, settings, getStrAttr(input.attrs, "url"), input.getName());
|
||||||
|
|
||||||
auto narHash = store.queryPathInfo(file.storePath)->narHash;
|
auto narHash = store->queryPathInfo(file.storePath)->narHash;
|
||||||
input.attrs.insert_or_assign("narHash", narHash.to_string(HashFormat::SRI, true));
|
input.attrs.insert_or_assign("narHash", narHash.to_string(HashFormat::SRI, true));
|
||||||
|
|
||||||
auto accessor = ref{store.getFSAccessor(file.storePath)};
|
auto accessor = ref{store->getFSAccessor(file.storePath)};
|
||||||
|
|
||||||
accessor->setPathDisplay("«" + input.to_string() + "»");
|
accessor->setPathDisplay("«" + input.to_string() + "»");
|
||||||
|
|
||||||
@@ -480,7 +480,7 @@ struct TarballInputScheme : CurlInputScheme
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::pair<ref<SourceAccessor>, Input>
|
std::pair<ref<SourceAccessor>, Input>
|
||||||
getAccessor(const Settings & settings, Store & store, const Input & _input) const override
|
getAccessor(const Settings & settings, ref<Store> store, const Input & _input) const override
|
||||||
{
|
{
|
||||||
auto input(_input);
|
auto input(_input);
|
||||||
|
|
||||||
@@ -505,7 +505,7 @@ struct TarballInputScheme : CurlInputScheme
|
|||||||
return {result.accessor, input};
|
return {result.accessor, input};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::string> getFingerprint(Store & store, const Input & input) const override
|
std::optional<std::string> getFingerprint(ref<Store> store, const Input & input) const override
|
||||||
{
|
{
|
||||||
if (auto narHash = input.getNarHash())
|
if (auto narHash = input.getNarHash())
|
||||||
return narHash->to_string(HashFormat::SRI, true);
|
return narHash->to_string(HashFormat::SRI, true);
|
||||||
|
|||||||
@@ -373,7 +373,7 @@ static Flake getFlake(
|
|||||||
{
|
{
|
||||||
// Fetch a lazy tree first.
|
// Fetch a lazy tree first.
|
||||||
auto cachedInput =
|
auto cachedInput =
|
||||||
state.inputCache->getAccessor(state.fetchSettings, *state.store, originalRef.input, useRegistries);
|
state.inputCache->getAccessor(state.fetchSettings, state.store, originalRef.input, useRegistries);
|
||||||
|
|
||||||
auto subdir = fetchers::maybeGetStrAttr(cachedInput.extraAttrs, "dir").value_or(originalRef.subdir);
|
auto subdir = fetchers::maybeGetStrAttr(cachedInput.extraAttrs, "dir").value_or(originalRef.subdir);
|
||||||
auto resolvedRef = FlakeRef(std::move(cachedInput.resolvedInput), subdir);
|
auto resolvedRef = FlakeRef(std::move(cachedInput.resolvedInput), subdir);
|
||||||
@@ -390,7 +390,7 @@ static Flake getFlake(
|
|||||||
// FIXME: need to remove attrs that are invalidated by the changed input attrs, such as 'narHash'.
|
// FIXME: need to remove attrs that are invalidated by the changed input attrs, such as 'narHash'.
|
||||||
newLockedRef.input.attrs.erase("narHash");
|
newLockedRef.input.attrs.erase("narHash");
|
||||||
auto cachedInput2 = state.inputCache->getAccessor(
|
auto cachedInput2 = state.inputCache->getAccessor(
|
||||||
state.fetchSettings, *state.store, newLockedRef.input, fetchers::UseRegistries::No);
|
state.fetchSettings, state.store, newLockedRef.input, fetchers::UseRegistries::No);
|
||||||
cachedInput.accessor = cachedInput2.accessor;
|
cachedInput.accessor = cachedInput2.accessor;
|
||||||
lockedRef = FlakeRef(std::move(cachedInput2.lockedInput), newLockedRef.subdir);
|
lockedRef = FlakeRef(std::move(cachedInput2.lockedInput), newLockedRef.subdir);
|
||||||
}
|
}
|
||||||
@@ -756,7 +756,7 @@ lockFlake(const Settings & settings, EvalState & state, const FlakeRef & topRef,
|
|||||||
return {*resolvedPath, *input.ref};
|
return {*resolvedPath, *input.ref};
|
||||||
} else {
|
} else {
|
||||||
auto cachedInput = state.inputCache->getAccessor(
|
auto cachedInput = state.inputCache->getAccessor(
|
||||||
state.fetchSettings, *state.store, input.ref->input, useRegistriesInputs);
|
state.fetchSettings, state.store, input.ref->input, useRegistriesInputs);
|
||||||
|
|
||||||
auto lockedRef = FlakeRef(std::move(cachedInput.lockedInput), input.ref->subdir);
|
auto lockedRef = FlakeRef(std::move(cachedInput.lockedInput), input.ref->subdir);
|
||||||
|
|
||||||
@@ -975,7 +975,7 @@ void callFlake(EvalState & state, const LockedFlake & lockedFlake, Value & vRes)
|
|||||||
state.callFunction(*vCallFlake, args, vRes, noPos);
|
state.callFunction(*vCallFlake, args, vRes, noPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<Fingerprint> LockedFlake::getFingerprint(Store & store, const fetchers::Settings & fetchSettings) const
|
std::optional<Fingerprint> LockedFlake::getFingerprint(ref<Store> store, const fetchers::Settings & fetchSettings) const
|
||||||
{
|
{
|
||||||
if (lockFile.isUnlocked(fetchSettings))
|
if (lockFile.isUnlocked(fetchSettings))
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
@@ -1005,7 +1005,7 @@ Flake::~Flake() {}
|
|||||||
ref<eval_cache::EvalCache> openEvalCache(EvalState & state, ref<const LockedFlake> lockedFlake)
|
ref<eval_cache::EvalCache> openEvalCache(EvalState & state, ref<const LockedFlake> lockedFlake)
|
||||||
{
|
{
|
||||||
auto fingerprint = state.settings.useEvalCache && state.settings.pureEval
|
auto fingerprint = state.settings.useEvalCache && state.settings.pureEval
|
||||||
? lockedFlake->getFingerprint(*state.store, state.fetchSettings)
|
? lockedFlake->getFingerprint(state.store, state.fetchSettings)
|
||||||
: std::nullopt;
|
: std::nullopt;
|
||||||
auto rootLoader = [&state, lockedFlake]() {
|
auto rootLoader = [&state, lockedFlake]() {
|
||||||
/* For testing whether the evaluation cache is
|
/* For testing whether the evaluation cache is
|
||||||
|
|||||||
@@ -64,8 +64,8 @@ std::ostream & operator<<(std::ostream & str, const FlakeRef & flakeRef)
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
FlakeRef
|
FlakeRef FlakeRef::resolve(
|
||||||
FlakeRef::resolve(const fetchers::Settings & fetchSettings, Store & store, fetchers::UseRegistries useRegistries) const
|
const fetchers::Settings & fetchSettings, ref<Store> store, fetchers::UseRegistries useRegistries) const
|
||||||
{
|
{
|
||||||
auto [input2, extraAttrs] = lookupInRegistries(fetchSettings, store, input, useRegistries);
|
auto [input2, extraAttrs] = lookupInRegistries(fetchSettings, store, input, useRegistries);
|
||||||
return FlakeRef(std::move(input2), fetchers::maybeGetStrAttr(extraAttrs, "dir").value_or(subdir));
|
return FlakeRef(std::move(input2), fetchers::maybeGetStrAttr(extraAttrs, "dir").value_or(subdir));
|
||||||
@@ -289,7 +289,7 @@ FlakeRef FlakeRef::fromAttrs(const fetchers::Settings & fetchSettings, const fet
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::pair<ref<SourceAccessor>, FlakeRef>
|
std::pair<ref<SourceAccessor>, FlakeRef>
|
||||||
FlakeRef::lazyFetch(const fetchers::Settings & fetchSettings, Store & store) const
|
FlakeRef::lazyFetch(const fetchers::Settings & fetchSettings, ref<Store> store) const
|
||||||
{
|
{
|
||||||
auto [accessor, lockedInput] = input.getAccessor(fetchSettings, store);
|
auto [accessor, lockedInput] = input.getAccessor(fetchSettings, store);
|
||||||
return {accessor, FlakeRef(std::move(lockedInput), subdir)};
|
return {accessor, FlakeRef(std::move(lockedInput), subdir)};
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ struct LockedFlake
|
|||||||
*/
|
*/
|
||||||
std::map<ref<Node>, SourcePath> nodePaths;
|
std::map<ref<Node>, SourcePath> nodePaths;
|
||||||
|
|
||||||
std::optional<Fingerprint> getFingerprint(Store & store, const fetchers::Settings & fetchSettings) const;
|
std::optional<Fingerprint> getFingerprint(ref<Store> store, const fetchers::Settings & fetchSettings) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LockFlags
|
struct LockFlags
|
||||||
|
|||||||
@@ -73,12 +73,13 @@ struct FlakeRef
|
|||||||
|
|
||||||
FlakeRef resolve(
|
FlakeRef resolve(
|
||||||
const fetchers::Settings & fetchSettings,
|
const fetchers::Settings & fetchSettings,
|
||||||
Store & store,
|
ref<Store> store,
|
||||||
fetchers::UseRegistries useRegistries = fetchers::UseRegistries::All) const;
|
fetchers::UseRegistries useRegistries = fetchers::UseRegistries::All) const;
|
||||||
|
|
||||||
static FlakeRef fromAttrs(const fetchers::Settings & fetchSettings, const fetchers::Attrs & attrs);
|
static FlakeRef fromAttrs(const fetchers::Settings & fetchSettings, const fetchers::Attrs & attrs);
|
||||||
|
|
||||||
std::pair<ref<SourceAccessor>, FlakeRef> lazyFetch(const fetchers::Settings & fetchSettings, Store & store) const;
|
std::pair<ref<SourceAccessor>, FlakeRef>
|
||||||
|
lazyFetch(const fetchers::Settings & fetchSettings, ref<Store> store) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Canonicalize a flakeref for the purpose of comparing "old" and
|
* Canonicalize a flakeref for the purpose of comparing "old" and
|
||||||
|
|||||||
@@ -35,8 +35,6 @@ include_dirs = [ include_directories('.') ]
|
|||||||
|
|
||||||
headers = files(
|
headers = files(
|
||||||
'nix_api_store.h',
|
'nix_api_store.h',
|
||||||
'nix_api_store/derivation.h',
|
|
||||||
'nix_api_store/store_path.h',
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO don't install this once tests don't use it and/or move the header into `libstore`, non-`c`
|
# TODO don't install this once tests don't use it and/or move the header into `libstore`, non-`c`
|
||||||
|
|||||||
@@ -12,8 +12,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "nix_api_util.h"
|
#include "nix_api_util.h"
|
||||||
#include "nix_api_store/store_path.h"
|
|
||||||
#include "nix_api_store/derivation.h"
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@@ -23,6 +21,10 @@ extern "C" {
|
|||||||
|
|
||||||
/** @brief Reference to a Nix store */
|
/** @brief Reference to a Nix store */
|
||||||
typedef struct Store Store;
|
typedef struct Store Store;
|
||||||
|
/** @brief Nix store path */
|
||||||
|
typedef struct StorePath StorePath;
|
||||||
|
/** @brief Nix Derivation */
|
||||||
|
typedef struct nix_derivation nix_derivation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initializes the Nix store library
|
* @brief Initializes the Nix store library
|
||||||
@@ -116,6 +118,30 @@ nix_store_get_storedir(nix_c_context * context, Store * store, nix_get_string_ca
|
|||||||
*/
|
*/
|
||||||
StorePath * nix_store_parse_path(nix_c_context * context, Store * store, const char * path);
|
StorePath * nix_store_parse_path(nix_c_context * context, Store * store, const char * path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the path name (e.g. "name" in /nix/store/...-name)
|
||||||
|
*
|
||||||
|
* @param[in] store_path the path to get the name from
|
||||||
|
* @param[in] callback called with the name
|
||||||
|
* @param[in] user_data arbitrary data, passed to the callback when it's called.
|
||||||
|
*/
|
||||||
|
void nix_store_path_name(const StorePath * store_path, nix_get_string_callback callback, void * user_data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Copy a StorePath
|
||||||
|
*
|
||||||
|
* @param[in] p the path to copy
|
||||||
|
* @return a new StorePath
|
||||||
|
*/
|
||||||
|
StorePath * nix_store_path_clone(const StorePath * p);
|
||||||
|
|
||||||
|
/** @brief Deallocate a StorePath
|
||||||
|
*
|
||||||
|
* Does not fail.
|
||||||
|
* @param[in] p the path to free
|
||||||
|
*/
|
||||||
|
void nix_store_path_free(StorePath * p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Check if a StorePath is valid (i.e. that corresponding store object and its closure of references exists in
|
* @brief Check if a StorePath is valid (i.e. that corresponding store object and its closure of references exists in
|
||||||
* the store)
|
* the store)
|
||||||
@@ -203,6 +229,14 @@ nix_derivation * nix_derivation_from_json(nix_c_context * context, Store * store
|
|||||||
*/
|
*/
|
||||||
StorePath * nix_add_derivation(nix_c_context * context, Store * store, nix_derivation * derivation);
|
StorePath * nix_add_derivation(nix_c_context * context, Store * store, nix_derivation * derivation);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Deallocate a `nix_derivation`
|
||||||
|
*
|
||||||
|
* Does not fail.
|
||||||
|
* @param[in] drv the derivation to free
|
||||||
|
*/
|
||||||
|
void nix_derivation_free(nix_derivation * drv);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Copy the closure of `path` from `srcStore` to `dstStore`.
|
* @brief Copy the closure of `path` from `srcStore` to `dstStore`.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
#ifndef NIX_API_STORE_DERIVATION_H
|
|
||||||
#define NIX_API_STORE_DERIVATION_H
|
|
||||||
/**
|
|
||||||
* @defgroup libstore_derivation Derivation
|
|
||||||
* @ingroup libstore
|
|
||||||
* @brief Derivation operations that don't require a Store
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
/** @file
|
|
||||||
* @brief Derivation operations
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "nix_api_util.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
// cffi start
|
|
||||||
|
|
||||||
/** @brief Nix Derivation */
|
|
||||||
typedef struct nix_derivation nix_derivation;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Deallocate a `nix_derivation`
|
|
||||||
*
|
|
||||||
* Does not fail.
|
|
||||||
* @param[in] drv the derivation to free
|
|
||||||
*/
|
|
||||||
void nix_derivation_free(nix_derivation * drv);
|
|
||||||
|
|
||||||
// cffi end
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
#endif // NIX_API_STORE_DERIVATION_H
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
#ifndef NIX_API_STORE_STORE_PATH_H
|
|
||||||
#define NIX_API_STORE_STORE_PATH_H
|
|
||||||
/**
|
|
||||||
* @defgroup libstore_storepath StorePath
|
|
||||||
* @ingroup libstore
|
|
||||||
* @brief Store path operations that don't require a Store
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
/** @file
|
|
||||||
* @brief Store path operations
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "nix_api_util.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
// cffi start
|
|
||||||
|
|
||||||
/** @brief Nix store path */
|
|
||||||
typedef struct StorePath StorePath;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Copy a StorePath
|
|
||||||
*
|
|
||||||
* @param[in] p the path to copy
|
|
||||||
* @return a new StorePath
|
|
||||||
*/
|
|
||||||
StorePath * nix_store_path_clone(const StorePath * p);
|
|
||||||
|
|
||||||
/** @brief Deallocate a StorePath
|
|
||||||
*
|
|
||||||
* Does not fail.
|
|
||||||
* @param[in] p the path to free
|
|
||||||
*/
|
|
||||||
void nix_store_path_free(StorePath * p);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Get the path name (e.g. "<name>" in /nix/store/<hash>-<name>)
|
|
||||||
*
|
|
||||||
* @param[in] store_path the path to get the name from
|
|
||||||
* @param[in] callback called with the name
|
|
||||||
* @param[in] user_data arbitrary data, passed to the callback when it's called.
|
|
||||||
*/
|
|
||||||
void nix_store_path_name(const StorePath * store_path, nix_get_string_callback callback, void * user_data);
|
|
||||||
|
|
||||||
// cffi end
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
#endif // NIX_API_STORE_STORE_PATH_H
|
|
||||||
@@ -386,17 +386,17 @@ struct curlFileTransfer : public FileTransfer
|
|||||||
if (settings.downloadSpeed.get() > 0)
|
if (settings.downloadSpeed.get() > 0)
|
||||||
curl_easy_setopt(req, CURLOPT_MAX_RECV_SPEED_LARGE, (curl_off_t) (settings.downloadSpeed.get() * 1024));
|
curl_easy_setopt(req, CURLOPT_MAX_RECV_SPEED_LARGE, (curl_off_t) (settings.downloadSpeed.get() * 1024));
|
||||||
|
|
||||||
if (request.method == HttpMethod::Head)
|
if (request.method == HttpMethod::HEAD)
|
||||||
curl_easy_setopt(req, CURLOPT_NOBODY, 1);
|
curl_easy_setopt(req, CURLOPT_NOBODY, 1);
|
||||||
|
|
||||||
if (request.method == HttpMethod::Delete)
|
if (request.method == HttpMethod::DELETE)
|
||||||
curl_easy_setopt(req, CURLOPT_CUSTOMREQUEST, "DELETE");
|
curl_easy_setopt(req, CURLOPT_CUSTOMREQUEST, "DELETE");
|
||||||
|
|
||||||
if (request.data) {
|
if (request.data) {
|
||||||
if (request.method == HttpMethod::Post) {
|
if (request.method == HttpMethod::POST) {
|
||||||
curl_easy_setopt(req, CURLOPT_POST, 1L);
|
curl_easy_setopt(req, CURLOPT_POST, 1L);
|
||||||
curl_easy_setopt(req, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t) request.data->sizeHint);
|
curl_easy_setopt(req, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t) request.data->sizeHint);
|
||||||
} else if (request.method == HttpMethod::Put) {
|
} else if (request.method == HttpMethod::PUT) {
|
||||||
curl_easy_setopt(req, CURLOPT_UPLOAD, 1L);
|
curl_easy_setopt(req, CURLOPT_UPLOAD, 1L);
|
||||||
curl_easy_setopt(req, CURLOPT_INFILESIZE_LARGE, (curl_off_t) request.data->sizeHint);
|
curl_easy_setopt(req, CURLOPT_INFILESIZE_LARGE, (curl_off_t) request.data->sizeHint);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ bool HttpBinaryCacheStore::fileExists(const std::string & path)
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
FileTransferRequest request(makeRequest(path));
|
FileTransferRequest request(makeRequest(path));
|
||||||
request.method = HttpMethod::Head;
|
request.method = HttpMethod::HEAD;
|
||||||
getFileTransfer()->download(request);
|
getFileTransfer()->download(request);
|
||||||
return true;
|
return true;
|
||||||
} catch (FileTransferError & e) {
|
} catch (FileTransferError & e) {
|
||||||
@@ -141,7 +141,7 @@ void HttpBinaryCacheStore::upload(
|
|||||||
std::optional<Headers> headers)
|
std::optional<Headers> headers)
|
||||||
{
|
{
|
||||||
auto req = makeRequest(path);
|
auto req = makeRequest(path);
|
||||||
req.method = HttpMethod::Put;
|
req.method = HttpMethod::PUT;
|
||||||
|
|
||||||
if (headers) {
|
if (headers) {
|
||||||
req.headers.reserve(req.headers.size() + headers->size());
|
req.headers.reserve(req.headers.size() + headers->size());
|
||||||
|
|||||||
@@ -87,11 +87,11 @@ extern const unsigned int RETRY_TIME_MS_DEFAULT;
|
|||||||
* HTTP methods supported by FileTransfer.
|
* HTTP methods supported by FileTransfer.
|
||||||
*/
|
*/
|
||||||
enum struct HttpMethod {
|
enum struct HttpMethod {
|
||||||
Get,
|
GET,
|
||||||
Put,
|
PUT,
|
||||||
Head,
|
HEAD,
|
||||||
Post,
|
POST,
|
||||||
Delete,
|
DELETE,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -110,7 +110,7 @@ struct FileTransferRequest
|
|||||||
VerbatimURL uri;
|
VerbatimURL uri;
|
||||||
Headers headers;
|
Headers headers;
|
||||||
std::string expectedETag;
|
std::string expectedETag;
|
||||||
HttpMethod method = HttpMethod::Get;
|
HttpMethod method = HttpMethod::GET;
|
||||||
size_t tries = fileTransferSettings.tries;
|
size_t tries = fileTransferSettings.tries;
|
||||||
unsigned int baseRetryTimeMs = RETRY_TIME_MS_DEFAULT;
|
unsigned int baseRetryTimeMs = RETRY_TIME_MS_DEFAULT;
|
||||||
ActivityId parentAct;
|
ActivityId parentAct;
|
||||||
@@ -164,14 +164,14 @@ struct FileTransferRequest
|
|||||||
std::string verb() const
|
std::string verb() const
|
||||||
{
|
{
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case HttpMethod::Head:
|
case HttpMethod::HEAD:
|
||||||
case HttpMethod::Get:
|
case HttpMethod::GET:
|
||||||
return "download";
|
return "download";
|
||||||
case HttpMethod::Put:
|
case HttpMethod::PUT:
|
||||||
case HttpMethod::Post:
|
case HttpMethod::POST:
|
||||||
assert(data);
|
assert(data);
|
||||||
return "upload";
|
return "upload";
|
||||||
case HttpMethod::Delete:
|
case HttpMethod::DELETE:
|
||||||
return "delet";
|
return "delet";
|
||||||
}
|
}
|
||||||
unreachable();
|
unreachable();
|
||||||
|
|||||||
@@ -1246,8 +1246,10 @@ StorePath LocalStore::addToStoreFromDump(
|
|||||||
|
|
||||||
auto desc = ContentAddressWithReferences::fromParts(
|
auto desc = ContentAddressWithReferences::fromParts(
|
||||||
hashMethod,
|
hashMethod,
|
||||||
methodsMatch ? dumpHash
|
methodsMatch
|
||||||
: hashPath(makeFSSourceAccessor(tempPath), hashMethod.getFileIngestionMethod(), hashAlgo).first,
|
? dumpHash
|
||||||
|
: hashPath(PosixSourceAccessor::createAtRoot(tempPath), hashMethod.getFileIngestionMethod(), hashAlgo)
|
||||||
|
.first,
|
||||||
{
|
{
|
||||||
.others = references,
|
.others = references,
|
||||||
// caller is not capable of creating a self-reference, because this is content-addressed without modulus
|
// caller is not capable of creating a self-reference, because this is content-addressed without modulus
|
||||||
@@ -1383,9 +1385,11 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair)
|
|||||||
checkInterrupt();
|
checkInterrupt();
|
||||||
auto name = link.path().filename();
|
auto name = link.path().filename();
|
||||||
printMsg(lvlTalkative, "checking contents of %s", name);
|
printMsg(lvlTalkative, "checking contents of %s", name);
|
||||||
std::string hash =
|
std::string hash = hashPath(
|
||||||
hashPath(makeFSSourceAccessor(link.path()), FileIngestionMethod::NixArchive, HashAlgorithm::SHA256)
|
PosixSourceAccessor::createAtRoot(link.path()),
|
||||||
.first.to_string(HashFormat::Nix32, false);
|
FileIngestionMethod::NixArchive,
|
||||||
|
HashAlgorithm::SHA256)
|
||||||
|
.first.to_string(HashFormat::Nix32, false);
|
||||||
if (hash != name.string()) {
|
if (hash != name.string()) {
|
||||||
printError("link %s was modified! expected hash %s, got '%s'", link.path(), name, hash);
|
printError("link %s was modified! expected hash %s, got '%s'", link.path(), name, hash);
|
||||||
if (repair) {
|
if (repair) {
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ void LocalStore::optimisePath_(
|
|||||||
auto stLink = lstat(linkPath.string());
|
auto stLink = lstat(linkPath.string());
|
||||||
if (st.st_size != stLink.st_size || (repair && hash != ({
|
if (st.st_size != stLink.st_size || (repair && hash != ({
|
||||||
hashPath(
|
hashPath(
|
||||||
makeFSSourceAccessor(linkPath),
|
PosixSourceAccessor::createAtRoot(linkPath),
|
||||||
FileSerialisationMethod::NixArchive,
|
FileSerialisationMethod::NixArchive,
|
||||||
HashAlgorithm::SHA256)
|
HashAlgorithm::SHA256)
|
||||||
.hash;
|
.hash;
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ std::string S3BinaryCacheStore::createMultipartUpload(
|
|||||||
url.query["uploads"] = "";
|
url.query["uploads"] = "";
|
||||||
req.uri = VerbatimURL(url);
|
req.uri = VerbatimURL(url);
|
||||||
|
|
||||||
req.method = HttpMethod::Post;
|
req.method = HttpMethod::POST;
|
||||||
StringSource payload{std::string_view("")};
|
StringSource payload{std::string_view("")};
|
||||||
req.data = {payload};
|
req.data = {payload};
|
||||||
req.mimeType = mimeType;
|
req.mimeType = mimeType;
|
||||||
@@ -325,7 +325,7 @@ S3BinaryCacheStore::uploadPart(std::string_view key, std::string_view uploadId,
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto req = makeRequest(key);
|
auto req = makeRequest(key);
|
||||||
req.method = HttpMethod::Put;
|
req.method = HttpMethod::PUT;
|
||||||
req.setupForS3();
|
req.setupForS3();
|
||||||
|
|
||||||
auto url = req.uri.parsed();
|
auto url = req.uri.parsed();
|
||||||
@@ -355,7 +355,7 @@ void S3BinaryCacheStore::abortMultipartUpload(std::string_view key, std::string_
|
|||||||
auto url = req.uri.parsed();
|
auto url = req.uri.parsed();
|
||||||
url.query["uploadId"] = uploadId;
|
url.query["uploadId"] = uploadId;
|
||||||
req.uri = VerbatimURL(url);
|
req.uri = VerbatimURL(url);
|
||||||
req.method = HttpMethod::Delete;
|
req.method = HttpMethod::DELETE;
|
||||||
|
|
||||||
getFileTransfer()->enqueueFileTransfer(req).get();
|
getFileTransfer()->enqueueFileTransfer(req).get();
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
@@ -372,7 +372,7 @@ void S3BinaryCacheStore::completeMultipartUpload(
|
|||||||
auto url = req.uri.parsed();
|
auto url = req.uri.parsed();
|
||||||
url.query["uploadId"] = uploadId;
|
url.query["uploadId"] = uploadId;
|
||||||
req.uri = VerbatimURL(url);
|
req.uri = VerbatimURL(url);
|
||||||
req.method = HttpMethod::Post;
|
req.method = HttpMethod::POST;
|
||||||
|
|
||||||
std::string xml = "<CompleteMultipartUpload>";
|
std::string xml = "<CompleteMultipartUpload>";
|
||||||
for (const auto & [idx, etag] : enumerate(partEtags)) {
|
for (const auto & [idx, etag] : enumerate(partEtags)) {
|
||||||
|
|||||||
@@ -1,81 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
///@file
|
|
||||||
|
|
||||||
#include "types.hh"
|
|
||||||
#include "util.hh"
|
|
||||||
|
|
||||||
#include <cmark.h>
|
|
||||||
|
|
||||||
namespace nix::cmark {
|
|
||||||
|
|
||||||
using Node = struct cmark_node;
|
|
||||||
using NodeType = cmark_node_type;
|
|
||||||
using ListType = cmark_list_type;
|
|
||||||
|
|
||||||
using Iter = struct cmark_iter;
|
|
||||||
|
|
||||||
struct Deleter
|
|
||||||
{
|
|
||||||
void operator()(Node * ptr)
|
|
||||||
{
|
|
||||||
cmark_node_free(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator()(Iter * ptr)
|
|
||||||
{
|
|
||||||
cmark_iter_free(ptr);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
using UniquePtr = std::unique_ptr<Node, Deleter>;
|
|
||||||
|
|
||||||
static inline void parse_document(Node & root, std::string_view s, int options)
|
|
||||||
{
|
|
||||||
cmark_parser * parser = cmark_parser_new_with_mem_into_root(options, cmark_get_default_mem_allocator(), &root);
|
|
||||||
cmark_parser_feed(parser, s.data(), s.size());
|
|
||||||
(void) cmark_parser_finish(parser);
|
|
||||||
cmark_parser_free(parser);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline UniquePtr<Node> parse_document(std::string_view s, int options)
|
|
||||||
{
|
|
||||||
return UniquePtr<Node>{cmark_parse_document(s.data(), s.size(), options)};
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline std::unique_ptr<char, FreeDeleter> render_commonmark(Node & root, int options, int width)
|
|
||||||
{
|
|
||||||
return std::unique_ptr<char, FreeDeleter>{cmark_render_commonmark(&root, options, width)};
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline std::unique_ptr<char, FreeDeleter> render_xml(Node & root, int options)
|
|
||||||
{
|
|
||||||
return std::unique_ptr<char, FreeDeleter>{cmark_render_xml(&root, options)};
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline UniquePtr<Node> node_new(NodeType type)
|
|
||||||
{
|
|
||||||
return UniquePtr<Node>{cmark_node_new(type)};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The parent takes ownership
|
|
||||||
*/
|
|
||||||
static inline Node & node_append_child(Node & node, UniquePtr<Node> child)
|
|
||||||
{
|
|
||||||
auto status = (bool) cmark_node_append_child(&node, &*child);
|
|
||||||
assert(status);
|
|
||||||
return *child.release();
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool node_set_literal(Node & node, const char * content)
|
|
||||||
{
|
|
||||||
return (bool) cmark_node_set_literal(&node, content);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool node_set_list_type(Node & node, ListType type)
|
|
||||||
{
|
|
||||||
return (bool) cmark_node_set_list_type(&node, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace nix::cmark
|
|
||||||
@@ -17,7 +17,6 @@ headers = files(
|
|||||||
'checked-arithmetic.hh',
|
'checked-arithmetic.hh',
|
||||||
'chunked-vector.hh',
|
'chunked-vector.hh',
|
||||||
'closure.hh',
|
'closure.hh',
|
||||||
'cmark-cpp.hh',
|
|
||||||
'comparator.hh',
|
'comparator.hh',
|
||||||
'compression.hh',
|
'compression.hh',
|
||||||
'compute-levels.hh',
|
'compute-levels.hh',
|
||||||
|
|||||||
@@ -114,4 +114,69 @@ std::string dropEmptyInitThenConcatStringsSep(const std::string_view sep, const
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Consteval helper for the "constexpr 2-step" pattern.
|
||||||
|
* Converts a std::string to a std::array<char, N> for stable compile-time storage.
|
||||||
|
*
|
||||||
|
* Usage:
|
||||||
|
* static constexpr auto str = stripIndentationConsteval(...);
|
||||||
|
* static constexpr auto arr = toArray<str.size()>(str);
|
||||||
|
* static constexpr std::string_view view{arr.data(), arr.size()};
|
||||||
|
*/
|
||||||
|
template<size_t N>
|
||||||
|
consteval std::string_view toArray(const std::string & s)
|
||||||
|
{
|
||||||
|
static std::array<char, N> arr{};
|
||||||
|
for (size_t i = 0; i < N; ++i) {
|
||||||
|
arr[i] = s[i];
|
||||||
|
}
|
||||||
|
return {arr.data(), N};
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr std::string stripIndentationImpl(std::string_view s)
|
||||||
|
{
|
||||||
|
size_t minIndent = 10000;
|
||||||
|
size_t curIndent = 0;
|
||||||
|
bool atStartOfLine = true;
|
||||||
|
|
||||||
|
for (auto & c : s) {
|
||||||
|
if (atStartOfLine && c == ' ')
|
||||||
|
curIndent++;
|
||||||
|
else if (c == '\n') {
|
||||||
|
if (atStartOfLine)
|
||||||
|
minIndent = std::max(minIndent, curIndent);
|
||||||
|
curIndent = 0;
|
||||||
|
atStartOfLine = true;
|
||||||
|
} else {
|
||||||
|
if (atStartOfLine) {
|
||||||
|
minIndent = std::min(minIndent, curIndent);
|
||||||
|
atStartOfLine = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string res;
|
||||||
|
|
||||||
|
size_t pos = 0;
|
||||||
|
while (pos < s.size()) {
|
||||||
|
auto eol = s.find('\n', pos);
|
||||||
|
if (eol == s.npos)
|
||||||
|
eol = s.size();
|
||||||
|
if (eol - pos > minIndent)
|
||||||
|
res.append(s.substr(pos + minIndent, eol - pos - minIndent));
|
||||||
|
res.push_back('\n');
|
||||||
|
pos = eol + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<std::string_view s>
|
||||||
|
consteval std::string_view stripIndentationConsteval()
|
||||||
|
{
|
||||||
|
constexpr auto stripped = stripIndentationImpl(s);
|
||||||
|
constexpr size_t n = stripped.size();
|
||||||
|
return toArray<n>(stripped);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace nix
|
} // namespace nix
|
||||||
@@ -132,6 +132,13 @@ std::string optionalBracket(std::string_view prefix, const std::optional<T> & co
|
|||||||
return optionalBracket(prefix, std::string_view(*content), suffix);
|
return optionalBracket(prefix, std::string_view(*content), suffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove common leading whitespace from the lines in the string
|
||||||
|
* 's'. For example, if every line is indented by at least 3 spaces,
|
||||||
|
* then we remove 3 spaces from the start of every line.
|
||||||
|
*/
|
||||||
|
std::string stripIndentation(std::string_view s);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hash implementation that can be used for zero-copy heterogenous lookup from
|
* Hash implementation that can be used for zero-copy heterogenous lookup from
|
||||||
* P1690R1[1] in unordered containers.
|
* P1690R1[1] in unordered containers.
|
||||||
|
|||||||
@@ -4,15 +4,7 @@
|
|||||||
#include <limits>
|
#include <limits>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "nix/util/file-descriptor.hh"
|
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine whether \param fd is a terminal.
|
|
||||||
*/
|
|
||||||
bool isTTY(Descriptor fd);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine whether ANSI escape sequences are appropriate for the
|
* Determine whether ANSI escape sequences are appropriate for the
|
||||||
* present output.
|
* present output.
|
||||||
|
|||||||
@@ -228,13 +228,6 @@ constexpr char treeLast[] = "└───";
|
|||||||
constexpr char treeLine[] = "│ ";
|
constexpr char treeLine[] = "│ ";
|
||||||
constexpr char treeNull[] = " ";
|
constexpr char treeNull[] = " ";
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove common leading whitespace from the lines in the string
|
|
||||||
* 's'. For example, if every line is indented by at least 3 spaces,
|
|
||||||
* then we remove 3 spaces from the start of every line.
|
|
||||||
*/
|
|
||||||
std::string stripIndentation(std::string_view s);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the prefix of 's' up to and excluding the next line break (LF
|
* Get the prefix of 's' up to and excluding the next line break (LF
|
||||||
* optionally preceded by CR), and the remainder following the line
|
* optionally preceded by CR), and the remainder following the line
|
||||||
|
|||||||
@@ -110,9 +110,6 @@ deps_private += cpuid
|
|||||||
nlohmann_json = dependency('nlohmann_json', version : '>= 3.9')
|
nlohmann_json = dependency('nlohmann_json', version : '>= 3.9')
|
||||||
deps_public += nlohmann_json
|
deps_public += nlohmann_json
|
||||||
|
|
||||||
cmark = dependency('libcmark', required : true)
|
|
||||||
deps_public += cmark
|
|
||||||
|
|
||||||
cxx = meson.get_compiler('cpp')
|
cxx = meson.get_compiler('cpp')
|
||||||
|
|
||||||
config_priv_h = configure_file(
|
config_priv_h = configure_file(
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
boost,
|
boost,
|
||||||
brotli,
|
brotli,
|
||||||
cmark,
|
|
||||||
libarchive,
|
libarchive,
|
||||||
libblake3,
|
libblake3,
|
||||||
libcpuid,
|
libcpuid,
|
||||||
@@ -58,7 +57,6 @@ mkMesonLibrary (finalAttrs: {
|
|||||||
|
|
||||||
propagatedBuildInputs = [
|
propagatedBuildInputs = [
|
||||||
boost
|
boost
|
||||||
cmark
|
|
||||||
libarchive
|
libarchive
|
||||||
nlohmann_json
|
nlohmann_json
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -152,4 +152,8 @@ std::string optionalBracket(std::string_view prefix, std::string_view content, s
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string stripIndentation(std::string_view s) {
|
||||||
|
return stripIndentationImpl(s);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace nix
|
} // namespace nix
|
||||||
@@ -64,16 +64,6 @@ inline std::pair<int, size_t> charWidthUTF8Helper(std::string_view s)
|
|||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
bool isTTY(Descriptor fd)
|
|
||||||
{
|
|
||||||
#ifndef _WIN32
|
|
||||||
return isatty(fd);
|
|
||||||
#else
|
|
||||||
DWORD mode;
|
|
||||||
return GetConsoleMode(fd, &mode);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isTTY()
|
bool isTTY()
|
||||||
{
|
{
|
||||||
static const bool tty = isatty(STDERR_FILENO) && getEnv("TERM").value_or("dumb") != "dumb"
|
static const bool tty = isatty(STDERR_FILENO) && getEnv("TERM").value_or("dumb") != "dumb"
|
||||||
|
|||||||
@@ -250,44 +250,6 @@ void ignoreExceptionExceptInterrupt(Verbosity lvl)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string stripIndentation(std::string_view s)
|
|
||||||
{
|
|
||||||
size_t minIndent = 10000;
|
|
||||||
size_t curIndent = 0;
|
|
||||||
bool atStartOfLine = true;
|
|
||||||
|
|
||||||
for (auto & c : s) {
|
|
||||||
if (atStartOfLine && c == ' ')
|
|
||||||
curIndent++;
|
|
||||||
else if (c == '\n') {
|
|
||||||
if (atStartOfLine)
|
|
||||||
minIndent = std::max(minIndent, curIndent);
|
|
||||||
curIndent = 0;
|
|
||||||
atStartOfLine = true;
|
|
||||||
} else {
|
|
||||||
if (atStartOfLine) {
|
|
||||||
minIndent = std::min(minIndent, curIndent);
|
|
||||||
atStartOfLine = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string res;
|
|
||||||
|
|
||||||
size_t pos = 0;
|
|
||||||
while (pos < s.size()) {
|
|
||||||
auto eol = s.find('\n', pos);
|
|
||||||
if (eol == s.npos)
|
|
||||||
eol = s.size();
|
|
||||||
if (eol - pos > minIndent)
|
|
||||||
res.append(s.substr(pos + minIndent, eol - pos - minIndent));
|
|
||||||
res.push_back('\n');
|
|
||||||
pos = eol + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::pair<std::string_view, std::string_view> getLine(std::string_view s)
|
std::pair<std::string_view, std::string_view> getLine(std::string_view s)
|
||||||
{
|
{
|
||||||
auto newline = s.find('\n');
|
auto newline = s.find('\n');
|
||||||
|
|||||||
+1
-1
@@ -75,7 +75,7 @@ struct CmdCatNar : StoreCommand, MixCat
|
|||||||
|
|
||||||
void run(ref<Store> store) override
|
void run(ref<Store> store) override
|
||||||
{
|
{
|
||||||
AutoCloseFD fd = toDescriptor(open(narPath.c_str(), O_RDONLY));
|
AutoCloseFD fd = open(narPath.c_str(), O_RDONLY);
|
||||||
if (!fd)
|
if (!fd)
|
||||||
throw SysError("opening NAR file '%s'", narPath);
|
throw SysError("opening NAR file '%s'", narPath);
|
||||||
auto source = FdSource{fd.get()};
|
auto source = FdSource{fd.get()};
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
#include "nix/cmd/command.hh"
|
#include "nix/cmd/command.hh"
|
||||||
#include "nix/store/store-api.hh"
|
#include "nix/store/store-api.hh"
|
||||||
#include "nix/util/archive.hh"
|
#include "nix/util/archive.hh"
|
||||||
#include "nix/util/terminal.hh"
|
|
||||||
|
|
||||||
using namespace nix;
|
using namespace nix;
|
||||||
|
|
||||||
static FdSink getNarSink()
|
static FdSink getNarSink()
|
||||||
{
|
{
|
||||||
auto fd = getStandardOutput();
|
auto fd = getStandardOutput();
|
||||||
if (isTTY(fd))
|
if (isatty(fd))
|
||||||
throw UsageError("refusing to write NAR to a terminal");
|
throw UsageError("refusing to write NAR to a terminal");
|
||||||
return FdSink(std::move(fd));
|
return FdSink(std::move(fd));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ struct CmdFlakePrefetchInputs : FlakeCommand
|
|||||||
if (auto lockedNode = dynamic_cast<const LockedNode *>(&node)) {
|
if (auto lockedNode = dynamic_cast<const LockedNode *>(&node)) {
|
||||||
try {
|
try {
|
||||||
Activity act(*logger, lvlInfo, actUnknown, fmt("fetching '%s'", lockedNode->lockedRef));
|
Activity act(*logger, lvlInfo, actUnknown, fmt("fetching '%s'", lockedNode->lockedRef));
|
||||||
auto accessor = lockedNode->lockedRef.input.getAccessor(fetchSettings, *store).first;
|
auto accessor = lockedNode->lockedRef.input.getAccessor(fetchSettings, store).first;
|
||||||
fetchToStore(
|
fetchToStore(
|
||||||
fetchSettings, *store, accessor, FetchMode::Copy, lockedNode->lockedRef.input.getName());
|
fetchSettings, *store, accessor, FetchMode::Copy, lockedNode->lockedRef.input.getName());
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
|
|||||||
+7
-7
@@ -240,7 +240,7 @@ struct CmdFlakeMetadata : FlakeCommand, MixJSON
|
|||||||
j["lastModified"] = *lastModified;
|
j["lastModified"] = *lastModified;
|
||||||
j["path"] = storePath;
|
j["path"] = storePath;
|
||||||
j["locks"] = lockedFlake.lockFile.toJSON().first;
|
j["locks"] = lockedFlake.lockFile.toJSON().first;
|
||||||
if (auto fingerprint = lockedFlake.getFingerprint(*store, fetchSettings))
|
if (auto fingerprint = lockedFlake.getFingerprint(store, fetchSettings))
|
||||||
j["fingerprint"] = fingerprint->to_string(HashFormat::Base16, false);
|
j["fingerprint"] = fingerprint->to_string(HashFormat::Base16, false);
|
||||||
printJSON(j);
|
printJSON(j);
|
||||||
} else {
|
} else {
|
||||||
@@ -260,7 +260,7 @@ struct CmdFlakeMetadata : FlakeCommand, MixJSON
|
|||||||
logger->cout(
|
logger->cout(
|
||||||
ANSI_BOLD "Last modified:" ANSI_NORMAL " %s",
|
ANSI_BOLD "Last modified:" ANSI_NORMAL " %s",
|
||||||
std::put_time(std::localtime(&*lastModified), "%F %T"));
|
std::put_time(std::localtime(&*lastModified), "%F %T"));
|
||||||
if (auto fingerprint = lockedFlake.getFingerprint(*store, fetchSettings))
|
if (auto fingerprint = lockedFlake.getFingerprint(store, fetchSettings))
|
||||||
logger->cout(
|
logger->cout(
|
||||||
ANSI_BOLD "Fingerprint:" ANSI_NORMAL " %s", fingerprint->to_string(HashFormat::Base16, false));
|
ANSI_BOLD "Fingerprint:" ANSI_NORMAL " %s", fingerprint->to_string(HashFormat::Base16, false));
|
||||||
|
|
||||||
@@ -1019,7 +1019,7 @@ struct CmdFlakeNew : CmdFlakeInitCommon
|
|||||||
|
|
||||||
struct CmdFlakeClone : FlakeCommand
|
struct CmdFlakeClone : FlakeCommand
|
||||||
{
|
{
|
||||||
std::filesystem::path destDir;
|
Path destDir;
|
||||||
|
|
||||||
std::string description() override
|
std::string description() override
|
||||||
{
|
{
|
||||||
@@ -1049,7 +1049,7 @@ struct CmdFlakeClone : FlakeCommand
|
|||||||
if (destDir.empty())
|
if (destDir.empty())
|
||||||
throw Error("missing flag '--dest'");
|
throw Error("missing flag '--dest'");
|
||||||
|
|
||||||
getFlakeRef().resolve(fetchSettings, *store).input.clone(fetchSettings, *store, destDir);
|
getFlakeRef().resolve(fetchSettings, store).input.clone(fetchSettings, destDir);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1100,7 +1100,7 @@ struct CmdFlakeArchive : FlakeCommand, MixJSON, MixDryRun, MixNoCheckSigs
|
|||||||
std::optional<StorePath> storePath;
|
std::optional<StorePath> storePath;
|
||||||
if (!(*inputNode)->lockedRef.input.isRelative()) {
|
if (!(*inputNode)->lockedRef.input.isRelative()) {
|
||||||
storePath = dryRun ? (*inputNode)->lockedRef.input.computeStorePath(*store)
|
storePath = dryRun ? (*inputNode)->lockedRef.input.computeStorePath(*store)
|
||||||
: (*inputNode)->lockedRef.input.fetchToStore(fetchSettings, *store).first;
|
: (*inputNode)->lockedRef.input.fetchToStore(fetchSettings, store).first;
|
||||||
sources.insert(*storePath);
|
sources.insert(*storePath);
|
||||||
}
|
}
|
||||||
if (json) {
|
if (json) {
|
||||||
@@ -1498,8 +1498,8 @@ struct CmdFlakePrefetch : FlakeCommand, MixJSON
|
|||||||
void run(ref<Store> store) override
|
void run(ref<Store> store) override
|
||||||
{
|
{
|
||||||
auto originalRef = getFlakeRef();
|
auto originalRef = getFlakeRef();
|
||||||
auto resolvedRef = originalRef.resolve(fetchSettings, *store);
|
auto resolvedRef = originalRef.resolve(fetchSettings, store);
|
||||||
auto [accessor, lockedRef] = resolvedRef.lazyFetch(getEvalState()->fetchSettings, *store);
|
auto [accessor, lockedRef] = resolvedRef.lazyFetch(getEvalState()->fetchSettings, store);
|
||||||
auto storePath =
|
auto storePath =
|
||||||
fetchToStore(getEvalState()->fetchSettings, *store, accessor, FetchMode::Copy, lockedRef.input.getName());
|
fetchToStore(getEvalState()->fetchSettings, *store, accessor, FetchMode::Copy, lockedRef.input.getName());
|
||||||
auto hash = store->queryPathInfo(storePath)->narHash;
|
auto hash = store->queryPathInfo(storePath)->narHash;
|
||||||
|
|||||||
+1
-1
@@ -145,7 +145,7 @@ struct CmdLsNar : Command, MixLs
|
|||||||
|
|
||||||
void run() override
|
void run() override
|
||||||
{
|
{
|
||||||
AutoCloseFD fd = toDescriptor(open(narPath.c_str(), O_RDONLY));
|
AutoCloseFD fd = open(narPath.c_str(), O_RDONLY);
|
||||||
if (!fd)
|
if (!fd)
|
||||||
throw SysError("opening NAR file '%s'", narPath);
|
throw SysError("opening NAR file '%s'", narPath);
|
||||||
auto source = FdSource{fd.get()};
|
auto source = FdSource{fd.get()};
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ static void update(const StringSet & channelNames)
|
|||||||
// We want to download the url to a file to see if it's a tarball while also checking if we
|
// We want to download the url to a file to see if it's a tarball while also checking if we
|
||||||
// got redirected in the process, so that we can grab the various parts of a nix channel
|
// got redirected in the process, so that we can grab the various parts of a nix channel
|
||||||
// definition from a consistent location if the redirect changes mid-download.
|
// definition from a consistent location if the redirect changes mid-download.
|
||||||
auto result = fetchers::downloadFile(*store, fetchSettings, url, std::string(baseNameOf(url)));
|
auto result = fetchers::downloadFile(store, fetchSettings, url, std::string(baseNameOf(url)));
|
||||||
url = result.effectiveUrl;
|
url = result.effectiveUrl;
|
||||||
|
|
||||||
bool unpacked = false;
|
bool unpacked = false;
|
||||||
@@ -139,10 +139,10 @@ static void update(const StringSet & channelNames)
|
|||||||
if (!unpacked) {
|
if (!unpacked) {
|
||||||
// Download the channel tarball.
|
// Download the channel tarball.
|
||||||
try {
|
try {
|
||||||
result = fetchers::downloadFile(*store, fetchSettings, url + "/nixexprs.tar.xz", "nixexprs.tar.xz");
|
result = fetchers::downloadFile(store, fetchSettings, url + "/nixexprs.tar.xz", "nixexprs.tar.xz");
|
||||||
} catch (FileTransferError & e) {
|
} catch (FileTransferError & e) {
|
||||||
result =
|
result =
|
||||||
fetchers::downloadFile(*store, fetchSettings, url + "/nixexprs.tar.bz2", "nixexprs.tar.bz2");
|
fetchers::downloadFile(store, fetchSettings, url + "/nixexprs.tar.bz2", "nixexprs.tar.bz2");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Regardless of where it came from, add the expression representing this channel to accumulated expression
|
// Regardless of where it came from, add the expression representing this channel to accumulated expression
|
||||||
|
|||||||
+2
-1
@@ -138,7 +138,8 @@ std::tuple<StorePath, Hash> prefetchFile(
|
|||||||
|
|
||||||
Activity act(*logger, lvlChatty, actUnknown, fmt("adding '%s' to the store", url.to_string()));
|
Activity act(*logger, lvlChatty, actUnknown, fmt("adding '%s' to the store", url.to_string()));
|
||||||
|
|
||||||
auto info = store->addToStoreSlow(*name, makeFSSourceAccessor(tmpFile), method, hashAlgo, {}, expectedHash);
|
auto info = store->addToStoreSlow(
|
||||||
|
*name, PosixSourceAccessor::createAtRoot(tmpFile), method, hashAlgo, {}, expectedHash);
|
||||||
storePath = info.path;
|
storePath = info.path;
|
||||||
assert(info.ca);
|
assert(info.ca);
|
||||||
hash = info.ca->hash;
|
hash = info.ca->hash;
|
||||||
|
|||||||
+4
-4
@@ -68,7 +68,7 @@ struct CmdRegistryList : StoreCommand
|
|||||||
{
|
{
|
||||||
using namespace fetchers;
|
using namespace fetchers;
|
||||||
|
|
||||||
auto registries = getRegistries(fetchSettings, *store);
|
auto registries = getRegistries(fetchSettings, store);
|
||||||
|
|
||||||
for (auto & registry : registries) {
|
for (auto & registry : registries) {
|
||||||
for (auto & entry : registry->entries) {
|
for (auto & entry : registry->entries) {
|
||||||
@@ -189,14 +189,14 @@ struct CmdRegistryPin : RegistryCommand, EvalCommand
|
|||||||
auto registry = getRegistry();
|
auto registry = getRegistry();
|
||||||
auto ref = parseFlakeRef(fetchSettings, url);
|
auto ref = parseFlakeRef(fetchSettings, url);
|
||||||
auto lockedRef = parseFlakeRef(fetchSettings, locked);
|
auto lockedRef = parseFlakeRef(fetchSettings, locked);
|
||||||
auto resolvedInput = lockedRef.resolve(fetchSettings, *store).input;
|
registry->remove(ref.input);
|
||||||
auto resolved = resolvedInput.getAccessor(fetchSettings, *store).second;
|
auto resolvedInput = lockedRef.resolve(fetchSettings, store).input;
|
||||||
|
auto resolved = resolvedInput.getAccessor(fetchSettings, store).second;
|
||||||
if (!resolved.isLocked(fetchSettings))
|
if (!resolved.isLocked(fetchSettings))
|
||||||
warn("flake '%s' is not locked", resolved.to_string());
|
warn("flake '%s' is not locked", resolved.to_string());
|
||||||
fetchers::Attrs extraAttrs;
|
fetchers::Attrs extraAttrs;
|
||||||
if (ref.subdir != "")
|
if (ref.subdir != "")
|
||||||
extraAttrs["dir"] = ref.subdir;
|
extraAttrs["dir"] = ref.subdir;
|
||||||
registry->remove(ref.input);
|
|
||||||
registry->add(ref.input, resolved, extraAttrs);
|
registry->add(ref.input, resolved, extraAttrs);
|
||||||
registry->write(getRegistryPath());
|
registry->write(getRegistryPath());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -369,10 +369,6 @@ tar cfz "$TEST_ROOT"/flake.tar.gz -C "$TEST_ROOT" flake5
|
|||||||
|
|
||||||
nix build -o "$TEST_ROOT"/result file://"$TEST_ROOT"/flake.tar.gz
|
nix build -o "$TEST_ROOT"/result file://"$TEST_ROOT"/flake.tar.gz
|
||||||
|
|
||||||
nix flake clone "file://$TEST_ROOT/flake.tar.gz" --dest "$TEST_ROOT/unpacked"
|
|
||||||
[[ -e $TEST_ROOT/unpacked/flake.nix ]]
|
|
||||||
expectStderr 1 nix flake clone "file://$TEST_ROOT/flake.tar.gz" --dest "$TEST_ROOT/unpacked" | grep 'existing path'
|
|
||||||
|
|
||||||
# Building with a tarball URL containing a SRI hash should also work.
|
# Building with a tarball URL containing a SRI hash should also work.
|
||||||
url=$(nix flake metadata --json file://"$TEST_ROOT"/flake.tar.gz | jq -r .url)
|
url=$(nix flake metadata --json file://"$TEST_ROOT"/flake.tar.gz | jq -r .url)
|
||||||
[[ $url =~ sha256- ]]
|
[[ $url =~ sha256- ]]
|
||||||
|
|||||||
@@ -120,9 +120,7 @@
|
|||||||
path_info_json = substituter.succeed(f"nix path-info --json {tarball_store_path}").strip()
|
path_info_json = substituter.succeed(f"nix path-info --json {tarball_store_path}").strip()
|
||||||
path_info_dict = json.loads(path_info_json)
|
path_info_dict = json.loads(path_info_json)
|
||||||
# nix path-info returns a dict with store paths as keys
|
# nix path-info returns a dict with store paths as keys
|
||||||
narHash_obj = path_info_dict[tarball_store_path]["narHash"]
|
tarball_hash_sri = path_info_dict[tarball_store_path]["narHash"]
|
||||||
# Convert from structured format {"algorithm": "sha256", "format": "base64", "hash": "..."} to SRI string
|
|
||||||
tarball_hash_sri = f"{narHash_obj['algorithm']}-{narHash_obj['hash']}"
|
|
||||||
print(f"Tarball NAR hash (SRI): {tarball_hash_sri}")
|
print(f"Tarball NAR hash (SRI): {tarball_hash_sri}")
|
||||||
|
|
||||||
# Also get the old format hash for fetchTarball (which uses sha256 parameter)
|
# Also get the old format hash for fetchTarball (which uses sha256 parameter)
|
||||||
|
|||||||
Reference in new issue
Block a user