Compare commits

..
Author SHA1 Message Date
John Ericson 156061409a Do some parsing of git hashes based on length.
Note that for Nix-native information we should *not* do length tricks,
but instead always rely on an explicit algorithm. This hack should be
only for foreign hash literals.
2025-11-09 18:52:35 -05:00
John Ericson 6da56d7ed4 Make changes to support libgit2 experimental API
This experimental interface is likely to become stable with libgit2 2.0.
2025-11-09 18:52:35 -05:00
John Ericson 9846305fee Switch to libgit2 experimental
Just patch the package for now, but we should make Nixpkgs provide what
we need (whether that the experimental variant, or a 2.x release with
the new API made non-experimental) before releasing this change.
2025-11-09 18:52:35 -05:00
205 changed files with 1284 additions and 4037 deletions

No files matched your search

+1 -1
View File
@@ -174,7 +174,7 @@ jobs:
echo "installer-url=file://$GITHUB_WORKSPACE/out" >> "$GITHUB_OUTPUT" echo "installer-url=file://$GITHUB_WORKSPACE/out" >> "$GITHUB_OUTPUT"
TARBALL_PATH="$(find "$GITHUB_WORKSPACE/out" -name 'nix*.tar.xz' -print | head -n 1)" TARBALL_PATH="$(find "$GITHUB_WORKSPACE/out" -name 'nix*.tar.xz' -print | head -n 1)"
echo "tarball-path=file://$TARBALL_PATH" >> "$GITHUB_OUTPUT" echo "tarball-path=file://$TARBALL_PATH" >> "$GITHUB_OUTPUT"
- uses: cachix/install-nix-action@7ec16f2c061ab07b235a7245e06ed46fe9a1cab6 # v31.8.3 - uses: cachix/install-nix-action@456688f15bc354bef6d396e4a35f4f89d40bf2b7 # v31.8.2
if: ${{ !matrix.experimental-installer }} if: ${{ !matrix.experimental-installer }}
with: with:
install_url: ${{ format('{0}/install', steps.installer-tarball-url.outputs.installer-url) }} install_url: ${{ format('{0}/install', steps.installer-tarball-url.outputs.installer-url) }}
+6 -2
View File
@@ -58,8 +58,8 @@ mkMesonDerivation (finalAttrs: {
"man" "man"
]; ];
nativeBuildInputs = [ # Hack for sake of the dev shell
nix-cli passthru.externalNativeBuildInputs = [
meson meson
ninja ninja
(lib.getBin lowdown-unsandboxed) (lib.getBin lowdown-unsandboxed)
@@ -78,6 +78,10 @@ mkMesonDerivation (finalAttrs: {
changelog-d changelog-d
]; ];
nativeBuildInputs = finalAttrs.passthru.externalNativeBuildInputs ++ [
nix-cli
];
preConfigure = '' preConfigure = ''
chmod u+w ./.version chmod u+w ./.version
echo ${finalAttrs.version} > ./.version echo ${finalAttrs.version} > ./.version
+1 -9
View File
@@ -22,15 +22,7 @@ The store path info JSON format has been updated from version 1 to version 2:
- New: `"ca": {"method": "nar", "hash": {"algorithm": "sha256", "format": "base64", "hash": "EMIJ+giQ..."}}` - New: `"ca": {"method": "nar", "hash": {"algorithm": "sha256", "format": "base64", "hash": "EMIJ+giQ..."}}`
- Still `null` values for input-addressed store objects - Still `null` values for input-addressed store objects
- **Structured hash fields**: Version 1 format is still accepted when reading for backward compatibility.
Hash values (`narHash` and `downloadHash`) are now structured JSON objects instead of strings:
- Old: `"narHash": "sha256:FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="`
- New: `"narHash": {"algorithm": "sha256", "format": "base64", "hash": "FePFYIlM..."}`
- Same structure applies to `downloadHash` in NAR info contexts
Nix currently only produces, and doesn't consume this format.
**Affected command**: `nix path-info --json` **Affected command**: `nix path-info --json`
-21
View File
@@ -1,21 +0,0 @@
---
synopsis: "S3 binary cache stores now support storage class configuration"
prs: [14464]
issues: [7015]
---
S3 binary cache stores now support configuring the storage class for uploaded objects via the `storage-class` parameter. This allows users to optimize costs by selecting appropriate storage tiers based on access patterns.
Example usage:
```bash
# Use Glacier storage for long-term archival
nix copy --to 's3://my-bucket?storage-class=GLACIER' /nix/store/...
# Use Intelligent Tiering for automatic cost optimization
nix copy --to 's3://my-bucket?storage-class=INTELLIGENT_TIERING' /nix/store/...
```
The storage class applies to both regular uploads and multipart uploads. When not specified, objects use the bucket's default storage class.
See the [S3 storage classes documentation](https://docs.aws.amazon.com/AmazonS3/latest/userguide/storage-class-intro.html) for available storage classes and their characteristics.
-1
View File
@@ -29,7 +29,6 @@
- [Build Trace](store/build-trace.md) - [Build Trace](store/build-trace.md)
- [Derivation Resolution](store/resolution.md) - [Derivation Resolution](store/resolution.md)
- [Building](store/building.md) - [Building](store/building.md)
- [Secrets](store/secrets.md)
- [Store Types](store/types/index.md) - [Store Types](store/types/index.md)
{{#include ./store/types/SUMMARY.md}} {{#include ./store/types/SUMMARY.md}}
- [Appendix: Math notation](store/math-notation.md) - [Appendix: Math notation](store/math-notation.md)
@@ -71,7 +71,7 @@ $defs:
Note: This field may not be present in all contexts, such as when the path is used as the key and the the store object info the value in map. Note: This field may not be present in all contexts, such as when the path is used as the key and the the store object info the value in map.
narHash: narHash:
"$ref": "./hash-v1.yaml" type: string
title: NAR Hash title: NAR Hash
description: | description: |
Hash of the [file system object](@docroot@/store/file-system-object.md) part of the store object when serialized as a [Nix Archive](@docroot@/store/file-system-object/content-address.md#serial-nix-archive). Hash of the [file system object](@docroot@/store/file-system-object.md) part of the store object when serialized as a [Nix Archive](@docroot@/store/file-system-object/content-address.md#serial-nix-archive).
@@ -229,7 +229,7 @@ $defs:
> This is an impure "`.narinfo`" field that may not be included in certain contexts. > This is an impure "`.narinfo`" field that may not be included in certain contexts.
downloadHash: downloadHash:
"$ref": "./hash-v1.yaml" type: string
title: Download Hash title: Download Hash
description: | description: |
A digest for the compressed archive itself, as opposed to the data contained within. A digest for the compressed archive itself, as opposed to the data contained within.
@@ -24,7 +24,7 @@ nar-obj-inner
| str("type"), str("directory") directory | str("type"), str("directory") directory
; ;
regular = [ str("executable"), str("") ], str("contents"), str(contents); regular = [ str("executable") ], str("contents"), str(contents);
symlink = str("target"), str(target); symlink = str("target"), str(target);
@@ -52,4 +52,4 @@ The Nix Archive (NAR) format is also formally described using [Kaitai Struct](ht
{{#include nar.ksy}} {{#include nar.ksy}}
``` ```
The source of the spec can be found [here](https://github.com/nixos/nix/blob/master/src/nix-manual/source/protocols/nix-archive/nar.ksy). Contributions and improvements to the spec are welcomed. The source of the spec can be found [here](https://github.com/nixos/nix/blob/master/src/nix-manual/source/protocols/nix-archive/nar.ksy). Contributions and improvements to the spec are welcomed.
-20
View File
@@ -1,20 +0,0 @@
# Secrets
The store is readable to all users on the system. For this reason, it
is generally discouraged to allow secrets to make it into the store.
Even on a single-user system, separate system users isolate services
from each other and having secrets that all local users can read
weakens that isolation. When using external store caches the secrets
may end up there, and on multi-user systems the secrets will be
available to all those users.
Organize your derivations so that secrets are read from the filesystem
(with appropriate access controls) at run time. Place the secrets on
the filesystem manually or use a scheme that includes the secret in
the store in encrypted form, and decrypts it adding the relevant
access control on system activation.
Several such schemes for NixOS can in the
[comparison of secret managing schemes] on the wiki.
[comparison of secret managing schemes]: https://wiki.nixos.org/wiki/Comparison_of_secret_managing_schemes
+1 -6
View File
@@ -60,9 +60,4 @@ if get_option('unit-tests')
subproject('libflake-tests') subproject('libflake-tests')
endif endif
subproject('nix-functional-tests') subproject('nix-functional-tests')
if get_option('json-schema-checks') subproject('json-schema-checks')
subproject('json-schema-checks')
endif
if get_option('kaitai-struct-checks')
subproject('kaitai-struct-checks')
endif
-14
View File
@@ -27,17 +27,3 @@ option(
value : false, value : false,
description : 'Build benchmarks (requires gbenchmark)', description : 'Build benchmarks (requires gbenchmark)',
) )
option(
'kaitai-struct-checks',
type : 'boolean',
value : true,
description : 'Check the Kaitai Struct specifications (requires Kaitai Struct)',
)
option(
'json-schema-checks',
type : 'boolean',
value : true,
description : 'Check JSON schema validity of schemas and examples (requires jv)',
)
+10
View File
@@ -74,4 +74,14 @@ scope: {
buildPhase = lib.replaceStrings [ "--without-python" ] [ "" ] old.buildPhase; buildPhase = lib.replaceStrings [ "--without-python" ] [ "" ] old.buildPhase;
installPhase = lib.replaceStrings [ "--without-python" ] [ "" ] old.installPhase; installPhase = lib.replaceStrings [ "--without-python" ] [ "" ] old.installPhase;
}); });
libgit2 = pkgs.libgit2.overrideAttrs (attrs: {
cmakeFlags = (attrs.cmakeFlags or [ ]) ++ [
(lib.mesonBool "EXPERIMENTAL_SHA256" true)
];
postInstall = (attrs.postInstall or "") + ''
substituteInPlace $(find $dev/include -type f) --replace-quiet '#include "git2/' '#include "git2-experimental/'
'';
});
} }
+25 -203
View File
@@ -3,118 +3,10 @@
devFlake, devFlake,
}: }:
let
# Some helper functions
/**
Compute a filtered closure of build inputs.
Specifically, `buildInputsClosure cond startSet` computes the closure formed
by recursive application of `p: filter cond p.buildInputs ++ filter cond p.propagatedBuildInputs`
to `startSet`.
Example:
```nix
builtInputsClosure isInternal [ pkg1 pkg2 ]
=> [ pkg1 pkg3 pkg2 pkg10 ]
```
Note: order tbd
Note: `startSet` is *NOT* filtered.
*/
buildInputsClosureCond =
cond: startSet:
let
closure = builtins.genericClosure {
startSet = map (d: {
key = d.drvPath;
value = d;
}) startSet;
operator =
d:
let
r =
map
(d': {
key = d'.drvPath;
value = d';
})
(
lib.filter cond d.value.buildInputs or [ ] ++ lib.filter cond d.value.propagatedBuildInputs or [ ]
);
in
r;
};
in
map (item: item.value) closure;
/**
`[ pkg1 pkg2 ]` -> `{ "...-pkg2.drv" = null; "...-pkg1.drv" = null }`
Note: fairly arbitrary order (hash based). Use for efficient set membership test only.
*/
byDrvPath =
l:
lib.listToAttrs (
map (c: {
name =
# Just a lookup key
builtins.unsafeDiscardStringContext c.drvPath;
value = null;
}) l
);
/**
Stable dedup.
Unlike `listToAttrs` -> `attrValues`, this preserves the input ordering,
which is more predictable ("deterministic") than e.g. sorting store paths,
whose hashes affect the ordering on every change.
*/
# TODO: add to Nixpkgs lib, refer from uniqueStrings
dedupByString =
key: l:
let
r =
lib.foldl'
(
a@{ list, set }:
elem:
let
k = builtins.unsafeDiscardStringContext (key elem);
in
if set ? ${k} then
a
else
let
# Note: O(n²) copying. Use linkedLists to concat them in one go at the end.
# https://github.com/NixOS/nixpkgs/pull/452088
newList = [ elem ] ++ list;
newSet = set // {
${k} = null;
};
in
builtins.seq newList builtins.seq newSet {
list = newList;
set = newSet;
}
)
{
list = [ ];
set = { };
}
l;
in
r.list;
in
{ pkgs }: { pkgs }:
# TODO: don't use nix-util for this?
pkgs.nixComponents2.nix-util.overrideAttrs ( pkgs.nixComponents2.nix-util.overrideAttrs (
finalAttrs: prevAttrs: attrs:
let let
stdenv = pkgs.nixDependencies2.stdenv; stdenv = pkgs.nixDependencies2.stdenv;
@@ -129,89 +21,13 @@ pkgs.nixComponents2.nix-util.overrideAttrs (
"-D${prefix}:${rest}"; "-D${prefix}:${rest}";
havePerl = stdenv.buildPlatform == stdenv.hostPlatform && stdenv.hostPlatform.isUnix; havePerl = stdenv.buildPlatform == stdenv.hostPlatform && stdenv.hostPlatform.isUnix;
ignoreCrossFile = flags: builtins.filter (flag: !(lib.strings.hasInfix "cross-file" flag)) flags; ignoreCrossFile = flags: builtins.filter (flag: !(lib.strings.hasInfix "cross-file" flag)) flags;
activeComponents = buildInputsClosureCond isInternal (
lib.attrValues (finalAttrs.passthru.config.getComponents allComponents)
);
allComponents = lib.filterAttrs (k: v: lib.isDerivation v) pkgs.nixComponents2;
internalDrvs = byDrvPath (
# Drop the attr names (not present in buildInputs anyway)
lib.attrValues allComponents
++ lib.concatMap (c: lib.attrValues c.tests or { }) (lib.attrValues allComponents)
);
isInternal =
dep: internalDrvs ? ${builtins.unsafeDiscardStringContext dep.drvPath or "_non-existent_"};
in in
{ {
pname = "shell-for-nix"; pname = "shell-for-" + attrs.pname;
passthru = {
inherit activeComponents;
# We use this attribute to store non-derivation values like functions and
# perhaps other things that are primarily for overriding and not the shell.
config = {
# Default getComponents
getComponents =
c:
builtins.removeAttrs c (
lib.optionals (!havePerl) [ "nix-perl-bindings" ]
++ lib.optionals (!buildCanExecuteHost) [ "nix-manual" ]
);
};
/**
Produce a devShell for a given set of nix components
Example:
```nix
shell.withActiveComponents (c: {
inherit (c) nix-util;
})
```
*/
withActiveComponents =
f2:
finalAttrs.finalPackage.overrideAttrs (
finalAttrs: prevAttrs: {
passthru = prevAttrs.passthru // {
config = prevAttrs.passthru.config // {
getComponents = f2;
};
};
}
);
small =
(finalAttrs.finalPackage.withActiveComponents (c: {
inherit (c)
nix-cli
nix-util-tests
nix-store-tests
nix-expr-tests
nix-fetchers-tests
nix-flake-tests
nix-functional-tests
# Currently required
nix-perl-bindings
;
})).overrideAttrs
(o: {
mesonFlags = o.mesonFlags ++ [
# TODO: infer from activeComponents or vice versa
"-Dkaitai-struct-checks=false"
"-Djson-schema-checks=false"
];
});
};
# Remove the version suffix to avoid unnecessary attempts to substitute in nix develop # Remove the version suffix to avoid unnecessary attempts to substitute in nix develop
version = lib.fileContents ../.version; version = lib.fileContents ../.version;
name = finalAttrs.pname; name = attrs.pname;
installFlags = "sysconfdir=$(out)/etc"; installFlags = "sysconfdir=$(out)/etc";
shellHook = '' shellHook = ''
@@ -282,9 +98,17 @@ pkgs.nixComponents2.nix-util.overrideAttrs (
nativeBuildInputs = nativeBuildInputs =
let let
inputs = inputs =
dedupByString (v: "${v}") ( attrs.nativeBuildInputs or [ ]
lib.filter (x: !isInternal x) (lib.lists.concatMap (c: c.nativeBuildInputs) activeComponents) ++ pkgs.nixComponents2.nix-util.nativeBuildInputs
) ++ pkgs.nixComponents2.nix-store.nativeBuildInputs
++ pkgs.nixComponents2.nix-fetchers.nativeBuildInputs
++ pkgs.nixComponents2.nix-expr.nativeBuildInputs
++ lib.optionals havePerl pkgs.nixComponents2.nix-perl-bindings.nativeBuildInputs
++ lib.optionals buildCanExecuteHost pkgs.nixComponents2.nix-manual.externalNativeBuildInputs
++ pkgs.nixComponents2.nix-internal-api-docs.nativeBuildInputs
++ pkgs.nixComponents2.nix-external-api-docs.nativeBuildInputs
++ pkgs.nixComponents2.nix-functional-tests.externalNativeBuildInputs
++ pkgs.nixComponents2.nix-json-schema-checks.externalNativeBuildInputs
++ lib.optional ( ++ lib.optional (
!buildCanExecuteHost !buildCanExecuteHost
# Hack around https://github.com/nixos/nixpkgs/commit/bf7ad8cfbfa102a90463433e2c5027573b462479 # Hack around https://github.com/nixos/nixpkgs/commit/bf7ad8cfbfa102a90463433e2c5027573b462479
@@ -293,7 +117,9 @@ pkgs.nixComponents2.nix-util.overrideAttrs (
&& lib.meta.availableOn stdenv.buildPlatform (stdenv.hostPlatform.emulator pkgs.buildPackages) && lib.meta.availableOn stdenv.buildPlatform (stdenv.hostPlatform.emulator pkgs.buildPackages)
) pkgs.buildPackages.mesonEmulatorHook ) pkgs.buildPackages.mesonEmulatorHook
++ [ ++ [
pkgs.buildPackages.cmake
pkgs.buildPackages.gnused pkgs.buildPackages.gnused
pkgs.buildPackages.changelog-d
modular.pre-commit.settings.package modular.pre-commit.settings.package
(pkgs.writeScriptBin "pre-commit-hooks-install" modular.pre-commit.settings.installationScript) (pkgs.writeScriptBin "pre-commit-hooks-install" modular.pre-commit.settings.installationScript)
pkgs.buildPackages.nixfmt-rfc-style pkgs.buildPackages.nixfmt-rfc-style
@@ -310,22 +136,18 @@ pkgs.nixComponents2.nix-util.overrideAttrs (
# from making its way into NIX_CFLAGS_COMPILE. # from making its way into NIX_CFLAGS_COMPILE.
lib.filter (p: !lib.hasInfix "separate-debug-info" p) inputs; lib.filter (p: !lib.hasInfix "separate-debug-info" p) inputs;
propagatedNativeBuildInputs = dedupByString (v: "${v}") (
lib.filter (x: !isInternal x) (
lib.lists.concatMap (c: c.propagatedNativeBuildInputs) activeComponents
)
);
buildInputs = [ buildInputs = [
pkgs.gbenchmark pkgs.gbenchmark
] ]
++ dedupByString (v: "${v}") ( ++ attrs.buildInputs or [ ]
lib.filter (x: !isInternal x) (lib.lists.concatMap (c: c.buildInputs) activeComponents) ++ pkgs.nixComponents2.nix-util.buildInputs
) ++ pkgs.nixComponents2.nix-store.buildInputs
++ pkgs.nixComponents2.nix-store-tests.externalBuildInputs
++ pkgs.nixComponents2.nix-fetchers.buildInputs
++ pkgs.nixComponents2.nix-expr.buildInputs
++ pkgs.nixComponents2.nix-expr.externalPropagatedBuildInputs
++ pkgs.nixComponents2.nix-cmd.buildInputs
++ lib.optionals havePerl pkgs.nixComponents2.nix-perl-bindings.externalBuildInputs
++ lib.optional havePerl pkgs.perl; ++ lib.optional havePerl pkgs.perl;
propagatedBuildInputs = dedupByString (v: "${v}") (
lib.filter (x: !isInternal x) (lib.lists.concatMap (c: c.propagatedBuildInputs) activeComponents)
);
} }
) )
+6 -2
View File
@@ -34,11 +34,15 @@ mkMesonDerivation (finalAttrs: {
outputs = [ "out" ]; outputs = [ "out" ];
passthru.externalNativeBuildInputs = [
jsonschema
];
nativeBuildInputs = [ nativeBuildInputs = [
meson meson
ninja ninja
jsonschema ]
]; ++ finalAttrs.passthru.externalNativeBuildInputs;
doCheck = true; doCheck = true;
+15 -9
View File
@@ -37,15 +37,7 @@ mkMesonDerivation (finalAttrs: {
outputs = [ "out" ]; outputs = [ "out" ];
buildInputs = [ passthru.externalNativeBuildInputs = [
gtest
kaitai-struct-cpp-stl-runtime
];
nativeBuildInputs = [
meson
ninja
pkg-config
# This can go away when we bump up to 25.11 # This can go away when we bump up to 25.11
(kaitai-struct-compiler.overrideAttrs (finalAttrs: { (kaitai-struct-compiler.overrideAttrs (finalAttrs: {
version = "0.11"; version = "0.11";
@@ -56,6 +48,20 @@ mkMesonDerivation (finalAttrs: {
})) }))
]; ];
passthru.externalBuildInputs = [
gtest
kaitai-struct-cpp-stl-runtime
];
buildInputs = finalAttrs.passthru.externalBuildInputs;
nativeBuildInputs = [
meson
ninja
pkg-config
]
++ finalAttrs.passthru.externalNativeBuildInputs;
doCheck = true; doCheck = true;
mesonCheckFlags = [ "--print-errorlogs" ]; mesonCheckFlags = [ "--print-errorlogs" ];
-13
View File
@@ -2,7 +2,6 @@
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include "nix/cmd/command.hh" #include "nix/cmd/command.hh"
#include "nix/cmd/legacy.hh"
#include "nix/cmd/markdown.hh" #include "nix/cmd/markdown.hh"
#include "nix/store/store-open.hh" #include "nix/store/store-open.hh"
#include "nix/store/local-fs-store.hh" #include "nix/store/local-fs-store.hh"
@@ -15,18 +14,6 @@
namespace nix { namespace nix {
RegisterCommand::Commands & RegisterCommand::commands()
{
static RegisterCommand::Commands commands;
return commands;
}
RegisterLegacyCommand::Commands & RegisterLegacyCommand::commands()
{
static RegisterLegacyCommand::Commands commands;
return commands;
}
nix::Commands RegisterCommand::getCommandsFor(const std::vector<std::string> & prefix) nix::Commands RegisterCommand::getCommandsFor(const std::vector<std::string> & prefix)
{ {
nix::Commands res; nix::Commands res;
+3 -4
View File
@@ -33,8 +33,7 @@ EvalSettings evalSettings{
// FIXME `parseFlakeRef` should take a `std::string_view`. // FIXME `parseFlakeRef` should take a `std::string_view`.
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(state.store).lazyFetch(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,
@@ -132,7 +131,7 @@ MixEvalArgs::MixEvalArgs()
fetchers::Attrs extraAttrs; fetchers::Attrs extraAttrs;
if (to.subdir != "") if (to.subdir != "")
extraAttrs["dir"] = to.subdir; extraAttrs["dir"] = to.subdir;
fetchers::overrideRegistry(fetchSettings, from.input, to.input, extraAttrs); fetchers::overrideRegistry(from.input, to.input, extraAttrs);
}}, }},
.completer = {[&](AddCompletions & completions, size_t, std::string_view prefix) { .completer = {[&](AddCompletions & completions, size_t, std::string_view prefix) {
completeFlakeRef(completions, openStore(), prefix); completeFlakeRef(completions, openStore(), prefix);
@@ -188,7 +187,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] = flakeRef.resolve(fetchSettings, state.store).lazyFetch(fetchSettings, state.store); auto [accessor, lockedRef] = flakeRef.resolve(state.store).lazyFetch(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);
+5 -1
View File
@@ -286,7 +286,11 @@ struct RegisterCommand
{ {
typedef std::map<std::vector<std::string>, std::function<ref<Command>()>> Commands; typedef std::map<std::vector<std::string>, std::function<ref<Command>()>> Commands;
static Commands & commands(); static Commands & commands()
{
static Commands commands;
return commands;
}
RegisterCommand(std::vector<std::string> && name, std::function<ref<Command>()> command) RegisterCommand(std::vector<std::string> && name, std::function<ref<Command>()> command)
{ {
+5 -1
View File
@@ -13,7 +13,11 @@ struct RegisterLegacyCommand
{ {
typedef std::map<std::string, MainFunction> Commands; typedef std::map<std::string, MainFunction> Commands;
static Commands & commands(); static Commands & commands()
{
static Commands commands;
return commands;
}
RegisterLegacyCommand(const std::string & name, MainFunction fun) RegisterLegacyCommand(const std::string & name, MainFunction fun)
{ {
-1
View File
@@ -185,7 +185,6 @@ MixFlakeOptions::MixFlakeOptions()
} }
overrideRegistry( overrideRegistry(
fetchSettings,
fetchers::Input::fromAttrs(fetchSettings, {{"type", "indirect"}, {"id", inputName}}), fetchers::Input::fromAttrs(fetchSettings, {{"type", "indirect"}, {"id", inputName}}),
input3->lockedRef.input, input3->lockedRef.input,
extraAttrs); extraAttrs);
+1 -1
View File
@@ -738,7 +738,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())
throw Error("cannot use ':load-flake' on locked 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;
-4
View File
@@ -137,8 +137,6 @@ nix_eval_state_builder * nix_eval_state_builder_new(nix_c_context * context, Sto
void nix_eval_state_builder_free(nix_eval_state_builder * builder) void nix_eval_state_builder_free(nix_eval_state_builder * builder)
{ {
if (builder)
builder->~nix_eval_state_builder();
operator delete(builder, static_cast<std::align_val_t>(alignof(nix_eval_state_builder))); operator delete(builder, static_cast<std::align_val_t>(alignof(nix_eval_state_builder)));
} }
@@ -205,8 +203,6 @@ EvalState * nix_state_create(nix_c_context * context, const char ** lookupPath_c
void nix_state_free(EvalState * state) void nix_state_free(EvalState * state)
{ {
if (state)
state->~EvalState();
operator delete(state, static_cast<std::align_val_t>(alignof(EvalState))); operator delete(state, static_cast<std::align_val_t>(alignof(EvalState)));
} }
@@ -104,7 +104,6 @@ MATCHER(IsAttrs, "")
MATCHER_P(IsStringEq, s, fmt("The string is equal to \"%1%\"", s)) MATCHER_P(IsStringEq, s, fmt("The string is equal to \"%1%\"", s))
{ {
if (arg.type() != nString) { if (arg.type() != nString) {
*result_listener << "Expected a string got " << arg.type();
return false; return false;
} }
return arg.string_view() == s; return arg.string_view() == s;
+2 -3
View File
@@ -1,6 +1,5 @@
#include "nix/expr/tests/libexpr.hh" #include "nix/expr/tests/libexpr.hh"
#include "nix/expr/value-to-json.hh" #include "nix/expr/value-to-json.hh"
#include "nix/expr/static-string-data.hh"
namespace nix { namespace nix {
// Testing the conversion to JSON // Testing the conversion to JSON
@@ -55,7 +54,7 @@ TEST_F(JSONValueTest, IntNegative)
TEST_F(JSONValueTest, String) TEST_F(JSONValueTest, String)
{ {
Value v; Value v;
v.mkStringNoCopy("test"_sds); v.mkStringNoCopy("test");
ASSERT_EQ(getJSONValue(v), "\"test\""); ASSERT_EQ(getJSONValue(v), "\"test\"");
} }
@@ -63,7 +62,7 @@ TEST_F(JSONValueTest, StringQuotes)
{ {
Value v; Value v;
v.mkStringNoCopy("test\""_sds); v.mkStringNoCopy("test\"");
ASSERT_EQ(getJSONValue(v), "\"test\\\"\""); ASSERT_EQ(getJSONValue(v), "\"test\\\"\"");
} }
+1 -5
View File
@@ -14,7 +14,7 @@
namespace nixC { namespace nixC {
TEST_F(nix_api_expr_test, nix_eval_state_lookup_path) TEST_F(nix_api_store_test, nix_eval_state_lookup_path)
{ {
auto tmpDir = nix::createTempDir(); auto tmpDir = nix::createTempDir();
auto delTmpDir = std::make_unique<nix::AutoDelete>(tmpDir, true); auto delTmpDir = std::make_unique<nix::AutoDelete>(tmpDir, true);
@@ -42,16 +42,12 @@ TEST_F(nix_api_expr_test, nix_eval_state_lookup_path)
nix_expr_eval_from_string(ctx, state, "builtins.seq <nixos-config> <nixpkgs>", ".", value); nix_expr_eval_from_string(ctx, state, "builtins.seq <nixos-config> <nixpkgs>", ".", value);
assert_ctx_ok(); assert_ctx_ok();
nix_state_free(state);
ASSERT_EQ(nix_get_type(ctx, value), NIX_TYPE_PATH); ASSERT_EQ(nix_get_type(ctx, value), NIX_TYPE_PATH);
assert_ctx_ok(); assert_ctx_ok();
auto pathStr = nix_get_path_string(ctx, value); auto pathStr = nix_get_path_string(ctx, value);
assert_ctx_ok(); assert_ctx_ok();
ASSERT_EQ(0, strcmp(pathStr, nixpkgs.c_str())); ASSERT_EQ(0, strcmp(pathStr, nixpkgs.c_str()));
nix_gc_decref(nullptr, value);
} }
TEST_F(nix_api_expr_test, nix_expr_eval_from_string) TEST_F(nix_api_expr_test, nix_expr_eval_from_string)
+2 -8
View File
@@ -661,14 +661,8 @@ INSTANTIATE_TEST_SUITE_P(
CASE(R"(null)", ""), CASE(R"(null)", ""),
CASE(R"({ v = "bar"; __toString = self: self.v; })", "bar"), CASE(R"({ v = "bar"; __toString = self: self.v; })", "bar"),
CASE(R"({ v = "bar"; __toString = self: self.v; outPath = "foo"; })", "bar"), CASE(R"({ v = "bar"; __toString = self: self.v; outPath = "foo"; })", "bar"),
CASE(R"({ outPath = "foo"; })", "foo") CASE(R"({ outPath = "foo"; })", "foo"),
// this is broken on cygwin because canonPath("//./test", false) returns //./test CASE(R"(./test)", "/test")));
// FIXME: don't use canonPath
#ifndef __CYGWIN__
,
CASE(R"(./test)", "/test")
#endif
));
#undef CASE #undef CASE
TEST_F(PrimOpTest, substring) TEST_F(PrimOpTest, substring)
+10 -11
View File
@@ -1,5 +1,4 @@
#include "nix/expr/tests/libexpr.hh" #include "nix/expr/tests/libexpr.hh"
#include "nix/expr/static-string-data.hh"
#include "nix/expr/value.hh" #include "nix/expr/value.hh"
#include "nix/expr/print.hh" #include "nix/expr/print.hh"
@@ -36,14 +35,14 @@ TEST_F(ValuePrintingTests, tBool)
TEST_F(ValuePrintingTests, tString) TEST_F(ValuePrintingTests, tString)
{ {
Value vString; Value vString;
vString.mkStringNoCopy("some-string"_sds); vString.mkStringNoCopy("some-string");
test(vString, "\"some-string\""); test(vString, "\"some-string\"");
} }
TEST_F(ValuePrintingTests, tPath) TEST_F(ValuePrintingTests, tPath)
{ {
Value vPath; Value vPath;
vPath.mkStringNoCopy("/foo"_sds); vPath.mkStringNoCopy("/foo");
test(vPath, "\"/foo\""); test(vPath, "\"/foo\"");
} }
@@ -290,10 +289,10 @@ TEST_F(StringPrintingTests, maxLengthTruncation)
TEST_F(ValuePrintingTests, attrsTypeFirst) TEST_F(ValuePrintingTests, attrsTypeFirst)
{ {
Value vType; Value vType;
vType.mkStringNoCopy("puppy"_sds); vType.mkStringNoCopy("puppy");
Value vApple; Value vApple;
vApple.mkStringNoCopy("apple"_sds); vApple.mkStringNoCopy("apple");
BindingsBuilder builder = state.buildBindings(10); BindingsBuilder builder = state.buildBindings(10);
builder.insert(state.symbols.create("type"), &vType); builder.insert(state.symbols.create("type"), &vType);
@@ -334,7 +333,7 @@ TEST_F(ValuePrintingTests, ansiColorsBool)
TEST_F(ValuePrintingTests, ansiColorsString) TEST_F(ValuePrintingTests, ansiColorsString)
{ {
Value v; Value v;
v.mkStringNoCopy("puppy"_sds); v.mkStringNoCopy("puppy");
test(v, ANSI_MAGENTA "\"puppy\"" ANSI_NORMAL, PrintOptions{.ansiColors = true}); test(v, ANSI_MAGENTA "\"puppy\"" ANSI_NORMAL, PrintOptions{.ansiColors = true});
} }
@@ -342,7 +341,7 @@ TEST_F(ValuePrintingTests, ansiColorsString)
TEST_F(ValuePrintingTests, ansiColorsStringElided) TEST_F(ValuePrintingTests, ansiColorsStringElided)
{ {
Value v; Value v;
v.mkStringNoCopy("puppy"_sds); v.mkStringNoCopy("puppy");
test( test(
v, v,
@@ -390,7 +389,7 @@ TEST_F(ValuePrintingTests, ansiColorsAttrs)
TEST_F(ValuePrintingTests, ansiColorsDerivation) TEST_F(ValuePrintingTests, ansiColorsDerivation)
{ {
Value vDerivation; Value vDerivation;
vDerivation.mkStringNoCopy("derivation"_sds); vDerivation.mkStringNoCopy("derivation");
BindingsBuilder builder = state.buildBindings(10); BindingsBuilder builder = state.buildBindings(10);
builder.insert(state.s.type, &vDerivation); builder.insert(state.s.type, &vDerivation);
@@ -413,7 +412,7 @@ TEST_F(ValuePrintingTests, ansiColorsError)
{ {
Value throw_ = state.getBuiltin("throw"); Value throw_ = state.getBuiltin("throw");
Value message; Value message;
message.mkStringNoCopy("uh oh!"_sds); message.mkStringNoCopy("uh oh!");
Value vError; Value vError;
vError.mkApp(&throw_, &message); vError.mkApp(&throw_, &message);
@@ -430,12 +429,12 @@ TEST_F(ValuePrintingTests, ansiColorsDerivationError)
{ {
Value throw_ = state.getBuiltin("throw"); Value throw_ = state.getBuiltin("throw");
Value message; Value message;
message.mkStringNoCopy("uh oh!"_sds); message.mkStringNoCopy("uh oh!");
Value vError; Value vError;
vError.mkApp(&throw_, &message); vError.mkApp(&throw_, &message);
Value vDerivation; Value vDerivation;
vDerivation.mkStringNoCopy("derivation"_sds); vDerivation.mkStringNoCopy("derivation");
BindingsBuilder builder = state.buildBindings(10); BindingsBuilder builder = state.buildBindings(10);
builder.insert(state.s.type, &vDerivation); builder.insert(state.s.type, &vDerivation);
+6 -7
View File
@@ -1,5 +1,4 @@
#include "nix/expr/value.hh" #include "nix/expr/value.hh"
#include "nix/expr/static-string-data.hh"
#include "nix/store/tests/libstore.hh" #include "nix/store/tests/libstore.hh"
#include <gtest/gtest.h> #include <gtest/gtest.h>
@@ -28,17 +27,17 @@ TEST_F(ValueTest, staticString)
{ {
Value vStr1; Value vStr1;
Value vStr2; Value vStr2;
vStr1.mkStringNoCopy("foo"_sds); vStr1.mkStringNoCopy("foo");
vStr2.mkStringNoCopy("foo"_sds); vStr2.mkStringNoCopy("foo");
auto & sd1 = vStr1.string_data(); auto sd1 = vStr1.string_view();
auto & sd2 = vStr2.string_data(); auto sd2 = vStr2.string_view();
// The strings should be the same // The strings should be the same
ASSERT_EQ(sd1.view(), sd2.view()); ASSERT_EQ(sd1, sd2);
// The strings should also be backed by the same (static) allocation // The strings should also be backed by the same (static) allocation
ASSERT_EQ(&sd1, &sd2); ASSERT_EQ(sd1.data(), sd2.data());
} }
} // namespace nix } // namespace nix
+1 -1
View File
@@ -147,7 +147,7 @@ struct AttrDb
for (auto * elem : *context) { for (auto * elem : *context) {
if (!first) if (!first)
ctx.push_back(' '); ctx.push_back(' ');
ctx.append(elem->view()); ctx.append(elem);
first = false; first = false;
} }
state->insertAttributeWithContext.use()(key.first)(symbols[key.second])(AttrType::String) (s) (ctx) state->insertAttributeWithContext.use()(key.first)(symbols[key.second])(AttrType::String) (s) (ctx)
+34 -69
View File
@@ -3,7 +3,6 @@
#include "nix/expr/primops.hh" #include "nix/expr/primops.hh"
#include "nix/expr/print-options.hh" #include "nix/expr/print-options.hh"
#include "nix/expr/symbol-table.hh" #include "nix/expr/symbol-table.hh"
#include "nix/expr/value.hh"
#include "nix/util/exit.hh" #include "nix/util/exit.hh"
#include "nix/util/types.hh" #include "nix/util/types.hh"
#include "nix/util/util.hh" #include "nix/util/util.hh"
@@ -29,8 +28,6 @@
#include "parser-tab.hh" #include "parser-tab.hh"
#include <algorithm> #include <algorithm>
#include <cstddef>
#include <cstdlib>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <cstring> #include <cstring>
@@ -51,9 +48,6 @@ using json = nlohmann::json;
namespace nix { namespace nix {
/**
* Just for doc strings. Not for regular string values.
*/
static char * allocString(size_t size) static char * allocString(size_t size)
{ {
char * t; char * t;
@@ -67,9 +61,6 @@ static char * allocString(size_t size)
// string allocations. // string allocations.
// This function handles makeImmutableString(std::string_view()) by returning // This function handles makeImmutableString(std::string_view()) by returning
// the empty string. // the empty string.
/**
* Just for doc strings. Not for regular string values.
*/
static const char * makeImmutableString(std::string_view s) static const char * makeImmutableString(std::string_view s)
{ {
const size_t size = s.size(); const size_t size = s.size();
@@ -81,25 +72,6 @@ static const char * makeImmutableString(std::string_view s)
return t; return t;
} }
StringData & StringData::alloc(size_t size)
{
void * t = GC_MALLOC_ATOMIC(sizeof(StringData) + size + 1);
if (!t)
throw std::bad_alloc();
auto res = new (t) StringData(size);
return *res;
}
const StringData & StringData::make(std::string_view s)
{
if (s.empty())
return ""_sds;
auto & res = alloc(s.size());
std::memcpy(&res.data_, s.data(), s.size());
res.data_[s.size()] = '\0';
return res;
}
RootValue allocRootValue(Value * v) RootValue allocRootValue(Value * v)
{ {
return std::allocate_shared<Value *>(traceable_allocator<Value *>(), v); return std::allocate_shared<Value *>(traceable_allocator<Value *>(), v);
@@ -517,16 +489,15 @@ Value * EvalState::addPrimOp(PrimOp && primOp)
if (primOp.arity == 0) { if (primOp.arity == 0) {
primOp.arity = 1; primOp.arity = 1;
auto vPrimOp = allocValue(); auto vPrimOp = allocValue();
vPrimOp->mkPrimOp(new PrimOp(std::move(primOp))); vPrimOp->mkPrimOp(new PrimOp(primOp));
Value v; Value v;
v.mkApp(vPrimOp, vPrimOp); v.mkApp(vPrimOp, vPrimOp);
auto & primOp1 = *vPrimOp->primOp();
return addConstant( return addConstant(
primOp1.name, primOp.name,
v, v,
{ {
.type = nThunk, // FIXME .type = nThunk, // FIXME
.doc = primOp1.doc ? primOp1.doc->c_str() : nullptr, .doc = primOp.doc,
}); });
} }
@@ -566,14 +537,13 @@ std::optional<EvalState::Doc> EvalState::getDoc(Value & v)
{ {
if (v.isPrimOp()) { if (v.isPrimOp()) {
auto v2 = &v; auto v2 = &v;
auto & primOp = *v2->primOp(); if (auto * doc = v2->primOp()->doc)
if (primOp.doc)
return Doc{ return Doc{
.pos = {}, .pos = {},
.name = primOp.name, .name = v2->primOp()->name,
.arity = primOp.arity, .arity = v2->primOp()->arity,
.args = primOp.args, .args = v2->primOp()->args,
.doc = primOp.doc->c_str(), .doc = doc,
}; };
} }
if (v.isLambda()) { if (v.isLambda()) {
@@ -615,9 +585,7 @@ std::optional<EvalState::Doc> EvalState::getDoc(Value & v)
.name = name, .name = name,
.arity = 0, // FIXME: figure out how deep by syntax only? It's not semantically useful though... .arity = 0, // FIXME: figure out how deep by syntax only? It's not semantically useful though...
.args = {}, .args = {},
/* N.B. Can't use StringData here, because that would lead to an interior pointer. .doc = makeImmutableString(s.view()), // NOTE: memory leak when compiled without GC
NOTE: memory leak when compiled without GC. */
.doc = makeImmutableString(s.view()),
}; };
} }
if (isFunctor(v)) { if (isFunctor(v)) {
@@ -851,34 +819,33 @@ DebugTraceStacker::DebugTraceStacker(EvalState & evalState, DebugTrace t)
void Value::mkString(std::string_view s) void Value::mkString(std::string_view s)
{ {
mkStringNoCopy(StringData::make(s)); mkStringNoCopy(makeImmutableString(s));
} }
Value::StringWithContext::Context * Value::StringWithContext::Context * Value::StringWithContext::Context::fromBuilder(const NixStringContext & context)
Value::StringWithContext::Context::fromBuilder(const NixStringContext & context, EvalMemory & mem)
{ {
if (context.empty()) if (context.empty())
return nullptr; return nullptr;
auto ctx = new (mem.allocBytes(sizeof(Context) + context.size() * sizeof(value_type))) Context(context.size()); auto ctx = new (allocBytes(sizeof(Context) + context.size() * sizeof(value_type))) Context(context.size());
std::ranges::transform( std::ranges::transform(
context, ctx->elems, [](const NixStringContextElem & elt) { return &StringData::make(elt.to_string()); }); context, ctx->elems, [](const NixStringContextElem & elt) { return makeImmutableString(elt.to_string()); });
return ctx; return ctx;
} }
void Value::mkString(std::string_view s, const NixStringContext & context, EvalMemory & mem) void Value::mkString(std::string_view s, const NixStringContext & context)
{ {
mkStringNoCopy(StringData::make(s), Value::StringWithContext::Context::fromBuilder(context, mem)); mkStringNoCopy(makeImmutableString(s), Value::StringWithContext::Context::fromBuilder(context));
} }
void Value::mkStringMove(const StringData & s, const NixStringContext & context, EvalMemory & mem) void Value::mkStringMove(const char * s, const NixStringContext & context)
{ {
mkStringNoCopy(s, Value::StringWithContext::Context::fromBuilder(context, mem)); mkStringNoCopy(s, Value::StringWithContext::Context::fromBuilder(context));
} }
void Value::mkPath(const SourcePath & path) void Value::mkPath(const SourcePath & path)
{ {
mkPath(&*path.accessor, StringData::make(path.path.abs())); mkPath(&*path.accessor, makeImmutableString(path.path.abs()));
} }
inline Value * EvalState::lookupVar(Env * env, const ExprVar & var, bool noEval) inline Value * EvalState::lookupVar(Env * env, const ExprVar & var, bool noEval)
@@ -914,9 +881,9 @@ inline Value * EvalState::lookupVar(Env * env, const ExprVar & var, bool noEval)
} }
} }
ListBuilder::ListBuilder(EvalMemory & mem, size_t size) ListBuilder::ListBuilder(size_t size)
: size(size) : size(size)
, elems(size <= 2 ? inlineElems : (Value **) mem.allocBytes(size * sizeof(Value *))) , elems(size <= 2 ? inlineElems : (Value **) allocBytes(size * sizeof(Value *)))
{ {
} }
@@ -956,8 +923,7 @@ void EvalState::mkStorePathString(const StorePath & p, Value & v)
store->printStorePath(p), store->printStorePath(p),
NixStringContext{ NixStringContext{
NixStringContextElem::Opaque{.path = p}, NixStringContextElem::Opaque{.path = p},
}, });
mem);
} }
std::string EvalState::mkOutputStringRaw( std::string EvalState::mkOutputStringRaw(
@@ -979,7 +945,7 @@ void EvalState::mkOutputString(
std::optional<StorePath> optStaticOutputPath, std::optional<StorePath> optStaticOutputPath,
const ExperimentalFeatureSettings & xpSettings) const ExperimentalFeatureSettings & xpSettings)
{ {
value.mkString(mkOutputStringRaw(b, optStaticOutputPath, xpSettings), NixStringContext{b}, mem); value.mkString(mkOutputStringRaw(b, optStaticOutputPath, xpSettings), NixStringContext{b});
} }
std::string EvalState::mkSingleDerivedPathStringRaw(const SingleDerivedPath & p) std::string EvalState::mkSingleDerivedPathStringRaw(const SingleDerivedPath & p)
@@ -1014,8 +980,7 @@ void EvalState::mkSingleDerivedPathString(const SingleDerivedPath & p, Value & v
mkSingleDerivedPathStringRaw(p), mkSingleDerivedPathStringRaw(p),
NixStringContext{ NixStringContext{
std::visit([](auto && v) -> NixStringContextElem { return v; }, p), std::visit([](auto && v) -> NixStringContextElem { return v; }, p),
}, });
mem);
} }
Value * Expr::maybeThunk(EvalState & state, Env & env) Value * Expr::maybeThunk(EvalState & state, Env & env)
@@ -2134,21 +2099,21 @@ void ExprConcatStrings::eval(EvalState & state, Env & env, Value & v)
.atPos(pos) .atPos(pos)
.withFrame(env, *this) .withFrame(env, *this)
.debugThrow(); .debugThrow();
std::string resultStr; std::string result_str;
resultStr.reserve(sSize); result_str.reserve(sSize);
for (const auto & part : strings) { for (const auto & part : strings) {
resultStr += *part; result_str += *part;
} }
v.mkPath(state.rootPath(CanonPath(resultStr))); v.mkPath(state.rootPath(CanonPath(result_str)));
} else { } else {
auto & resultStr = StringData::alloc(sSize); char * result_str = allocString(sSize + 1);
auto * tmp = resultStr.data(); char * tmp = result_str;
for (const auto & part : strings) { for (const auto & part : strings) {
std::memcpy(tmp, part->data(), part->size()); memcpy(tmp, part->data(), part->size());
tmp += part->size(); tmp += part->size();
} }
*tmp = '\0'; *tmp = 0;
v.mkStringMove(resultStr, context, state.mem); v.mkStringMove(result_str, context);
} }
} }
@@ -2323,7 +2288,7 @@ void copyContext(const Value & v, NixStringContext & context, const Experimental
{ {
if (auto * ctx = v.context()) if (auto * ctx = v.context())
for (auto * elem : *ctx) for (auto * elem : *ctx)
context.insert(NixStringContextElem::parse(elem->view(), xpSettings)); context.insert(NixStringContextElem::parse(elem, xpSettings));
} }
std::string_view EvalState::forceString( std::string_view EvalState::forceString(
@@ -2345,7 +2310,7 @@ std::string_view EvalState::forceStringNoCtx(Value & v, const PosIdx pos, std::s
error<EvalError>( error<EvalError>(
"the string '%1%' is not allowed to refer to a store path (such as '%2%')", "the string '%1%' is not allowed to refer to a store path (such as '%2%')",
v.string_view(), v.string_view(),
(*v.context()->begin())->view()) *v.context()->begin())
.withTrace(pos, errorCtx) .withTrace(pos, errorCtx)
.debugThrow(); .debugThrow();
} }
+1 -1
View File
@@ -12,7 +12,7 @@ namespace nix {
* Note: Various places expect the allocated memory to be zeroed. * Note: Various places expect the allocated memory to be zeroed.
*/ */
[[gnu::always_inline]] [[gnu::always_inline]]
inline void * EvalMemory::allocBytes(size_t n) inline void * allocBytes(size_t n)
{ {
void * p; void * p;
#if NIX_USE_BOEHMGC #if NIX_USE_BOEHMGC
+2 -3
View File
@@ -108,7 +108,7 @@ struct PrimOp
/** /**
* Optional free-form documentation about the primop. * Optional free-form documentation about the primop.
*/ */
std::optional<std::string> doc; const char * doc = nullptr;
/** /**
* Add a trace item, while calling the `<name>` builtin. * Add a trace item, while calling the `<name>` builtin.
@@ -335,7 +335,6 @@ public:
EvalMemory & operator=(const EvalMemory &) = delete; EvalMemory & operator=(const EvalMemory &) = delete;
EvalMemory & operator=(EvalMemory &&) = delete; EvalMemory & operator=(EvalMemory &&) = delete;
inline void * allocBytes(size_t n);
inline Value * allocValue(); inline Value * allocValue();
inline Env & allocEnv(size_t size); inline Env & allocEnv(size_t size);
@@ -349,7 +348,7 @@ public:
ListBuilder buildList(size_t size) ListBuilder buildList(size_t size)
{ {
stats.nrListElems += size; stats.nrListElems += size;
return ListBuilder(*this, size); return ListBuilder(size);
} }
const Statistics & getStats() const & const Statistics & getStats() const &
-1
View File
@@ -31,7 +31,6 @@ headers = [ config_pub_h ] + files(
'print.hh', 'print.hh',
'repl-exit-status.hh', 'repl-exit-status.hh',
'search-path.hh', 'search-path.hh',
'static-string-data.hh',
'symbol-table.hh', 'symbol-table.hh',
'value-to-json.hh', 'value-to-json.hh',
'value-to-xml.hh', 'value-to-xml.hh',
+18 -36
View File
@@ -3,7 +3,6 @@
#include <map> #include <map>
#include <span> #include <span>
#include <memory>
#include <vector> #include <vector>
#include <memory_resource> #include <memory_resource>
#include <algorithm> #include <algorithm>
@@ -12,7 +11,6 @@
#include "nix/expr/value.hh" #include "nix/expr/value.hh"
#include "nix/expr/symbol-table.hh" #include "nix/expr/symbol-table.hh"
#include "nix/expr/eval-error.hh" #include "nix/expr/eval-error.hh"
#include "nix/expr/static-string-data.hh"
#include "nix/util/pos-idx.hh" #include "nix/util/pos-idx.hh"
#include "nix/expr/counter.hh" #include "nix/expr/counter.hh"
#include "nix/util/pos-table.hh" #include "nix/util/pos-table.hh"
@@ -188,18 +186,22 @@ struct ExprString : Expr
* This is only for strings already allocated in our polymorphic allocator, * This is only for strings already allocated in our polymorphic allocator,
* or that live at least that long (e.g. c++ string literals) * or that live at least that long (e.g. c++ string literals)
*/ */
ExprString(const StringData & s) ExprString(const char * s)
{ {
v.mkStringNoCopy(s); v.mkStringNoCopy(s);
}; };
ExprString(std::pmr::polymorphic_allocator<char> & alloc, std::string_view sv) ExprString(std::pmr::polymorphic_allocator<char> & alloc, std::string_view sv)
{ {
if (sv.size() == 0) { auto len = sv.length();
v.mkStringNoCopy(""_sds); if (len == 0) {
v.mkStringNoCopy("");
return; return;
} }
v.mkStringNoCopy(StringData::make(*alloc.resource(), sv)); char * s = alloc.allocate(len + 1);
sv.copy(s, len);
s[len] = '\0';
v.mkStringNoCopy(s);
}; };
Value * maybeThunk(EvalState & state, Env & env) override; Value * maybeThunk(EvalState & state, Env & env) override;
@@ -214,7 +216,11 @@ struct ExprPath : Expr
ExprPath(std::pmr::polymorphic_allocator<char> & alloc, ref<SourceAccessor> accessor, std::string_view sv) ExprPath(std::pmr::polymorphic_allocator<char> & alloc, ref<SourceAccessor> accessor, std::string_view sv)
: accessor(accessor) : accessor(accessor)
{ {
v.mkPath(&*accessor, StringData::make(*alloc.resource(), sv)); auto len = sv.length();
char * s = alloc.allocate(len + 1);
sv.copy(s, len);
s[len] = '\0';
v.mkPath(&*accessor, s);
} }
Value * maybeThunk(EvalState & state, Env & env) override; Value * maybeThunk(EvalState & state, Env & env) override;
@@ -339,7 +345,7 @@ struct ExprOpHasAttr : Expr
Expr * e; Expr * e;
std::span<AttrName> attrPath; std::span<AttrName> attrPath;
ExprOpHasAttr(std::pmr::polymorphic_allocator<char> & alloc, Expr * e, std::span<AttrName> attrPath) ExprOpHasAttr(std::pmr::polymorphic_allocator<char> & alloc, Expr * e, std::vector<AttrName> attrPath)
: e(e) : e(e)
, attrPath({alloc.allocate_object<AttrName>(attrPath.size()), attrPath.size()}) , attrPath({alloc.allocate_object<AttrName>(attrPath.size()), attrPath.size()})
{ {
@@ -433,7 +439,7 @@ struct ExprList : Expr
{ {
std::span<Expr *> elems; std::span<Expr *> elems;
ExprList(std::pmr::polymorphic_allocator<char> & alloc, std::span<Expr *> exprs) ExprList(std::pmr::polymorphic_allocator<char> & alloc, std::vector<Expr *> exprs)
: elems({alloc.allocate_object<Expr *>(exprs.size()), exprs.size()}) : elems({alloc.allocate_object<Expr *>(exprs.size()), exprs.size()})
{ {
std::ranges::copy(exprs, elems.begin()); std::ranges::copy(exprs, elems.begin());
@@ -562,7 +568,7 @@ public:
const PosTable & positions, const PosTable & positions,
std::pmr::polymorphic_allocator<char> & alloc, std::pmr::polymorphic_allocator<char> & alloc,
PosIdx pos, PosIdx pos,
const FormalsBuilder & formals, FormalsBuilder formals,
Expr * body) Expr * body)
: ExprLambda(positions, alloc, pos, Symbol(), formals, body) {}; : ExprLambda(positions, alloc, pos, Symbol(), formals, body) {};
@@ -753,19 +759,7 @@ struct ExprConcatStrings : Expr
std::pmr::polymorphic_allocator<char> & alloc, std::pmr::polymorphic_allocator<char> & alloc,
const PosIdx & pos, const PosIdx & pos,
bool forceString, bool forceString,
std::span<std::pair<PosIdx, Expr *>> es) const std::vector<std::pair<PosIdx, Expr *>> & es)
: pos(pos)
, forceString(forceString)
, es({alloc.allocate_object<std::pair<PosIdx, Expr *>>(es.size()), es.size()})
{
std::ranges::copy(es, this->es.begin());
};
ExprConcatStrings(
std::pmr::polymorphic_allocator<char> & alloc,
const PosIdx & pos,
bool forceString,
std::initializer_list<std::pair<PosIdx, Expr *>> es)
: pos(pos) : pos(pos)
, forceString(forceString) , forceString(forceString)
, es({alloc.allocate_object<std::pair<PosIdx, Expr *>>(es.size()), es.size()}) , es({alloc.allocate_object<std::pair<PosIdx, Expr *>>(es.size()), es.size()})
@@ -845,19 +839,7 @@ public:
add(std::pmr::polymorphic_allocator<char> & alloc, add(std::pmr::polymorphic_allocator<char> & alloc,
const PosIdx & pos, const PosIdx & pos,
bool forceString, bool forceString,
std::span<std::pair<PosIdx, Expr *>> es) const std::vector<std::pair<PosIdx, Expr *>> & es)
requires(std::same_as<C, ExprConcatStrings>)
{
return alloc.new_object<C>(alloc, pos, forceString, es);
}
template<class C>
[[gnu::always_inline]]
C *
add(std::pmr::polymorphic_allocator<char> & alloc,
const PosIdx & pos,
bool forceString,
std::initializer_list<std::pair<PosIdx, Expr *>> es)
requires(std::same_as<C, ExprConcatStrings>) requires(std::same_as<C, ExprConcatStrings>)
{ {
return alloc.new_object<C>(alloc, pos, forceString, es); return alloc.new_object<C>(alloc, pos, forceString, es);
+5 -7
View File
@@ -4,8 +4,6 @@
#include <limits> #include <limits>
#include "nix/expr/eval.hh" #include "nix/expr/eval.hh"
#include "nix/expr/value.hh"
#include "nix/expr/static-string-data.hh"
namespace nix { namespace nix {
@@ -96,7 +94,7 @@ struct ParserState
ExprAttrs * attrs, AttrPath && attrPath, const ParserLocation & loc, Expr * e, const ParserLocation & exprLoc); ExprAttrs * attrs, AttrPath && attrPath, const ParserLocation & loc, Expr * e, const ParserLocation & exprLoc);
void addAttr(ExprAttrs * attrs, AttrPath & attrPath, const Symbol & symbol, ExprAttrs::AttrDef && def); void addAttr(ExprAttrs * attrs, AttrPath & attrPath, const Symbol & symbol, ExprAttrs::AttrDef && def);
void validateFormals(FormalsBuilder & formals, PosIdx pos = noPos, Symbol arg = {}); void validateFormals(FormalsBuilder & formals, PosIdx pos = noPos, Symbol arg = {});
Expr * stripIndentation(const PosIdx pos, std::span<std::pair<PosIdx, std::variant<Expr *, StringToken>>> es); Expr * stripIndentation(const PosIdx pos, std::vector<std::pair<PosIdx, std::variant<Expr *, StringToken>>> && es);
PosIdx at(const ParserLocation & loc); PosIdx at(const ParserLocation & loc);
}; };
@@ -239,10 +237,10 @@ inline void ParserState::validateFormals(FormalsBuilder & formals, PosIdx pos, S
} }
inline Expr * inline Expr *
ParserState::stripIndentation(const PosIdx pos, std::span<std::pair<PosIdx, std::variant<Expr *, StringToken>>> es) ParserState::stripIndentation(const PosIdx pos, std::vector<std::pair<PosIdx, std::variant<Expr *, StringToken>>> && es)
{ {
if (es.empty()) if (es.empty())
return exprs.add<ExprString>(""_sds); return exprs.add<ExprString>("");
/* Figure out the minimum indentation. Note that by design /* Figure out the minimum indentation. Note that by design
whitespace-only final lines are not taken into account. (So whitespace-only final lines are not taken into account. (So
@@ -334,7 +332,7 @@ ParserState::stripIndentation(const PosIdx pos, std::span<std::pair<PosIdx, std:
// If there is nothing at all, return the empty string directly. // If there is nothing at all, return the empty string directly.
// This also ensures that equivalent empty strings result in the same ast, which is helpful when testing formatters. // This also ensures that equivalent empty strings result in the same ast, which is helpful when testing formatters.
if (es2.size() == 0) { if (es2.size() == 0) {
auto * const result = exprs.add<ExprString>(""_sds); auto * const result = exprs.add<ExprString>("");
return result; return result;
} }
@@ -343,7 +341,7 @@ ParserState::stripIndentation(const PosIdx pos, std::span<std::pair<PosIdx, std:
auto * const result = (es2)[0].second; auto * const result = (es2)[0].second;
return result; return result;
} }
return exprs.add<ExprConcatStrings>(exprs.alloc, pos, true, es2); return exprs.add<ExprConcatStrings>(exprs.alloc, pos, true, std::move(es2));
} }
inline PosIdx LexerState::at(const ParserLocation & loc) inline PosIdx LexerState::at(const ParserLocation & loc)
+5 -1
View File
@@ -12,7 +12,11 @@ struct RegisterPrimOp
{ {
typedef std::vector<PrimOp> PrimOps; typedef std::vector<PrimOp> PrimOps;
static PrimOps & primOps(); static PrimOps & primOps()
{
static PrimOps primOps;
return primOps;
}
/** /**
* You can register a constant by passing an arity of 0. fun * You can register a constant by passing an arity of 0. fun
@@ -110,7 +110,7 @@ struct PrintOptions
* `PrintOptions` for unknown and therefore potentially large values in error messages, * `PrintOptions` for unknown and therefore potentially large values in error messages,
* to avoid printing "too much" output. * to avoid printing "too much" output.
*/ */
static constexpr PrintOptions errorPrintOptions = PrintOptions{ static PrintOptions errorPrintOptions = PrintOptions{
.ansiColors = true, .ansiColors = true,
.maxDepth = 10, .maxDepth = 10,
.maxAttrs = 10, .maxAttrs = 10,
@@ -1,44 +0,0 @@
#pragma once
///@file
#include "nix/expr/value.hh"
namespace nix {
template<size_t N>
struct StringData::Static
{
/**
* @note Must be first to make layout compatible with StringData.
*/
const size_t size = N - 1;
char data[N];
consteval Static(const char (&str)[N])
{
static_assert(N > 0);
if (str[size] != '\0')
throw;
std::copy_n(str, N, data);
}
operator const StringData &() const &
{
static_assert(sizeof(decltype(*this)) >= sizeof(StringData));
static_assert(alignof(decltype(*this)) == alignof(StringData));
/* NOTE: This cast is somewhat on the fence of what's legal in C++.
The question boils down to whether flexible array members are
layout compatible with fixed-size arrays. This is a gray area, since
FAMs are not standard anyway.
*/
return *reinterpret_cast<const StringData *>(this);
}
};
template<StringData::Static S>
const StringData & operator""_sds()
{
return S;
}
} // namespace nix
+15 -20
View File
@@ -3,7 +3,6 @@
#include <memory_resource> #include <memory_resource>
#include "nix/expr/value.hh" #include "nix/expr/value.hh"
#include "nix/expr/static-string-data.hh"
#include "nix/util/chunked-vector.hh" #include "nix/util/chunked-vector.hh"
#include "nix/util/error.hh" #include "nix/util/error.hh"
@@ -17,6 +16,7 @@ class SymbolValue : protected Value
friend class SymbolStr; friend class SymbolStr;
friend class SymbolTable; friend class SymbolTable;
uint32_t size_;
uint32_t idx; uint32_t idx;
SymbolValue() = default; SymbolValue() = default;
@@ -24,7 +24,7 @@ class SymbolValue : protected Value
public: public:
operator std::string_view() const noexcept operator std::string_view() const noexcept
{ {
return string_view(); return {c_str(), size_};
} }
}; };
@@ -96,13 +96,13 @@ class SymbolStr
SymbolValueStore & store; SymbolValueStore & store;
std::string_view s; std::string_view s;
std::size_t hash; std::size_t hash;
std::pmr::memory_resource & resource; std::pmr::polymorphic_allocator<char> & alloc;
Key(SymbolValueStore & store, std::string_view s, std::pmr::memory_resource & stringMemory) Key(SymbolValueStore & store, std::string_view s, std::pmr::polymorphic_allocator<char> & stringAlloc)
: store(store) : store(store)
, s(s) , s(s)
, hash(HashType{}(s)) , hash(HashType{}(s))
, resource(stringMemory) , alloc(stringAlloc)
{ {
} }
}; };
@@ -122,10 +122,14 @@ public:
// for multi-threaded implementations: lock store and allocator here // for multi-threaded implementations: lock store and allocator here
const auto & [v, idx] = key.store.add(SymbolValue{}); const auto & [v, idx] = key.store.add(SymbolValue{});
if (size == 0) { if (size == 0) {
v.mkStringNoCopy(""_sds, nullptr); v.mkStringNoCopy("", nullptr);
} else { } else {
v.mkStringNoCopy(StringData::make(key.resource, key.s)); auto s = key.alloc.allocate(size + 1);
memcpy(s, key.s.data(), size);
s[size] = '\0';
v.mkStringNoCopy(s, nullptr);
} }
v.size_ = size;
v.idx = idx; v.idx = idx;
this->s = &v; this->s = &v;
} }
@@ -135,12 +139,6 @@ public:
return *s == s2; return *s == s2;
} }
[[gnu::always_inline]]
const StringData & string_data() const noexcept
{
return s->string_data();
}
[[gnu::always_inline]] [[gnu::always_inline]]
const char * c_str() const noexcept const char * c_str() const noexcept
{ {
@@ -157,17 +155,13 @@ public:
[[gnu::always_inline]] [[gnu::always_inline]]
bool empty() const noexcept bool empty() const noexcept
{ {
auto * p = &s->string_data(); return s->size_ == 0;
// Save a dereference in the sentinel value case
if (p == &""_sds)
return true;
return p->size() == 0;
} }
[[gnu::always_inline]] [[gnu::always_inline]]
size_t size() const noexcept size_t size() const noexcept
{ {
return s->string_data().size(); return s->size_;
} }
[[gnu::always_inline]] [[gnu::always_inline]]
@@ -265,6 +259,7 @@ private:
* During its lifetime the monotonic buffer holds all strings and nodes, if the symbol set is node based. * During its lifetime the monotonic buffer holds all strings and nodes, if the symbol set is node based.
*/ */
std::pmr::monotonic_buffer_resource buffer; std::pmr::monotonic_buffer_resource buffer;
std::pmr::polymorphic_allocator<char> stringAlloc{&buffer};
SymbolStr::SymbolValueStore store{16}; SymbolStr::SymbolValueStore store{16};
/** /**
@@ -287,7 +282,7 @@ public:
// Most symbols are looked up more than once, so we trade off insertion performance // Most symbols are looked up more than once, so we trade off insertion performance
// for lookup performance. // for lookup performance.
// FIXME: make this thread-safe. // FIXME: make this thread-safe.
return Symbol(*symbols.insert(SymbolStr::Key{store, s, buffer}).first); return Symbol(*symbols.insert(SymbolStr::Key{store, s, stringAlloc}).first);
} }
std::vector<SymbolStr> resolve(const std::vector<Symbol> & symbols) const std::vector<SymbolStr> resolve(const std::vector<Symbol> & symbols) const
+23 -121
View File
@@ -1,14 +1,8 @@
#pragma once #pragma once
///@file ///@file
#include <bit>
#include <cassert> #include <cassert>
#include <cstddef>
#include <cstring>
#include <memory>
#include <memory_resource>
#include <span> #include <span>
#include <string_view>
#include <type_traits> #include <type_traits>
#include <concepts> #include <concepts>
@@ -88,7 +82,6 @@ class PosIdx;
struct Pos; struct Pos;
class StorePath; class StorePath;
class EvalState; class EvalState;
class EvalMemory;
class XMLWriter; class XMLWriter;
class Printer; class Printer;
@@ -162,7 +155,7 @@ class ListBuilder
Value * inlineElems[2] = {nullptr, nullptr}; Value * inlineElems[2] = {nullptr, nullptr};
public: public:
Value ** elems; Value ** elems;
ListBuilder(EvalMemory & mem, size_t size); ListBuilder(size_t size);
// NOTE: Can be noexcept because we are just copying integral values and // NOTE: Can be noexcept because we are just copying integral values and
// raw pointers. // raw pointers.
@@ -193,91 +186,6 @@ public:
friend struct Value; friend struct Value;
}; };
class StringData
{
public:
using size_type = std::size_t;
size_type size_;
char data_[];
/*
* This in particular ensures that we cannot have a `StringData`
* that we use by value, which is just what we want!
*
* Dynamically sized types aren't a thing in C++ and even flexible array
* members are a language extension and beyond the realm of standard C++.
* Technically, sizeof data_ member is 0 and the intended way to use flexible
* array members is to allocate sizeof(StrindData) + count * sizeof(char) bytes
* and the compiler will consider alignment restrictions for the FAM.
*
*/
StringData(StringData &&) = delete;
StringData & operator=(StringData &&) = delete;
StringData(const StringData &) = delete;
StringData & operator=(const StringData &) = delete;
~StringData() = default;
private:
StringData() = delete;
explicit StringData(size_type size)
: size_(size)
{
}
public:
/**
* Allocate StringData on the (possibly) GC-managed heap and copy
* the contents of s to it.
*/
static const StringData & make(std::string_view s);
/**
* Allocate StringData on the (possibly) GC-managed heap.
* @param size Length of the string (without the NUL terminator).
*/
static StringData & alloc(size_t size);
size_t size() const
{
return size_;
}
char * data() noexcept
{
return data_;
}
const char * data() const noexcept
{
return data_;
}
const char * c_str() const noexcept
{
return data_;
}
constexpr std::string_view view() const noexcept
{
return std::string_view(data_, size_);
}
template<size_t N>
struct Static;
static StringData & make(std::pmr::memory_resource & resource, std::string_view s)
{
auto & res =
*new (resource.allocate(sizeof(StringData) + s.size() + 1, alignof(StringData))) StringData(s.size());
std::memcpy(res.data_, s.data(), s.size());
res.data_[s.size()] = '\0';
return res;
}
};
namespace detail { namespace detail {
/** /**
@@ -311,7 +219,7 @@ struct ValueBase
*/ */
struct StringWithContext struct StringWithContext
{ {
const StringData * str; const char * c_str;
/** /**
* The type of the context itself. * The type of the context itself.
@@ -326,7 +234,7 @@ struct ValueBase
*/ */
struct Context struct Context
{ {
using value_type = const StringData *; using value_type = const char *;
using size_type = std::size_t; using size_type = std::size_t;
using iterator = const value_type *; using iterator = const value_type *;
@@ -365,7 +273,7 @@ struct ValueBase
/** /**
* @return null pointer when context.empty() * @return null pointer when context.empty()
*/ */
static Context * fromBuilder(const NixStringContext & context, EvalMemory & mem); static Context * fromBuilder(const NixStringContext & context);
}; };
/** /**
@@ -377,7 +285,7 @@ struct ValueBase
struct Path struct Path
{ {
SourceAccessor * accessor; SourceAccessor * accessor;
const StringData * path; const char * path;
}; };
struct Null struct Null
@@ -738,13 +646,13 @@ protected:
void getStorage(StringWithContext & string) const noexcept void getStorage(StringWithContext & string) const noexcept
{ {
string.context = untagPointer<decltype(string.context)>(payload[0]); string.context = untagPointer<decltype(string.context)>(payload[0]);
string.str = std::bit_cast<const StringData *>(payload[1]); string.c_str = std::bit_cast<const char *>(payload[1]);
} }
void getStorage(Path & path) const noexcept void getStorage(Path & path) const noexcept
{ {
path.accessor = untagPointer<decltype(path.accessor)>(payload[0]); path.accessor = untagPointer<decltype(path.accessor)>(payload[0]);
path.path = std::bit_cast<const StringData *>(payload[1]); path.path = std::bit_cast<const char *>(payload[1]);
} }
void setStorage(NixInt integer) noexcept void setStorage(NixInt integer) noexcept
@@ -789,7 +697,7 @@ protected:
void setStorage(StringWithContext string) noexcept void setStorage(StringWithContext string) noexcept
{ {
setUntaggablePayload<pdString>(string.context, string.str); setUntaggablePayload<pdString>(string.context, string.c_str);
} }
void setStorage(Path path) noexcept void setStorage(Path path) noexcept
@@ -1142,22 +1050,22 @@ public:
setStorage(b); setStorage(b);
} }
void mkStringNoCopy(const StringData & s, const Value::StringWithContext::Context * context = nullptr) noexcept void mkStringNoCopy(const char * s, const Value::StringWithContext::Context * context = nullptr) noexcept
{ {
setStorage(StringWithContext{.str = &s, .context = context}); setStorage(StringWithContext{.c_str = s, .context = context});
} }
void mkString(std::string_view s); void mkString(std::string_view s);
void mkString(std::string_view s, const NixStringContext & context, EvalMemory & mem); void mkString(std::string_view s, const NixStringContext & context);
void mkStringMove(const StringData & s, const NixStringContext & context, EvalMemory & mem); void mkStringMove(const char * s, const NixStringContext & context);
void mkPath(const SourcePath & path); void mkPath(const SourcePath & path);
inline void mkPath(SourceAccessor * accessor, const StringData & path) noexcept inline void mkPath(SourceAccessor * accessor, const char * path) noexcept
{ {
setStorage(Path{.accessor = accessor, .path = &path}); setStorage(Path{.accessor = accessor, .path = path});
} }
inline void mkNull() noexcept inline void mkNull() noexcept
@@ -1255,23 +1163,17 @@ public:
SourcePath path() const SourcePath path() const
{ {
return SourcePath( return SourcePath(ref(pathAccessor()->shared_from_this()), CanonPath(CanonPath::unchecked_t(), pathStr()));
ref(pathAccessor()->shared_from_this()), CanonPath(CanonPath::unchecked_t(), std::string(pathStrView())));
}
const StringData & string_data() const noexcept
{
return *getStorage<StringWithContext>().str;
}
const char * c_str() const noexcept
{
return getStorage<StringWithContext>().str->data();
} }
std::string_view string_view() const noexcept std::string_view string_view() const noexcept
{ {
return string_data().view(); return std::string_view{getStorage<StringWithContext>().c_str};
}
const char * c_str() const noexcept
{
return getStorage<StringWithContext>().c_str;
} }
const Value::StringWithContext::Context * context() const noexcept const Value::StringWithContext::Context * context() const noexcept
@@ -1331,12 +1233,12 @@ public:
const char * pathStr() const noexcept const char * pathStr() const noexcept
{ {
return getStorage<Path>().path->c_str(); return getStorage<Path>().path;
} }
std::string_view pathStrView() const noexcept std::string_view pathStrView() const noexcept
{ {
return getStorage<Path>().path->view(); return std::string_view{getStorage<Path>().path};
} }
SourceAccessor * pathAccessor() const noexcept SourceAccessor * pathAccessor() const noexcept
+5
View File
@@ -70,6 +70,11 @@ mkMesonLibrary (finalAttrs: {
nix-util nix-util
nix-store nix-store
nix-fetchers nix-fetchers
]
++ finalAttrs.passthru.externalPropagatedBuildInputs;
# Hack for sake of the dev shell
passthru.externalPropagatedBuildInputs = [
boost boost
nlohmann_json nlohmann_json
] ]
+30 -30
View File
@@ -126,26 +126,26 @@ static Expr * makeCall(Exprs & exprs, PosIdx pos, Expr * fn, Expr * arg) {
%define api.value.type variant %define api.value.type variant
%type <Expr *> start expr expr_function expr_if expr_op %type <nix::Expr *> start expr expr_function expr_if expr_op
%type <Expr *> expr_select expr_simple expr_app %type <nix::Expr *> expr_select expr_simple expr_app
%type <Expr *> expr_pipe_from expr_pipe_into %type <nix::Expr *> expr_pipe_from expr_pipe_into
%type <std::vector<Expr *>> list %type <std::vector<Expr *>> list
%type <ExprAttrs *> binds binds1 %type <nix::ExprAttrs *> binds binds1
%type <FormalsBuilder> formals formal_set %type <nix::FormalsBuilder> formals formal_set
%type <Formal> formal %type <nix::Formal> formal
%type <std::vector<AttrName>> attrpath %type <std::vector<nix::AttrName>> attrpath
%type <std::vector<std::pair<AttrName, PosIdx>>> attrs %type <std::vector<std::pair<nix::AttrName, nix::PosIdx>>> attrs
%type <std::vector<std::pair<PosIdx, Expr *>>> string_parts_interpolated %type <std::vector<std::pair<nix::PosIdx, nix::Expr *>>> string_parts_interpolated
%type <std::vector<std::pair<PosIdx, std::variant<Expr *, StringToken>>>> ind_string_parts %type <std::vector<std::pair<nix::PosIdx, std::variant<nix::Expr *, nix::StringToken>>>> ind_string_parts
%type <Expr *> path_start %type <nix::Expr *> path_start
%type <std::variant<Expr *, std::string_view>> string_parts string_attr %type <std::variant<nix::Expr *, std::string_view>> string_parts string_attr
%type <StringToken> attr %type <nix::StringToken> attr
%token <StringToken> ID %token <nix::StringToken> ID
%token <StringToken> STR IND_STR %token <nix::StringToken> STR IND_STR
%token <NixInt> INT_LIT %token <nix::NixInt> INT_LIT
%token <NixFloat> FLOAT_LIT %token <nix::NixFloat> FLOAT_LIT
%token <StringToken> PATH HPATH SPATH PATH_END %token <nix::StringToken> PATH HPATH SPATH PATH_END
%token <StringToken> URI %token <nix::StringToken> URI
%token IF THEN ELSE ASSERT WITH LET IN_KW REC INHERIT EQ NEQ AND OR IMPL OR_KW %token IF THEN ELSE ASSERT WITH LET IN_KW REC INHERIT EQ NEQ AND OR IMPL OR_KW
%token PIPE_FROM PIPE_INTO /* <| and |> */ %token PIPE_FROM PIPE_INTO /* <| and |> */
%token DOLLAR_CURLY /* == ${ */ %token DOLLAR_CURLY /* == ${ */
@@ -186,7 +186,7 @@ expr_function
| formal_set ':' expr_function[body] | formal_set ':' expr_function[body]
{ {
state->validateFormals($formal_set); state->validateFormals($formal_set);
auto me = state->exprs.add<ExprLambda>(state->positions, state->exprs.alloc, CUR_POS, $formal_set, $body); auto me = state->exprs.add<ExprLambda>(state->positions, state->exprs.alloc, CUR_POS, std::move($formal_set), $body);
$$ = me; $$ = me;
SET_DOC_POS(me, @1); SET_DOC_POS(me, @1);
} }
@@ -194,7 +194,7 @@ expr_function
{ {
auto arg = state->symbols.create($ID); auto arg = state->symbols.create($ID);
state->validateFormals($formal_set, CUR_POS, arg); state->validateFormals($formal_set, CUR_POS, arg);
auto me = state->exprs.add<ExprLambda>(state->positions, state->exprs.alloc, CUR_POS, arg, $formal_set, $body); auto me = state->exprs.add<ExprLambda>(state->positions, state->exprs.alloc, CUR_POS, arg, std::move($formal_set), $body);
$$ = me; $$ = me;
SET_DOC_POS(me, @1); SET_DOC_POS(me, @1);
} }
@@ -202,7 +202,7 @@ expr_function
{ {
auto arg = state->symbols.create($ID); auto arg = state->symbols.create($ID);
state->validateFormals($formal_set, CUR_POS, arg); state->validateFormals($formal_set, CUR_POS, arg);
auto me = state->exprs.add<ExprLambda>(state->positions, state->exprs.alloc, CUR_POS, arg, $formal_set, $body); auto me = state->exprs.add<ExprLambda>(state->positions, state->exprs.alloc, CUR_POS, arg, std::move($formal_set), $body);
$$ = me; $$ = me;
SET_DOC_POS(me, @1); SET_DOC_POS(me, @1);
} }
@@ -251,7 +251,7 @@ expr_op
| expr_op OR expr_op { $$ = state->exprs.add<ExprOpOr>(state->at(@2), $1, $3); } | expr_op OR expr_op { $$ = state->exprs.add<ExprOpOr>(state->at(@2), $1, $3); }
| expr_op IMPL expr_op { $$ = state->exprs.add<ExprOpImpl>(state->at(@2), $1, $3); } | expr_op IMPL expr_op { $$ = state->exprs.add<ExprOpImpl>(state->at(@2), $1, $3); }
| expr_op UPDATE expr_op { $$ = state->exprs.add<ExprOpUpdate>(state->at(@2), $1, $3); } | expr_op UPDATE expr_op { $$ = state->exprs.add<ExprOpUpdate>(state->at(@2), $1, $3); }
| expr_op '?' attrpath { $$ = state->exprs.add<ExprOpHasAttr>(state->exprs.alloc, $1, $3); } | expr_op '?' attrpath { $$ = state->exprs.add<ExprOpHasAttr>(state->exprs.alloc, $1, std::move($3)); }
| expr_op '+' expr_op | expr_op '+' expr_op
{ $$ = state->exprs.add<ExprConcatStrings>(state->exprs.alloc, state->at(@2), false, {{state->at(@1), $1}, {state->at(@3), $3}}); } { $$ = state->exprs.add<ExprConcatStrings>(state->exprs.alloc, state->at(@2), false, {{state->at(@1), $1}, {state->at(@3), $3}}); }
| expr_op '-' expr_op { $$ = state->exprs.add<ExprCall>(state->at(@2), state->exprs.add<ExprVar>(state->s.sub), {$1, $3}); } | expr_op '-' expr_op { $$ = state->exprs.add<ExprCall>(state->at(@2), state->exprs.add<ExprVar>(state->s.sub), {$1, $3}); }
@@ -272,9 +272,9 @@ expr_app
expr_select expr_select
: expr_simple '.' attrpath : expr_simple '.' attrpath
{ $$ = state->exprs.add<ExprSelect>(state->exprs.alloc, CUR_POS, $1, $3, nullptr); } { $$ = state->exprs.add<ExprSelect>(state->exprs.alloc, CUR_POS, $1, std::move($3), nullptr); }
| expr_simple '.' attrpath OR_KW expr_select | expr_simple '.' attrpath OR_KW expr_select
{ $$ = state->exprs.add<ExprSelect>(state->exprs.alloc, CUR_POS, $1, $3, $5); $5->warnIfCursedOr(state->symbols, state->positions); } { $$ = state->exprs.add<ExprSelect>(state->exprs.alloc, CUR_POS, $1, std::move($3), $5); $5->warnIfCursedOr(state->symbols, state->positions); }
| /* Backwards compatibility: because Nixpkgs has a function named ‘or’, | /* Backwards compatibility: because Nixpkgs has a function named ‘or’,
allow stuff like ‘map or [...]’. This production is problematic (see allow stuff like ‘map or [...]’. This production is problematic (see
https://github.com/NixOS/nix/issues/11118) and will be refactored in the https://github.com/NixOS/nix/issues/11118) and will be refactored in the
@@ -304,12 +304,12 @@ expr_simple
$2); $2);
} }
| IND_STRING_OPEN ind_string_parts IND_STRING_CLOSE { | IND_STRING_OPEN ind_string_parts IND_STRING_CLOSE {
$$ = state->stripIndentation(CUR_POS, $2); $$ = state->stripIndentation(CUR_POS, std::move($2));
} }
| path_start PATH_END | path_start PATH_END
| path_start string_parts_interpolated PATH_END { | path_start string_parts_interpolated PATH_END {
$2.insert($2.begin(), {state->at(@1), $1}); $2.insert($2.begin(), {state->at(@1), $1});
$$ = state->exprs.add<ExprConcatStrings>(state->exprs.alloc, CUR_POS, false, $2); $$ = state->exprs.add<ExprConcatStrings>(state->exprs.alloc, CUR_POS, false, std::move($2));
} }
| SPATH { | SPATH {
std::string_view path($1.p + 1, $1.l - 2); std::string_view path($1.p + 1, $1.l - 2);
@@ -338,12 +338,12 @@ expr_simple
{ $2->pos = CUR_POS; $$ = $2; } { $2->pos = CUR_POS; $$ = $2; }
| '{' '}' | '{' '}'
{ $$ = state->exprs.add<ExprAttrs>(CUR_POS); } { $$ = state->exprs.add<ExprAttrs>(CUR_POS); }
| '[' list ']' { $$ = state->exprs.add<ExprList>(state->exprs.alloc, $2); } | '[' list ']' { $$ = state->exprs.add<ExprList>(state->exprs.alloc, std::move($2)); }
; ;
string_parts string_parts
: STR { $$ = $1; } : STR { $$ = $1; }
| string_parts_interpolated { $$ = state->exprs.add<ExprConcatStrings>(state->exprs.alloc, CUR_POS, true, $1); } | string_parts_interpolated { $$ = state->exprs.add<ExprConcatStrings>(state->exprs.alloc, CUR_POS, true, std::move($1)); }
| { $$ = std::string_view(); } | { $$ = std::string_view(); }
; ;
@@ -425,7 +425,7 @@ binds1
if (!$accum->inheritFromExprs) if (!$accum->inheritFromExprs)
$accum->inheritFromExprs = std::make_unique<std::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 = new nix::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);
+29 -39
View File
@@ -5,7 +5,6 @@
#include "nix/expr/eval-settings.hh" #include "nix/expr/eval-settings.hh"
#include "nix/expr/gc-small-vector.hh" #include "nix/expr/gc-small-vector.hh"
#include "nix/expr/json-to-value.hh" #include "nix/expr/json-to-value.hh"
#include "nix/expr/static-string-data.hh"
#include "nix/store/globals.hh" #include "nix/store/globals.hh"
#include "nix/store/names.hh" #include "nix/store/names.hh"
#include "nix/store/path-references.hh" #include "nix/store/path-references.hh"
@@ -40,12 +39,6 @@
namespace nix { namespace nix {
RegisterPrimOp::PrimOps & RegisterPrimOp::primOps()
{
static RegisterPrimOp::PrimOps primOps;
return primOps;
}
/************************************************************* /*************************************************************
* Miscellaneous * Miscellaneous
*************************************************************/ *************************************************************/
@@ -228,8 +221,7 @@ void derivationToValue(
path2, path2,
{ {
NixStringContextElem::DrvDeep{.drvPath = storePath}, NixStringContextElem::DrvDeep{.drvPath = storePath},
}, });
state.mem);
attrs.alloc(state.s.name).mkString(drv.env["name"]); attrs.alloc(state.s.name).mkString(drv.env["name"]);
auto list = state.buildList(drv.outputs.size()); auto list = state.buildList(drv.outputs.size());
@@ -495,34 +487,34 @@ static void prim_typeOf(EvalState & state, const PosIdx pos, Value ** args, Valu
state.forceValue(*args[0], pos); state.forceValue(*args[0], pos);
switch (args[0]->type()) { switch (args[0]->type()) {
case nInt: case nInt:
v.mkStringNoCopy("int"_sds); v.mkStringNoCopy("int");
break; break;
case nBool: case nBool:
v.mkStringNoCopy("bool"_sds); v.mkStringNoCopy("bool");
break; break;
case nString: case nString:
v.mkStringNoCopy("string"_sds); v.mkStringNoCopy("string");
break; break;
case nPath: case nPath:
v.mkStringNoCopy("path"_sds); v.mkStringNoCopy("path");
break; break;
case nNull: case nNull:
v.mkStringNoCopy("null"_sds); v.mkStringNoCopy("null");
break; break;
case nAttrs: case nAttrs:
v.mkStringNoCopy("set"_sds); v.mkStringNoCopy("set");
break; break;
case nList: case nList:
v.mkStringNoCopy("list"_sds); v.mkStringNoCopy("list");
break; break;
case nFunction: case nFunction:
v.mkStringNoCopy("lambda"_sds); v.mkStringNoCopy("lambda");
break; break;
case nExternal: case nExternal:
v.mkString(args[0]->external()->typeOf()); v.mkString(args[0]->external()->typeOf());
break; break;
case nFloat: case nFloat:
v.mkStringNoCopy("float"_sds); v.mkStringNoCopy("float");
break; break;
case nThunk: case nThunk:
unreachable(); unreachable();
@@ -1818,8 +1810,7 @@ static void derivationStrictInternal(EvalState & state, std::string_view drvName
drvPathS, drvPathS,
{ {
NixStringContextElem::DrvDeep{.drvPath = drvPath}, NixStringContextElem::DrvDeep{.drvPath = drvPath},
}, });
state.mem);
for (auto & i : drv.outputs) for (auto & i : drv.outputs)
mkOutputString(state, result, drvPath, i); mkOutputString(state, result, drvPath, i);
@@ -1872,7 +1863,7 @@ static void prim_toPath(EvalState & state, const PosIdx pos, Value ** args, Valu
NixStringContext context; NixStringContext context;
auto path = auto path =
state.coerceToPath(pos, *args[0], context, "while evaluating the first argument passed to builtins.toPath"); state.coerceToPath(pos, *args[0], context, "while evaluating the first argument passed to builtins.toPath");
v.mkString(path.path.abs(), context, state.mem); v.mkString(path.path.abs(), context);
} }
static RegisterPrimOp primop_toPath({ static RegisterPrimOp primop_toPath({
@@ -1915,7 +1906,7 @@ static void prim_storePath(EvalState & state, const PosIdx pos, Value ** args, V
if (!settings.readOnlyMode) if (!settings.readOnlyMode)
state.store->ensurePath(path2); state.store->ensurePath(path2);
context.insert(NixStringContextElem::Opaque{.path = path2}); context.insert(NixStringContextElem::Opaque{.path = path2});
v.mkString(path.abs(), context, state.mem); v.mkString(path.abs(), context);
} }
static RegisterPrimOp primop_storePath({ static RegisterPrimOp primop_storePath({
@@ -1997,8 +1988,7 @@ static void prim_baseNameOf(EvalState & state, const PosIdx pos, Value ** args,
v.mkString( v.mkString(
legacyBaseNameOf(*state.coerceToString( legacyBaseNameOf(*state.coerceToString(
pos, *args[0], context, "while evaluating the first argument passed to builtins.baseNameOf", false, false)), pos, *args[0], context, "while evaluating the first argument passed to builtins.baseNameOf", false, false)),
context, context);
state.mem);
} }
static RegisterPrimOp primop_baseNameOf({ static RegisterPrimOp primop_baseNameOf({
@@ -2034,11 +2024,11 @@ static void prim_dirOf(EvalState & state, const PosIdx pos, Value ** args, Value
pos, *args[0], context, "while evaluating the first argument passed to 'builtins.dirOf'", false, false); pos, *args[0], context, "while evaluating the first argument passed to 'builtins.dirOf'", false, false);
auto pos = path->rfind('/'); auto pos = path->rfind('/');
if (pos == path->npos) if (pos == path->npos)
v.mkStringMove("."_sds, context, state.mem); v.mkStringMove(".", context);
else if (pos == 0) else if (pos == 0)
v.mkStringMove("/"_sds, context, state.mem); v.mkStringMove("/", context);
else else
v.mkString(path->substr(0, pos), context, state.mem); v.mkString(path->substr(0, pos), context);
} }
} }
@@ -2080,7 +2070,7 @@ static void prim_readFile(EvalState & state, const PosIdx pos, Value ** args, Va
.path = std::move((StorePath &&) p), .path = std::move((StorePath &&) p),
}); });
} }
v.mkString(s, context, state.mem); v.mkString(s, context);
} }
static RegisterPrimOp primop_readFile({ static RegisterPrimOp primop_readFile({
@@ -2319,10 +2309,10 @@ static const Value & fileTypeToString(EvalState & state, SourceAccessor::Type ty
static const Constants stringValues = []() { static const Constants stringValues = []() {
Constants res; Constants res;
res.regular.mkStringNoCopy("regular"_sds); res.regular.mkStringNoCopy("regular");
res.directory.mkStringNoCopy("directory"_sds); res.directory.mkStringNoCopy("directory");
res.symlink.mkStringNoCopy("symlink"_sds); res.symlink.mkStringNoCopy("symlink");
res.unknown.mkStringNoCopy("unknown"_sds); res.unknown.mkStringNoCopy("unknown");
return res; return res;
}(); }();
@@ -2476,7 +2466,7 @@ static void prim_toXML(EvalState & state, const PosIdx pos, Value ** args, Value
std::ostringstream out; std::ostringstream out;
NixStringContext context; NixStringContext context;
printValueAsXML(state, true, false, *args[0], out, context, pos); printValueAsXML(state, true, false, *args[0], out, context, pos);
v.mkString(out.view(), context, state.mem); v.mkString(out.view(), context);
} }
static RegisterPrimOp primop_toXML({ static RegisterPrimOp primop_toXML({
@@ -2584,7 +2574,7 @@ static void prim_toJSON(EvalState & state, const PosIdx pos, Value ** args, Valu
std::ostringstream out; std::ostringstream out;
NixStringContext context; NixStringContext context;
printValueAsJSON(state, true, *args[0], pos, out, context); printValueAsJSON(state, true, *args[0], pos, out, context);
v.mkString(out.view(), context, state.mem); v.mkString(out.view(), context);
} }
static RegisterPrimOp primop_toJSON({ static RegisterPrimOp primop_toJSON({
@@ -4413,7 +4403,7 @@ static void prim_toString(EvalState & state, const PosIdx pos, Value ** args, Va
NixStringContext context; NixStringContext context;
auto s = state.coerceToString( auto s = state.coerceToString(
pos, *args[0], context, "while evaluating the first argument passed to builtins.toString", true, false); pos, *args[0], context, "while evaluating the first argument passed to builtins.toString", true, false);
v.mkString(*s, context, state.mem); v.mkString(*s, context);
} }
static RegisterPrimOp primop_toString({ static RegisterPrimOp primop_toString({
@@ -4473,7 +4463,7 @@ static void prim_substring(EvalState & state, const PosIdx pos, Value ** args, V
if (len == 0) { if (len == 0) {
state.forceValue(*args[2], pos); state.forceValue(*args[2], pos);
if (args[2]->type() == nString) { if (args[2]->type() == nString) {
v.mkStringNoCopy(""_sds, args[2]->context()); v.mkStringNoCopy("", args[2]->context());
return; return;
} }
} }
@@ -4486,7 +4476,7 @@ static void prim_substring(EvalState & state, const PosIdx pos, Value ** args, V
auto s = state.coerceToString( auto s = state.coerceToString(
pos, *args[2], context, "while evaluating the third argument (the string) passed to builtins.substring"); pos, *args[2], context, "while evaluating the third argument (the string) passed to builtins.substring");
v.mkString(NixUInt(start) >= s->size() ? "" : s->substr(start, _len), context, state.mem); v.mkString(NixUInt(start) >= s->size() ? "" : s->substr(start, _len), context);
} }
static RegisterPrimOp primop_substring({ static RegisterPrimOp primop_substring({
@@ -4884,7 +4874,7 @@ static void prim_concatStringsSep(EvalState & state, const PosIdx pos, Value **
"while evaluating one element of the list of strings to concat passed to builtins.concatStringsSep"); "while evaluating one element of the list of strings to concat passed to builtins.concatStringsSep");
} }
v.mkString(res, context, state.mem); v.mkString(res, context);
} }
static RegisterPrimOp primop_concatStringsSep({ static RegisterPrimOp primop_concatStringsSep({
@@ -4959,7 +4949,7 @@ static void prim_replaceStrings(EvalState & state, const PosIdx pos, Value ** ar
} }
} }
v.mkString(res, context, state.mem); v.mkString(res, context);
} }
static RegisterPrimOp primop_replaceStrings({ static RegisterPrimOp primop_replaceStrings({
+3 -3
View File
@@ -69,7 +69,7 @@ static void prim_unsafeDiscardOutputDependency(EvalState & state, const PosIdx p
} }
} }
v.mkString(*s, context2, state.mem); v.mkString(*s, context2);
} }
static RegisterPrimOp primop_unsafeDiscardOutputDependency( static RegisterPrimOp primop_unsafeDiscardOutputDependency(
@@ -137,7 +137,7 @@ static void prim_addDrvOutputDependencies(EvalState & state, const PosIdx pos, V
context.begin()->raw)}), context.begin()->raw)}),
}; };
v.mkString(*s, context2, state.mem); v.mkString(*s, context2);
} }
static RegisterPrimOp primop_addDrvOutputDependencies( static RegisterPrimOp primop_addDrvOutputDependencies(
@@ -321,7 +321,7 @@ static void prim_appendContext(EvalState & state, const PosIdx pos, Value ** arg
} }
} }
v.mkString(orig, context, state.mem); v.mkString(orig, context);
} }
static RegisterPrimOp primop_appendContext({.name = "__appendContext", .arity = 2, .fun = prim_appendContext}); static RegisterPrimOp primop_appendContext({.name = "__appendContext", .arity = 2, .fun = prim_appendContext});
+1 -1
View File
@@ -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.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));
+198 -97
View File
@@ -82,7 +82,7 @@ struct FetchTreeParams
static void fetchTree( static void fetchTree(
EvalState & state, const PosIdx pos, Value ** args, Value & v, const FetchTreeParams & params = FetchTreeParams{}) EvalState & state, const PosIdx pos, Value ** args, Value & v, const FetchTreeParams & params = FetchTreeParams{})
{ {
fetchers::Input input{}; fetchers::Input input{state.fetchSettings};
NixStringContext context; NixStringContext context;
std::optional<std::string> type; std::optional<std::string> type;
auto fetcher = params.isFetchGit ? "fetchGit" : "fetchTree"; auto fetcher = params.isFetchGit ? "fetchGit" : "fetchTree";
@@ -194,9 +194,9 @@ 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.store, input, fetchers::UseRegistries::Limited).first;
if (state.settings.pureEval && !input.isLocked(state.fetchSettings)) { if (state.settings.pureEval && !input.isLocked()) {
if (input.getNarHash()) if (input.getNarHash())
warn( warn(
"Input '%s' is unlocked (e.g. lacks a Git revision) but is checked by NAR hash. " "Input '%s' is unlocked (e.g. lacks a Git revision) but is checked by NAR hash. "
@@ -219,8 +219,7 @@ static void fetchTree(
throw Error("input '%s' is not allowed to use the '__final' attribute", input.to_string()); throw Error("input '%s' is not allowed to use the '__final' attribute", input.to_string());
} }
auto cachedInput = auto cachedInput = state.inputCache->getAccessor(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);
@@ -235,127 +234,229 @@ static void prim_fetchTree(EvalState & state, const PosIdx pos, Value ** args, V
static RegisterPrimOp primop_fetchTree({ static RegisterPrimOp primop_fetchTree({
.name = "fetchTree", .name = "fetchTree",
.args = {"input"}, .args = {"input"},
.doc = []() -> std::string { .doc = R"(
std::string doc = 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)
- the corresponding [NAR](@docroot@/store/file-system-object/content-address.md#serial-nix-archive) hash - the corresponding [NAR](@docroot@/store/file-system-object/content-address.md#serial-nix-archive) hash
- backend-specific metadata (currently not documented). <!-- TODO: document output attributes --> - backend-specific metadata (currently not documented). <!-- TODO: document output attributes -->
*input* must be an attribute set with the following attributes: *input* must be an attribute set with the following attributes:
- `type` (String, required) - `type` (String, required)
One of the [supported source types](#source-types). One of the [supported source types](#source-types).
This determines other required and allowed input attributes. This determines other required and allowed input attributes.
- `narHash` (String, optional) - `narHash` (String, optional)
The `narHash` parameter can be used to substitute the source of the tree. The `narHash` parameter can be used to substitute the source of the tree.
It also allows for verification of tree contents that may not be provided by the underlying transfer mechanism. It also allows for verification of tree contents that may not be provided by the underlying transfer mechanism.
If `narHash` is set, the source is first looked up is the Nix store and [substituters](@docroot@/command-ref/conf-file.md#conf-substituters), and only fetched if not available. If `narHash` is set, the source is first looked up is the Nix store and [substituters](@docroot@/command-ref/conf-file.md#conf-substituters), and only fetched if not available.
A subset of the output attributes of `fetchTree` can be re-used for subsequent calls to `fetchTree` to produce the same result again. A subset of the output attributes of `fetchTree` can be re-used for subsequent calls to `fetchTree` to produce the same result again.
That is, `fetchTree` is idempotent. That is, `fetchTree` is idempotent.
Downloads are cached in `$XDG_CACHE_HOME/nix`. Downloads are cached in `$XDG_CACHE_HOME/nix`.
The remote source is fetched from the network if both are true: The remote source is fetched from the network if both are true:
- A NAR hash is supplied and the corresponding store path is not [valid](@docroot@/glossary.md#gloss-validity), that is, not available in the store - A NAR hash is supplied and the corresponding store path is not [valid](@docroot@/glossary.md#gloss-validity), that is, not available in the store
> **Note** > **Note**
>
> [Substituters](@docroot@/command-ref/conf-file.md#conf-substituters) are not used in fetching.
- There is no cache entry or the cache entry is older than [`tarball-ttl`](@docroot@/command-ref/conf-file.md#conf-tarball-ttl)
## Source types
The following source types and associated input attributes are supported.
<!-- TODO: It would be soooo much more predictable to work with (and
document) if `fetchTree` was a curried call with the first parameter for
`type` or an attribute like `builtins.fetchTree.git`! -->
- `"file"`
Place a plain file into the Nix store.
This is similar to [`builtins.fetchurl`](@docroot@/language/builtins.md#builtins-fetchurl)
- `url` (String, required)
Supported protocols:
- `https`
> **Example**
> >
> [Substituters](@docroot@/command-ref/conf-file.md#conf-substituters) are not used in fetching. > ```nix
> fetchTree {
> type = "file";
> url = "https://example.com/index.html";
> }
> ```
- There is no cache entry or the cache entry is older than [`tarball-ttl`](@docroot@/command-ref/conf-file.md#conf-tarball-ttl) - `http`
## Source types Insecure HTTP transfer for legacy sources.
The following source types and associated input attributes are supported. > **Warning**
>
> HTTP performs no encryption or authentication.
> Use a `narHash` known in advance to ensure the output has expected contents.
<!-- TODO: It would be soooo much more predictable to work with (and - `file`
document) if `fetchTree` was a curried call with the first parameter for
`type` or an attribute like `builtins.fetchTree.git`! -->
)");
auto indentString = [](std::string const & str, std::string const & indent) { A file on the local file system.
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()) { > **Example**
doc += "\n- `" + quoteString(schemeName, '"') + "`\n\n"; >
doc += indentString(scheme->schemeDescription(), " "); > ```nix
if (!doc.empty() && doc.back() != '\n') > fetchTree {
doc += "\n"; > type = "file";
> url = "file:///home/eelco/nix/README.md";
> }
> ```
for (const auto & [attrName, attribute] : scheme->allowedAttrs()) { - `"tarball"`
doc += "\n - `" + attrName + "` (" + attribute.type + ", "
+ (attribute.required ? "required" : "optional") + ")\n\n";
doc += indentString(stripIndentation(attribute.doc), " ");
if (!doc.empty() && doc.back() != '\n')
doc += "\n";
}
}
doc += "\n" + stripIndentation(R"( Download a tar archive and extract it into the Nix store.
The following input types are still subject to change: This has the same underlying implementation as [`builtins.fetchTarball`](@docroot@/language/builtins.md#builtins-fetchTarball)
- `"path"` - `url` (String, required)
- `"github"`
- `"gitlab"`
- `"sourcehut"`
- `"mercurial"`
*input* can also be a [URL-like reference](@docroot@/command-ref/new-cli/nix3-flake.md#flake-references). > **Example**
The additional input types and the URL-like syntax requires the [`flakes` experimental feature](@docroot@/development/experimental-features.md#xp-feature-flakes) to be enabled. >
> ```nix
> fetchTree {
> type = "tarball";
> url = "https://github.com/NixOS/nixpkgs/tarball/nixpkgs-23.11";
> }
> ```
- `"git"`
Fetch a Git tree and copy it to the Nix store.
This is similar to [`builtins.fetchGit`](@docroot@/language/builtins.md#builtins-fetchGit).
- `url` (String, required)
The URL formats supported are the same as for Git itself.
> **Example** > **Example**
> >
> Fetch a GitHub repository using the attribute set representation:
>
> ```nix > ```nix
> builtins.fetchTree { > fetchTree {
> type = "github"; > type = "git";
> owner = "NixOS"; > url = "git@github.com:NixOS/nixpkgs.git";
> repo = "nixpkgs";
> rev = "ae2e6b3958682513d28f7d633734571fb18285dd";
> }
> ```
>
> This evaluates to the following attribute set:
>
> ```nix
> {
> lastModified = 1686503798;
> lastModifiedDate = "20230611171638";
> narHash = "sha256-rA9RqKP9OlBrgGCPvfd5HVAXDOy8k2SmPtB/ijShNXc=";
> outPath = "/nix/store/l5m6qlvfs9sdw14ja3qbzpglcjlb6j1x-source";
> rev = "ae2e6b3958682513d28f7d633734571fb18285dd";
> shortRev = "ae2e6b3";
> } > }
> ``` > ```
> **Example** > **Note**
> >
> Fetch the same GitHub repository using the URL-like syntax: > If the URL points to a local directory, and no `ref` or `rev` is given, Nix only considers files added to the Git index, as listed by `git ls-files` but use the *current file contents* of the Git working directory.
>
> ```nix
> builtins.fetchTree "github:NixOS/nixpkgs/ae2e6b3958682513d28f7d633734571fb18285dd"
> ```
)");
return doc; - `ref` (String, optional)
}(),
By default, this has no effect. This becomes relevant only once `shallow` cloning is disabled.
A [Git reference](https://git-scm.com/book/en/v2/Git-Internals-Git-References), such as a branch or tag name.
Default: `"HEAD"`
- `rev` (String, optional)
A Git revision; a commit hash.
Default: the tip of `ref`
- `shallow` (Bool, optional)
Make a shallow clone when fetching the Git tree.
When this is enabled, the options `ref` and `allRefs` have no effect anymore.
Default: `true`
- `submodules` (Bool, optional)
Also fetch submodules if available.
Default: `false`
- `lfs` (Bool, optional)
Fetch any [Git LFS](https://git-lfs.com/) files.
Default: `false`
- `allRefs` (Bool, optional)
By default, this has no effect. This becomes relevant only once `shallow` cloning is disabled.
Whether to fetch all references (eg. branches and tags) of the repository.
With this argument being true, it's possible to load a `rev` from *any* `ref`.
(Without setting this option, only `rev`s from the specified `ref` are supported).
Default: `false`
- `lastModified` (Integer, optional)
Unix timestamp of the fetched commit.
If set, pass through the value to the output attribute set.
Otherwise, generated from the fetched Git tree.
- `revCount` (Integer, optional)
Number of revisions in the history of the Git repository before the fetched commit.
If set, pass through the value to the output attribute set.
Otherwise, generated from the fetched Git tree.
The following input types are still subject to change:
- `"path"`
- `"github"`
- `"gitlab"`
- `"sourcehut"`
- `"mercurial"`
*input* can also be a [URL-like reference](@docroot@/command-ref/new-cli/nix3-flake.md#flake-references).
The additional input types and the URL-like syntax requires the [`flakes` experimental feature](@docroot@/development/experimental-features.md#xp-feature-flakes) to be enabled.
> **Example**
>
> Fetch a GitHub repository using the attribute set representation:
>
> ```nix
> builtins.fetchTree {
> type = "github";
> owner = "NixOS";
> repo = "nixpkgs";
> rev = "ae2e6b3958682513d28f7d633734571fb18285dd";
> }
> ```
>
> This evaluates to the following attribute set:
>
> ```nix
> {
> lastModified = 1686503798;
> lastModifiedDate = "20230611171638";
> narHash = "sha256-rA9RqKP9OlBrgGCPvfd5HVAXDOy8k2SmPtB/ijShNXc=";
> outPath = "/nix/store/l5m6qlvfs9sdw14ja3qbzpglcjlb6j1x-source";
> rev = "ae2e6b3958682513d28f7d633734571fb18285dd";
> shortRev = "ae2e6b3";
> }
> ```
> **Example**
>
> Fetch the same GitHub repository using the URL-like syntax:
>
> ```nix
> builtins.fetchTree "github:NixOS/nixpkgs/ae2e6b3958682513d28f7d633734571fb18285dd"
> ```
)",
.fun = prim_fetchTree, .fun = prim_fetchTree,
.experimentalFeature = Xp::FetchTree, .experimentalFeature = Xp::FetchTree,
}); });
+1 -2
View File
@@ -1,6 +1,5 @@
#include "nix/expr/primops.hh" #include "nix/expr/primops.hh"
#include "nix/expr/eval-inline.hh" #include "nix/expr/eval-inline.hh"
#include "nix/expr/static-string-data.hh"
#include "expr-config-private.hh" #include "expr-config-private.hh"
@@ -137,7 +136,7 @@ static void prim_fromTOML(EvalState & state, const PosIdx pos, Value ** args, Va
normalizeDatetimeFormat(t); normalizeDatetimeFormat(t);
#endif #endif
auto attrs = state.buildBindings(2); auto attrs = state.buildBindings(2);
attrs.alloc("_type").mkStringNoCopy("timestamp"_sds); attrs.alloc("_type").mkStringNoCopy("timestamp");
std::ostringstream s; std::ostringstream s;
s << t; s << t;
auto str = s.view(); auto str = s.view();
+8 -8
View File
@@ -1,19 +1,19 @@
#include "nix/fetchers/git-utils.hh" #include "nix/fetchers/git-utils.hh"
#include "nix/util/file-system.hh" #include "nix/util/file-system.hh"
#include <gmock/gmock.h> #include <gmock/gmock.h>
#include <git2/global.h> #include <git2-experimental/global.h>
#include <git2/repository.h> #include <git2-experimental/repository.h>
#include <git2/signature.h> #include <git2-experimental/signature.h>
#include <git2/types.h> #include <git2-experimental/types.h>
#include <git2/object.h> #include <git2-experimental/object.h>
#include <git2/tag.h> #include <git2-experimental/tag.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "nix/util/fs-sink.hh" #include "nix/util/fs-sink.hh"
#include "nix/util/serialise.hh" #include "nix/util/serialise.hh"
#include "nix/fetchers/git-lfs-fetch.hh" #include "nix/fetchers/git-lfs-fetch.hh"
#include <git2/blob.h> #include <git2-experimental/blob.h>
#include <git2/tree.h> #include <git2-experimental/tree.h>
namespace nix { namespace nix {
+2 -2
View File
@@ -5,7 +5,7 @@
#include "nix/fetchers/fetchers.hh" #include "nix/fetchers/fetchers.hh"
#include "nix/fetchers/git-utils.hh" #include "nix/fetchers/git-utils.hh"
#include <git2.h> #include <git2-experimental.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <filesystem> #include <filesystem>
@@ -196,7 +196,7 @@ TEST_F(GitTest, submodulePeriodSupport)
{"ref", "main"}, {"ref", "main"},
}); });
auto [accessor, i] = input.getAccessor(settings, store); auto [accessor, i] = input.getAccessor(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");
} }
-61
View File
@@ -1,61 +0,0 @@
#include "nix/fetchers/fetch-settings.hh"
#include "nix/fetchers/attrs.hh"
#include "nix/fetchers/fetchers.hh"
#include <gtest/gtest.h>
#include <string>
namespace nix {
using fetchers::Attr;
struct InputFromAttrsTestCase
{
fetchers::Attrs attrs;
std::string expectedUrl;
std::string description;
fetchers::Attrs expectedAttrs = attrs;
};
class InputFromAttrsTest : public ::testing::WithParamInterface<InputFromAttrsTestCase>, public ::testing::Test
{};
TEST_P(InputFromAttrsTest, attrsAreCorrectAndRoundTrips)
{
fetchers::Settings fetchSettings;
const auto & testCase = GetParam();
auto input = fetchers::Input::fromAttrs(fetchSettings, fetchers::Attrs(testCase.attrs));
EXPECT_EQ(input.toAttrs(), testCase.expectedAttrs);
EXPECT_EQ(input.toURLString(), testCase.expectedUrl);
auto input2 = fetchers::Input::fromAttrs(fetchSettings, input.toAttrs());
EXPECT_EQ(input, input2);
EXPECT_EQ(input.toAttrs(), input2.toAttrs());
}
INSTANTIATE_TEST_SUITE_P(
InputFromAttrs,
InputFromAttrsTest,
::testing::Values(
// Test for issue #14429.
InputFromAttrsTestCase{
.attrs =
{
{"url", Attr("git+ssh://git@github.com/NixOS/nixpkgs")},
{"type", Attr("git")},
},
.expectedUrl = "git+ssh://git@github.com/NixOS/nixpkgs",
.description = "strips_git_plus_prefix",
.expectedAttrs =
{
{"url", Attr("ssh://git@github.com/NixOS/nixpkgs")},
{"type", Attr("git")},
},
}),
[](const ::testing::TestParamInfo<InputFromAttrsTestCase> & info) { return info.param.description; });
} // namespace nix
+1 -2
View File
@@ -33,7 +33,7 @@ deps_private += rapidcheck
gtest = dependency('gtest', main : true) gtest = dependency('gtest', main : true)
deps_private += gtest deps_private += gtest
libgit2 = dependency('libgit2') libgit2 = dependency('libgit2-experimental')
deps_private += libgit2 deps_private += libgit2
subdir('nix-meson-build-support/common') subdir('nix-meson-build-support/common')
@@ -42,7 +42,6 @@ sources = files(
'access-tokens.cc', 'access-tokens.cc',
'git-utils.cc', 'git-utils.cc',
'git.cc', 'git.cc',
'input.cc',
'nix_api_fetchers.cc', 'nix_api_fetchers.cc',
'public-key.cc', 'public-key.cc',
) )
+2 -1
View File
@@ -1,5 +1,6 @@
#include "nix/fetchers/attrs.hh" #include "nix/fetchers/attrs.hh"
#include "nix/fetchers/fetchers.hh" #include "nix/fetchers/fetchers.hh"
#include "nix/fetchers/git-utils.hh"
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
@@ -111,7 +112,7 @@ StringMap attrsToQuery(const Attrs & attrs)
Hash getRevAttr(const Attrs & attrs, const std::string & name) Hash getRevAttr(const Attrs & attrs, const std::string & name)
{ {
return Hash::parseAny(getStrAttr(attrs, name), HashAlgorithm::SHA1); return parseGitHash(getStrAttr(attrs, name));
} }
} // namespace nix::fetchers } // namespace nix::fetchers
+28 -16
View File
@@ -26,9 +26,18 @@ void registerInputScheme(std::shared_ptr<InputScheme> && inputScheme)
throw Error("Input scheme with name %s already registered", schemeName); throw Error("Input scheme with name %s already registered", schemeName);
} }
const InputSchemeMap & getAllInputSchemes() nlohmann::json dumpRegisterInputSchemeInfo()
{ {
return inputSchemes(); using nlohmann::json;
auto res = json::object();
for (auto & [name, scheme] : inputSchemes()) {
auto & r = res[name] = json::object();
r["allowedAttrs"] = scheme->allowedAttrs();
}
return res;
} }
Input Input::fromURL(const Settings & settings, const std::string & url, bool requireTree) Input Input::fromURL(const Settings & settings, const std::string & url, bool requireTree)
@@ -80,7 +89,7 @@ Input Input::fromAttrs(const Settings & settings, Attrs && attrs)
// but not all of them. Doing this is to support those other // but not all of them. Doing this is to support those other
// operations which are supposed to be robust on // operations which are supposed to be robust on
// unknown/uninterpretable inputs. // unknown/uninterpretable inputs.
Input input; Input input{settings};
input.attrs = attrs; input.attrs = attrs;
fixupInput(input); fixupInput(input);
return input; return input;
@@ -150,9 +159,9 @@ bool Input::isDirect() const
return !scheme || scheme->isDirect(*this); return !scheme || scheme->isDirect(*this);
} }
bool Input::isLocked(const Settings & settings) const bool Input::isLocked() const
{ {
return scheme && scheme->isLocked(settings, *this); return scheme && scheme->isLocked(*this);
} }
bool Input::isFinal() const bool Input::isFinal() const
@@ -189,17 +198,17 @@ bool Input::contains(const Input & other) const
} }
// FIXME: remove // FIXME: remove
std::pair<StorePath, Input> Input::fetchToStore(const Settings & settings, ref<Store> store) const std::pair<StorePath, Input> Input::fetchToStore(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()));
auto [storePath, input] = [&]() -> std::pair<StorePath, Input> { auto [storePath, input] = [&]() -> std::pair<StorePath, Input> {
try { try {
auto [accessor, result] = getAccessorUnchecked(settings, store); auto [accessor, result] = getAccessorUnchecked(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));
@@ -288,10 +297,10 @@ void Input::checkLocks(Input specified, Input & result)
} }
} }
std::pair<ref<SourceAccessor>, Input> Input::getAccessor(const Settings & settings, ref<Store> store) const std::pair<ref<SourceAccessor>, Input> Input::getAccessor(ref<Store> store) const
{ {
try { try {
auto [accessor, result] = getAccessorUnchecked(settings, store); auto [accessor, result] = getAccessorUnchecked(store);
result.attrs.insert_or_assign("__final", Explicit<bool>(true)); result.attrs.insert_or_assign("__final", Explicit<bool>(true));
@@ -304,7 +313,7 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessor(const Settings & settin
} }
} }
std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(const Settings & settings, ref<Store> store) const std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(ref<Store> store) const
{ {
// FIXME: cache the accessor // FIXME: cache the accessor
@@ -340,7 +349,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() + "»");
@@ -351,7 +360,7 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(const Settings
} }
} }
auto [accessor, result] = scheme->getAccessor(settings, store, *this); auto [accessor, result] = scheme->getAccessor(store, *this);
if (!accessor->fingerprint) if (!accessor->fingerprint)
accessor->fingerprint = result.getFingerprint(store); accessor->fingerprint = result.getFingerprint(store);
@@ -368,10 +377,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, const Path & destDir) const void Input::clone(const Path & destDir) const
{ {
assert(scheme); assert(scheme);
scheme->clone(settings, *this, destDir); scheme->clone(*this, destDir);
} }
std::optional<std::filesystem::path> Input::getSourcePath() const std::optional<std::filesystem::path> Input::getSourcePath() const
@@ -438,6 +447,9 @@ std::optional<Hash> Input::getRev() const
} catch (BadHash & e) { } catch (BadHash & e) {
// Default to sha1 for backwards compatibility with existing // Default to sha1 for backwards compatibility with existing
// usages (e.g. `builtins.fetchTree` calls or flake inputs). // usages (e.g. `builtins.fetchTree` calls or flake inputs).
//
// Note that means that for SHA-256 git repos, prefixing
// must be used.
hash = Hash::parseAny(*s, HashAlgorithm::SHA1); hash = Hash::parseAny(*s, HashAlgorithm::SHA1);
} }
} }
@@ -484,7 +496,7 @@ 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(const Settings & settings, const Input & input, const Path & destDir) const void InputScheme::clone(const Input & input, const Path & destDir) const
{ {
throw Error("do not know how to clone input '%s'", input.to_string()); throw Error("do not know how to clone input '%s'", input.to_string());
} }
+4 -4
View File
@@ -7,10 +7,10 @@
#include "nix/util/hash.hh" #include "nix/util/hash.hh"
#include "nix/store/ssh.hh" #include "nix/store/ssh.hh"
#include <git2/attr.h> #include <git2-experimental/attr.h>
#include <git2/config.h> #include <git2-experimental/config.h>
#include <git2/errors.h> #include <git2-experimental/errors.h>
#include <git2/remote.h> #include <git2-experimental/remote.h>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
+74 -36
View File
@@ -13,27 +13,27 @@
#include "nix/util/thread-pool.hh" #include "nix/util/thread-pool.hh"
#include "nix/util/pool.hh" #include "nix/util/pool.hh"
#include <git2/attr.h> #include <git2-experimental/attr.h>
#include <git2/blob.h> #include <git2-experimental/blob.h>
#include <git2/branch.h> #include <git2-experimental/branch.h>
#include <git2/commit.h> #include <git2-experimental/commit.h>
#include <git2/config.h> #include <git2-experimental/config.h>
#include <git2/describe.h> #include <git2-experimental/describe.h>
#include <git2/errors.h> #include <git2-experimental/errors.h>
#include <git2/global.h> #include <git2-experimental/global.h>
#include <git2/indexer.h> #include <git2-experimental/indexer.h>
#include <git2/object.h> #include <git2-experimental/object.h>
#include <git2/odb.h> #include <git2-experimental/odb.h>
#include <git2/refs.h> #include <git2-experimental/refs.h>
#include <git2/remote.h> #include <git2-experimental/remote.h>
#include <git2/repository.h> #include <git2-experimental/repository.h>
#include <git2/revparse.h> #include <git2-experimental/revparse.h>
#include <git2/status.h> #include <git2-experimental/status.h>
#include <git2/submodule.h> #include <git2-experimental/submodule.h>
#include <git2/sys/odb_backend.h> #include <git2-experimental/sys/odb_backend.h>
#include <git2/sys/mempack.h> #include <git2-experimental/sys/mempack.h>
#include <git2/tag.h> #include <git2-experimental/tag.h>
#include <git2/tree.h> #include <git2-experimental/tree.h>
#include <boost/unordered/concurrent_flat_set.hpp> #include <boost/unordered/concurrent_flat_set.hpp>
#include <boost/unordered/unordered_flat_map.hpp> #include <boost/unordered/unordered_flat_map.hpp>
@@ -91,10 +91,21 @@ typedef std::unique_ptr<git_indexer, Deleter<git_indexer_free>> Indexer;
Hash toHash(const git_oid & oid) Hash toHash(const git_oid & oid)
{ {
#ifdef GIT_EXPERIMENTAL_SHA256 HashAlgorithm algo;
assert(oid.type == GIT_OID_SHA1); #pragma GCC diagnostic push
#endif #pragma GCC diagnostic ignored "-Wswitch-enum"
Hash hash(HashAlgorithm::SHA1); switch (oid.type) {
case GIT_OID_SHA1:
algo = HashAlgorithm::SHA1;
break;
case GIT_OID_SHA256:
algo = HashAlgorithm::SHA256;
break;
default:
unreachable();
}
#pragma GCC diagnostic pop
Hash hash(algo);
memcpy(hash.hash, oid.id, hash.hashSize); memcpy(hash.hash, oid.id, hash.hashSize);
return hash; return hash;
} }
@@ -111,7 +122,21 @@ static void initLibGit2()
git_oid hashToOID(const Hash & hash) git_oid hashToOID(const Hash & hash)
{ {
git_oid oid; git_oid oid;
if (git_oid_fromstr(&oid, hash.gitRev().c_str())) git_oid_t t;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch-enum"
switch (hash.algo) {
case HashAlgorithm::SHA1:
t = GIT_OID_SHA1;
break;
case HashAlgorithm::SHA256:
t = GIT_OID_SHA256;
break;
default:
throw Error("unsupported hash algorithm for Git: %s", printHashAlgo(hash.algo));
}
#pragma GCC diagnostic pop
if (git_oid_fromstr(&oid, hash.gitRev().c_str(), t))
throw Error("cannot convert '%s' to a Git OID", hash.gitRev()); throw Error("cannot convert '%s' to a Git OID", hash.gitRev());
return oid; return oid;
} }
@@ -304,7 +329,8 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
// (synchronously on the git_packbuilder_write_buf thread) // (synchronously on the git_packbuilder_write_buf thread)
Indexer indexer; Indexer indexer;
git_indexer_progress stats; git_indexer_progress stats;
if (git_indexer_new(Setter(indexer), pack_dir_path.c_str(), 0, nullptr, nullptr)) git_indexer_options indexer_opts = GIT_INDEXER_OPTIONS_INIT;
if (git_indexer_new(Setter(indexer), pack_dir_path.c_str(), &indexer_opts))
throw Error("creating git packfile indexer: %s", git_error_last()->message); throw Error("creating git packfile indexer: %s", git_error_last()->message);
// TODO: provide index callback for checkInterrupt() termination // TODO: provide index callback for checkInterrupt() termination
@@ -1328,17 +1354,12 @@ std::vector<std::tuple<GitRepoImpl::Submodule, Hash>> GitRepoImpl::getSubmodules
return result; return result;
} }
namespace fetchers { ref<GitRepo> getTarballCache()
ref<GitRepo> Settings::getTarballCache() const
{ {
auto tarballCache(_tarballCache.lock()); static auto repoDir = std::filesystem::path(getCacheDir()) / "tarball-cache";
if (!*tarballCache)
*tarballCache = GitRepo::openRepo(std::filesystem::path(getCacheDir()) / "tarball-cache", true, true);
return ref<GitRepo>(*tarballCache);
}
} // namespace fetchers return GitRepo::openRepo(repoDir, true, true);
}
GitRepo::WorkdirInfo GitRepo::getCachedWorkdirInfo(const std::filesystem::path & path) GitRepo::WorkdirInfo GitRepo::getCachedWorkdirInfo(const std::filesystem::path & path)
{ {
@@ -1383,4 +1404,21 @@ bool isLegalRefName(const std::string & refName)
return false; return false;
} }
Hash parseGitHash(std::string_view hashStr)
{
HashAlgorithm algo;
switch (hashStr.size()) {
case 40:
algo = HashAlgorithm::SHA1;
break;
case 64:
algo = HashAlgorithm::SHA256;
break;
default:
throw Error(
"invalid git hash '%s': expected 40 (SHA1) or 64 (SHA256) hex characters, got %d", hashStr, hashStr.size());
}
return Hash::parseNonSRIUnprefixed(hashStr, algo);
}
} // namespace nix } // namespace nix
+41 -194
View File
@@ -168,6 +168,8 @@ struct GitInputScheme : InputScheme
return {}; return {};
auto url2(url); auto url2(url);
if (hasPrefix(url2.scheme, "git+"))
url2.scheme = std::string(url2.scheme, 4);
url2.query.clear(); url2.query.clear();
Attrs attrs; Attrs attrs;
@@ -194,183 +196,28 @@ struct GitInputScheme : InputScheme
return "git"; return "git";
} }
std::string schemeDescription() const override StringSet allowedAttrs() const override
{ {
return stripIndentation(R"( return {
Fetch a Git tree and copy it to the Nix store. "url",
This is similar to [`builtins.fetchGit`](@docroot@/language/builtins.md#builtins-fetchGit). "ref",
)"); "rev",
} "shallow",
"submodules",
const std::map<std::string, AttributeInfo> & allowedAttrs() const override "lfs",
{ "exportIgnore",
static const std::map<std::string, AttributeInfo> attrs = { "lastModified",
{ "revCount",
"url", "narHash",
{ "allRefs",
.type = "String", "name",
.required = true, "dirtyRev",
.doc = R"( "dirtyShortRev",
The URL formats supported are the same as for Git itself. "verifyCommit",
"keytype",
> **Example** "publicKey",
> "publicKeys",
> ```nix
> fetchTree {
> type = "git";
> url = "git@github.com:NixOS/nixpkgs.git";
> }
> ```
> **Note**
>
> If the URL points to a local directory, and no `ref` or `rev` is given, Nix only considers files added to the Git index, as listed by `git ls-files` but uses the *current file contents* of the Git working directory.
)",
},
},
{
"ref",
{
.type = "String",
.required = false,
.doc = R"(
By default, this has no effect. This becomes relevant only once `shallow` cloning is disabled.
A [Git reference](https://git-scm.com/book/en/v2/Git-Internals-Git-References), such as a branch or tag name.
Default: `"HEAD"`
)",
},
},
{
"rev",
{
.type = "String",
.required = false,
.doc = R"(
A Git revision; a commit hash.
Default: the tip of `ref`
)",
},
},
{
"shallow",
{
.type = "Bool",
.required = false,
.doc = R"(
Make a shallow clone when fetching the Git tree.
When this is enabled, the options `ref` and `allRefs` have no effect anymore.
Default: `true`
)",
},
},
{
"submodules",
{
.type = "Bool",
.required = false,
.doc = R"(
Also fetch submodules if available.
Default: `false`
)",
},
},
{
"lfs",
{
.type = "Bool",
.required = false,
.doc = R"(
Fetch any [Git LFS](https://git-lfs.com/) files.
Default: `false`
)",
},
},
{
"exportIgnore",
{},
},
{
"lastModified",
{
.type = "Integer",
.required = false,
.doc = R"(
Unix timestamp of the fetched commit.
If set, pass through the value to the output attribute set.
Otherwise, generated from the fetched Git tree.
)",
},
},
{
"revCount",
{
.type = "Integer",
.required = false,
.doc = R"(
Number of revisions in the history of the Git repository before the fetched commit.
If set, pass through the value to the output attribute set.
Otherwise, generated from the fetched Git tree.
)",
},
},
{
"narHash",
{},
},
{
"allRefs",
{
.type = "Bool",
.required = false,
.doc = R"(
By default, this has no effect. This becomes relevant only once `shallow` cloning is disabled.
Whether to fetch all references (eg. branches and tags) of the repository.
With this argument being true, it's possible to load a `rev` from *any* `ref`.
(Without setting this option, only `rev`s from the specified `ref` are supported).
Default: `false`
)",
},
},
{
"name",
{},
},
{
"dirtyRev",
{},
},
{
"dirtyShortRev",
{},
},
{
"verifyCommit",
{},
},
{
"keytype",
{},
},
{
"publicKey",
{},
},
{
"publicKeys",
{},
},
}; };
return attrs;
} }
std::optional<Input> inputFromAttrs(const Settings & settings, const Attrs & attrs) const override std::optional<Input> inputFromAttrs(const Settings & settings, const Attrs & attrs) const override
@@ -384,7 +231,7 @@ struct GitInputScheme : InputScheme
if (auto ref = maybeGetStrAttr(attrs, "ref"); ref && !isLegalRefName(*ref)) if (auto ref = maybeGetStrAttr(attrs, "ref"); ref && !isLegalRefName(*ref))
throw BadURL("invalid Git branch/tag name '%s'", *ref); throw BadURL("invalid Git branch/tag name '%s'", *ref);
Input input{}; Input input{settings};
input.attrs = attrs; input.attrs = attrs;
input.attrs["url"] = fixGitURL(getStrAttr(attrs, "url")).to_string(); input.attrs["url"] = fixGitURL(getStrAttr(attrs, "url")).to_string();
getShallowAttr(input); getShallowAttr(input);
@@ -433,7 +280,7 @@ struct GitInputScheme : InputScheme
return res; return res;
} }
void clone(const Settings & settings, const Input & input, const Path & destDir) const override void clone(const Input & input, const Path & destDir) const override
{ {
auto repoInfo = getRepoInfo(input); auto repoInfo = getRepoInfo(input);
@@ -778,7 +625,7 @@ struct GitInputScheme : InputScheme
} }
std::pair<ref<SourceAccessor>, Input> std::pair<ref<SourceAccessor>, Input>
getAccessorFromCommit(const Settings & settings, ref<Store> store, RepoInfo & repoInfo, Input && input) const getAccessorFromCommit(ref<Store> store, RepoInfo & repoInfo, Input && input) const
{ {
assert(!repoInfo.workdirInfo.isDirty); assert(!repoInfo.workdirInfo.isDirty);
@@ -888,10 +735,10 @@ struct GitInputScheme : InputScheme
auto rev = *input.getRev(); auto rev = *input.getRev();
input.attrs.insert_or_assign("lastModified", getLastModified(settings, repoInfo, repoDir, rev)); input.attrs.insert_or_assign("lastModified", getLastModified(*input.settings, repoInfo, repoDir, rev));
if (!getShallowAttr(input)) if (!getShallowAttr(input))
input.attrs.insert_or_assign("revCount", getRevCount(settings, repoInfo, repoDir, rev)); input.attrs.insert_or_assign("revCount", getRevCount(*input.settings, repoInfo, repoDir, rev));
printTalkative("using revision %s of repo '%s'", rev.gitRev(), repoInfo.locationToArg()); printTalkative("using revision %s of repo '%s'", rev.gitRev(), repoInfo.locationToArg());
@@ -934,8 +781,8 @@ struct GitInputScheme : InputScheme
attrs.insert_or_assign("submodules", Explicit<bool>{true}); attrs.insert_or_assign("submodules", Explicit<bool>{true});
attrs.insert_or_assign("lfs", Explicit<bool>{smudgeLfs}); attrs.insert_or_assign("lfs", Explicit<bool>{smudgeLfs});
attrs.insert_or_assign("allRefs", Explicit<bool>{true}); attrs.insert_or_assign("allRefs", Explicit<bool>{true});
auto submoduleInput = fetchers::Input::fromAttrs(settings, std::move(attrs)); auto submoduleInput = fetchers::Input::fromAttrs(*input.settings, std::move(attrs));
auto [submoduleAccessor, submoduleInput2] = submoduleInput.getAccessor(settings, store); auto [submoduleAccessor, submoduleInput2] = submoduleInput.getAccessor(store);
submoduleAccessor->setPathDisplay("«" + submoduleInput.to_string() + "»"); submoduleAccessor->setPathDisplay("«" + submoduleInput.to_string() + "»");
mounts.insert_or_assign(submodule.path, submoduleAccessor); mounts.insert_or_assign(submodule.path, submoduleAccessor);
} }
@@ -952,7 +799,7 @@ struct GitInputScheme : InputScheme
} }
std::pair<ref<SourceAccessor>, Input> std::pair<ref<SourceAccessor>, Input>
getAccessorFromWorkdir(const Settings & settings, ref<Store> store, RepoInfo & repoInfo, Input && input) const getAccessorFromWorkdir(ref<Store> store, RepoInfo & repoInfo, Input && input) const
{ {
auto repoPath = repoInfo.getPath().value(); auto repoPath = repoInfo.getPath().value();
@@ -984,8 +831,8 @@ struct GitInputScheme : InputScheme
// TODO: fall back to getAccessorFromCommit-like fetch when submodules aren't checked out // TODO: fall back to getAccessorFromCommit-like fetch when submodules aren't checked out
// attrs.insert_or_assign("allRefs", Explicit<bool>{ true }); // attrs.insert_or_assign("allRefs", Explicit<bool>{ true });
auto submoduleInput = fetchers::Input::fromAttrs(settings, std::move(attrs)); auto submoduleInput = fetchers::Input::fromAttrs(*input.settings, std::move(attrs));
auto [submoduleAccessor, submoduleInput2] = submoduleInput.getAccessor(settings, store); auto [submoduleAccessor, submoduleInput2] = submoduleInput.getAccessor(store);
submoduleAccessor->setPathDisplay("«" + submoduleInput.to_string() + "»"); submoduleAccessor->setPathDisplay("«" + submoduleInput.to_string() + "»");
/* If the submodule is dirty, mark this repo dirty as /* If the submodule is dirty, mark this repo dirty as
@@ -1012,12 +859,12 @@ struct GitInputScheme : InputScheme
input.attrs.insert_or_assign("rev", rev.gitRev()); input.attrs.insert_or_assign("rev", rev.gitRev());
if (!getShallowAttr(input)) { if (!getShallowAttr(input)) {
input.attrs.insert_or_assign( input.attrs.insert_or_assign(
"revCount", rev == nullRev ? 0 : getRevCount(settings, repoInfo, repoPath, rev)); "revCount", rev == nullRev ? 0 : getRevCount(*input.settings, repoInfo, repoPath, rev));
} }
verifyCommit(input, repo); verifyCommit(input, repo);
} else { } else {
repoInfo.warnDirty(settings); repoInfo.warnDirty(*input.settings);
if (repoInfo.workdirInfo.headRev) { if (repoInfo.workdirInfo.headRev) {
input.attrs.insert_or_assign("dirtyRev", repoInfo.workdirInfo.headRev->gitRev() + "-dirty"); input.attrs.insert_or_assign("dirtyRev", repoInfo.workdirInfo.headRev->gitRev() + "-dirty");
@@ -1029,14 +876,14 @@ struct GitInputScheme : InputScheme
input.attrs.insert_or_assign( input.attrs.insert_or_assign(
"lastModified", "lastModified",
repoInfo.workdirInfo.headRev ? getLastModified(settings, repoInfo, repoPath, *repoInfo.workdirInfo.headRev) repoInfo.workdirInfo.headRev
: 0); ? getLastModified(*input.settings, repoInfo, repoPath, *repoInfo.workdirInfo.headRev)
: 0);
return {accessor, std::move(input)}; return {accessor, std::move(input)};
} }
std::pair<ref<SourceAccessor>, Input> std::pair<ref<SourceAccessor>, Input> getAccessor(ref<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);
@@ -1052,8 +899,8 @@ struct GitInputScheme : InputScheme
} }
auto [accessor, final] = input.getRef() || input.getRev() || !repoInfo.getPath() auto [accessor, final] = input.getRef() || input.getRev() || !repoInfo.getPath()
? getAccessorFromCommit(settings, store, repoInfo, std::move(input)) ? getAccessorFromCommit(store, repoInfo, std::move(input))
: getAccessorFromWorkdir(settings, store, repoInfo, std::move(input)); : getAccessorFromWorkdir(store, repoInfo, std::move(input));
return {accessor, std::move(final)}; return {accessor, std::move(final)};
} }
@@ -1089,7 +936,7 @@ struct GitInputScheme : InputScheme
} }
} }
bool isLocked(const Settings & settings, const Input & input) const override bool isLocked(const Input & input) const override
{ {
auto rev = input.getRev(); auto rev = input.getRev();
return rev && rev != nullRev; return rev && rev != nullRev;
+58 -101
View File
@@ -48,7 +48,7 @@ struct GitArchiveInputScheme : InputScheme
auto size = path.size(); auto size = path.size();
if (size == 3) { if (size == 3) {
if (std::regex_match(path[2], revRegex)) if (std::regex_match(path[2], revRegex))
rev = Hash::parseAny(path[2], HashAlgorithm::SHA1); rev = parseGitHash(path[2]);
else if (isLegalRefName(path[2])) else if (isLegalRefName(path[2]))
ref = path[2]; ref = path[2];
else else
@@ -74,7 +74,7 @@ struct GitArchiveInputScheme : InputScheme
if (name == "rev") { if (name == "rev") {
if (rev) if (rev)
throw BadURL("URL '%s' contains multiple commit hashes", url); throw BadURL("URL '%s' contains multiple commit hashes", url);
rev = Hash::parseAny(value, HashAlgorithm::SHA1); rev = parseGitHash(value);
} else if (name == "ref") { } else if (name == "ref") {
if (!isLegalRefName(value)) if (!isLegalRefName(value))
throw BadURL("URL '%s' contains an invalid branch/tag name", url); throw BadURL("URL '%s' contains an invalid branch/tag name", url);
@@ -92,7 +92,7 @@ struct GitArchiveInputScheme : InputScheme
if (ref && rev) if (ref && rev)
throw BadURL("URL '%s' contains both a commit hash and a branch/tag name %s %s", url, *ref, rev->gitRev()); throw BadURL("URL '%s' contains both a commit hash and a branch/tag name %s %s", url, *ref, rev->gitRev());
Input input{}; Input input{settings};
input.attrs.insert_or_assign("type", std::string{schemeName()}); input.attrs.insert_or_assign("type", std::string{schemeName()});
input.attrs.insert_or_assign("owner", path[0]); input.attrs.insert_or_assign("owner", path[0]);
input.attrs.insert_or_assign("repo", path[1]); input.attrs.insert_or_assign("repo", path[1]);
@@ -110,43 +110,18 @@ struct GitArchiveInputScheme : InputScheme
return input; return input;
} }
const std::map<std::string, AttributeInfo> & allowedAttrs() const override StringSet allowedAttrs() const override
{ {
static const std::map<std::string, AttributeInfo> attrs = { return {
{ "owner",
"owner", "repo",
{}, "ref",
}, "rev",
{ "narHash",
"repo", "lastModified",
{}, "host",
}, "treeHash",
{
"ref",
{},
},
{
"rev",
{},
},
{
"narHash",
{},
},
{
"lastModified",
{},
},
{
"host",
{},
},
{
"treeHash",
{},
},
}; };
return attrs;
} }
std::optional<Input> inputFromAttrs(const fetchers::Settings & settings, const Attrs & attrs) const override std::optional<Input> inputFromAttrs(const fetchers::Settings & settings, const Attrs & attrs) const override
@@ -154,7 +129,7 @@ struct GitArchiveInputScheme : InputScheme
getStrAttr(attrs, "owner"); getStrAttr(attrs, "owner");
getStrAttr(attrs, "repo"); getStrAttr(attrs, "repo");
Input input{}; Input input{settings};
input.attrs = attrs; input.attrs = attrs;
return input; return input;
} }
@@ -258,9 +233,9 @@ struct GitArchiveInputScheme : InputScheme
std::optional<Hash> treeHash; std::optional<Hash> treeHash;
}; };
virtual RefInfo getRevFromRef(const Settings & settings, nix::ref<Store> store, const Input & input) const = 0; virtual RefInfo getRevFromRef(nix::ref<Store> store, const Input & input) const = 0;
virtual DownloadUrl getDownloadUrl(const Settings & settings, const Input & input) const = 0; virtual DownloadUrl getDownloadUrl(const Input & input) const = 0;
struct TarballInfo struct TarballInfo
{ {
@@ -268,7 +243,7 @@ struct GitArchiveInputScheme : InputScheme
time_t lastModified; time_t lastModified;
}; };
std::pair<Input, TarballInfo> downloadArchive(const Settings & settings, ref<Store> store, Input input) const std::pair<Input, TarballInfo> downloadArchive(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");
@@ -277,7 +252,7 @@ struct GitArchiveInputScheme : InputScheme
auto rev = input.getRev(); auto rev = input.getRev();
if (!rev) { if (!rev) {
auto refInfo = getRevFromRef(settings, store, input); auto refInfo = getRevFromRef(store, input);
rev = refInfo.rev; rev = refInfo.rev;
upstreamTreeHash = refInfo.treeHash; upstreamTreeHash = refInfo.treeHash;
debug("HEAD revision for '%s' is %s", input.to_string(), refInfo.rev.gitRev()); debug("HEAD revision for '%s' is %s", input.to_string(), refInfo.rev.gitRev());
@@ -286,7 +261,7 @@ struct GitArchiveInputScheme : InputScheme
input.attrs.erase("ref"); input.attrs.erase("ref");
input.attrs.insert_or_assign("rev", rev->gitRev()); input.attrs.insert_or_assign("rev", rev->gitRev());
auto cache = settings.getCache(); auto cache = input.settings->getCache();
Cache::Key treeHashKey{"gitRevToTreeHash", {{"rev", rev->gitRev()}}}; Cache::Key treeHashKey{"gitRevToTreeHash", {{"rev", rev->gitRev()}}};
Cache::Key lastModifiedKey{"gitRevToLastModified", {{"rev", rev->gitRev()}}}; Cache::Key lastModifiedKey{"gitRevToLastModified", {{"rev", rev->gitRev()}}};
@@ -295,7 +270,7 @@ struct GitArchiveInputScheme : InputScheme
if (auto lastModifiedAttrs = cache->lookup(lastModifiedKey)) { if (auto lastModifiedAttrs = cache->lookup(lastModifiedKey)) {
auto treeHash = getRevAttr(*treeHashAttrs, "treeHash"); auto treeHash = getRevAttr(*treeHashAttrs, "treeHash");
auto lastModified = getIntAttr(*lastModifiedAttrs, "lastModified"); auto lastModified = getIntAttr(*lastModifiedAttrs, "lastModified");
if (settings.getTarballCache()->hasObject(treeHash)) if (getTarballCache()->hasObject(treeHash))
return {std::move(input), TarballInfo{.treeHash = treeHash, .lastModified = (time_t) lastModified}}; return {std::move(input), TarballInfo{.treeHash = treeHash, .lastModified = (time_t) lastModified}};
else else
debug("Git tree with hash '%s' has disappeared from the cache, refetching...", treeHash.gitRev()); debug("Git tree with hash '%s' has disappeared from the cache, refetching...", treeHash.gitRev());
@@ -303,7 +278,7 @@ struct GitArchiveInputScheme : InputScheme
} }
/* Stream the tarball into the tarball cache. */ /* Stream the tarball into the tarball cache. */
auto url = getDownloadUrl(settings, input); auto url = getDownloadUrl(input);
auto source = sinkToSource([&](Sink & sink) { auto source = sinkToSource([&](Sink & sink) {
FileTransferRequest req(url.url); FileTransferRequest req(url.url);
@@ -315,7 +290,7 @@ struct GitArchiveInputScheme : InputScheme
*logger, lvlInfo, actUnknown, fmt("unpacking '%s' into the Git cache", input.to_string())); *logger, lvlInfo, actUnknown, fmt("unpacking '%s' into the Git cache", input.to_string()));
TarArchive archive{*source}; TarArchive archive{*source};
auto tarballCache = settings.getTarballCache(); auto tarballCache = getTarballCache();
auto parseSink = tarballCache->getFileSystemObjectSink(); auto parseSink = tarballCache->getFileSystemObjectSink();
auto lastModified = unpackTarfileToSink(archive, *parseSink); auto lastModified = unpackTarfileToSink(archive, *parseSink);
auto tree = parseSink->flush(); auto tree = parseSink->flush();
@@ -340,29 +315,28 @@ struct GitArchiveInputScheme : InputScheme
return {std::move(input), tarballInfo}; return {std::move(input), tarballInfo};
} }
std::pair<ref<SourceAccessor>, Input> std::pair<ref<SourceAccessor>, Input> getAccessor(ref<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(store, _input);
#if 0 #if 0
input.attrs.insert_or_assign("treeHash", tarballInfo.treeHash.gitRev()); input.attrs.insert_or_assign("treeHash", tarballInfo.treeHash.gitRev());
#endif #endif
input.attrs.insert_or_assign("lastModified", uint64_t(tarballInfo.lastModified)); input.attrs.insert_or_assign("lastModified", uint64_t(tarballInfo.lastModified));
auto accessor = auto accessor = getTarballCache()->getAccessor(tarballInfo.treeHash, false, "«" + input.to_string() + "»");
settings.getTarballCache()->getAccessor(tarballInfo.treeHash, false, "«" + input.to_string() + "»");
return {accessor, input}; return {accessor, input};
} }
bool isLocked(const Settings & settings, const Input & input) const override bool isLocked(const Input & input) const override
{ {
/* Since we can't verify the integrity of the tarball from the /* Since we can't verify the integrity of the tarball from the
Git revision alone, we also require a NAR hash for Git revision alone, we also require a NAR hash for
locking. FIXME: in the future, we may want to require a Git locking. FIXME: in the future, we may want to require a Git
tree hash instead of a NAR hash. */ tree hash instead of a NAR hash. */
return input.getRev().has_value() && (settings.trustTarballsFromGitForges || input.getNarHash().has_value()); return input.getRev().has_value()
&& (input.settings->trustTarballsFromGitForges || input.getNarHash().has_value());
} }
std::optional<ExperimentalFeature> experimentalFeature() const override std::optional<ExperimentalFeature> experimentalFeature() const override
@@ -386,12 +360,6 @@ struct GitHubInputScheme : GitArchiveInputScheme
return "github"; return "github";
} }
std::string schemeDescription() const override
{
// TODO
return "";
}
std::optional<std::pair<std::string, std::string>> accessHeaderFromToken(const std::string & token) const override std::optional<std::pair<std::string, std::string>> accessHeaderFromToken(const std::string & token) const override
{ {
// Github supports PAT/OAuth2 tokens and HTTP Basic // Github supports PAT/OAuth2 tokens and HTTP Basic
@@ -418,7 +386,7 @@ struct GitHubInputScheme : GitArchiveInputScheme
return getStrAttr(input.attrs, "repo"); return getStrAttr(input.attrs, "repo");
} }
RefInfo getRevFromRef(const Settings & settings, nix::ref<Store> store, const Input & input) const override RefInfo getRevFromRef(nix::ref<Store> store, const Input & input) const override
{ {
auto host = getHost(input); auto host = getHost(input);
auto url = fmt( auto url = fmt(
@@ -428,22 +396,22 @@ struct GitHubInputScheme : GitArchiveInputScheme
getRepo(input), getRepo(input),
*input.getRef()); *input.getRef());
Headers headers = makeHeadersWithAuthTokens(settings, host, input); Headers headers = makeHeadersWithAuthTokens(*input.settings, host, input);
auto downloadResult = downloadFile(store, settings, url, "source", headers); auto downloadResult = downloadFile(store, *input.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 = parseGitHash(std::string{json["sha"]}),
.treeHash = Hash::parseAny(std::string{json["commit"]["tree"]["sha"]}, HashAlgorithm::SHA1)}; .treeHash = parseGitHash(std::string{json["commit"]["tree"]["sha"]})};
} }
DownloadUrl getDownloadUrl(const Settings & settings, const Input & input) const override DownloadUrl getDownloadUrl(const Input & input) const override
{ {
auto host = getHost(input); auto host = getHost(input);
Headers headers = makeHeadersWithAuthTokens(settings, host, input); Headers headers = makeHeadersWithAuthTokens(*input.settings, host, input);
// If we have no auth headers then we default to the public archive // If we have no auth headers then we default to the public archive
// urls so we do not run into rate limits. // urls so we do not run into rate limits.
@@ -457,12 +425,12 @@ struct GitHubInputScheme : GitArchiveInputScheme
return DownloadUrl{parseURL(url), headers}; return DownloadUrl{parseURL(url), headers};
} }
void clone(const Settings & settings, const Input & input, const Path & destDir) const override void clone(const Input & input, const Path & destDir) 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(*input.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, destDir); .clone(destDir);
} }
}; };
@@ -473,12 +441,6 @@ struct GitLabInputScheme : GitArchiveInputScheme
return "gitlab"; return "gitlab";
} }
std::string schemeDescription() const override
{
// TODO
return "";
}
std::optional<std::pair<std::string, std::string>> accessHeaderFromToken(const std::string & token) const override std::optional<std::pair<std::string, std::string>> accessHeaderFromToken(const std::string & token) const override
{ {
// Gitlab supports 4 kinds of authorization, two of which are // Gitlab supports 4 kinds of authorization, two of which are
@@ -498,7 +460,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::ref<Store> store, const Input & input) const override RefInfo getRevFromRef(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
@@ -509,14 +471,14 @@ struct GitLabInputScheme : GitArchiveInputScheme
getStrAttr(input.attrs, "repo"), getStrAttr(input.attrs, "repo"),
*input.getRef()); *input.getRef());
Headers headers = makeHeadersWithAuthTokens(settings, host, input); Headers headers = makeHeadersWithAuthTokens(*input.settings, host, input);
auto downloadResult = downloadFile(store, settings, url, "source", headers); auto downloadResult = downloadFile(store, *input.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 = parseGitHash(std::string(json[0]["id"]))};
} }
if (json.is_array() && json.size() == 0) { if (json.is_array() && json.size() == 0) {
throw Error("No commits returned by GitLab API -- does the git ref really exist?"); throw Error("No commits returned by GitLab API -- does the git ref really exist?");
@@ -525,7 +487,7 @@ struct GitLabInputScheme : GitArchiveInputScheme
} }
} }
DownloadUrl getDownloadUrl(const Settings & settings, const Input & input) const override DownloadUrl getDownloadUrl(const Input & input) const override
{ {
// This endpoint has a rate limit threshold that may be // This endpoint has a rate limit threshold that may be
// server-specific and vary based whether the user is // server-specific and vary based whether the user is
@@ -540,19 +502,19 @@ struct GitLabInputScheme : GitArchiveInputScheme
getStrAttr(input.attrs, "repo"), getStrAttr(input.attrs, "repo"),
input.getRev()->to_string(HashFormat::Base16, false)); input.getRev()->to_string(HashFormat::Base16, false));
Headers headers = makeHeadersWithAuthTokens(settings, host, input); Headers headers = makeHeadersWithAuthTokens(*input.settings, host, input);
return DownloadUrl{parseURL(url), headers}; return DownloadUrl{parseURL(url), headers};
} }
void clone(const Settings & settings, const Input & input, const Path & destDir) const override void clone(const Input & input, const Path & destDir) 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
Input::fromURL( Input::fromURL(
settings, *input.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, destDir); .clone(destDir);
} }
}; };
@@ -563,12 +525,6 @@ struct SourceHutInputScheme : GitArchiveInputScheme
return "sourcehut"; return "sourcehut";
} }
std::string schemeDescription() const override
{
// TODO
return "";
}
std::optional<std::pair<std::string, std::string>> accessHeaderFromToken(const std::string & token) const override std::optional<std::pair<std::string, std::string>> accessHeaderFromToken(const std::string & token) const override
{ {
// SourceHut supports both PAT and OAuth2. See // SourceHut supports both PAT and OAuth2. See
@@ -579,7 +535,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::ref<Store> store, const Input & input) const override RefInfo getRevFromRef(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.
@@ -590,11 +546,11 @@ struct SourceHutInputScheme : GitArchiveInputScheme
auto base_url = auto base_url =
fmt("https://%s/%s/%s", host, getStrAttr(input.attrs, "owner"), getStrAttr(input.attrs, "repo")); fmt("https://%s/%s/%s", host, getStrAttr(input.attrs, "owner"), getStrAttr(input.attrs, "repo"));
Headers headers = makeHeadersWithAuthTokens(settings, host, input); Headers headers = makeHeadersWithAuthTokens(*input.settings, host, input);
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, *input.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);
@@ -607,7 +563,8 @@ 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, *input.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);
@@ -622,10 +579,10 @@ struct SourceHutInputScheme : GitArchiveInputScheme
if (!id) if (!id)
throw BadURL("in '%d', couldn't find ref '%d'", input.to_string(), ref); throw BadURL("in '%d', couldn't find ref '%d'", input.to_string(), ref);
return RefInfo{.rev = Hash::parseAny(*id, HashAlgorithm::SHA1)}; return RefInfo{.rev = parseGitHash(*id)};
} }
DownloadUrl getDownloadUrl(const Settings & settings, const Input & input) const override DownloadUrl getDownloadUrl(const Input & input) const override
{ {
auto host = maybeGetStrAttr(input.attrs, "host").value_or("git.sr.ht"); auto host = maybeGetStrAttr(input.attrs, "host").value_or("git.sr.ht");
auto url = auto url =
@@ -635,18 +592,18 @@ struct SourceHutInputScheme : GitArchiveInputScheme
getStrAttr(input.attrs, "repo"), getStrAttr(input.attrs, "repo"),
input.getRev()->to_string(HashFormat::Base16, false)); input.getRev()->to_string(HashFormat::Base16, false));
Headers headers = makeHeadersWithAuthTokens(settings, host, input); Headers headers = makeHeadersWithAuthTokens(*input.settings, host, input);
return DownloadUrl{parseURL(url), headers}; return DownloadUrl{parseURL(url), headers};
} }
void clone(const Settings & settings, const Input & input, const Path & destDir) const override void clone(const Input & input, const Path & destDir) 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, *input.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, destDir); .clone(destDir);
} }
}; };
@@ -11,12 +11,6 @@
#include <sys/types.h> #include <sys/types.h>
namespace nix {
struct GitRepo;
}
namespace nix::fetchers { namespace nix::fetchers {
struct Cache; struct Cache;
@@ -131,12 +125,8 @@ struct Settings : public Config
ref<Cache> getCache() const; ref<Cache> getCache() const;
ref<GitRepo> getTarballCache() const;
private: private:
mutable Sync<std::shared_ptr<Cache>> _cache; mutable Sync<std::shared_ptr<Cache>> _cache;
mutable Sync<std::shared_ptr<GitRepo>> _tarballCache;
}; };
} // namespace nix::fetchers } // namespace nix::fetchers
@@ -36,6 +36,13 @@ struct Input
{ {
friend struct InputScheme; friend struct InputScheme;
const Settings * settings;
Input(const Settings & settings)
: settings{&settings}
{
}
std::shared_ptr<InputScheme> scheme; // note: can be null std::shared_ptr<InputScheme> scheme; // note: can be null
Attrs attrs; Attrs attrs;
@@ -80,7 +87,7 @@ public:
* attributes like a Git revision or NAR hash that uniquely * attributes like a Git revision or NAR hash that uniquely
* identify its contents. * identify its contents.
*/ */
bool isLocked(const Settings & settings) const; bool isLocked() const;
/** /**
* Only for relative path flakes, i.e. 'path:./foo', returns the * Only for relative path flakes, i.e. 'path:./foo', returns the
@@ -113,7 +120,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, ref<Store> store) const; std::pair<StorePath, Input> fetchToStore(ref<Store> store) const;
/** /**
* Check the locking attributes in `result` against * Check the locking attributes in `result` against
@@ -133,17 +140,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, ref<Store> store) const; std::pair<ref<SourceAccessor>, Input> getAccessor(ref<Store> store) const;
private: private:
std::pair<ref<SourceAccessor>, Input> getAccessorUnchecked(const Settings & settings, ref<Store> store) const; std::pair<ref<SourceAccessor>, Input> getAccessorUnchecked(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, const Path & destDir) const; void clone(const Path & destDir) const;
std::optional<std::filesystem::path> getSourcePath() const; std::optional<std::filesystem::path> getSourcePath() const;
@@ -203,33 +210,20 @@ struct InputScheme
*/ */
virtual std::string_view schemeName() const = 0; virtual std::string_view schemeName() const = 0;
/**
* Longform description of this scheme, for documentation purposes.
*/
virtual std::string schemeDescription() const = 0;
// TODO remove these defaults
struct AttributeInfo
{
const char * type = "String";
bool required = true;
const char * doc = "";
};
/** /**
* Allowed attributes in an attribute set that is converted to an * Allowed attributes in an attribute set that is converted to an
* input, and documentation for each attribute. * input.
* *
* `type` is not included from this map, because the `type` field is * `type` is not included from this set, because the `type` field is
parsed first to choose which scheme; `type` is always required. parsed first to choose which scheme; `type` is always required.
*/ */
virtual const std::map<std::string, AttributeInfo> & allowedAttrs() const = 0; virtual StringSet allowedAttrs() const = 0;
virtual ParsedURL toURL(const Input & input) const; virtual ParsedURL toURL(const Input & input) const;
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 clone(const Settings & settings, const Input & input, const Path & destDir) const; virtual void clone(const Input & input, const 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;
@@ -239,8 +233,7 @@ struct InputScheme
std::string_view contents, std::string_view contents,
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(ref<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?
@@ -257,7 +250,7 @@ struct InputScheme
return std::nullopt; return std::nullopt;
} }
virtual bool isLocked(const Settings & settings, const Input & input) const virtual bool isLocked(const Input & input) const
{ {
return false; return false;
} }
@@ -276,12 +269,7 @@ struct InputScheme
void registerInputScheme(std::shared_ptr<InputScheme> && fetcher); void registerInputScheme(std::shared_ptr<InputScheme> && fetcher);
using InputSchemeMap = std::map<std::string_view, std::shared_ptr<InputScheme>>; nlohmann::json dumpRegisterInputSchemeInfo();
/**
* Use this for docs, not for finding a specific scheme
*/
const InputSchemeMap & getAllInputSchemes();
struct PublicKey struct PublicKey
{ {
@@ -5,7 +5,7 @@
#include "nix/util/serialise.hh" #include "nix/util/serialise.hh"
#include "nix/util/url.hh" #include "nix/util/url.hh"
#include <git2/repository.h> #include <git2-experimental/repository.h>
#include <nlohmann/json_fwd.hpp> #include <nlohmann/json_fwd.hpp>
@@ -120,6 +120,8 @@ struct GitRepo
virtual Hash dereferenceSingletonDirectory(const Hash & oid) = 0; virtual Hash dereferenceSingletonDirectory(const Hash & oid) = 0;
}; };
ref<GitRepo> getTarballCache();
// A helper to ensure that the `git_*_free` functions get called. // A helper to ensure that the `git_*_free` functions get called.
template<auto del> template<auto del>
struct Deleter struct Deleter
@@ -165,4 +167,14 @@ struct Setter
*/ */
bool isLegalRefName(const std::string & refName); bool isLegalRefName(const std::string & refName);
/**
* Parse a base16-encoded git hash string and determine the hash
* algorithm based on the length (40 chars = SHA1, 64 chars = SHA256).
*
* @note For Nix-native information we should *not* do length tricks,
* but instead always rely on an explicit algorithm. This hack should be
* only for foreign hash literals.
*/
Hash parseGitHash(std::string_view hashStr);
} // namespace nix } // namespace nix
@@ -3,7 +3,6 @@
namespace nix::fetchers { namespace nix::fetchers {
enum class UseRegistries : int; enum class UseRegistries : int;
struct Settings;
struct InputCache struct InputCache
{ {
@@ -15,8 +14,7 @@ struct InputCache
Attrs extraAttrs; Attrs extraAttrs;
}; };
CachedResult CachedResult getAccessor(ref<Store> store, const Input & originalInput, UseRegistries useRegistries);
getAccessor(const Settings & settings, ref<Store> store, const Input & originalInput, UseRegistries useRegistries);
struct CachedInput struct CachedInput
{ {
@@ -59,7 +59,7 @@ Path getUserRegistryPath();
Registries getRegistries(const Settings & settings, ref<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 Input & from, const Input & to, const Attrs & extraAttrs);
enum class UseRegistries : int { enum class UseRegistries : int {
No, No,
@@ -71,7 +71,6 @@ enum class UseRegistries : int {
* Rewrite a flakeref using the registries. If `filter` is set, only * Rewrite a flakeref using the registries. If `filter` is set, only
* 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(ref<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
+11 -31
View File
@@ -23,7 +23,7 @@ struct IndirectInputScheme : InputScheme
if (path.size() == 1) { if (path.size() == 1) {
} else if (path.size() == 2) { } else if (path.size() == 2) {
if (std::regex_match(path[1], revRegex)) if (std::regex_match(path[1], revRegex))
rev = Hash::parseAny(path[1], HashAlgorithm::SHA1); rev = parseGitHash(path[1]);
else if (isLegalRefName(path[1])) else if (isLegalRefName(path[1]))
ref = path[1]; ref = path[1];
else else
@@ -34,7 +34,7 @@ struct IndirectInputScheme : InputScheme
ref = path[1]; ref = path[1];
if (!std::regex_match(path[2], revRegex)) if (!std::regex_match(path[2], revRegex))
throw BadURL("in flake URL '%s', '%s' is not a commit hash", url, path[2]); throw BadURL("in flake URL '%s', '%s' is not a commit hash", url, path[2]);
rev = Hash::parseAny(path[2], HashAlgorithm::SHA1); rev = parseGitHash(path[2]);
} else } else
throw BadURL("GitHub URL '%s' is invalid", url); throw BadURL("GitHub URL '%s' is invalid", url);
@@ -44,7 +44,7 @@ struct IndirectInputScheme : InputScheme
// FIXME: forbid query params? // FIXME: forbid query params?
Input input{}; Input input{settings};
input.attrs.insert_or_assign("type", "indirect"); input.attrs.insert_or_assign("type", "indirect");
input.attrs.insert_or_assign("id", id); input.attrs.insert_or_assign("id", id);
if (rev) if (rev)
@@ -60,33 +60,14 @@ struct IndirectInputScheme : InputScheme
return "indirect"; return "indirect";
} }
std::string schemeDescription() const override StringSet allowedAttrs() const override
{ {
// TODO return {
return ""; "id",
} "ref",
"rev",
const std::map<std::string, AttributeInfo> & allowedAttrs() const override "narHash",
{
static const std::map<std::string, AttributeInfo> attrs = {
{
"id",
{},
},
{
"ref",
{},
},
{
"rev",
{},
},
{
"narHash",
{},
},
}; };
return attrs;
} }
std::optional<Input> inputFromAttrs(const Settings & settings, const Attrs & attrs) const override std::optional<Input> inputFromAttrs(const Settings & settings, const Attrs & attrs) const override
@@ -95,7 +76,7 @@ struct IndirectInputScheme : InputScheme
if (!std::regex_match(id, flakeRegex)) if (!std::regex_match(id, flakeRegex))
throw BadURL("'%s' is not a valid flake ID", id); throw BadURL("'%s' is not a valid flake ID", id);
Input input{}; Input input{settings};
input.attrs = attrs; input.attrs = attrs;
return input; return input;
} }
@@ -125,8 +106,7 @@ struct IndirectInputScheme : InputScheme
return input; return input;
} }
std::pair<ref<SourceAccessor>, Input> std::pair<ref<SourceAccessor>, Input> getAccessor(ref<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());
} }
+5 -5
View File
@@ -5,23 +5,23 @@
namespace nix::fetchers { namespace nix::fetchers {
InputCache::CachedResult InputCache::getAccessor( InputCache::CachedResult
const Settings & settings, ref<Store> store, const Input & originalInput, UseRegistries useRegistries) InputCache::getAccessor(ref<Store> store, const Input & originalInput, UseRegistries useRegistries)
{ {
auto fetched = lookup(originalInput); auto fetched = lookup(originalInput);
Input resolvedInput = originalInput; Input resolvedInput = originalInput;
if (!fetched) { if (!fetched) {
if (originalInput.isDirect()) { if (originalInput.isDirect()) {
auto [accessor, lockedInput] = originalInput.getAccessor(settings, store); auto [accessor, lockedInput] = originalInput.getAccessor(store);
fetched.emplace(CachedInput{.lockedInput = lockedInput, .accessor = accessor}); fetched.emplace(CachedInput{.lockedInput = lockedInput, .accessor = accessor});
} else { } else {
if (useRegistries != UseRegistries::No) { if (useRegistries != UseRegistries::No) {
auto [res, extraAttrs] = lookupInRegistries(settings, store, originalInput, useRegistries); auto [res, extraAttrs] = lookupInRegistries(store, originalInput, useRegistries);
resolvedInput = std::move(res); resolvedInput = std::move(res);
fetched = lookup(resolvedInput); fetched = lookup(resolvedInput);
if (!fetched) { if (!fetched) {
auto [accessor, lockedInput] = resolvedInput.getAccessor(settings, store); auto [accessor, lockedInput] = resolvedInput.getAccessor(store);
fetched.emplace( fetched.emplace(
CachedInput{.lockedInput = lockedInput, .accessor = accessor, .extraAttrs = extraAttrs}); CachedInput{.lockedInput = lockedInput, .accessor = accessor, .extraAttrs = extraAttrs});
} }
+20 -46
View File
@@ -68,41 +68,16 @@ struct MercurialInputScheme : InputScheme
return "hg"; return "hg";
} }
std::string schemeDescription() const override StringSet allowedAttrs() const override
{ {
// TODO return {
return ""; "url",
} "ref",
"rev",
const std::map<std::string, AttributeInfo> & allowedAttrs() const override "revCount",
{ "narHash",
static const std::map<std::string, AttributeInfo> attrs = { "name",
{
"url",
{},
},
{
"ref",
{},
},
{
"rev",
{},
},
{
"revCount",
{},
},
{
"narHash",
{},
},
{
"name",
{},
},
}; };
return attrs;
} }
std::optional<Input> inputFromAttrs(const Settings & settings, const Attrs & attrs) const override std::optional<Input> inputFromAttrs(const Settings & settings, const Attrs & attrs) const override
@@ -114,7 +89,7 @@ struct MercurialInputScheme : InputScheme
throw BadURL("invalid Mercurial branch/tag name '%s'", *ref); throw BadURL("invalid Mercurial branch/tag name '%s'", *ref);
} }
Input input{}; Input input{settings};
input.attrs = attrs; input.attrs = attrs;
return input; return input;
} }
@@ -179,7 +154,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, ref<Store> store, Input & input) const StorePath fetchToStore(ref<Store> store, Input & input) const
{ {
auto origRev = input.getRev(); auto origRev = input.getRev();
@@ -201,10 +176,10 @@ struct MercurialInputScheme : InputScheme
/* This is an unclean working tree. So copy all tracked /* This is an unclean working tree. So copy all tracked
files. */ files. */
if (!settings.allowDirty) if (!input.settings->allowDirty)
throw Error("Mercurial tree '%s' is unclean", actualUrl); throw Error("Mercurial tree '%s' is unclean", actualUrl);
if (settings.warnDirty) if (input.settings->warnDirty)
warn("Mercurial tree '%s' is unclean", actualUrl); warn("Mercurial tree '%s' is unclean", actualUrl);
input.attrs.insert_or_assign("ref", chomp(runHg({"branch", "-R", actualUrl}))); input.attrs.insert_or_assign("ref", chomp(runHg({"branch", "-R", actualUrl})));
@@ -265,13 +240,13 @@ struct MercurialInputScheme : InputScheme
Cache::Key refToRevKey{"hgRefToRev", {{"url", actualUrl}, {"ref", *input.getRef()}}}; Cache::Key refToRevKey{"hgRefToRev", {{"url", actualUrl}, {"ref", *input.getRef()}}};
if (!input.getRev()) { if (!input.getRev()) {
if (auto res = settings.getCache()->lookupWithTTL(refToRevKey)) if (auto res = input.settings->getCache()->lookupWithTTL(refToRevKey))
input.attrs.insert_or_assign("rev", getRevAttr(*res, "rev").gitRev()); input.attrs.insert_or_assign("rev", getRevAttr(*res, "rev").gitRev());
} }
/* 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 = input.settings->getCache()->lookupStorePath(revInfoKey(*rev), *store))
return makeResult(res->value, res->storePath); return makeResult(res->value, res->storePath);
} }
@@ -325,7 +300,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 = input.settings->getCache()->lookupStorePath(revInfoKey(rev), *store))
return makeResult(res->value, res->storePath); return makeResult(res->value, res->storePath);
Path tmpDir = createTempDir(); Path tmpDir = createTempDir();
@@ -342,19 +317,18 @@ struct MercurialInputScheme : InputScheme
}); });
if (!origRev) if (!origRev)
settings.getCache()->upsert(refToRevKey, {{"rev", rev.gitRev()}}); input.settings->getCache()->upsert(refToRevKey, {{"rev", rev.gitRev()}});
settings.getCache()->upsert(revInfoKey(rev), *store, infoAttrs, storePath); input.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(ref<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(store, input);
auto accessor = store->requireStoreObjectAccessor(storePath); auto accessor = store->requireStoreObjectAccessor(storePath);
accessor->setPathDisplay("«" + input.to_string() + "»"); accessor->setPathDisplay("«" + input.to_string() + "»");
@@ -362,7 +336,7 @@ struct MercurialInputScheme : InputScheme
return {accessor, input}; return {accessor, input};
} }
bool isLocked(const Settings & settings, const Input & input) const override bool isLocked(const Input & input) const override
{ {
return (bool) input.getRev(); return (bool) input.getRev();
} }
+1 -1
View File
@@ -28,7 +28,7 @@ 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
libgit2 = dependency('libgit2', version : '>= 1.9') libgit2 = dependency('libgit2-experimental', version : '>= 1.9')
deps_private += libgit2 deps_private += libgit2
subdir('nix-meson-build-support/common') subdir('nix-meson-build-support/common')
+12 -35
View File
@@ -17,7 +17,7 @@ struct PathInputScheme : InputScheme
if (url.authority && url.authority->host.size()) if (url.authority && url.authority->host.size())
throw Error("path URL '%s' should not have an authority ('%s')", url, *url.authority); throw Error("path URL '%s' should not have an authority ('%s')", url, *url.authority);
Input input{}; Input input{settings};
input.attrs.insert_or_assign("type", "path"); input.attrs.insert_or_assign("type", "path");
input.attrs.insert_or_assign("path", renderUrlPathEnsureLegal(url.path)); input.attrs.insert_or_assign("path", renderUrlPathEnsureLegal(url.path));
@@ -40,49 +40,27 @@ struct PathInputScheme : InputScheme
return "path"; return "path";
} }
std::string schemeDescription() const override StringSet allowedAttrs() const override
{ {
// TODO return {
return ""; "path",
}
const std::map<std::string, AttributeInfo> & allowedAttrs() const override
{
static const std::map<std::string, AttributeInfo> attrs = {
{
"path",
{},
},
/* Allow the user to pass in "fake" tree info /* Allow the user to pass in "fake" tree info
attributes. This is useful for making a pinned tree work attributes. This is useful for making a pinned tree work
the same as the repository from which is exported (e.g. the same as the repository from which is exported (e.g.
path:/nix/store/...-source?lastModified=1585388205&rev=b0c285...). path:/nix/store/...-source?lastModified=1585388205&rev=b0c285...).
*/ */
{ "rev",
"rev", "revCount",
{}, "lastModified",
}, "narHash",
{
"revCount",
{},
},
{
"lastModified",
{},
},
{
"narHash",
{},
},
}; };
return attrs;
} }
std::optional<Input> inputFromAttrs(const Settings & settings, const Attrs & attrs) const override std::optional<Input> inputFromAttrs(const Settings & settings, const Attrs & attrs) const override
{ {
getStrAttr(attrs, "path"); getStrAttr(attrs, "path");
Input input{}; Input input{settings};
input.attrs = attrs; input.attrs = attrs;
return input; return input;
} }
@@ -123,7 +101,7 @@ struct PathInputScheme : InputScheme
return path; return path;
} }
bool isLocked(const Settings & settings, const Input & input) const override bool isLocked(const Input & input) const override
{ {
return (bool) input.getNarHash(); return (bool) input.getNarHash();
} }
@@ -138,8 +116,7 @@ struct PathInputScheme : InputScheme
throw Error("cannot fetch input '%s' because it uses a relative path", input.to_string()); throw Error("cannot fetch input '%s' because it uses a relative path", input.to_string());
} }
std::pair<ref<SourceAccessor>, Input> std::pair<ref<SourceAccessor>, Input> getAccessor(ref<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");
@@ -168,7 +145,7 @@ struct PathInputScheme : InputScheme
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( input.settings->getCache()->upsert(
makeFetchToStoreCacheKey( makeFetchToStoreCacheKey(
input.getName(), *accessor->fingerprint, ContentAddressMethod::Raw::NixArchive, "/"), input.getName(), *accessor->fingerprint, ContentAddressMethod::Raw::NixArchive, "/"),
*store, *store,
+4 -5
View File
@@ -131,9 +131,9 @@ std::shared_ptr<Registry> getFlagRegistry(const Settings & settings)
return flagRegistry; return flagRegistry;
} }
void overrideRegistry(const Settings & settings, const Input & from, const Input & to, const Attrs & extraAttrs) void overrideRegistry(const Input & from, const Input & to, const Attrs & extraAttrs)
{ {
getFlagRegistry(settings)->add(from, to, extraAttrs); getFlagRegistry(*from.settings)->add(from, to, extraAttrs);
} }
static std::shared_ptr<Registry> getGlobalRegistry(const Settings & settings, ref<Store> store) static std::shared_ptr<Registry> getGlobalRegistry(const Settings & settings, ref<Store> store)
@@ -172,8 +172,7 @@ Registries getRegistries(const Settings & settings, ref<Store> store)
return registries; return registries;
} }
std::pair<Input, Attrs> std::pair<Input, Attrs> lookupInRegistries(ref<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;
@@ -188,7 +187,7 @@ restart:
if (n > 100) if (n > 100)
throw Error("cycle detected in flake registry for '%s'", input.to_string()); throw Error("cycle detected in flake registry for '%s'", input.to_string());
for (auto & registry : getRegistries(settings, store)) { for (auto & registry : getRegistries(*input.settings, store)) {
if (useRegistries == UseRegistries::Limited if (useRegistries == UseRegistries::Limited
&& !(registry->type == fetchers::Registry::Flag || registry->type == fetchers::Registry::Global)) && !(registry->type == fetchers::Registry::Flag || registry->type == fetchers::Registry::Global))
continue; continue;
+25 -127
View File
@@ -136,11 +136,11 @@ static DownloadTarballResult downloadTarball_(
.treeHash = treeHash, .treeHash = treeHash,
.lastModified = (time_t) getIntAttr(infoAttrs, "lastModified"), .lastModified = (time_t) getIntAttr(infoAttrs, "lastModified"),
.immutableUrl = maybeGetStrAttr(infoAttrs, "immutableUrl"), .immutableUrl = maybeGetStrAttr(infoAttrs, "immutableUrl"),
.accessor = settings.getTarballCache()->getAccessor(treeHash, false, displayPrefix), .accessor = getTarballCache()->getAccessor(treeHash, false, displayPrefix),
}; };
}; };
if (cached && !settings.getTarballCache()->hasObject(getRevAttr(cached->value, "treeHash"))) if (cached && !getTarballCache()->hasObject(getRevAttr(cached->value, "treeHash")))
cached.reset(); cached.reset();
if (cached && !cached->expired) if (cached && !cached->expired)
@@ -179,7 +179,7 @@ static DownloadTarballResult downloadTarball_(
TarArchive{path}; TarArchive{path};
}) })
: TarArchive{*source}; : TarArchive{*source};
auto tarballCache = settings.getTarballCache(); auto tarballCache = getTarballCache();
auto parseSink = tarballCache->getFileSystemObjectSink(); auto parseSink = tarballCache->getFileSystemObjectSink();
auto lastModified = unpackTarfileToSink(archive, *parseSink); auto lastModified = unpackTarfileToSink(archive, *parseSink);
auto tree = parseSink->flush(); auto tree = parseSink->flush();
@@ -224,7 +224,7 @@ ref<SourceAccessor> downloadTarball(ref<Store> store, const Settings & settings,
auto input = Input::fromAttrs(settings, std::move(attrs)); auto input = Input::fromAttrs(settings, std::move(attrs));
return input.getAccessor(settings, store).first; return input.getAccessor(store).first;
} }
// An input scheme corresponding to a curl-downloadable resource. // An input scheme corresponding to a curl-downloadable resource.
@@ -252,7 +252,7 @@ struct CurlInputScheme : InputScheme
if (!isValidURL(_url, requireTree)) if (!isValidURL(_url, requireTree))
return std::nullopt; return std::nullopt;
Input input{}; Input input{settings};
auto url = _url; auto url = _url;
@@ -278,7 +278,7 @@ struct CurlInputScheme : InputScheme
HTTP request. Now that we've processed the Nix-specific HTTP request. Now that we've processed the Nix-specific
attributes above, remove them so we don't also send them as attributes above, remove them so we don't also send them as
part of the HTTP request. */ part of the HTTP request. */
for (auto & [param, _] : allowedAttrs()) for (auto & param : allowedAttrs())
url.query.erase(param); url.query.erase(param);
input.attrs.insert_or_assign("type", std::string{schemeName()}); input.attrs.insert_or_assign("type", std::string{schemeName()});
@@ -286,88 +286,23 @@ struct CurlInputScheme : InputScheme
return input; return input;
} }
static const std::map<std::string, AttributeInfo> & allowedAttrsImpl() StringSet allowedAttrs() const override
{ {
static const std::map<std::string, AttributeInfo> attrs = { return {
{ "type",
"url", "url",
{ "narHash",
.type = "String", "name",
.required = true, "unpack",
.doc = R"( "rev",
Supported protocols: "revCount",
"lastModified",
- `https`
> **Example**
>
> ```nix
> fetchTree {
> type = "file";
> url = "https://example.com/index.html";
> }
> ```
- `http`
Insecure HTTP transfer for legacy sources.
> **Warning**
>
> HTTP performs no encryption or authentication.
> Use a `narHash` known in advance to ensure the output has expected contents.
- `file`
A file on the local file system.
> **Example**
>
> ```nix
> fetchTree {
> type = "file";
> url = "file:///home/eelco/nix/README.md";
> }
> ```
)",
},
},
{
"narHash",
{},
},
{
"name",
{},
},
{
"unpack",
{},
},
{
"rev",
{},
},
{
"revCount",
{},
},
{
"lastModified",
{},
},
}; };
return attrs;
}
const std::map<std::string, AttributeInfo> & allowedAttrs() const override
{
return allowedAttrsImpl();
} }
std::optional<Input> inputFromAttrs(const Settings & settings, const Attrs & attrs) const override std::optional<Input> inputFromAttrs(const Settings & settings, const Attrs & attrs) const override
{ {
Input input{}; Input input{settings};
input.attrs = attrs; input.attrs = attrs;
// input.locked = (bool) maybeGetStrAttr(input.attrs, "hash"); // input.locked = (bool) maybeGetStrAttr(input.attrs, "hash");
@@ -384,7 +319,7 @@ struct CurlInputScheme : InputScheme
return url; return url;
} }
bool isLocked(const Settings & settings, const Input & input) const override bool isLocked(const Input & input) const override
{ {
return (bool) input.getNarHash(); return (bool) input.getNarHash();
} }
@@ -397,14 +332,6 @@ struct FileInputScheme : CurlInputScheme
return "file"; return "file";
} }
std::string schemeDescription() const override
{
return stripIndentation(R"(
Place a plain file into the Nix store.
This is similar to [`builtins.fetchurl`](@docroot@/language/builtins.md#builtins-fetchurl)
)");
}
bool isValidURL(const ParsedURL & url, bool requireTree) const override bool isValidURL(const ParsedURL & url, bool requireTree) const override
{ {
auto parsedUrlScheme = parseUrlScheme(url.scheme); auto parsedUrlScheme = parseUrlScheme(url.scheme);
@@ -413,8 +340,7 @@ struct FileInputScheme : CurlInputScheme
: (!requireTree && !hasTarballExtension(url))); : (!requireTree && !hasTarballExtension(url)));
} }
std::pair<ref<SourceAccessor>, Input> std::pair<ref<SourceAccessor>, Input> getAccessor(ref<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);
@@ -422,7 +348,7 @@ struct FileInputScheme : CurlInputScheme
the Nix store directly, since there is little deduplication the Nix store directly, since there is little deduplication
benefit in using the Git cache for single big files like benefit in using the Git cache for single big files like
tarballs. */ tarballs. */
auto file = downloadFile(store, settings, getStrAttr(input.attrs, "url"), input.getName()); auto file = downloadFile(store, *input.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));
@@ -442,34 +368,6 @@ struct TarballInputScheme : CurlInputScheme
return "tarball"; return "tarball";
} }
std::string schemeDescription() const override
{
return stripIndentation(R"(
Download a tar archive and extract it into the Nix store.
This has the same underlying implementation as [`builtins.fetchTarball`](@docroot@/language/builtins.md#builtins-fetchTarball)
)");
}
const std::map<std::string, AttributeInfo> & allowedAttrs() const override
{
static const std::map<std::string, AttributeInfo> attrs = [] {
auto attrs = CurlInputScheme::allowedAttrsImpl();
// Override the "url" attribute to add tarball-specific example
attrs["url"].doc = R"(
> **Example**
>
> ```nix
> fetchTree {
> type = "tarball";
> url = "https://github.com/NixOS/nixpkgs/tarball/nixpkgs-23.11";
> }
> ```
)";
return attrs;
}();
return attrs;
}
bool isValidURL(const ParsedURL & url, bool requireTree) const override bool isValidURL(const ParsedURL & url, bool requireTree) const override
{ {
auto parsedUrlScheme = parseUrlScheme(url.scheme); auto parsedUrlScheme = parseUrlScheme(url.scheme);
@@ -479,15 +377,15 @@ struct TarballInputScheme : CurlInputScheme
: (requireTree || hasTarballExtension(url))); : (requireTree || hasTarballExtension(url)));
} }
std::pair<ref<SourceAccessor>, Input> std::pair<ref<SourceAccessor>, Input> getAccessor(ref<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);
auto result = downloadTarball_(settings, getStrAttr(input.attrs, "url"), {}, "«" + input.to_string() + "»"); auto result =
downloadTarball_(*input.settings, getStrAttr(input.attrs, "url"), {}, "«" + input.to_string() + "»");
if (result.immutableUrl) { if (result.immutableUrl) {
auto immutableInput = Input::fromURL(settings, *result.immutableUrl); auto immutableInput = Input::fromURL(*input.settings, *result.immutableUrl);
// FIXME: would be nice to support arbitrary flakerefs // FIXME: would be nice to support arbitrary flakerefs
// here, e.g. git flakes. // here, e.g. git flakes.
if (immutableInput.getType() != "tarball") if (immutableInput.getType() != "tarball")
@@ -500,7 +398,7 @@ struct TarballInputScheme : CurlInputScheme
input.attrs.insert_or_assign( input.attrs.insert_or_assign(
"narHash", "narHash",
settings.getTarballCache()->treeHashToNarHash(settings, result.treeHash).to_string(HashFormat::SRI, true)); getTarballCache()->treeHashToNarHash(*input.settings, result.treeHash).to_string(HashFormat::SRI, true));
return {result.accessor, input}; return {result.accessor, input};
} }
+1 -1
View File
@@ -38,7 +38,7 @@ PrimOp getFlake(const Settings & settings)
std::string flakeRefS( std::string flakeRefS(
state.forceStringNoCtx(*args[0], pos, "while evaluating the argument passed to builtins.getFlake")); state.forceStringNoCtx(*args[0], pos, "while evaluating the argument passed to builtins.getFlake"));
auto flakeRef = nix::parseFlakeRef(state.fetchSettings, flakeRefS, {}, true); auto flakeRef = nix::parseFlakeRef(state.fetchSettings, flakeRefS, {}, true);
if (state.settings.pureEval && !flakeRef.input.isLocked(state.fetchSettings)) if (state.settings.pureEval && !flakeRef.input.isLocked())
throw Error( throw Error(
"cannot call 'getFlake' on unlocked flake reference '%s', at %s (use --impure to override)", "cannot call 'getFlake' on unlocked flake reference '%s', at %s (use --impure to override)",
flakeRefS, flakeRefS,
+4 -7
View File
@@ -372,8 +372,7 @@ static Flake getFlake(
const InputAttrPath & lockRootAttrPath) const InputAttrPath & lockRootAttrPath)
{ {
// Fetch a lazy tree first. // Fetch a lazy tree first.
auto cachedInput = auto cachedInput = state.inputCache->getAccessor(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);
@@ -389,8 +388,7 @@ static Flake getFlake(
debug("refetching input '%s' due to self attribute", newLockedRef); debug("refetching input '%s' due to self attribute", newLockedRef);
// 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.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);
} }
@@ -706,8 +704,7 @@ lockFlake(const Settings & settings, EvalState & state, const FlakeRef & topRef,
this input. */ this input. */
debug("creating new input '%s'", inputAttrPathS); debug("creating new input '%s'", inputAttrPathS);
if (!lockFlags.allowUnlocked && !input.ref->input.isLocked(state.fetchSettings) if (!lockFlags.allowUnlocked && !input.ref->input.isLocked() && !input.ref->input.isRelative())
&& !input.ref->input.isRelative())
throw Error("cannot update unlocked flake input '%s' in pure mode", inputAttrPathS); throw Error("cannot update unlocked flake input '%s' in pure mode", inputAttrPathS);
/* Note: in case of an --override-input, we use /* Note: in case of an --override-input, we use
@@ -756,7 +753,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.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);
+4 -6
View File
@@ -64,10 +64,9 @@ std::ostream & operator<<(std::ostream & str, const FlakeRef & flakeRef)
return str; return str;
} }
FlakeRef FlakeRef::resolve( FlakeRef FlakeRef::resolve(ref<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(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));
} }
@@ -288,10 +287,9 @@ FlakeRef FlakeRef::fromAttrs(const fetchers::Settings & fetchSettings, const fet
fetchers::maybeGetStrAttr(attrs, "dir").value_or("")); fetchers::maybeGetStrAttr(attrs, "dir").value_or(""));
} }
std::pair<ref<SourceAccessor>, FlakeRef> std::pair<ref<SourceAccessor>, FlakeRef> FlakeRef::lazyFetch(ref<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(store);
return {accessor, FlakeRef(std::move(lockedInput), subdir)}; return {accessor, FlakeRef(std::move(lockedInput), subdir)};
} }
+2 -6
View File
@@ -71,15 +71,11 @@ struct FlakeRef
fetchers::Attrs toAttrs() const; fetchers::Attrs toAttrs() const;
FlakeRef resolve( FlakeRef resolve(ref<Store> store, fetchers::UseRegistries useRegistries = fetchers::UseRegistries::All) const;
const fetchers::Settings & fetchSettings,
ref<Store> store,
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> std::pair<ref<SourceAccessor>, FlakeRef> lazyFetch(ref<Store> store) const;
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
+2 -2
View File
@@ -74,7 +74,7 @@ LockedNode::LockedNode(const fetchers::Settings & fetchSettings, const nlohmann:
, parentInputAttrPath( , parentInputAttrPath(
json.find("parent") != json.end() ? (std::optional<InputAttrPath>) json["parent"] : std::nullopt) json.find("parent") != json.end() ? (std::optional<InputAttrPath>) json["parent"] : std::nullopt)
{ {
if (!lockedRef.input.isLocked(fetchSettings) && !lockedRef.input.isRelative()) { if (!lockedRef.input.isLocked() && !lockedRef.input.isRelative()) {
if (lockedRef.input.getNarHash()) if (lockedRef.input.getNarHash())
warn( warn(
"Lock file entry '%s' is unlocked (e.g. lacks a Git revision) but is checked by NAR hash. " "Lock file entry '%s' is unlocked (e.g. lacks a Git revision) but is checked by NAR hash. "
@@ -282,7 +282,7 @@ std::optional<FlakeRef> LockFile::isUnlocked(const fetchers::Settings & fetchSet
latter case, we can verify the input but we may not be able to latter case, we can verify the input but we may not be able to
fetch it from anywhere. */ fetch it from anywhere. */
auto isConsideredLocked = [&](const fetchers::Input & input) { auto isConsideredLocked = [&](const fetchers::Input & input) {
return input.isLocked(fetchSettings) || (fetchSettings.allowDirtyLocks && input.getNarHash()); return input.isLocked() || (fetchSettings.allowDirtyLocks && input.getNarHash());
}; };
for (auto & i : nodes) { for (auto & i : nodes) {
+5 -62
View File
@@ -467,6 +467,8 @@ public:
std::string getStatus(State & state) std::string getStatus(State & state)
{ {
auto MiB = 1024.0 * 1024.0;
std::string res; std::string res;
auto renderActivity = auto renderActivity =
@@ -514,65 +516,6 @@ public:
return s; return s;
}; };
auto renderSizeActivity = [&](ActivityType type, const std::string & itemFmt = "%s") {
auto & act = state.activitiesByType[type];
uint64_t done = act.done, expected = act.done, running = 0, failed = act.failed;
for (auto & j : act.its) {
done += j.second->done;
expected += j.second->expected;
running += j.second->running;
failed += j.second->failed;
}
expected = std::max(expected, act.expected);
std::optional<SizeUnit> commonUnit;
std::string s;
if (running || done || expected || failed) {
if (running)
if (expected != 0) {
commonUnit = getCommonSizeUnit({(int64_t) running, (int64_t) done, (int64_t) expected});
s =
fmt(ANSI_BLUE "%s" ANSI_NORMAL "/" ANSI_GREEN "%s" ANSI_NORMAL "/%s",
commonUnit ? renderSizeWithoutUnit(running, *commonUnit) : renderSize(running),
commonUnit ? renderSizeWithoutUnit(done, *commonUnit) : renderSize(done),
commonUnit ? renderSizeWithoutUnit(expected, *commonUnit) : renderSize(expected));
} else {
commonUnit = getCommonSizeUnit({(int64_t) running, (int64_t) done});
s =
fmt(ANSI_BLUE "%s" ANSI_NORMAL "/" ANSI_GREEN "%s" ANSI_NORMAL,
commonUnit ? renderSizeWithoutUnit(running, *commonUnit) : renderSize(running),
commonUnit ? renderSizeWithoutUnit(done, *commonUnit) : renderSize(done));
}
else if (expected != done)
if (expected != 0) {
commonUnit = getCommonSizeUnit({(int64_t) done, (int64_t) expected});
s =
fmt(ANSI_GREEN "%s" ANSI_NORMAL "/%s",
commonUnit ? renderSizeWithoutUnit(done, *commonUnit) : renderSize(done),
commonUnit ? renderSizeWithoutUnit(expected, *commonUnit) : renderSize(expected));
} else {
commonUnit = getSizeUnit(done);
s = fmt(ANSI_GREEN "%s" ANSI_NORMAL, renderSizeWithoutUnit(done, *commonUnit));
}
else {
commonUnit = getSizeUnit(done);
s = fmt(done ? ANSI_GREEN "%s" ANSI_NORMAL : "%s", renderSizeWithoutUnit(done, *commonUnit));
}
if (commonUnit)
s = fmt("%s %siB", s, getSizeUnitSuffix(*commonUnit));
s = fmt(itemFmt, s);
if (failed)
s += fmt(" (" ANSI_RED "%s failed" ANSI_NORMAL ")", renderSize(failed));
}
return s;
};
auto showActivity = auto showActivity =
[&](ActivityType type, const std::string & itemFmt, const std::string & numberFmt = "%d", double unit = 1) { [&](ActivityType type, const std::string & itemFmt, const std::string & numberFmt = "%d", double unit = 1) {
auto s = renderActivity(type, itemFmt, numberFmt, unit); auto s = renderActivity(type, itemFmt, numberFmt, unit);
@@ -586,7 +529,7 @@ public:
showActivity(actBuilds, "%s built"); showActivity(actBuilds, "%s built");
auto s1 = renderActivity(actCopyPaths, "%s copied"); auto s1 = renderActivity(actCopyPaths, "%s copied");
auto s2 = renderSizeActivity(actCopyPath); auto s2 = renderActivity(actCopyPath, "%s MiB", "%.1f", MiB);
if (!s1.empty() || !s2.empty()) { if (!s1.empty() || !s2.empty()) {
if (!res.empty()) if (!res.empty())
@@ -602,12 +545,12 @@ public:
} }
} }
renderSizeActivity(actFileTransfer, "%s DL"); showActivity(actFileTransfer, "%s MiB DL", "%.1f", MiB);
{ {
auto s = renderActivity(actOptimiseStore, "%s paths optimised"); auto s = renderActivity(actOptimiseStore, "%s paths optimised");
if (s != "") { if (s != "") {
s += fmt(", %s / %d inodes freed", renderSize(state.bytesLinked), state.filesLinked); s += fmt(", %.1f MiB / %d inodes freed", state.bytesLinked / MiB, state.filesLinked);
if (!res.empty()) if (!res.empty())
res += ", "; res += ", ";
res += s; res += s;
@@ -6,7 +6,6 @@
#include "nix/store/tests/libstore.hh" #include "nix/store/tests/libstore.hh"
#include "nix/util/tests/characterization.hh" #include "nix/util/tests/characterization.hh"
#include "nix/util/tests/json-characterization.hh"
namespace nix { namespace nix {
@@ -17,30 +16,12 @@ class ProtoTest : public CharacterizationTest
std::filesystem::path goldenMaster(std::string_view testStem) const override std::filesystem::path goldenMaster(std::string_view testStem) const override
{ {
return unitTestData / testStem; return unitTestData / (std::string{testStem + ".bin"});
} }
public: public:
Path storeDir = "/nix/store"; Path storeDir = "/nix/store";
StoreDirConfig store{storeDir}; StoreDirConfig store{storeDir};
/**
* Golden test for `T` JSON reading
*/
template<typename T>
void readJsonTest(PathView testStem, const T & expected)
{
nix::readJsonTest(*this, testStem, expected);
}
/**
* Golden test for `T` JSON write
*/
template<typename T>
void writeJsonTest(PathView testStem, const T & decoded)
{
nix::writeJsonTest(*this, testStem, decoded);
}
}; };
template<class Proto, const char * protocolDir> template<class Proto, const char * protocolDir>
@@ -53,7 +34,7 @@ public:
template<typename T> template<typename T>
void readProtoTest(PathView testStem, typename Proto::Version version, T expected) void readProtoTest(PathView testStem, typename Proto::Version version, T expected)
{ {
CharacterizationTest::readTest(std::string{testStem + ".bin"}, [&](const auto & encoded) { CharacterizationTest::readTest(testStem, [&](const auto & encoded) {
T got = ({ T got = ({
StringSource from{encoded}; StringSource from{encoded};
Proto::template Serialise<T>::read( Proto::template Serialise<T>::read(
@@ -74,7 +55,7 @@ public:
template<typename T> template<typename T>
void writeProtoTest(PathView testStem, typename Proto::Version version, const T & decoded) void writeProtoTest(PathView testStem, typename Proto::Version version, const T & decoded)
{ {
CharacterizationTest::writeTest(std::string{testStem + ".bin"}, [&]() { CharacterizationTest::writeTest(testStem, [&]() {
StringSink to; StringSink to;
Proto::template Serialise<T>::write( Proto::template Serialise<T>::write(
this->store, this->store,
@@ -88,25 +69,14 @@ public:
} }
}; };
#define VERSIONED_CHARACTERIZATION_TEST_NO_JSON(FIXTURE, NAME, STEM, VERSION, VALUE) \ #define VERSIONED_CHARACTERIZATION_TEST(FIXTURE, NAME, STEM, VERSION, VALUE) \
TEST_F(FIXTURE, NAME##_read) \ TEST_F(FIXTURE, NAME##_read) \
{ \ { \
readProtoTest(STEM, VERSION, VALUE); \ readProtoTest(STEM, VERSION, VALUE); \
} \ } \
TEST_F(FIXTURE, NAME##_write) \ TEST_F(FIXTURE, NAME##_write) \
{ \ { \
writeProtoTest(STEM, VERSION, VALUE); \ writeProtoTest(STEM, VERSION, VALUE); \
}
#define VERSIONED_CHARACTERIZATION_TEST(FIXTURE, NAME, STEM, VERSION, VALUE) \
VERSIONED_CHARACTERIZATION_TEST_NO_JSON(FIXTURE, NAME, STEM, VERSION, VALUE) \
TEST_F(FIXTURE, NAME##_json_read) \
{ \
readJsonTest(STEM, VALUE); \
} \
TEST_F(FIXTURE, NAME##_json_write) \
{ \
writeJsonTest(STEM, VALUE); \
} }
} // namespace nix } // namespace nix
+2 -11
View File
@@ -3,7 +3,6 @@
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "nix/util/json-utils.hh"
#include "nix/store/common-protocol.hh" #include "nix/store/common-protocol.hh"
#include "nix/store/common-protocol-impl.hh" #include "nix/store/common-protocol-impl.hh"
#include "nix/store/build-result.hh" #include "nix/store/build-result.hh"
@@ -23,7 +22,7 @@ public:
template<typename T> template<typename T>
void readProtoTest(PathView testStem, const T & expected) void readProtoTest(PathView testStem, const T & expected)
{ {
CharacterizationTest::readTest(std::string{testStem + ".bin"}, [&](const auto & encoded) { CharacterizationTest::readTest(testStem, [&](const auto & encoded) {
T got = ({ T got = ({
StringSource from{encoded}; StringSource from{encoded};
CommonProto::Serialise<T>::read(store, CommonProto::ReadConn{.from = from}); CommonProto::Serialise<T>::read(store, CommonProto::ReadConn{.from = from});
@@ -39,7 +38,7 @@ public:
template<typename T> template<typename T>
void writeProtoTest(PathView testStem, const T & decoded) void writeProtoTest(PathView testStem, const T & decoded)
{ {
CharacterizationTest::writeTest(std::string{testStem + ".bin"}, [&]() -> std::string { CharacterizationTest::writeTest(testStem, [&]() -> std::string {
StringSink to; StringSink to;
CommonProto::Serialise<T>::write(store, CommonProto::WriteConn{.to = to}, decoded); CommonProto::Serialise<T>::write(store, CommonProto::WriteConn{.to = to}, decoded);
return to.s; return to.s;
@@ -55,14 +54,6 @@ public:
TEST_F(CommonProtoTest, NAME##_write) \ TEST_F(CommonProtoTest, NAME##_write) \
{ \ { \
writeProtoTest(STEM, VALUE); \ writeProtoTest(STEM, VALUE); \
} \
TEST_F(CommonProtoTest, NAME##_json_read) \
{ \
readJsonTest(STEM, VALUE); \
} \
TEST_F(CommonProtoTest, NAME##_json_write) \
{ \
writeJsonTest(STEM, VALUE); \
} }
CHARACTERIZATION_TEST( CHARACTERIZATION_TEST(
@@ -1,26 +0,0 @@
[
{
"hash": {
"algorithm": "sha256",
"format": "base64",
"hash": "+Xc9Ll6mcPltwaewrk/BAQ56Y3G5T//wzhKUc0zrYu0="
},
"method": "text"
},
{
"hash": {
"algorithm": "sha1",
"format": "base64",
"hash": "gGemBoenViNZM3hiwqns/Fgzqwo="
},
"method": "flat"
},
{
"hash": {
"algorithm": "sha256",
"format": "base64",
"hash": "EMIJ+giQ/gLIWoxmPKjno3zHZrxbGymgzGGyZvZBIdM="
},
"method": "nar"
}
]
@@ -1,4 +0,0 @@
[
"sha256:15e3c560894cbb27085cf65b5a2ecb18488c999497f4531b6907a7581ce6d527!baz",
"sha256:6f869f9ea2823bda165e06076fd0de4366dead2c0e8d2dbbad277d4f15c373f5!quux"
]
@@ -1,11 +0,0 @@
[
null,
{
"hash": {
"algorithm": "sha1",
"format": "base64",
"hash": "gGemBoenViNZM3hiwqns/Fgzqwo="
},
"method": "flat"
}
]
@@ -1,4 +0,0 @@
[
null,
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo-bar"
]
@@ -1,13 +0,0 @@
[
{
"dependentRealisations": {
"sha256:6f869f9ea2823bda165e06076fd0de4366dead2c0e8d2dbbad277d4f15c373f5!quux": "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo"
},
"id": "sha256:15e3c560894cbb27085cf65b5a2ecb18488c999497f4531b6907a7581ce6d527!baz",
"outPath": "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo",
"signatures": [
"asdf",
"qwer"
]
}
]
@@ -1,17 +0,0 @@
[
{
"dependentRealisations": {},
"id": "sha256:15e3c560894cbb27085cf65b5a2ecb18488c999497f4531b6907a7581ce6d527!baz",
"outPath": "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo",
"signatures": []
},
{
"dependentRealisations": {},
"id": "sha256:15e3c560894cbb27085cf65b5a2ecb18488c999497f4531b6907a7581ce6d527!baz",
"outPath": "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo",
"signatures": [
"asdf",
"qwer"
]
}
]
@@ -1,22 +0,0 @@
[
[],
[
""
],
[
"",
"bar",
"foo"
],
[
[],
[
""
],
[
"",
"1",
"2"
]
]
]
@@ -1,4 +0,0 @@
[
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo",
"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo-bar"
]
@@ -1,7 +0,0 @@
[
"",
"hi",
"white rabbit",
"大白兔",
"oh no "
]
@@ -1,22 +0,0 @@
[
[],
[
""
],
[
"",
"foo",
"bar"
],
[
[],
[
""
],
[
"",
"1",
"2"
]
]
]
@@ -69,8 +69,7 @@
"outputChecks": { "outputChecks": {
"bin": { "bin": {
"disallowedReferences": [ "disallowedReferences": [
"/0nyw57wm2iicnm9rglvjmbci3ikmcp823czdqdzdcgsnnwqps71g", "/0nyw57wm2iicnm9rglvjmbci3ikmcp823czdqdzdcgsnnwqps71g"
"dev"
], ],
"disallowedRequisites": [ "disallowedRequisites": [
"/07f301yqyz8c6wf6bbbavb2q39j4n8kmcly1s09xadyhgy6x2wr8" "/07f301yqyz8c6wf6bbbavb2q39j4n8kmcly1s09xadyhgy6x2wr8"
@@ -85,8 +84,7 @@
"/164j69y6zir9z0339n8pjigg3rckinlr77bxsavzizdaaljb7nh9" "/164j69y6zir9z0339n8pjigg3rckinlr77bxsavzizdaaljb7nh9"
], ],
"allowedRequisites": [ "allowedRequisites": [
"/0nr45p69vn6izw9446wsh9bng9nndhvn19kpsm4n96a5mycw0s4z", "/0nr45p69vn6izw9446wsh9bng9nndhvn19kpsm4n96a5mycw0s4z"
"bin"
] ]
} }
}, },
@@ -11,9 +11,9 @@
"__sandboxProfile": "sandcastle", "__sandboxProfile": "sandcastle",
"allowSubstitutes": "", "allowSubstitutes": "",
"allowedReferences": "/164j69y6zir9z0339n8pjigg3rckinlr77bxsavzizdaaljb7nh9", "allowedReferences": "/164j69y6zir9z0339n8pjigg3rckinlr77bxsavzizdaaljb7nh9",
"allowedRequisites": "/0nr45p69vn6izw9446wsh9bng9nndhvn19kpsm4n96a5mycw0s4z bin", "allowedRequisites": "/0nr45p69vn6izw9446wsh9bng9nndhvn19kpsm4n96a5mycw0s4z",
"builder": "/bin/bash", "builder": "/bin/bash",
"disallowedReferences": "/0nyw57wm2iicnm9rglvjmbci3ikmcp823czdqdzdcgsnnwqps71g dev", "disallowedReferences": "/0nyw57wm2iicnm9rglvjmbci3ikmcp823czdqdzdcgsnnwqps71g",
"disallowedRequisites": "/07f301yqyz8c6wf6bbbavb2q39j4n8kmcly1s09xadyhgy6x2wr8", "disallowedRequisites": "/07f301yqyz8c6wf6bbbavb2q39j4n8kmcly1s09xadyhgy6x2wr8",
"exportReferencesGraph": "refs1 /164j69y6zir9z0339n8pjigg3rckinlr77bxsavzizdaaljb7nh9 refs2 /nix/store/qnml92yh97a6fbrs2m5qg5cqlc8vni58-bar.drv", "exportReferencesGraph": "refs1 /164j69y6zir9z0339n8pjigg3rckinlr77bxsavzizdaaljb7nh9 refs2 /nix/store/qnml92yh97a6fbrs2m5qg5cqlc8vni58-bar.drv",
"impureEnvVars": "UNICORN", "impureEnvVars": "UNICORN",
@@ -23,12 +23,10 @@
"/164j69y6zir9z0339n8pjigg3rckinlr77bxsavzizdaaljb7nh9" "/164j69y6zir9z0339n8pjigg3rckinlr77bxsavzizdaaljb7nh9"
], ],
"allowedRequisites": [ "allowedRequisites": [
"/0nr45p69vn6izw9446wsh9bng9nndhvn19kpsm4n96a5mycw0s4z", "/0nr45p69vn6izw9446wsh9bng9nndhvn19kpsm4n96a5mycw0s4z"
"bin"
], ],
"disallowedReferences": [ "disallowedReferences": [
"/0nyw57wm2iicnm9rglvjmbci3ikmcp823czdqdzdcgsnnwqps71g", "/0nyw57wm2iicnm9rglvjmbci3ikmcp823czdqdzdcgsnnwqps71g"
"dev"
], ],
"disallowedRequisites": [ "disallowedRequisites": [
"/07f301yqyz8c6wf6bbbavb2q39j4n8kmcly1s09xadyhgy6x2wr8" "/07f301yqyz8c6wf6bbbavb2q39j4n8kmcly1s09xadyhgy6x2wr8"
@@ -23,8 +23,7 @@
"allowedReferences": null, "allowedReferences": null,
"allowedRequisites": null, "allowedRequisites": null,
"disallowedReferences": [ "disallowedReferences": [
"/0nyw57wm2iicnm9rglvjmbci3ikmcp823czdqdzdcgsnnwqps71g", "/0nyw57wm2iicnm9rglvjmbci3ikmcp823czdqdzdcgsnnwqps71g"
"dev"
], ],
"disallowedRequisites": [ "disallowedRequisites": [
"/07f301yqyz8c6wf6bbbavb2q39j4n8kmcly1s09xadyhgy6x2wr8" "/07f301yqyz8c6wf6bbbavb2q39j4n8kmcly1s09xadyhgy6x2wr8"
@@ -47,8 +46,7 @@
"/164j69y6zir9z0339n8pjigg3rckinlr77bxsavzizdaaljb7nh9" "/164j69y6zir9z0339n8pjigg3rckinlr77bxsavzizdaaljb7nh9"
], ],
"allowedRequisites": [ "allowedRequisites": [
"/0nr45p69vn6izw9446wsh9bng9nndhvn19kpsm4n96a5mycw0s4z", "/0nr45p69vn6izw9446wsh9bng9nndhvn19kpsm4n96a5mycw0s4z"
"bin"
], ],
"disallowedReferences": [], "disallowedReferences": [],
"disallowedRequisites": [], "disallowedRequisites": [],
@@ -5,9 +5,9 @@
], ],
"builder": "/bin/bash", "builder": "/bin/bash",
"env": { "env": {
"bin": "/nix/store/cnpasdljgkhnwaf78cf3qygcp4qbki1c-advanced-attributes-structured-attrs-bin", "bin": "/nix/store/33qms3h55wlaspzba3brlzlrm8m2239g-advanced-attributes-structured-attrs-bin",
"dev": "/nix/store/ijq6mwpa9jbnpnl33qldfqihrr38kprx-advanced-attributes-structured-attrs-dev", "dev": "/nix/store/wyfgwsdi8rs851wmy1xfzdxy7y5vrg5l-advanced-attributes-structured-attrs-dev",
"out": "/nix/store/h1vh648d3p088kdimy0r8ngpfx7c3nzw-advanced-attributes-structured-attrs" "out": "/nix/store/7cxy4zx1vqc885r4jl2l64pymqbdmhii-advanced-attributes-structured-attrs"
}, },
"inputs": { "inputs": {
"drvs": { "drvs": {
@@ -33,13 +33,13 @@
"name": "advanced-attributes-structured-attrs", "name": "advanced-attributes-structured-attrs",
"outputs": { "outputs": {
"bin": { "bin": {
"path": "cnpasdljgkhnwaf78cf3qygcp4qbki1c-advanced-attributes-structured-attrs-bin" "path": "33qms3h55wlaspzba3brlzlrm8m2239g-advanced-attributes-structured-attrs-bin"
}, },
"dev": { "dev": {
"path": "ijq6mwpa9jbnpnl33qldfqihrr38kprx-advanced-attributes-structured-attrs-dev" "path": "wyfgwsdi8rs851wmy1xfzdxy7y5vrg5l-advanced-attributes-structured-attrs-dev"
}, },
"out": { "out": {
"path": "h1vh648d3p088kdimy0r8ngpfx7c3nzw-advanced-attributes-structured-attrs" "path": "7cxy4zx1vqc885r4jl2l64pymqbdmhii-advanced-attributes-structured-attrs"
} }
}, },
"structuredAttrs": { "structuredAttrs": {
@@ -66,8 +66,7 @@
"outputChecks": { "outputChecks": {
"bin": { "bin": {
"disallowedReferences": [ "disallowedReferences": [
"/nix/store/r5cff30838majxk5mp3ip2diffi8vpaj-bar", "/nix/store/r5cff30838majxk5mp3ip2diffi8vpaj-bar"
"dev"
], ],
"disallowedRequisites": [ "disallowedRequisites": [
"/nix/store/9b61w26b4avv870dw0ymb6rw4r1hzpws-bar-dev" "/nix/store/9b61w26b4avv870dw0ymb6rw4r1hzpws-bar-dev"
@@ -82,8 +81,7 @@
"/nix/store/p0hax2lzvjpfc2gwkk62xdglz0fcqfzn-foo" "/nix/store/p0hax2lzvjpfc2gwkk62xdglz0fcqfzn-foo"
], ],
"allowedRequisites": [ "allowedRequisites": [
"/nix/store/z0rjzy29v9k5qa4nqpykrbzirj7sd43v-foo-dev", "/nix/store/z0rjzy29v9k5qa4nqpykrbzirj7sd43v-foo-dev"
"bin"
] ]
} }
}, },
@@ -11,14 +11,14 @@
"__sandboxProfile": "sandcastle", "__sandboxProfile": "sandcastle",
"allowSubstitutes": "", "allowSubstitutes": "",
"allowedReferences": "/nix/store/p0hax2lzvjpfc2gwkk62xdglz0fcqfzn-foo", "allowedReferences": "/nix/store/p0hax2lzvjpfc2gwkk62xdglz0fcqfzn-foo",
"allowedRequisites": "/nix/store/z0rjzy29v9k5qa4nqpykrbzirj7sd43v-foo-dev bin", "allowedRequisites": "/nix/store/z0rjzy29v9k5qa4nqpykrbzirj7sd43v-foo-dev",
"builder": "/bin/bash", "builder": "/bin/bash",
"disallowedReferences": "/nix/store/r5cff30838majxk5mp3ip2diffi8vpaj-bar dev", "disallowedReferences": "/nix/store/r5cff30838majxk5mp3ip2diffi8vpaj-bar",
"disallowedRequisites": "/nix/store/9b61w26b4avv870dw0ymb6rw4r1hzpws-bar-dev", "disallowedRequisites": "/nix/store/9b61w26b4avv870dw0ymb6rw4r1hzpws-bar-dev",
"exportReferencesGraph": "refs1 /nix/store/p0hax2lzvjpfc2gwkk62xdglz0fcqfzn-foo refs2 /nix/store/vj2i49jm2868j2fmqvxm70vlzmzvgv14-bar.drv", "exportReferencesGraph": "refs1 /nix/store/p0hax2lzvjpfc2gwkk62xdglz0fcqfzn-foo refs2 /nix/store/vj2i49jm2868j2fmqvxm70vlzmzvgv14-bar.drv",
"impureEnvVars": "UNICORN", "impureEnvVars": "UNICORN",
"name": "advanced-attributes", "name": "advanced-attributes",
"out": "/nix/store/ymqmybkq5j4nd1xplw6ccdpbjnfi017v-advanced-attributes", "out": "/nix/store/wyhpwd748pns4k7svh48wdrc8kvjk0ra-advanced-attributes",
"preferLocalBuild": "1", "preferLocalBuild": "1",
"requiredSystemFeatures": "rainbow uid-range", "requiredSystemFeatures": "rainbow uid-range",
"system": "my-system" "system": "my-system"
@@ -47,7 +47,7 @@
"name": "advanced-attributes", "name": "advanced-attributes",
"outputs": { "outputs": {
"out": { "out": {
"path": "ymqmybkq5j4nd1xplw6ccdpbjnfi017v-advanced-attributes" "path": "wyhpwd748pns4k7svh48wdrc8kvjk0ra-advanced-attributes"
} }
}, },
"system": "my-system", "system": "my-system",
@@ -23,12 +23,10 @@
"/nix/store/p0hax2lzvjpfc2gwkk62xdglz0fcqfzn-foo" "/nix/store/p0hax2lzvjpfc2gwkk62xdglz0fcqfzn-foo"
], ],
"allowedRequisites": [ "allowedRequisites": [
"/nix/store/z0rjzy29v9k5qa4nqpykrbzirj7sd43v-foo-dev", "/nix/store/z0rjzy29v9k5qa4nqpykrbzirj7sd43v-foo-dev"
"bin"
], ],
"disallowedReferences": [ "disallowedReferences": [
"/nix/store/r5cff30838majxk5mp3ip2diffi8vpaj-bar", "/nix/store/r5cff30838majxk5mp3ip2diffi8vpaj-bar"
"dev"
], ],
"disallowedRequisites": [ "disallowedRequisites": [
"/nix/store/9b61w26b4avv870dw0ymb6rw4r1hzpws-bar-dev" "/nix/store/9b61w26b4avv870dw0ymb6rw4r1hzpws-bar-dev"
@@ -23,8 +23,7 @@
"allowedReferences": null, "allowedReferences": null,
"allowedRequisites": null, "allowedRequisites": null,
"disallowedReferences": [ "disallowedReferences": [
"/nix/store/r5cff30838majxk5mp3ip2diffi8vpaj-bar", "/nix/store/r5cff30838majxk5mp3ip2diffi8vpaj-bar"
"dev"
], ],
"disallowedRequisites": [ "disallowedRequisites": [
"/nix/store/9b61w26b4avv870dw0ymb6rw4r1hzpws-bar-dev" "/nix/store/9b61w26b4avv870dw0ymb6rw4r1hzpws-bar-dev"
@@ -47,8 +46,7 @@
"/nix/store/p0hax2lzvjpfc2gwkk62xdglz0fcqfzn-foo" "/nix/store/p0hax2lzvjpfc2gwkk62xdglz0fcqfzn-foo"
], ],
"allowedRequisites": [ "allowedRequisites": [
"/nix/store/z0rjzy29v9k5qa4nqpykrbzirj7sd43v-foo-dev", "/nix/store/z0rjzy29v9k5qa4nqpykrbzirj7sd43v-foo-dev"
"bin"
], ],
"disallowedReferences": [], "disallowedReferences": [],
"disallowedRequisites": [], "disallowedRequisites": [],
+2 -10
View File
@@ -9,17 +9,9 @@
}, },
"compression": "xz", "compression": "xz",
"deriver": "/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar.drv", "deriver": "/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar.drv",
"downloadHash": { "downloadHash": "sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=",
"algorithm": "sha256",
"format": "base64",
"hash": "FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="
},
"downloadSize": 4029176, "downloadSize": 4029176,
"narHash": { "narHash": "sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=",
"algorithm": "sha256",
"format": "base64",
"hash": "FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="
},
"narSize": 34878, "narSize": 34878,
"references": [ "references": [
"/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar", "/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar",
+1 -5
View File
@@ -7,11 +7,7 @@
}, },
"method": "nar" "method": "nar"
}, },
"narHash": { "narHash": "sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=",
"algorithm": "sha256",
"format": "base64",
"hash": "FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="
},
"narSize": 34878, "narSize": 34878,
"references": [ "references": [
"/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar", "/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar",
@@ -1,11 +1,7 @@
{ {
"ca": null, "ca": null,
"deriver": null, "deriver": null,
"narHash": { "narHash": "sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=",
"algorithm": "sha256",
"format": "base64",
"hash": "FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="
},
"narSize": 0, "narSize": 0,
"references": [], "references": [],
"registrationTime": null, "registrationTime": null,
@@ -1,10 +1,6 @@
{ {
"ca": null, "ca": null,
"narHash": { "narHash": "sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=",
"algorithm": "sha256",
"format": "base64",
"hash": "FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="
},
"narSize": 0, "narSize": 0,
"references": [], "references": [],
"version": 2 "version": 2
@@ -8,11 +8,7 @@
"method": "nar" "method": "nar"
}, },
"deriver": "/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar.drv", "deriver": "/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar.drv",
"narHash": { "narHash": "sha256-FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc=",
"algorithm": "sha256",
"format": "base64",
"hash": "FePFYIlMuycIXPZbWi7LGEiMmZSX9FMbaQenWBzm1Sc="
},
"narSize": 34878, "narSize": 34878,
"references": [ "references": [
"/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar", "/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar",
Loaded 100 of 205 files, more files were not shown because too many files have changed in this diff. Show more