Compare commits
1
Commits
2
..
json-schema-fso
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4b62a646a |
No files matched your search
@@ -1,14 +0,0 @@
|
||||
# Disable CodeRabbit auto-review to prevent verbose comments on PRs.
|
||||
# When enabled: false, CodeRabbit won't attempt reviews and won't post
|
||||
# "Review skipped" or other automated comments.
|
||||
reviews:
|
||||
auto_review:
|
||||
enabled: false
|
||||
review_status: false
|
||||
high_level_summary: false
|
||||
poem: false
|
||||
sequence_diagrams: false
|
||||
changed_files_summary: false
|
||||
tools:
|
||||
github-checks:
|
||||
enabled: false
|
||||
@@ -16,17 +16,13 @@ inputs:
|
||||
install_url:
|
||||
description: "URL of the Nix installer"
|
||||
required: false
|
||||
default: "https://releases.nixos.org/nix/nix-2.32.1/install"
|
||||
default: "https://releases.nixos.org/nix/nix-2.30.2/install"
|
||||
tarball_url:
|
||||
description: "URL of the Nix tarball to use with the experimental installer"
|
||||
required: false
|
||||
github_token:
|
||||
description: "Github token"
|
||||
required: true
|
||||
use_cache:
|
||||
description: "Whether to setup magic-nix-cache"
|
||||
default: true
|
||||
required: false
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
@@ -122,10 +118,3 @@ runs:
|
||||
source-url: ${{ inputs.experimental-installer-version != 'latest' && 'https://artifacts.nixos.org/experimental-installer/tag/${{ inputs.experimental-installer-version }}/${{ env.EXPERIMENTAL_INSTALLER_ARTIFACT }}' || '' }}
|
||||
nix-package-url: ${{ inputs.dogfood == 'true' && steps.download-nix-installer.outputs.tarball-path || (inputs.tarball_url || '') }}
|
||||
extra-conf: ${{ inputs.extra_nix_config }}
|
||||
- uses: DeterminateSystems/magic-nix-cache-action@565684385bcd71bad329742eefe8d12f2e765b39 # v13
|
||||
if: ${{ inputs.use_cache == 'true' }}
|
||||
with:
|
||||
diagnostic-endpoint: ''
|
||||
use-flakehub: false
|
||||
use-gha-cache: true
|
||||
source-revision: 92d9581367be2233c2d5714a2640e1339f4087d8 # main
|
||||
+10
-12
@@ -14,10 +14,6 @@ on:
|
||||
default: true
|
||||
type: boolean
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
permissions: read-all
|
||||
|
||||
jobs:
|
||||
@@ -33,7 +29,6 @@ jobs:
|
||||
extra_nix_config:
|
||||
experimental-features = nix-command flakes
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
use_cache: false
|
||||
- run: nix flake show --all-systems --json
|
||||
|
||||
pre-commit-checks:
|
||||
@@ -46,6 +41,7 @@ jobs:
|
||||
dogfood: ${{ github.event_name == 'workflow_dispatch' && inputs.dogfood || github.event_name != 'workflow_dispatch' }}
|
||||
extra_nix_config: experimental-features = nix-command flakes
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
- uses: DeterminateSystems/magic-nix-cache-action@main
|
||||
- run: ./ci/gha/tests/pre-commit-checks
|
||||
|
||||
basic-checks:
|
||||
@@ -96,6 +92,7 @@ jobs:
|
||||
dogfood: ${{ github.event_name == 'workflow_dispatch' && inputs.dogfood || github.event_name != 'workflow_dispatch' }}
|
||||
# The sandbox would otherwise be disabled by default on Darwin
|
||||
extra_nix_config: "sandbox = true"
|
||||
- uses: DeterminateSystems/magic-nix-cache-action@main
|
||||
# Since ubuntu 22.30, unprivileged usernamespaces are no longer allowed to map to the root user:
|
||||
# https://ubuntu.com/blog/ubuntu-23-10-restricted-unprivileged-user-namespaces
|
||||
- run: sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
|
||||
@@ -174,7 +171,7 @@ jobs:
|
||||
echo "installer-url=file://$GITHUB_WORKSPACE/out" >> "$GITHUB_OUTPUT"
|
||||
TARBALL_PATH="$(find "$GITHUB_WORKSPACE/out" -name 'nix*.tar.xz' -print | head -n 1)"
|
||||
echo "tarball-path=file://$TARBALL_PATH" >> "$GITHUB_OUTPUT"
|
||||
- uses: cachix/install-nix-action@c134e4c9e34bac6cab09cf239815f9339aaaf84e # v31.5.1
|
||||
- uses: cachix/install-nix-action@v31
|
||||
if: ${{ !matrix.experimental-installer }}
|
||||
with:
|
||||
install_url: ${{ format('{0}/install', steps.installer-tarball-url.outputs.installer-url) }}
|
||||
@@ -230,13 +227,12 @@ jobs:
|
||||
- uses: actions/checkout@v5
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- uses: ./.github/actions/install-nix-action
|
||||
- uses: cachix/install-nix-action@v31
|
||||
with:
|
||||
dogfood: false
|
||||
extra_nix_config: |
|
||||
experimental-features = flakes nix-command
|
||||
- run: echo NIX_VERSION="$(nix eval .\#nix.version | tr -d \")" >> $GITHUB_ENV
|
||||
- run: nix build .#dockerImage -L
|
||||
install_url: https://releases.nixos.org/nix/nix-2.20.3/install
|
||||
- uses: DeterminateSystems/magic-nix-cache-action@main
|
||||
- run: echo NIX_VERSION="$(nix --experimental-features 'nix-command flakes' eval .\#nix.version | tr -d \")" >> $GITHUB_ENV
|
||||
- run: nix --experimental-features 'nix-command flakes' build .#dockerImage -L
|
||||
- run: docker load -i ./result/image.tar.gz
|
||||
- run: docker tag nix:$NIX_VERSION ${{ secrets.DOCKERHUB_USERNAME }}/nix:$NIX_VERSION
|
||||
- run: docker tag nix:$NIX_VERSION ${{ secrets.DOCKERHUB_USERNAME }}/nix:master
|
||||
@@ -293,6 +289,7 @@ jobs:
|
||||
extra_nix_config:
|
||||
experimental-features = nix-command flakes
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
- uses: DeterminateSystems/magic-nix-cache-action@main
|
||||
- run: nix build -L --out-link ./new-nix && PATH=$(pwd)/new-nix/bin:$PATH MAX_FLAKES=25 flake-regressions/eval-all.sh
|
||||
|
||||
profile_build:
|
||||
@@ -313,6 +310,7 @@ jobs:
|
||||
extra_nix_config: |
|
||||
experimental-features = flakes nix-command ca-derivations impure-derivations
|
||||
max-jobs = 1
|
||||
- uses: DeterminateSystems/magic-nix-cache-action@main
|
||||
- run: |
|
||||
nix build -L --file ./ci/gha/profile-build buildTimeReport --out-link build-time-report.md
|
||||
cat build-time-report.md >> $GITHUB_STEP_SUMMARY
|
||||
@@ -34,12 +34,8 @@ mkMesonDerivation (finalAttrs: {
|
||||
(fileset.unions [
|
||||
../../.version
|
||||
# For example JSON
|
||||
../../src/libutil-tests/data/memory-source-accessor
|
||||
../../src/libutil-tests/data/hash
|
||||
../../src/libstore-tests/data/content-address
|
||||
../../src/libstore-tests/data/store-path
|
||||
../../src/libstore-tests/data/derived-path
|
||||
../../src/libstore-tests/data/path-info
|
||||
../../src/libstore-tests/data/nar-info
|
||||
# Too many different types of files to filter for now
|
||||
../../doc/manual
|
||||
./.
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
---
|
||||
synopsis: "S3 URLs now support object versioning via versionId parameter"
|
||||
prs: [14274]
|
||||
issues: [13955]
|
||||
---
|
||||
|
||||
S3 URLs now support a `versionId` query parameter to fetch specific versions
|
||||
of objects from S3 buckets with versioning enabled. This allows pinning to
|
||||
exact object versions for reproducibility and protection against unexpected
|
||||
changes:
|
||||
|
||||
```
|
||||
s3://bucket/key?region=us-east-1&versionId=abc123def456
|
||||
```
|
||||
@@ -117,12 +117,10 @@
|
||||
- [Architecture and Design](architecture/architecture.md)
|
||||
- [Formats and Protocols](protocols/index.md)
|
||||
- [JSON Formats](protocols/json/index.md)
|
||||
- [File System Object](protocols/json/file-system-object.md)
|
||||
- [Hash](protocols/json/hash.md)
|
||||
- [Content Address](protocols/json/content-address.md)
|
||||
- [Store Path](protocols/json/store-path.md)
|
||||
- [Store Object Info](protocols/json/store-object-info.md)
|
||||
- [Derivation](protocols/json/derivation.md)
|
||||
- [Deriving Path](protocols/json/deriving-path.md)
|
||||
- [Serving Tarball Flakes](protocols/tarball-fetcher.md)
|
||||
- [Store Path Specification](protocols/store-path.md)
|
||||
- [Nix Archive (NAR) Format](protocols/nix-archive.md)
|
||||
|
||||
@@ -48,7 +48,8 @@ The behaviour of the collector is also influenced by the
|
||||
configuration file.
|
||||
|
||||
By default, the collector prints the total number of freed bytes when it
|
||||
finishes (or when it is interrupted).
|
||||
finishes (or when it is interrupted). With `--print-dead`, it prints the
|
||||
number of bytes that would be freed.
|
||||
|
||||
{{#include ./opt-common.md}}
|
||||
|
||||
|
||||
@@ -240,9 +240,3 @@ $ configurePhase
|
||||
$ ninja src/external-api-docs/html
|
||||
$ xdg-open src/external-api-docs/html/index.html
|
||||
```
|
||||
|
||||
If you use direnv, or otherwise want to run `configurePhase` in a transient shell, use:
|
||||
|
||||
```bash
|
||||
nix-shell -A devShells.x86_64-linux.native-clangStdenv --command 'appendToVar mesonFlags "-Ddoc-gen=true"; mesonConfigurePhase'
|
||||
```
|
||||
@@ -3,21 +3,19 @@
|
||||
To run the latest stable release of Nix with Docker run the following command:
|
||||
|
||||
```console
|
||||
$ docker run -ti docker.io/nixos/nix
|
||||
Unable to find image 'docker.io/nixos/nix:latest' locally
|
||||
latest: Pulling from docker.io/nixos/nix
|
||||
$ docker run -ti ghcr.io/nixos/nix
|
||||
Unable to find image 'ghcr.io/nixos/nix:latest' locally
|
||||
latest: Pulling from ghcr.io/nixos/nix
|
||||
5843afab3874: Pull complete
|
||||
b52bf13f109c: Pull complete
|
||||
1e2415612aa3: Pull complete
|
||||
Digest: sha256:27f6e7f60227e959ee7ece361f75d4844a40e1cc6878b6868fe30140420031ff
|
||||
Status: Downloaded newer image for docker.io/nixos/nix:latest
|
||||
Status: Downloaded newer image for ghcr.io/nixos/nix:latest
|
||||
35ca4ada6e96:/# nix --version
|
||||
nix (Nix) 2.3.12
|
||||
35ca4ada6e96:/# exit
|
||||
```
|
||||
|
||||
> If you want the latest pre-release you can use ghcr.io/nixos/nix and view them at https://github.com/nixos/nix/pkgs/container/nix
|
||||
|
||||
# What is included in Nix's Docker image?
|
||||
|
||||
The official Docker image is created using `pkgs.dockerTools.buildLayeredImage`
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
{{#include content-address-v1-fixed.md}}
|
||||
|
||||
## Examples
|
||||
|
||||
### [Text](@docroot@/store/store-object/content-address.html#method-text) method
|
||||
|
||||
```json
|
||||
{{#include schema/content-address-v1/text.json}}
|
||||
```
|
||||
|
||||
### [Nix Archive](@docroot@/store/store-object/content-address.html#method-nix-archive) method
|
||||
|
||||
```json
|
||||
{{#include schema/content-address-v1/nar.json}}
|
||||
```
|
||||
|
||||
<!-- need to convert YAML to JSON first
|
||||
## Raw Schema
|
||||
|
||||
[JSON Schema for Hash v1](schema/content-address-v1.json)
|
||||
-->
|
||||
@@ -1,6 +1,6 @@
|
||||
{{#include derivation-v3-fixed.md}}
|
||||
|
||||
<!-- need to convert YAML to JSON first
|
||||
<!--
|
||||
## Raw Schema
|
||||
|
||||
[JSON Schema for Derivation v3](schema/derivation-v3.json)
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
{{#include deriving-path-v1-fixed.md}}
|
||||
|
||||
## Examples
|
||||
|
||||
### Constant
|
||||
|
||||
```json
|
||||
{{#include schema/deriving-path-v1/single_opaque.json}}
|
||||
```
|
||||
|
||||
### Output of static derivation
|
||||
|
||||
```json
|
||||
{{#include schema/deriving-path-v1/single_built.json}}
|
||||
```
|
||||
|
||||
### Output of dynamic derivation
|
||||
|
||||
```json
|
||||
{{#include schema/deriving-path-v1/single_built_built.json}}
|
||||
```
|
||||
@@ -0,0 +1,21 @@
|
||||
{{#include file-system-object-v1-fixed.md}}
|
||||
|
||||
## Examples
|
||||
|
||||
### Simple
|
||||
|
||||
```json
|
||||
{{#include schema/file-system-object-v1/simple.json}}
|
||||
```
|
||||
|
||||
### Complex
|
||||
|
||||
```json
|
||||
{{#include schema/file-system-object-v1/complex.json}}
|
||||
```
|
||||
|
||||
<!--
|
||||
## Raw Schema
|
||||
|
||||
[JSON Schema for File System Object v1](schema/file-system-object-v1.json)
|
||||
-->
|
||||
@@ -12,6 +12,4 @@ s/\\`/`/g
|
||||
# As we have more such relative links, more replacements of this nature
|
||||
# should appear below.
|
||||
s^\(./hash-v1.yaml\)\?#/$defs/algorithm^[JSON format for `Hash`](./hash.html#algorithm)^g
|
||||
s^\(./hash-v1.yaml\)^[JSON format for `Hash`](./hash.html)^g
|
||||
s^\(./content-address-v1.yaml\)\?#/$defs/method^[JSON format for `ContentAddress`](./content-address.html#method)^g
|
||||
s^\(./content-address-v1.yaml\)^[JSON format for `ContentAddress`](./content-address.html)^g
|
||||
s^#/\$defs/\(regular\|symlink\|directory\)^In this schema^g
|
||||
@@ -26,7 +26,7 @@
|
||||
{{#include schema/hash-v1/blake3-base64.json}}
|
||||
```
|
||||
|
||||
<!-- need to convert YAML to JSON first
|
||||
<!--
|
||||
## Raw Schema
|
||||
|
||||
[JSON Schema for Hash v1](schema/hash-v1.json)
|
||||
|
||||
@@ -9,12 +9,9 @@ json_schema_for_humans = find_program('generate-schema-doc', required : false)
|
||||
json_schema_config = files('json-schema-for-humans-config.yaml')
|
||||
|
||||
schemas = [
|
||||
'file-system-object-v1',
|
||||
'hash-v1',
|
||||
'content-address-v1',
|
||||
'store-path-v1',
|
||||
'store-object-info-v1',
|
||||
'derivation-v3',
|
||||
'deriving-path-v1',
|
||||
]
|
||||
|
||||
schema_files = files()
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
../../../../../../src/libstore-tests/data/content-address
|
||||
@@ -1,55 +0,0 @@
|
||||
"$schema": "http://json-schema.org/draft-04/schema"
|
||||
"$id": "https://nix.dev/manual/nix/latest/protocols/json/schema/content-address-v1.json"
|
||||
title: Content Address
|
||||
description: |
|
||||
This schema describes the JSON representation of Nix's `ContentAddress` type, which conveys information about [content-addressing store objects](@docroot@/store/store-object/content-address.md).
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> For current methods of content addressing, this data type is a bit suspicious, because it is neither simply a content address of a file system object (the `method` is richer), nor simply a content address of a store object (the `hash` doesn't account for the references).
|
||||
> It should thus only be used in contexts where the references are also known / otherwise made tamper-resistant.
|
||||
|
||||
<!--
|
||||
TODO currently `ContentAddress` is used in both of these, and so same rationale applies, but actually in both cases the JSON is currently ad-hoc.
|
||||
That will be fixed, and as each is fixed, the example (along with a more precise link to the field in question) should be become part of the above note, so what is is saying is more clear.
|
||||
|
||||
> For example:
|
||||
|
||||
> - Fixed outputs of derivations are not allowed to have any references, so an empty reference set is statically known by assumption.
|
||||
|
||||
> - [Store object info](./store-object-info.md) includes the set of references along side the (optional) content address.
|
||||
|
||||
> This data type is thus safely used in both of these contexts.
|
||||
|
||||
-->
|
||||
|
||||
type: object
|
||||
properties:
|
||||
method:
|
||||
"$ref": "#/$defs/method"
|
||||
hash:
|
||||
title: Content Address
|
||||
description: |
|
||||
This would be the content-address itself.
|
||||
|
||||
For all current methods, this is just a content address of the file system object of the store object, [as described in the store chapter](@docroot@/store/file-system-object/content-address.md), and not of the store object as a whole.
|
||||
In particular, the references of the store object are *not* taken into account with this hash (and currently-supported methods).
|
||||
"$ref": "./hash-v1.yaml"
|
||||
required:
|
||||
- method
|
||||
- hash
|
||||
additionalProperties: false
|
||||
"$defs":
|
||||
method:
|
||||
type: string
|
||||
enum: [flat, nar, text, git]
|
||||
title: Content-Addressing Method
|
||||
description: |
|
||||
A string representing the [method](@docroot@/store/store-object/content-address.md) of content addressing that is chosen.
|
||||
|
||||
Valid method strings are:
|
||||
|
||||
- [`flat`](@docroot@/store/store-object/content-address.md#method-flat) (provided the contents are a single file)
|
||||
- [`nar`](@docroot@/store/store-object/content-address.md#method-nix-archive)
|
||||
- [`text`](@docroot@/store/store-object/content-address.md#method-text)
|
||||
- [`git`](@docroot@/store/store-object/content-address.md#method-git)
|
||||
@@ -1,5 +1,5 @@
|
||||
"$schema": "http://json-schema.org/draft-04/schema"
|
||||
"$id": "https://nix.dev/manual/nix/latest/protocols/json/schema/derivation-v3.json"
|
||||
"$schema": http://json-schema.org/draft-04/schema#
|
||||
"$id": https://nix.dev/manual/nix/latest/protocols/json/schema/derivation-v3.json
|
||||
title: Derivation
|
||||
description: |
|
||||
Experimental JSON representation of a Nix derivation (version 3).
|
||||
@@ -85,7 +85,7 @@ properties:
|
||||
> ]
|
||||
> ```
|
||||
items:
|
||||
$ref: "store-path-v1.yaml"
|
||||
type: string
|
||||
|
||||
inputDrvs:
|
||||
type: object
|
||||
@@ -103,15 +103,6 @@ properties:
|
||||
> ```
|
||||
>
|
||||
> specifies that this derivation depends on the `dev` output of `curl`, and the `out` output of `unzip`.
|
||||
patternProperties:
|
||||
"^[0123456789abcdfghijklmnpqrsvwxyz]{32}-.+\\.drv$":
|
||||
title: Store Path
|
||||
description: |
|
||||
A store path to a derivation, mapped to the outputs of that derivation.
|
||||
oneOf:
|
||||
- "$ref": "#/$defs/outputNames"
|
||||
- "$ref": "#/$defs/dynamicOutputs"
|
||||
additionalProperties: false
|
||||
|
||||
system:
|
||||
type: string
|
||||
@@ -157,16 +148,25 @@ properties:
|
||||
type: object
|
||||
properties:
|
||||
path:
|
||||
$ref: "store-path-v1.yaml"
|
||||
type: string
|
||||
title: Output path
|
||||
description: |
|
||||
The output path, if known in advance.
|
||||
|
||||
method:
|
||||
"$ref": "./content-address-v1.yaml#/$defs/method"
|
||||
type: string
|
||||
title: Content addressing method
|
||||
enum: [flat, nar, text, git]
|
||||
description: |
|
||||
For an output which will be [content addressed](@docroot@/store/derivation/outputs/content-address.md), a string representing the [method](@docroot@/store/store-object/content-address.md) of content addressing that is chosen.
|
||||
See the linked original definition for further details.
|
||||
|
||||
Valid method strings are:
|
||||
|
||||
- [`flat`](@docroot@/store/store-object/content-address.md#method-flat)
|
||||
- [`nar`](@docroot@/store/store-object/content-address.md#method-nix-archive)
|
||||
- [`text`](@docroot@/store/store-object/content-address.md#method-text)
|
||||
- [`git`](@docroot@/store/store-object/content-address.md#method-git)
|
||||
|
||||
hashAlgo:
|
||||
title: Hash algorithm
|
||||
"$ref": "./hash-v1.yaml#/$defs/algorithm"
|
||||
@@ -176,28 +176,3 @@ properties:
|
||||
title: Expected hash value
|
||||
description: |
|
||||
For fixed-output derivations, the expected content hash in base-16.
|
||||
|
||||
outputName:
|
||||
type: string
|
||||
title: Output name
|
||||
description: Name of the derivation output to depend on
|
||||
|
||||
outputNames:
|
||||
type: array
|
||||
title: Output Names
|
||||
description: Set of names of derivation outputs to depend on
|
||||
items:
|
||||
"$ref": "#/$defs/outputName"
|
||||
|
||||
dynamicOutputs:
|
||||
type: object
|
||||
title: Dynamic Outputs
|
||||
description: |
|
||||
**Experimental feature**: [`dynamic-derivations`](@docroot@/development/experimental-features.md#xp-feature-dynamic-derivations)
|
||||
|
||||
This recursive data type allows for depending on outputs of outputs.
|
||||
properties:
|
||||
outputs:
|
||||
"$ref": "#/$defs/outputNames"
|
||||
dynamicOutputs:
|
||||
"$ref": "#/$defs/dynamicOutputs"
|
||||
@@ -1 +0,0 @@
|
||||
../../../../../../src/libstore-tests/data/derived-path
|
||||
@@ -1,27 +0,0 @@
|
||||
"$schema": "http://json-schema.org/draft-04/schema"
|
||||
"$id": "https://nix.dev/manual/nix/latest/protocols/json/schema/deriving-path-v1.json"
|
||||
title: Deriving Path
|
||||
description: |
|
||||
This schema describes the JSON representation of Nix's [Deriving Path](@docroot@/store/derivation/index.md#deriving-path).
|
||||
oneOf:
|
||||
- title: Constant
|
||||
description: |
|
||||
See [Constant](@docroot@/store/derivation/index.md#deriving-path-constant) deriving path.
|
||||
$ref: "store-path-v1.yaml"
|
||||
- title: Output
|
||||
description: |
|
||||
See [Output](@docroot@/store/derivation/index.md#deriving-path-output) deriving path.
|
||||
type: object
|
||||
properties:
|
||||
drvPath:
|
||||
"$ref": "#"
|
||||
description: |
|
||||
A deriving path to a [Derivation](@docroot@/store/derivation/index.md#store-derivation), whose output is being referred to.
|
||||
output:
|
||||
type: string
|
||||
description: |
|
||||
The name of an output produced by that derivation (e.g. "out", "doc", etc.).
|
||||
required:
|
||||
- drvPath
|
||||
- output
|
||||
additionalProperties: false
|
||||
@@ -0,0 +1 @@
|
||||
../../../../../../src/libutil-tests/data/memory-source-accessor
|
||||
@@ -0,0 +1,65 @@
|
||||
"$schema": http://json-schema.org/draft-04/schema#
|
||||
"$id": https://nix.dev/manual/nix/latest/protocols/json/schema/file-system-object-v1.json
|
||||
title: File System Object
|
||||
description: |
|
||||
This schema describes the JSON representation of Nix's [File System Object](@docroot@/store/file-system-object.md).
|
||||
|
||||
The schema is recursive because file system objects contain other file system objects.
|
||||
type: object
|
||||
required: ["type"]
|
||||
properties:
|
||||
type:
|
||||
type: string
|
||||
enum: ["regular", "symlink", "directory"]
|
||||
|
||||
# Enforce conditional structure based on `type`
|
||||
anyOf:
|
||||
- $ref: "#/$defs/regular"
|
||||
required: ["type", "contents"]
|
||||
|
||||
- $ref: "#/$defs/symlink"
|
||||
required: ["type", "target"]
|
||||
|
||||
- $ref: "#/$defs/directory"
|
||||
required: ["type", "contents"]
|
||||
|
||||
"$defs":
|
||||
regular:
|
||||
title: Regular File
|
||||
required: ["contents"]
|
||||
properties:
|
||||
type:
|
||||
const: "regular"
|
||||
contents:
|
||||
type: string
|
||||
description: Base64-encoded file contents
|
||||
executable:
|
||||
type: boolean
|
||||
description: Whether the file is executable.
|
||||
default: false
|
||||
additionalProperties: false
|
||||
|
||||
symlink:
|
||||
title: Symbolic Link
|
||||
required: ["target"]
|
||||
properties:
|
||||
type:
|
||||
const: "symlink"
|
||||
target:
|
||||
type: string
|
||||
description: Target path of the symlink.
|
||||
additionalProperties: false
|
||||
|
||||
directory:
|
||||
title: Directory
|
||||
required: ["contents"]
|
||||
properties:
|
||||
type:
|
||||
const: "directory"
|
||||
contents:
|
||||
type: object
|
||||
description: |
|
||||
Map of names to nested file system objects (for type=directory)
|
||||
additionalProperties:
|
||||
$ref: "#"
|
||||
additionalProperties: false
|
||||
@@ -1,5 +1,5 @@
|
||||
"$schema": "http://json-schema.org/draft-04/schema"
|
||||
"$id": "https://nix.dev/manual/nix/latest/protocols/json/schema/hash-v1.json"
|
||||
"$schema": http://json-schema.org/draft-04/schema#
|
||||
"$id": https://nix.dev/manual/nix/latest/protocols/json/schema/hash-v1.json
|
||||
title: Hash
|
||||
description: |
|
||||
A cryptographic hash value used throughout Nix for content addressing and integrity verification.
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
../../../../../../src/libstore-tests/data/nar-info
|
||||
@@ -1 +0,0 @@
|
||||
../../../../../../src/libstore-tests/data/path-info
|
||||
@@ -1,235 +0,0 @@
|
||||
"$schema": "http://json-schema.org/draft-07/schema"
|
||||
"$id": "https://nix.dev/manual/nix/latest/protocols/json/schema/store-object-info-v1.json"
|
||||
title: Store Object Info
|
||||
description: |
|
||||
Information about a [store object](@docroot@/store/store-object.md).
|
||||
|
||||
This schema describes the JSON representation of store object metadata as returned by commands like [`nix path-info --json`](@docroot@/command-ref/new-cli/nix3-path-info.md).
|
||||
|
||||
> **Warning**
|
||||
>
|
||||
> This JSON format is currently
|
||||
> [**experimental**](@docroot@/development/experimental-features.md#xp-feature-nix-command)
|
||||
> and subject to change.
|
||||
|
||||
### Field Categories
|
||||
|
||||
Store object information can come in a few different variations.
|
||||
|
||||
Firstly, "impure" fields, which contain non-intrinsic information about the store object, may or may not be included.
|
||||
|
||||
Second, binary cache stores have extra non-intrinsic infomation about the store objects they contain.
|
||||
|
||||
Thirdly, [`nix path-info --json --closure-size`](@docroot@/command-ref/new-cli/nix3-path-info.html#opt-closure-size) can compute some extra information about not just the single store object in question, but the store object and its [closure](@docroot@/glossary.md#gloss-closure).
|
||||
|
||||
The impure and NAR fields are grouped into separate variants below.
|
||||
See their descriptions for additional information.
|
||||
The closure fields however as just included as optional fields, to avoid a combinatorial explosion of variants.
|
||||
|
||||
oneOf:
|
||||
- $ref: "#/$defs/base"
|
||||
|
||||
- $ref: "#/$defs/impure"
|
||||
|
||||
- $ref: "#/$defs/narInfo"
|
||||
|
||||
$defs:
|
||||
base:
|
||||
title: Store Object Info
|
||||
description: |
|
||||
Basic store object metadata containing only intrinsic properties.
|
||||
This is the minimal set of fields that describe what a store object contains.
|
||||
type: object
|
||||
required:
|
||||
- narHash
|
||||
- narSize
|
||||
- references
|
||||
- ca
|
||||
properties:
|
||||
path:
|
||||
type: string
|
||||
title: Store Path
|
||||
description: |
|
||||
[Store path](@docroot@/store/store-path.md) to the given store object.
|
||||
|
||||
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:
|
||||
type: string
|
||||
title: NAR Hash
|
||||
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).
|
||||
|
||||
narSize:
|
||||
type: integer
|
||||
minimum: 0
|
||||
title: NAR Size
|
||||
description: |
|
||||
Size 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).
|
||||
|
||||
references:
|
||||
type: array
|
||||
title: References
|
||||
description: |
|
||||
An array of [store paths](@docroot@/store/store-path.md), possibly including this one.
|
||||
items:
|
||||
type: string
|
||||
|
||||
ca:
|
||||
type: ["string", "null"]
|
||||
title: Content Address
|
||||
description: |
|
||||
If the store object is [content-addressed](@docroot@/store/store-object/content-address.md),
|
||||
this is the content address of this store object's file system object, used to compute its store path.
|
||||
Otherwise (i.e. if it is [input-addressed](@docroot@/glossary.md#gloss-input-addressed-store-object)), this is `null`.
|
||||
additionalProperties: false
|
||||
|
||||
impure:
|
||||
title: Store Object Info with Impure Fields
|
||||
description: |
|
||||
Store object metadata including impure fields that are not *intrinsic* properties.
|
||||
In other words, the same store object in different stores could have different values for these impure fields.
|
||||
type: object
|
||||
required:
|
||||
- narHash
|
||||
- narSize
|
||||
- references
|
||||
- ca
|
||||
# impure
|
||||
- deriver
|
||||
- registrationTime
|
||||
- ultimate
|
||||
- signatures
|
||||
properties:
|
||||
path: { $ref: "#/$defs/base/properties/path" }
|
||||
narHash: { $ref: "#/$defs/base/properties/narHash" }
|
||||
narSize: { $ref: "#/$defs/base/properties/narSize" }
|
||||
references: { $ref: "#/$defs/base/properties/references" }
|
||||
ca: { $ref: "#/$defs/base/properties/ca" }
|
||||
deriver:
|
||||
type: ["string", "null"]
|
||||
title: Deriver
|
||||
description: |
|
||||
If known, the path to the [store derivation](@docroot@/glossary.md#gloss-store-derivation) from which this store object was produced.
|
||||
Otherwise `null`.
|
||||
|
||||
> This is an "impure" field that may not be included in certain contexts.
|
||||
|
||||
registrationTime:
|
||||
type: ["integer", "null"]
|
||||
title: Registration Time
|
||||
description: |
|
||||
If known, when this derivation was added to the store (Unix timestamp).
|
||||
Otherwise `null`.
|
||||
|
||||
> This is an "impure" field that may not be included in certain contexts.
|
||||
|
||||
ultimate:
|
||||
type: boolean
|
||||
title: Ultimate
|
||||
description: |
|
||||
Whether this store object is trusted because we built it ourselves, rather than substituted a build product from elsewhere.
|
||||
|
||||
> This is an "impure" field that may not be included in certain contexts.
|
||||
|
||||
signatures:
|
||||
type: array
|
||||
title: Signatures
|
||||
description: |
|
||||
Signatures claiming that this store object is what it claims to be.
|
||||
Not relevant for [content-addressed](@docroot@/store/store-object/content-address.md) store objects,
|
||||
but useful for [input-addressed](@docroot@/glossary.md#gloss-input-addressed-store-object) store objects.
|
||||
|
||||
> This is an "impure" field that may not be included in certain contexts.
|
||||
items:
|
||||
type: string
|
||||
|
||||
# Computed closure fields
|
||||
closureSize:
|
||||
type: integer
|
||||
minimum: 0
|
||||
title: Closure Size
|
||||
description: |
|
||||
The total size of this store object and every other object in its [closure](@docroot@/glossary.md#gloss-closure).
|
||||
|
||||
> This field is not stored at all, but computed by traversing the other fields across all the store objects in a closure.
|
||||
additionalProperties: false
|
||||
|
||||
narInfo:
|
||||
title: Store Object Info with Impure fields and NAR Info
|
||||
description: |
|
||||
The store object info in the "binary cache" family of Nix store type contain extra information pertaining to *downloads* of the store object in question.
|
||||
(This store info is called "NAR info", since the downloads take the form of [Nix Archives](@docroot@/store/file-system-object/content-address.md#serial-nix-archive, and the metadata is served in a file with a `.narinfo` extension.)
|
||||
|
||||
This download information, being specific to how the store object happens to be stored and transferred, is also considered to be non-intrinsic / impure.
|
||||
type: object
|
||||
required:
|
||||
- narHash
|
||||
- narSize
|
||||
- references
|
||||
- ca
|
||||
# impure
|
||||
- deriver
|
||||
- registrationTime
|
||||
- ultimate
|
||||
- signatures
|
||||
# nar
|
||||
- url
|
||||
- compression
|
||||
- downloadHash
|
||||
- downloadSize
|
||||
properties:
|
||||
path: { $ref: "#/$defs/base/properties/path" }
|
||||
narHash: { $ref: "#/$defs/base/properties/narHash" }
|
||||
narSize: { $ref: "#/$defs/base/properties/narSize" }
|
||||
references: { $ref: "#/$defs/base/properties/references" }
|
||||
ca: { $ref: "#/$defs/base/properties/ca" }
|
||||
deriver: { $ref: "#/$defs/impure/properties/deriver" }
|
||||
registrationTime: { $ref: "#/$defs/impure/properties/registrationTime" }
|
||||
ultimate: { $ref: "#/$defs/impure/properties/ultimate" }
|
||||
signatures: { $ref: "#/$defs/impure/properties/signatures" }
|
||||
closureSize: { $ref: "#/$defs/impure/properties/closureSize" }
|
||||
url:
|
||||
type: string
|
||||
title: URL
|
||||
description: |
|
||||
Where to download a compressed archive of the file system objects of this store object.
|
||||
|
||||
> This is an impure "`.narinfo`" field that may not be included in certain contexts.
|
||||
|
||||
compression:
|
||||
type: string
|
||||
title: Compression
|
||||
description: |
|
||||
The compression format that the archive is in.
|
||||
|
||||
> This is an impure "`.narinfo`" field that may not be included in certain contexts.
|
||||
|
||||
downloadHash:
|
||||
type: string
|
||||
title: Download Hash
|
||||
description: |
|
||||
A digest for the compressed archive itself, as opposed to the data contained within.
|
||||
|
||||
> This is an impure "`.narinfo`" field that may not be included in certain contexts.
|
||||
|
||||
downloadSize:
|
||||
type: integer
|
||||
minimum: 0
|
||||
title: Download Size
|
||||
description: |
|
||||
The size of the compressed archive itself.
|
||||
|
||||
> This is an impure "`.narinfo`" field that may not be included in certain contexts.
|
||||
|
||||
closureDownloadSize:
|
||||
type: integer
|
||||
minimum: 0
|
||||
title: Closure Download Size
|
||||
description: |
|
||||
The total size of the compressed archive itself for this object, and the compressed archive of every object in this object's [closure](@docroot@/glossary.md#gloss-closure).
|
||||
|
||||
> This is an impure "`.narinfo`" field that may not be included in certain contexts.
|
||||
|
||||
> This field is not stored at all, but computed by traversing the other fields across all the store objects in a closure.
|
||||
additionalProperties: false
|
||||
@@ -1 +0,0 @@
|
||||
../../../../../../src/libstore-tests/data/store-path
|
||||
@@ -1,32 +0,0 @@
|
||||
"$schema": "http://json-schema.org/draft-07/schema"
|
||||
"$id": "https://nix.dev/manual/nix/latest/protocols/json/schema/store-path-v1.json"
|
||||
title: Store Path
|
||||
description: |
|
||||
A [store path](@docroot@/store/store-path.md) identifying a store object.
|
||||
|
||||
This schema describes the JSON representation of store paths as used in various Nix JSON APIs.
|
||||
|
||||
> **Warning**
|
||||
>
|
||||
> This JSON format is currently
|
||||
> [**experimental**](@docroot@/development/experimental-features.md#xp-feature-nix-command)
|
||||
> and subject to change.
|
||||
|
||||
## Format
|
||||
|
||||
Store paths in JSON are represented as strings containing just the hash and name portion, without the store directory prefix.
|
||||
|
||||
For example: `"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv"`
|
||||
|
||||
(If the store dir is `/nix/store`, then this corresponds to the path `/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv`.)
|
||||
|
||||
## Structure
|
||||
|
||||
The format follows this pattern: `${digest}-${name}`
|
||||
|
||||
- **hash**: Digest rendered in a custom variant of [Base32](https://en.wikipedia.org/wiki/Base32) (20 arbitrary bytes become 32 ASCII characters)
|
||||
- **name**: The package name and optional version/suffix information
|
||||
|
||||
type: string
|
||||
pattern: "^[0123456789abcdfghijklmnpqrsvwxyz]{32}-.+$"
|
||||
minLength: 34
|
||||
@@ -1,45 +1,102 @@
|
||||
{{#include store-object-info-v1-fixed.md}}
|
||||
# Store object info JSON format
|
||||
|
||||
## Examples
|
||||
> **Warning**
|
||||
>
|
||||
> This JSON format is currently
|
||||
> [**experimental**](@docroot@/development/experimental-features.md#xp-feature-nix-command)
|
||||
> and subject to change.
|
||||
|
||||
### Minimal store object (content-addressed)
|
||||
Info about a [store object].
|
||||
|
||||
```json
|
||||
{{#include schema/store-object-info-v1/pure.json}}
|
||||
```
|
||||
* `path`:
|
||||
|
||||
### Store object with impure fields
|
||||
[Store path][store path] to the given store object.
|
||||
|
||||
```json
|
||||
{{#include schema/store-object-info-v1/impure.json}}
|
||||
```
|
||||
* `narHash`:
|
||||
|
||||
### Minimal store object (empty)
|
||||
Hash of the [file system object] part of the store object when serialized as a [Nix Archive].
|
||||
|
||||
```json
|
||||
{{#include schema/store-object-info-v1/empty_pure.json}}
|
||||
```
|
||||
* `narSize`:
|
||||
|
||||
### Store object with all impure fields
|
||||
Size of the [file system object] part of the store object when serialized as a [Nix Archive].
|
||||
|
||||
```json
|
||||
{{#include schema/store-object-info-v1/empty_impure.json}}
|
||||
```
|
||||
* `references`:
|
||||
|
||||
### NAR info (minimal)
|
||||
An array of [store paths][store path], possibly including this one.
|
||||
|
||||
```json
|
||||
{{#include schema/nar-info-v1/pure.json}}
|
||||
```
|
||||
* `ca`:
|
||||
|
||||
### NAR info (with binary cache fields)
|
||||
If the store object is [content-addressed],
|
||||
this is the content address of this store object's file system object, used to compute its store path.
|
||||
Otherwise (i.e. if it is [input-addressed]), this is `null`.
|
||||
|
||||
```json
|
||||
{{#include schema/nar-info-v1/impure.json}}
|
||||
```
|
||||
[store path]: @docroot@/store/store-path.md
|
||||
[file system object]: @docroot@/store/file-system-object.md
|
||||
[Nix Archive]: @docroot@/store/file-system-object/content-address.md#serial-nix-archive
|
||||
|
||||
<!-- need to convert YAML to JSON first
|
||||
## Raw Schema
|
||||
## Impure fields
|
||||
|
||||
[JSON Schema for Store Object Info v1](schema/store-object-info-v1.json)
|
||||
-->
|
||||
These are not intrinsic properties of the store object.
|
||||
In other words, the same store object residing in different store could have different values for these properties.
|
||||
|
||||
* `deriver`:
|
||||
|
||||
If known, the path to the [store derivation] from which this store object was produced.
|
||||
Otherwise `null`.
|
||||
|
||||
[store derivation]: @docroot@/glossary.md#gloss-store-derivation
|
||||
|
||||
* `registrationTime` (optional):
|
||||
|
||||
If known, when this derivation was added to the store.
|
||||
Otherwise `null`.
|
||||
|
||||
* `ultimate`:
|
||||
|
||||
Whether this store object is trusted because we built it ourselves, rather than substituted a build product from elsewhere.
|
||||
|
||||
* `signatures`:
|
||||
|
||||
Signatures claiming that this store object is what it claims to be.
|
||||
Not relevant for [content-addressed] store objects,
|
||||
but useful for [input-addressed] store objects.
|
||||
|
||||
[content-addressed]: @docroot@/store/store-object/content-address.md
|
||||
[input-addressed]: @docroot@/glossary.md#gloss-input-addressed-store-object
|
||||
|
||||
### `.narinfo` extra fields
|
||||
|
||||
This meta data is specific to the "binary cache" family of Nix store types.
|
||||
This information is not intrinsic to the store object, but about how it is stored.
|
||||
|
||||
* `url`:
|
||||
|
||||
Where to download a compressed archive of the file system objects of this store object.
|
||||
|
||||
* `compression`:
|
||||
|
||||
The compression format that the archive is in.
|
||||
|
||||
* `fileHash`:
|
||||
|
||||
A digest for the compressed archive itself, as opposed to the data contained within.
|
||||
|
||||
* `fileSize`:
|
||||
|
||||
The size of the compressed archive itself.
|
||||
|
||||
## Computed closure fields
|
||||
|
||||
These fields are not stored at all, but computed by traversing the other fields across all the store objects in a [closure].
|
||||
|
||||
* `closureSize`:
|
||||
|
||||
The total size of the compressed archive itself for this object, and the compressed archive of every object in this object's [closure].
|
||||
|
||||
### `.narinfo` extra fields
|
||||
|
||||
* `closureSize`:
|
||||
|
||||
The total size of this store object and every other object in its [closure].
|
||||
|
||||
[closure]: @docroot@/glossary.md#gloss-closure
|
||||
@@ -1,15 +0,0 @@
|
||||
{{#include store-path-v1-fixed.md}}
|
||||
|
||||
## Examples
|
||||
|
||||
### Simple store path
|
||||
|
||||
```json
|
||||
{{#include schema/store-path-v1/simple.json}}
|
||||
```
|
||||
|
||||
<!-- need to convert YAML to JSON first
|
||||
## Raw Schema
|
||||
|
||||
[JSON Schema for Store Path v1](schema/store-path-v1.json)
|
||||
-->
|
||||
@@ -471,27 +471,6 @@
|
||||
}
|
||||
);
|
||||
|
||||
apps = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgsFor.${system}.native;
|
||||
opener = if pkgs.stdenv.isDarwin then "open" else "xdg-open";
|
||||
in
|
||||
{
|
||||
open-manual = {
|
||||
type = "app";
|
||||
program = "${pkgs.writeShellScript "open-nix-manual" ''
|
||||
manual_path="${self.packages.${system}.nix-manual}/share/doc/nix/manual/index.html"
|
||||
if ! ${opener} "$manual_path"; then
|
||||
echo "Failed to open manual with ${opener}. Manual is located at:"
|
||||
echo "$manual_path"
|
||||
fi
|
||||
''}";
|
||||
meta.description = "Open the Nix manual in your browser";
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
devShells =
|
||||
let
|
||||
makeShell = import ./packaging/dev-shell.nix { inherit lib devFlake; };
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#compdef nix
|
||||
# shellcheck disable=all
|
||||
#compdef nix
|
||||
|
||||
function _nix() {
|
||||
local ifs_bk="$IFS"
|
||||
|
||||
@@ -42,8 +42,8 @@ if cxx.get_id() == 'clang'
|
||||
add_project_arguments('-fpch-instantiate-templates', language : 'cpp')
|
||||
endif
|
||||
|
||||
# Darwin ld doesn't like "X.Y.ZpreABCD+W"
|
||||
nix_soversion = meson.project_version().split('+')[0].split('pre')[0]
|
||||
# Darwin ld doesn't like "X.Y.Zpre"
|
||||
nix_soversion = meson.project_version().split('pre')[0]
|
||||
|
||||
subdir('assert-fail')
|
||||
subdir('asan-options')
|
||||
@@ -15,7 +15,7 @@ programmatically:
|
||||
1. Embedding the evaluator
|
||||
2. Writing language plug-ins
|
||||
|
||||
Embedding means you link the Nix C API libraries in your program and use them from
|
||||
Embedding means you link the Nix C libraries in your program and use them from
|
||||
there. Adding a plug-in means you make a library that gets loaded by the Nix
|
||||
language evaluator, specified through a configuration option.
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
../../src/libstore-tests/data/content-address
|
||||
@@ -1 +0,0 @@
|
||||
../../src/libstore-tests/data/derived-path
|
||||
@@ -0,0 +1 @@
|
||||
../../src/libutil-tests/data/memory-source-accessor
|
||||
@@ -20,6 +20,14 @@ schema_dir = meson.current_source_dir() / 'schema'
|
||||
|
||||
# Get all example files
|
||||
schemas = [
|
||||
{
|
||||
'stem' : 'file-system-object',
|
||||
'schema' : schema_dir / 'file-system-object-v1.yaml',
|
||||
'files' : [
|
||||
'simple.json',
|
||||
'complex.json',
|
||||
],
|
||||
},
|
||||
{
|
||||
'stem' : 'hash',
|
||||
'schema' : schema_dir / 'hash-v1.yaml',
|
||||
@@ -30,21 +38,6 @@ schemas = [
|
||||
'blake3-base64.json',
|
||||
],
|
||||
},
|
||||
{
|
||||
'stem' : 'content-address',
|
||||
'schema' : schema_dir / 'content-address-v1.yaml',
|
||||
'files' : [
|
||||
'text.json',
|
||||
'nar.json',
|
||||
],
|
||||
},
|
||||
{
|
||||
'stem' : 'store-path',
|
||||
'schema' : schema_dir / 'store-path-v1.yaml',
|
||||
'files' : [
|
||||
'simple.json',
|
||||
],
|
||||
},
|
||||
{
|
||||
'stem' : 'derivation',
|
||||
'schema' : schema_dir / 'derivation-v3.yaml',
|
||||
@@ -53,78 +46,20 @@ schemas = [
|
||||
'simple-derivation.json',
|
||||
],
|
||||
},
|
||||
{
|
||||
'stem' : 'derivation',
|
||||
'schema' : schema_dir / 'derivation-v3.yaml#/$defs/output',
|
||||
'files' : [
|
||||
'output-caFixedFlat.json',
|
||||
'output-caFixedNAR.json',
|
||||
'output-caFixedText.json',
|
||||
'output-caFloating.json',
|
||||
'output-deferred.json',
|
||||
'output-impure.json',
|
||||
'output-inputAddressed.json',
|
||||
],
|
||||
},
|
||||
{
|
||||
'stem' : 'deriving-path',
|
||||
'schema' : schema_dir / 'deriving-path-v1.yaml',
|
||||
'files' : [
|
||||
'single_opaque.json',
|
||||
'single_built.json',
|
||||
'single_built_built.json',
|
||||
],
|
||||
},
|
||||
# Match overall
|
||||
{
|
||||
'stem' : 'store-object-info',
|
||||
'schema' : schema_dir / 'store-object-info-v1.yaml',
|
||||
'files' : [
|
||||
'pure.json',
|
||||
'impure.json',
|
||||
'empty_pure.json',
|
||||
'empty_impure.json',
|
||||
],
|
||||
},
|
||||
{
|
||||
'stem' : 'nar-info',
|
||||
'schema' : schema_dir / 'store-object-info-v1.yaml',
|
||||
'files' : [
|
||||
'pure.json',
|
||||
'impure.json',
|
||||
],
|
||||
},
|
||||
# Match exact variant
|
||||
{
|
||||
'stem' : 'store-object-info',
|
||||
'schema' : schema_dir / 'store-object-info-v1.yaml#/$defs/base',
|
||||
'files' : [
|
||||
'pure.json',
|
||||
'empty_pure.json',
|
||||
],
|
||||
},
|
||||
{
|
||||
'stem' : 'store-object-info',
|
||||
'schema' : schema_dir / 'store-object-info-v1.yaml#/$defs/impure',
|
||||
'files' : [
|
||||
'impure.json',
|
||||
'empty_impure.json',
|
||||
],
|
||||
},
|
||||
{
|
||||
'stem' : 'nar-info',
|
||||
'schema' : schema_dir / 'store-object-info-v1.yaml#/$defs/base',
|
||||
'files' : [
|
||||
'pure.json',
|
||||
],
|
||||
},
|
||||
{
|
||||
'stem' : 'nar-info',
|
||||
'schema' : schema_dir / 'store-object-info-v1.yaml#/$defs/narInfo',
|
||||
'files' : [
|
||||
'impure.json',
|
||||
],
|
||||
},
|
||||
# # Not sure how to make subschema work
|
||||
# {
|
||||
# 'stem': 'derivation',
|
||||
# 'schema': schema_dir / 'derivation-v3.yaml#output',
|
||||
# 'files' : [
|
||||
# 'output-caFixedFlat.json',
|
||||
# 'output-caFixedNAR.json',
|
||||
# 'output-caFixedText.json',
|
||||
# 'output-caFloating.json',
|
||||
# 'output-deferred.json',
|
||||
# 'output-impure.json',
|
||||
# 'output-inputAddressed.json',
|
||||
# ],
|
||||
# },
|
||||
]
|
||||
|
||||
# Validate each example against the schema
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
../../src/libstore-tests/data/nar-info
|
||||
@@ -20,13 +20,9 @@ mkMesonDerivation (finalAttrs: {
|
||||
fileset = lib.fileset.unions [
|
||||
../../.version
|
||||
../../doc/manual/source/protocols/json/schema
|
||||
../../src/libutil-tests/data/memory-source-accessor
|
||||
../../src/libutil-tests/data/hash
|
||||
../../src/libstore-tests/data/content-address
|
||||
../../src/libstore-tests/data/store-path
|
||||
../../src/libstore-tests/data/derivation
|
||||
../../src/libstore-tests/data/derived-path
|
||||
../../src/libstore-tests/data/path-info
|
||||
../../src/libstore-tests/data/nar-info
|
||||
./.
|
||||
];
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
../../src/libstore-tests/data/path-info
|
||||
@@ -1 +0,0 @@
|
||||
../../src/libstore-tests/data/store-path
|
||||
@@ -4,14 +4,11 @@
|
||||
* @brief Bindings to the Nix language evaluator
|
||||
*
|
||||
* See *[Embedding the Nix Evaluator](@ref nix_evaluator_example)* for an example.
|
||||
* @{
|
||||
*/
|
||||
/** @file
|
||||
* @brief Main entry for the libexpr C bindings
|
||||
*/
|
||||
/** @defgroup libexpr_init Initialization
|
||||
* @ingroup libexpr
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "nix_api_store.h"
|
||||
#include "nix_api_util.h"
|
||||
@@ -48,10 +45,7 @@ typedef struct nix_eval_state_builder nix_eval_state_builder;
|
||||
*/
|
||||
typedef struct EvalState EvalState; // nix::EvalState
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @brief A Nix language value, or thunk that may evaluate to a value.
|
||||
* @ingroup value
|
||||
*
|
||||
* Values are the primary objects manipulated in the Nix language.
|
||||
* They are considered to be immutable from a user's perspective, but the process of evaluating a value changes its
|
||||
@@ -62,8 +56,7 @@ typedef struct EvalState EvalState; // nix::EvalState
|
||||
*
|
||||
* The evaluator manages its own memory, but your use of the C API must follow the reference counting rules.
|
||||
*
|
||||
* @struct nix_value
|
||||
* @see value_create, value_extract
|
||||
* @see value_manip
|
||||
* @see nix_value_incref, nix_value_decref
|
||||
*/
|
||||
typedef struct nix_value nix_value;
|
||||
@@ -72,7 +65,6 @@ NIX_DEPRECATED("use nix_value instead") typedef nix_value Value;
|
||||
// Function prototypes
|
||||
/**
|
||||
* @brief Initialize the Nix language evaluator.
|
||||
* @ingroup libexpr_init
|
||||
*
|
||||
* This function must be called at least once,
|
||||
* at some point before constructing a EvalState for the first time.
|
||||
@@ -85,7 +77,6 @@ nix_err nix_libexpr_init(nix_c_context * context);
|
||||
|
||||
/**
|
||||
* @brief Parses and evaluates a Nix expression from a string.
|
||||
* @ingroup value_create
|
||||
*
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] state The state of the evaluation.
|
||||
@@ -102,7 +93,6 @@ nix_err nix_expr_eval_from_string(
|
||||
|
||||
/**
|
||||
* @brief Calls a Nix function with an argument.
|
||||
* @ingroup value_create
|
||||
*
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] state The state of the evaluation.
|
||||
@@ -117,7 +107,6 @@ nix_err nix_value_call(nix_c_context * context, EvalState * state, nix_value * f
|
||||
|
||||
/**
|
||||
* @brief Calls a Nix function with multiple arguments.
|
||||
* @ingroup value_create
|
||||
*
|
||||
* Technically these are functions that return functions. It is common for Nix
|
||||
* functions to be curried, so this function is useful for calling them.
|
||||
@@ -137,12 +126,10 @@ nix_err nix_value_call_multi(
|
||||
|
||||
/**
|
||||
* @brief Calls a Nix function with multiple arguments.
|
||||
* @ingroup value_create
|
||||
*
|
||||
* Technically these are functions that return functions. It is common for Nix
|
||||
* functions to be curried, so this function is useful for calling them.
|
||||
*
|
||||
* @def NIX_VALUE_CALL
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] state The state of the evaluation.
|
||||
* @param[out] value The result of the function call.
|
||||
@@ -160,7 +147,6 @@ nix_err nix_value_call_multi(
|
||||
|
||||
/**
|
||||
* @brief Forces the evaluation of a Nix value.
|
||||
* @ingroup value_create
|
||||
*
|
||||
* The Nix interpreter is lazy, and not-yet-evaluated values can be
|
||||
* of type NIX_TYPE_THUNK instead of their actual value.
|
||||
@@ -194,20 +180,18 @@ nix_err nix_value_force_deep(nix_c_context * context, EvalState * state, nix_val
|
||||
|
||||
/**
|
||||
* @brief Create a new nix_eval_state_builder
|
||||
* @ingroup libexpr_init
|
||||
*
|
||||
* The settings are initialized to their default value.
|
||||
* Values can be sourced elsewhere with nix_eval_state_builder_load.
|
||||
*
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] store The Nix store to use.
|
||||
* @return A new nix_eval_state_builder or NULL on failure. Call nix_eval_state_builder_free() when you're done.
|
||||
* @return A new nix_eval_state_builder or NULL on failure.
|
||||
*/
|
||||
nix_eval_state_builder * nix_eval_state_builder_new(nix_c_context * context, Store * store);
|
||||
|
||||
/**
|
||||
* @brief Read settings from the ambient environment
|
||||
* @ingroup libexpr_init
|
||||
*
|
||||
* Settings are sourced from environment variables and configuration files,
|
||||
* as documented in the Nix manual.
|
||||
@@ -220,7 +204,6 @@ nix_err nix_eval_state_builder_load(nix_c_context * context, nix_eval_state_buil
|
||||
|
||||
/**
|
||||
* @brief Set the lookup path for `<...>` expressions
|
||||
* @ingroup libexpr_init
|
||||
*
|
||||
* @param[in] context Optional, stores error information
|
||||
* @param[in] builder The builder to modify.
|
||||
@@ -231,21 +214,18 @@ nix_err nix_eval_state_builder_set_lookup_path(
|
||||
|
||||
/**
|
||||
* @brief Create a new Nix language evaluator state
|
||||
* @ingroup libexpr_init
|
||||
*
|
||||
* The builder becomes unusable after this call. Remember to call nix_eval_state_builder_free()
|
||||
* after building the state.
|
||||
* Remember to nix_eval_state_builder_free after building the state.
|
||||
*
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] builder The builder to use and free
|
||||
* @return A new Nix state or NULL on failure. Call nix_state_free() when you're done.
|
||||
* @return A new Nix state or NULL on failure.
|
||||
* @see nix_eval_state_builder_new, nix_eval_state_builder_free
|
||||
*/
|
||||
EvalState * nix_eval_state_build(nix_c_context * context, nix_eval_state_builder * builder);
|
||||
|
||||
/**
|
||||
* @brief Free a nix_eval_state_builder
|
||||
* @ingroup libexpr_init
|
||||
*
|
||||
* Does not fail.
|
||||
*
|
||||
@@ -255,21 +235,19 @@ void nix_eval_state_builder_free(nix_eval_state_builder * builder);
|
||||
|
||||
/**
|
||||
* @brief Create a new Nix language evaluator state
|
||||
* @ingroup libexpr_init
|
||||
*
|
||||
* For more control, use nix_eval_state_builder
|
||||
*
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] lookupPath Null-terminated array of strings corresponding to entries in NIX_PATH.
|
||||
* @param[in] store The Nix store to use.
|
||||
* @return A new Nix state or NULL on failure. Call nix_state_free() when you're done.
|
||||
* @return A new Nix state or NULL on failure.
|
||||
* @see nix_state_builder_new
|
||||
*/
|
||||
EvalState * nix_state_create(nix_c_context * context, const char ** lookupPath, Store * store);
|
||||
|
||||
/**
|
||||
* @brief Frees a Nix state.
|
||||
* @ingroup libexpr_init
|
||||
*
|
||||
* Does not fail.
|
||||
*
|
||||
@@ -278,7 +256,6 @@ EvalState * nix_state_create(nix_c_context * context, const char ** lookupPath,
|
||||
void nix_state_free(EvalState * state);
|
||||
|
||||
/** @addtogroup GC
|
||||
* @ingroup libexpr
|
||||
* @brief Reference counting and garbage collector operations
|
||||
*
|
||||
* The Nix language evaluator uses a garbage collector. To ease C interop, we implement
|
||||
@@ -309,9 +286,6 @@ nix_err nix_gc_incref(nix_c_context * context, const void * object);
|
||||
/**
|
||||
* @brief Decrement the garbage collector reference counter for the given object
|
||||
*
|
||||
* @deprecated We are phasing out the general nix_gc_decref() in favor of type-specified free functions, such as
|
||||
* nix_value_decref().
|
||||
*
|
||||
* We also provide typed `nix_*_decref` functions, which are
|
||||
* - safer to use
|
||||
* - easier to integrate when deriving bindings
|
||||
@@ -340,11 +314,12 @@ void nix_gc_now();
|
||||
*/
|
||||
void nix_gc_register_finalizer(void * obj, void * cd, void (*finalizer)(void * obj, void * cd));
|
||||
|
||||
/** @} */ // doxygen group GC
|
||||
|
||||
/** @} */
|
||||
// cffi end
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif // NIX_API_EXPR_H
|
||||
@@ -2,12 +2,11 @@
|
||||
#define NIX_API_EXTERNAL_H
|
||||
/** @ingroup libexpr
|
||||
* @addtogroup Externals
|
||||
* @brief Externals let Nix expressions work with foreign values that aren't part of the normal Nix value data model
|
||||
* @brief Deal with external values
|
||||
* @{
|
||||
*/
|
||||
/** @file
|
||||
* @brief libexpr C bindings dealing with external values
|
||||
* @see Externals
|
||||
*/
|
||||
|
||||
#include "nix_api_expr.h"
|
||||
@@ -116,7 +115,7 @@ typedef struct NixCExternalValueDesc
|
||||
* @brief Try to compare two external values
|
||||
*
|
||||
* Optional, the default is always false.
|
||||
* If the other object was not a Nix C API external value, this comparison will
|
||||
* If the other object was not a Nix C external value, this comparison will
|
||||
* also return false
|
||||
* @param[in] self the void* passed to nix_create_external_value
|
||||
* @param[in] other the void* passed to the other object's
|
||||
@@ -169,7 +168,7 @@ typedef struct NixCExternalValueDesc
|
||||
/**
|
||||
* @brief Create an external value, that can be given to nix_init_external
|
||||
*
|
||||
* Call nix_gc_decref() when you're done with the pointer.
|
||||
* Owned by the GC. Use nix_gc_decref when you're done with the pointer.
|
||||
*
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] desc a NixCExternalValueDesc, you should keep this alive as long
|
||||
@@ -181,11 +180,10 @@ typedef struct NixCExternalValueDesc
|
||||
ExternalValue * nix_create_external_value(nix_c_context * context, NixCExternalValueDesc * desc, void * v);
|
||||
|
||||
/**
|
||||
* @brief Extract the pointer from a Nix C API external value.
|
||||
* @brief Extract the pointer from a nix c external value.
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] b The external value
|
||||
* @returns The pointer, valid while the external value is valid, or null if the external value was not from the Nix C
|
||||
* API.
|
||||
* @returns The pointer, or null if the external value was not from nix c.
|
||||
* @see nix_get_external
|
||||
*/
|
||||
void * nix_get_external_value_content(nix_c_context * context, ExternalValue * b);
|
||||
|
||||
+63
-187
@@ -1,6 +1,9 @@
|
||||
#ifndef NIX_API_VALUE_H
|
||||
#define NIX_API_VALUE_H
|
||||
|
||||
/** @addtogroup libexpr
|
||||
* @{
|
||||
*/
|
||||
/** @file
|
||||
* @brief libexpr C bindings dealing with values
|
||||
*/
|
||||
@@ -17,89 +20,18 @@ extern "C" {
|
||||
#endif
|
||||
// cffi start
|
||||
|
||||
/** @defgroup value Value
|
||||
* @ingroup libexpr
|
||||
* @brief nix_value type and core operations for working with Nix values
|
||||
* @see value_create
|
||||
* @see value_extract
|
||||
*/
|
||||
|
||||
/** @defgroup value_create Value Creation
|
||||
* @ingroup libexpr
|
||||
* @brief Functions for allocating and initializing Nix values
|
||||
*
|
||||
* Values are usually created with `nix_alloc_value` followed by `nix_init_*` functions.
|
||||
* In primop callbacks, allocation is already done and only initialization is needed.
|
||||
*/
|
||||
|
||||
/** @defgroup value_extract Value Extraction
|
||||
* @ingroup libexpr
|
||||
* @brief Functions for extracting data from Nix values
|
||||
*/
|
||||
|
||||
/** @defgroup primops PrimOps and Builtins
|
||||
* @ingroup libexpr
|
||||
*/
|
||||
|
||||
// Type definitions
|
||||
/** @brief Represents the state of a Nix value
|
||||
*
|
||||
* Thunk values (NIX_TYPE_THUNK) change to their final, unchanging type when forced.
|
||||
*
|
||||
* @see https://nix.dev/manual/nix/latest/language/evaluation.html
|
||||
* @enum ValueType
|
||||
* @ingroup value
|
||||
*/
|
||||
typedef enum {
|
||||
/** Unevaluated expression
|
||||
*
|
||||
* Thunks often contain an expression and closure, but may contain other
|
||||
* representations too.
|
||||
*
|
||||
* Their state is mutable, unlike that of the other types.
|
||||
*/
|
||||
NIX_TYPE_THUNK,
|
||||
/**
|
||||
* A 64 bit signed integer.
|
||||
*/
|
||||
NIX_TYPE_INT,
|
||||
/** @brief IEEE 754 double precision floating point number
|
||||
* @see https://nix.dev/manual/nix/latest/language/types.html#type-float
|
||||
*/
|
||||
NIX_TYPE_FLOAT,
|
||||
/** @brief Boolean true or false value
|
||||
* @see https://nix.dev/manual/nix/latest/language/types.html#type-bool
|
||||
*/
|
||||
NIX_TYPE_BOOL,
|
||||
/** @brief String value with context
|
||||
*
|
||||
* String content may contain arbitrary bytes, not necessarily UTF-8.
|
||||
* @see https://nix.dev/manual/nix/latest/language/types.html#type-string
|
||||
*/
|
||||
NIX_TYPE_STRING,
|
||||
/** @brief Filesystem path
|
||||
* @see https://nix.dev/manual/nix/latest/language/types.html#type-path
|
||||
*/
|
||||
NIX_TYPE_PATH,
|
||||
/** @brief Null value
|
||||
* @see https://nix.dev/manual/nix/latest/language/types.html#type-null
|
||||
*/
|
||||
NIX_TYPE_NULL,
|
||||
/** @brief Attribute set (key-value mapping)
|
||||
* @see https://nix.dev/manual/nix/latest/language/types.html#type-attrs
|
||||
*/
|
||||
NIX_TYPE_ATTRS,
|
||||
/** @brief Ordered list of values
|
||||
* @see https://nix.dev/manual/nix/latest/language/types.html#type-list
|
||||
*/
|
||||
NIX_TYPE_LIST,
|
||||
/** @brief Function (lambda or builtin)
|
||||
* @see https://nix.dev/manual/nix/latest/language/types.html#type-function
|
||||
*/
|
||||
NIX_TYPE_FUNCTION,
|
||||
/** @brief External value from C++ plugins or C API
|
||||
* @see Externals
|
||||
*/
|
||||
NIX_TYPE_EXTERNAL
|
||||
} ValueType;
|
||||
|
||||
@@ -107,41 +39,22 @@ typedef enum {
|
||||
typedef struct nix_value nix_value;
|
||||
typedef struct EvalState EvalState;
|
||||
|
||||
/** @deprecated Use nix_value instead */
|
||||
[[deprecated("use nix_value instead")]] typedef nix_value Value;
|
||||
|
||||
// type defs
|
||||
/** @brief Stores an under-construction set of bindings
|
||||
* @ingroup value_create
|
||||
* @ingroup value_manip
|
||||
*
|
||||
* Each builder can only be used once. After calling nix_make_attrs(), the builder
|
||||
* becomes invalid and must not be used again. Call nix_bindings_builder_free() to release it.
|
||||
*
|
||||
* Typical usage pattern:
|
||||
* 1. Create with nix_make_bindings_builder()
|
||||
* 2. Insert attributes with nix_bindings_builder_insert()
|
||||
* 3. Create final attribute set with nix_make_attrs()
|
||||
* 4. Free builder with nix_bindings_builder_free()
|
||||
*
|
||||
* @struct BindingsBuilder
|
||||
* Do not reuse.
|
||||
* @see nix_make_bindings_builder, nix_bindings_builder_free, nix_make_attrs
|
||||
* @see nix_bindings_builder_insert
|
||||
*/
|
||||
typedef struct BindingsBuilder BindingsBuilder;
|
||||
|
||||
/** @brief Stores an under-construction list
|
||||
* @ingroup value_create
|
||||
* @ingroup value_manip
|
||||
*
|
||||
* Each builder can only be used once. After calling nix_make_list(), the builder
|
||||
* becomes invalid and must not be used again. Call nix_list_builder_free() to release it.
|
||||
*
|
||||
* Typical usage pattern:
|
||||
* 1. Create with nix_make_list_builder()
|
||||
* 2. Insert elements with nix_list_builder_insert()
|
||||
* 3. Create final list with nix_make_list()
|
||||
* 4. Free builder with nix_list_builder_free()
|
||||
*
|
||||
* @struct ListBuilder
|
||||
* Do not reuse.
|
||||
* @see nix_make_list_builder, nix_list_builder_free, nix_make_list
|
||||
* @see nix_list_builder_insert
|
||||
*/
|
||||
@@ -150,28 +63,25 @@ typedef struct ListBuilder ListBuilder;
|
||||
/** @brief PrimOp function
|
||||
* @ingroup primops
|
||||
*
|
||||
* Can be released with nix_gc_decref() when necessary.
|
||||
* @struct PrimOp
|
||||
* @see nix_alloc_primop, nix_init_primop, nix_register_primop
|
||||
* Owned by the GC
|
||||
* @see nix_alloc_primop, nix_init_primop
|
||||
*/
|
||||
typedef struct PrimOp PrimOp;
|
||||
/** @brief External Value
|
||||
* @ingroup Externals
|
||||
*
|
||||
* Can be released with nix_gc_decref() when necessary.
|
||||
* @struct ExternalValue
|
||||
* @see nix_create_external_value, nix_init_external, nix_get_external
|
||||
* Owned by the GC
|
||||
*/
|
||||
typedef struct ExternalValue ExternalValue;
|
||||
|
||||
/** @brief String without placeholders, and realised store paths
|
||||
* @struct nix_realised_string
|
||||
* @see nix_string_realise, nix_realised_string_free
|
||||
*/
|
||||
typedef struct nix_realised_string nix_realised_string;
|
||||
|
||||
/** @defgroup primops Adding primops
|
||||
* @{
|
||||
*/
|
||||
/** @brief Function pointer for primops
|
||||
* @ingroup primops
|
||||
*
|
||||
* When you want to return an error, call nix_set_err_msg(context, NIX_ERR_UNKNOWN, "your error message here").
|
||||
*
|
||||
@@ -187,9 +97,9 @@ typedef void (*PrimOpFun)(
|
||||
void * user_data, nix_c_context * context, EvalState * state, nix_value ** args, nix_value * ret);
|
||||
|
||||
/** @brief Allocate a PrimOp
|
||||
* @ingroup primops
|
||||
*
|
||||
* Call nix_gc_decref() when you're done with the returned PrimOp.
|
||||
* Owned by the garbage collector.
|
||||
* Use nix_gc_decref() when you're done with the returned PrimOp.
|
||||
*
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] fun callback
|
||||
@@ -211,38 +121,35 @@ PrimOp * nix_alloc_primop(
|
||||
void * user_data);
|
||||
|
||||
/** @brief add a primop to the `builtins` attribute set
|
||||
* @ingroup primops
|
||||
*
|
||||
* Only applies to States created after this call.
|
||||
*
|
||||
* Moves your PrimOp content into the global evaluator registry, meaning
|
||||
* your input PrimOp pointer becomes invalid. The PrimOp must not be used
|
||||
* with nix_init_primop() before or after this call, as this would cause
|
||||
* undefined behavior.
|
||||
* You must call nix_gc_decref() on the original PrimOp pointer
|
||||
* after this call to release your reference.
|
||||
* Moves your PrimOp content into the global evaluator
|
||||
* registry, meaning your input PrimOp pointer is no longer usable.
|
||||
* You are free to remove your references to it,
|
||||
* after which it will be garbage collected.
|
||||
*
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] primOp PrimOp to register
|
||||
* @return error code, NIX_OK on success
|
||||
* @return primop, or null in case of errors
|
||||
*
|
||||
*/
|
||||
nix_err nix_register_primop(nix_c_context * context, PrimOp * primOp);
|
||||
/** @} */
|
||||
|
||||
// Function prototypes
|
||||
|
||||
/** @brief Allocate a Nix value
|
||||
* @ingroup value_create
|
||||
*
|
||||
* Call nix_value_decref() when you're done with the pointer
|
||||
* Owned by the GC. Use nix_gc_decref() when you're done with the pointer
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] state nix evaluator state
|
||||
* @return value, or null in case of errors
|
||||
*
|
||||
*/
|
||||
nix_value * nix_alloc_value(nix_c_context * context, EvalState * state);
|
||||
|
||||
/**
|
||||
* @brief Increment the garbage collector reference counter for the given `nix_value`.
|
||||
* @ingroup value
|
||||
*
|
||||
* The Nix language evaluator C API keeps track of alive objects by reference counting.
|
||||
* When you're done with a refcounted pointer, call nix_value_decref().
|
||||
@@ -254,19 +161,21 @@ nix_err nix_value_incref(nix_c_context * context, nix_value * value);
|
||||
|
||||
/**
|
||||
* @brief Decrement the garbage collector reference counter for the given object
|
||||
* @ingroup value
|
||||
*
|
||||
* When the counter reaches zero, the `nix_value` object becomes invalid.
|
||||
* The data referenced by `nix_value` may not be deallocated until the memory
|
||||
* garbage collector has run, but deallocation is not guaranteed.
|
||||
*
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value The object to stop referencing
|
||||
*/
|
||||
nix_err nix_value_decref(nix_c_context * context, nix_value * value);
|
||||
|
||||
/** @addtogroup value_manip Manipulating values
|
||||
* @brief Functions to inspect and change Nix language values, represented by nix_value.
|
||||
* @{
|
||||
*/
|
||||
/** @anchor getters
|
||||
* @name Getters
|
||||
*/
|
||||
/**@{*/
|
||||
/** @brief Get value type
|
||||
* @ingroup value_extract
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value Nix value to inspect
|
||||
* @return type of nix value
|
||||
@@ -274,15 +183,14 @@ nix_err nix_value_decref(nix_c_context * context, nix_value * value);
|
||||
ValueType nix_get_type(nix_c_context * context, const nix_value * value);
|
||||
|
||||
/** @brief Get type name of value as defined in the evaluator
|
||||
* @ingroup value_extract
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value Nix value to inspect
|
||||
* @return type name string, free with free()
|
||||
* @return type name, owned string
|
||||
* @todo way to free the result
|
||||
*/
|
||||
const char * nix_get_typename(nix_c_context * context, const nix_value * value);
|
||||
|
||||
/** @brief Get boolean value
|
||||
* @ingroup value_extract
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value Nix value to inspect
|
||||
* @return true or false, error info via context
|
||||
@@ -290,7 +198,6 @@ const char * nix_get_typename(nix_c_context * context, const nix_value * value);
|
||||
bool nix_get_bool(nix_c_context * context, const nix_value * value);
|
||||
|
||||
/** @brief Get the raw string
|
||||
* @ingroup value_extract
|
||||
*
|
||||
* This may contain placeholders.
|
||||
*
|
||||
@@ -298,21 +205,21 @@ bool nix_get_bool(nix_c_context * context, const nix_value * value);
|
||||
* @param[in] value Nix value to inspect
|
||||
* @param[in] callback Called with the string value.
|
||||
* @param[in] user_data optional, arbitrary data, passed to the callback when it's called.
|
||||
* @return string
|
||||
* @return error code, NIX_OK on success.
|
||||
*/
|
||||
nix_err
|
||||
nix_get_string(nix_c_context * context, const nix_value * value, nix_get_string_callback callback, void * user_data);
|
||||
|
||||
/** @brief Get path as string
|
||||
* @ingroup value_extract
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value Nix value to inspect
|
||||
* @return string valid while value is valid, NULL in case of error
|
||||
* @return string, if the type is NIX_TYPE_PATH
|
||||
* @return NULL in case of error.
|
||||
*/
|
||||
const char * nix_get_path_string(nix_c_context * context, const nix_value * value);
|
||||
|
||||
/** @brief Get the length of a list
|
||||
* @ingroup value_extract
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value Nix value to inspect
|
||||
* @return length of list, error info via context
|
||||
@@ -320,7 +227,6 @@ const char * nix_get_path_string(nix_c_context * context, const nix_value * valu
|
||||
unsigned int nix_get_list_size(nix_c_context * context, const nix_value * value);
|
||||
|
||||
/** @brief Get the element count of an attrset
|
||||
* @ingroup value_extract
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value Nix value to inspect
|
||||
* @return attrset element count, error info via context
|
||||
@@ -328,7 +234,6 @@ unsigned int nix_get_list_size(nix_c_context * context, const nix_value * value)
|
||||
unsigned int nix_get_attrs_size(nix_c_context * context, const nix_value * value);
|
||||
|
||||
/** @brief Get float value in 64 bits
|
||||
* @ingroup value_extract
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value Nix value to inspect
|
||||
* @return float contents, error info via context
|
||||
@@ -336,7 +241,6 @@ unsigned int nix_get_attrs_size(nix_c_context * context, const nix_value * value
|
||||
double nix_get_float(nix_c_context * context, const nix_value * value);
|
||||
|
||||
/** @brief Get int value
|
||||
* @ingroup value_extract
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value Nix value to inspect
|
||||
* @return int contents, error info via context
|
||||
@@ -344,18 +248,15 @@ double nix_get_float(nix_c_context * context, const nix_value * value);
|
||||
int64_t nix_get_int(nix_c_context * context, const nix_value * value);
|
||||
|
||||
/** @brief Get external reference
|
||||
* @ingroup value_extract
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value Nix value to inspect
|
||||
* @return reference valid while value is valid. Call nix_gc_incref() if you need it to live longer, then only in that
|
||||
* case call nix_gc_decref() when done. NULL in case of error
|
||||
* @return reference to external, NULL in case of error
|
||||
*/
|
||||
ExternalValue * nix_get_external(nix_c_context * context, nix_value * value);
|
||||
|
||||
/** @brief Get the ix'th element of a list
|
||||
* @ingroup value_extract
|
||||
*
|
||||
* Call nix_value_decref() when you're done with the pointer
|
||||
* Owned by the GC. Use nix_gc_decref when you're done with the pointer
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value Nix value to inspect
|
||||
* @param[in] state nix evaluator state
|
||||
@@ -365,12 +266,11 @@ ExternalValue * nix_get_external(nix_c_context * context, nix_value * value);
|
||||
nix_value * nix_get_list_byidx(nix_c_context * context, const nix_value * value, EvalState * state, unsigned int ix);
|
||||
|
||||
/** @brief Get the ix'th element of a list without forcing evaluation of the element
|
||||
* @ingroup value_extract
|
||||
*
|
||||
* Returns the list element without forcing its evaluation, allowing access to lazy values.
|
||||
* The list value itself must already be evaluated.
|
||||
*
|
||||
* Call nix_value_decref() when you're done with the pointer
|
||||
* Owned by the GC. Use nix_gc_decref when you're done with the pointer
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value Nix value to inspect (must be an evaluated list)
|
||||
* @param[in] state nix evaluator state
|
||||
@@ -381,9 +281,8 @@ nix_value *
|
||||
nix_get_list_byidx_lazy(nix_c_context * context, const nix_value * value, EvalState * state, unsigned int ix);
|
||||
|
||||
/** @brief Get an attr by name
|
||||
* @ingroup value_extract
|
||||
*
|
||||
* Call nix_value_decref() when you're done with the pointer
|
||||
* Use nix_gc_decref when you're done with the pointer
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value Nix value to inspect
|
||||
* @param[in] state nix evaluator state
|
||||
@@ -393,12 +292,11 @@ nix_get_list_byidx_lazy(nix_c_context * context, const nix_value * value, EvalSt
|
||||
nix_value * nix_get_attr_byname(nix_c_context * context, const nix_value * value, EvalState * state, const char * name);
|
||||
|
||||
/** @brief Get an attribute value by attribute name, without forcing evaluation of the attribute's value
|
||||
* @ingroup value_extract
|
||||
*
|
||||
* Returns the attribute value without forcing its evaluation, allowing access to lazy values.
|
||||
* The attribute set value itself must already be evaluated.
|
||||
*
|
||||
* Call nix_value_decref() when you're done with the pointer
|
||||
* Use nix_gc_decref when you're done with the pointer
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value Nix value to inspect (must be an evaluated attribute set)
|
||||
* @param[in] state nix evaluator state
|
||||
@@ -409,7 +307,6 @@ nix_value *
|
||||
nix_get_attr_byname_lazy(nix_c_context * context, const nix_value * value, EvalState * state, const char * name);
|
||||
|
||||
/** @brief Check if an attribute name exists on a value
|
||||
* @ingroup value_extract
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value Nix value to inspect
|
||||
* @param[in] state nix evaluator state
|
||||
@@ -419,7 +316,6 @@ nix_get_attr_byname_lazy(nix_c_context * context, const nix_value * value, EvalS
|
||||
bool nix_has_attr_byname(nix_c_context * context, const nix_value * value, EvalState * state, const char * name);
|
||||
|
||||
/** @brief Get an attribute by index
|
||||
* @ingroup value_extract
|
||||
*
|
||||
* Also gives you the name.
|
||||
*
|
||||
@@ -433,19 +329,18 @@ bool nix_has_attr_byname(nix_c_context * context, const nix_value * value, EvalS
|
||||
* lexicographic order by Unicode scalar value for valid UTF-8). We recommend
|
||||
* applying this same ordering for consistency.
|
||||
*
|
||||
* Call nix_value_decref() when you're done with the pointer
|
||||
* Use nix_gc_decref when you're done with the pointer
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value Nix value to inspect
|
||||
* @param[in] state nix evaluator state
|
||||
* @param[in] i attribute index
|
||||
* @param[out] name will store a pointer to the attribute name, valid until state is freed
|
||||
* @param[out] name will store a pointer to the attribute name
|
||||
* @return value, NULL in case of errors
|
||||
*/
|
||||
nix_value *
|
||||
nix_get_attr_byidx(nix_c_context * context, nix_value * value, EvalState * state, unsigned int i, const char ** name);
|
||||
|
||||
/** @brief Get an attribute by index, without forcing evaluation of the attribute's value
|
||||
* @ingroup value_extract
|
||||
*
|
||||
* Also gives you the name.
|
||||
*
|
||||
@@ -462,19 +357,18 @@ nix_get_attr_byidx(nix_c_context * context, nix_value * value, EvalState * state
|
||||
* lexicographic order by Unicode scalar value for valid UTF-8). We recommend
|
||||
* applying this same ordering for consistency.
|
||||
*
|
||||
* Call nix_value_decref() when you're done with the pointer
|
||||
* Use nix_gc_decref when you're done with the pointer
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value Nix value to inspect (must be an evaluated attribute set)
|
||||
* @param[in] state nix evaluator state
|
||||
* @param[in] i attribute index
|
||||
* @param[out] name will store a pointer to the attribute name, valid until state is freed
|
||||
* @param[out] name will store a pointer to the attribute name
|
||||
* @return value, NULL in case of errors
|
||||
*/
|
||||
nix_value * nix_get_attr_byidx_lazy(
|
||||
nix_c_context * context, nix_value * value, EvalState * state, unsigned int i, const char ** name);
|
||||
|
||||
/** @brief Get an attribute name by index
|
||||
* @ingroup value_extract
|
||||
*
|
||||
* Returns the attribute name without forcing evaluation of the attribute's value.
|
||||
*
|
||||
@@ -488,14 +382,16 @@ nix_value * nix_get_attr_byidx_lazy(
|
||||
* lexicographic order by Unicode scalar value for valid UTF-8). We recommend
|
||||
* applying this same ordering for consistency.
|
||||
*
|
||||
* Owned by the nix EvalState
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] value Nix value to inspect
|
||||
* @param[in] state nix evaluator state
|
||||
* @param[in] i attribute index
|
||||
* @return name string valid until state is freed, NULL in case of errors
|
||||
* @return name, NULL in case of errors
|
||||
*/
|
||||
const char * nix_get_attr_name_byidx(nix_c_context * context, nix_value * value, EvalState * state, unsigned int i);
|
||||
|
||||
/**@}*/
|
||||
/** @name Initializers
|
||||
*
|
||||
* Values are typically "returned" by initializing already allocated memory that serves as the return value.
|
||||
@@ -505,7 +401,6 @@ const char * nix_get_attr_name_byidx(nix_c_context * context, nix_value * value,
|
||||
*/
|
||||
/**@{*/
|
||||
/** @brief Set boolean value
|
||||
* @ingroup value_create
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[out] value Nix value to modify
|
||||
* @param[in] b the boolean value
|
||||
@@ -514,7 +409,6 @@ const char * nix_get_attr_name_byidx(nix_c_context * context, nix_value * value,
|
||||
nix_err nix_init_bool(nix_c_context * context, nix_value * value, bool b);
|
||||
|
||||
/** @brief Set a string
|
||||
* @ingroup value_create
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[out] value Nix value to modify
|
||||
* @param[in] str the string, copied
|
||||
@@ -523,7 +417,6 @@ nix_err nix_init_bool(nix_c_context * context, nix_value * value, bool b);
|
||||
nix_err nix_init_string(nix_c_context * context, nix_value * value, const char * str);
|
||||
|
||||
/** @brief Set a path
|
||||
* @ingroup value_create
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[out] value Nix value to modify
|
||||
* @param[in] str the path string, copied
|
||||
@@ -532,7 +425,6 @@ nix_err nix_init_string(nix_c_context * context, nix_value * value, const char *
|
||||
nix_err nix_init_path_string(nix_c_context * context, EvalState * s, nix_value * value, const char * str);
|
||||
|
||||
/** @brief Set a float
|
||||
* @ingroup value_create
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[out] value Nix value to modify
|
||||
* @param[in] d the float, 64-bits
|
||||
@@ -541,7 +433,6 @@ nix_err nix_init_path_string(nix_c_context * context, EvalState * s, nix_value *
|
||||
nix_err nix_init_float(nix_c_context * context, nix_value * value, double d);
|
||||
|
||||
/** @brief Set an int
|
||||
* @ingroup value_create
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[out] value Nix value to modify
|
||||
* @param[in] i the int
|
||||
@@ -550,7 +441,6 @@ nix_err nix_init_float(nix_c_context * context, nix_value * value, double d);
|
||||
|
||||
nix_err nix_init_int(nix_c_context * context, nix_value * value, int64_t i);
|
||||
/** @brief Set null
|
||||
* @ingroup value_create
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[out] value Nix value to modify
|
||||
* @return error code, NIX_OK on success.
|
||||
@@ -558,7 +448,6 @@ nix_err nix_init_int(nix_c_context * context, nix_value * value, int64_t i);
|
||||
nix_err nix_init_null(nix_c_context * context, nix_value * value);
|
||||
|
||||
/** @brief Set the value to a thunk that will perform a function application when needed.
|
||||
* @ingroup value_create
|
||||
*
|
||||
* Thunks may be put into attribute sets and lists to perform some computation lazily; on demand.
|
||||
* However, note that in some places, a thunk must not be returned, such as in the return value of a PrimOp.
|
||||
@@ -575,7 +464,6 @@ nix_err nix_init_null(nix_c_context * context, nix_value * value);
|
||||
nix_err nix_init_apply(nix_c_context * context, nix_value * value, nix_value * fn, nix_value * arg);
|
||||
|
||||
/** @brief Set an external value
|
||||
* @ingroup value_create
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[out] value Nix value to modify
|
||||
* @param[in] val the external value to set. Will be GC-referenced by the value.
|
||||
@@ -584,25 +472,18 @@ nix_err nix_init_apply(nix_c_context * context, nix_value * value, nix_value * f
|
||||
nix_err nix_init_external(nix_c_context * context, nix_value * value, ExternalValue * val);
|
||||
|
||||
/** @brief Create a list from a list builder
|
||||
* @ingroup value_create
|
||||
*
|
||||
* After this call, the list builder becomes invalid and cannot be used again.
|
||||
* The only necessary next step is to free it with nix_list_builder_free().
|
||||
*
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] list_builder list builder to use
|
||||
* @param[in] list_builder list builder to use. Make sure to unref this afterwards.
|
||||
* @param[out] value Nix value to modify
|
||||
* @return error code, NIX_OK on success.
|
||||
* @see nix_list_builder_free
|
||||
*/
|
||||
nix_err nix_make_list(nix_c_context * context, ListBuilder * list_builder, nix_value * value);
|
||||
|
||||
/** @brief Create a list builder
|
||||
* @ingroup value_create
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] state nix evaluator state
|
||||
* @param[in] capacity how many bindings you'll add. Don't exceed.
|
||||
* @return list builder. Call nix_list_builder_free() when you're done.
|
||||
* @return owned reference to a list builder. Make sure to unref when you're done.
|
||||
*/
|
||||
ListBuilder * nix_make_list_builder(nix_c_context * context, EvalState * state, size_t capacity);
|
||||
|
||||
@@ -624,21 +505,14 @@ nix_list_builder_insert(nix_c_context * context, ListBuilder * list_builder, uns
|
||||
void nix_list_builder_free(ListBuilder * list_builder);
|
||||
|
||||
/** @brief Create an attribute set from a bindings builder
|
||||
* @ingroup value_create
|
||||
*
|
||||
* After this call, the bindings builder becomes invalid and cannot be used again.
|
||||
* The only necessary next step is to free it with nix_bindings_builder_free().
|
||||
*
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[out] value Nix value to modify
|
||||
* @param[in] b bindings builder to use
|
||||
* @param[in] b bindings builder to use. Make sure to unref this afterwards.
|
||||
* @return error code, NIX_OK on success.
|
||||
* @see nix_bindings_builder_free
|
||||
*/
|
||||
nix_err nix_make_attrs(nix_c_context * context, nix_value * value, BindingsBuilder * b);
|
||||
|
||||
/** @brief Set primop
|
||||
* @ingroup value_create
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[out] value Nix value to modify
|
||||
* @param[in] op primop, will be gc-referenced by the value
|
||||
@@ -647,7 +521,6 @@ nix_err nix_make_attrs(nix_c_context * context, nix_value * value, BindingsBuild
|
||||
*/
|
||||
nix_err nix_init_primop(nix_c_context * context, nix_value * value, PrimOp * op);
|
||||
/** @brief Copy from another value
|
||||
* @ingroup value_create
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[out] value Nix value to modify
|
||||
* @param[in] source value to copy from
|
||||
@@ -657,11 +530,12 @@ nix_err nix_copy_value(nix_c_context * context, nix_value * value, const nix_val
|
||||
/**@}*/
|
||||
|
||||
/** @brief Create a bindings builder
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] state nix evaluator state
|
||||
* @param[in] capacity how many bindings you'll add. Don't exceed.
|
||||
* @return bindings builder. Call nix_bindings_builder_free() when you're done.
|
||||
*/
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] state nix evaluator state
|
||||
* @param[in] capacity how many bindings you'll add. Don't exceed.
|
||||
* @return owned reference to a bindings builder. Make sure to unref when you're
|
||||
done.
|
||||
*/
|
||||
BindingsBuilder * nix_make_bindings_builder(nix_c_context * context, EvalState * state, size_t capacity);
|
||||
|
||||
/** @brief Insert bindings into a builder
|
||||
@@ -680,6 +554,7 @@ nix_bindings_builder_insert(nix_c_context * context, BindingsBuilder * builder,
|
||||
* @param[in] builder the builder to free
|
||||
*/
|
||||
void nix_bindings_builder_free(BindingsBuilder * builder);
|
||||
/**@}*/
|
||||
|
||||
/** @brief Realise a string context.
|
||||
*
|
||||
@@ -696,13 +571,13 @@ void nix_bindings_builder_free(BindingsBuilder * builder);
|
||||
* @param[in] isIFD If true, disallow derivation outputs if setting `allow-import-from-derivation` is false.
|
||||
You should set this to true when this call is part of a primop.
|
||||
You should set this to false when building for your application's purpose.
|
||||
* @return NULL if failed, or a new nix_realised_string, which must be freed with nix_realised_string_free
|
||||
* @return NULL if failed, are a new nix_realised_string, which must be freed with nix_realised_string_free
|
||||
*/
|
||||
nix_realised_string * nix_string_realise(nix_c_context * context, EvalState * state, nix_value * value, bool isIFD);
|
||||
|
||||
/** @brief Start of the string
|
||||
* @param[in] realised_string
|
||||
* @return pointer to the start of the string, valid until realised_string is freed. It may not be null-terminated.
|
||||
* @return pointer to the start of the string. It may not be null-terminated.
|
||||
*/
|
||||
const char * nix_realised_string_get_buffer_start(nix_realised_string * realised_string);
|
||||
|
||||
@@ -721,7 +596,7 @@ size_t nix_realised_string_get_store_path_count(nix_realised_string * realised_s
|
||||
/** @brief Get a store path. The store paths are stored in an arbitrary order.
|
||||
* @param[in] realised_string
|
||||
* @param[in] index index of the store path, must be less than the count
|
||||
* @return store path valid until realised_string is freed
|
||||
* @return store path
|
||||
*/
|
||||
const StorePath * nix_realised_string_get_store_path(nix_realised_string * realised_string, size_t index);
|
||||
|
||||
@@ -735,4 +610,5 @@ void nix_realised_string_free(nix_realised_string * realised_string);
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif // NIX_API_VALUE_H
|
||||
@@ -771,7 +771,7 @@ TEST_F(PrimOpTest, derivation)
|
||||
ASSERT_EQ(v.type(), nFunction);
|
||||
ASSERT_TRUE(v.isLambda());
|
||||
ASSERT_NE(v.lambda().fun, nullptr);
|
||||
ASSERT_TRUE(v.lambda().fun->getFormals());
|
||||
ASSERT_TRUE(v.lambda().fun->hasFormals());
|
||||
}
|
||||
|
||||
TEST_F(PrimOpTest, currentTime)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "nix/expr/tests/libexpr.hh"
|
||||
#include "nix/util/tests/gmock-matchers.hh"
|
||||
|
||||
namespace nix {
|
||||
// Testing of trivial expressions
|
||||
@@ -161,8 +160,7 @@ TEST_F(TrivialExpressionTest, assertPassed)
|
||||
ASSERT_THAT(v, IsIntEq(123));
|
||||
}
|
||||
|
||||
class AttrSetMergeTrvialExpressionTest : public TrivialExpressionTest,
|
||||
public ::testing::WithParamInterface<const char *>
|
||||
class AttrSetMergeTrvialExpressionTest : public TrivialExpressionTest, public testing::WithParamInterface<const char *>
|
||||
{};
|
||||
|
||||
TEST_P(AttrSetMergeTrvialExpressionTest, attrsetMergeLazy)
|
||||
@@ -198,7 +196,7 @@ TEST_P(AttrSetMergeTrvialExpressionTest, attrsetMergeLazy)
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
attrsetMergeLazy,
|
||||
AttrSetMergeTrvialExpressionTest,
|
||||
::testing::Values("{ a.b = 1; a.c = 2; }", "{ a = { b = 1; }; a = { c = 2; }; }"));
|
||||
testing::Values("{ a.b = 1; a.c = 2; }", "{ a = { b = 1; }; a = { c = 2; }; }"));
|
||||
|
||||
// The following macros ultimately define 48 tests (16 variations on three
|
||||
// templates). Each template tests an expression that can be written in 2^4
|
||||
@@ -341,18 +339,4 @@ TEST_F(TrivialExpressionTest, orCantBeUsed)
|
||||
{
|
||||
ASSERT_THROW(eval("let or = 1; in or"), Error);
|
||||
}
|
||||
|
||||
TEST_F(TrivialExpressionTest, tooManyFormals)
|
||||
{
|
||||
std::string expr = "let f = { ";
|
||||
for (uint32_t i = 0; i <= std::numeric_limits<uint16_t>::max(); ++i) {
|
||||
expr += fmt("arg%d, ", i);
|
||||
}
|
||||
expr += " }: 0 in; f {}";
|
||||
ASSERT_THAT(
|
||||
[&]() { eval(expr); },
|
||||
::testing::ThrowsMessage<Error>(::nix::testing::HasSubstrIgnoreANSIMatcher(
|
||||
"too many formal arguments, implementation supports at most 65535")));
|
||||
}
|
||||
|
||||
} /* namespace nix */
|
||||
@@ -10,7 +10,7 @@ using namespace testing;
|
||||
struct ValuePrintingTests : LibExprTest
|
||||
{
|
||||
template<class... A>
|
||||
void test(Value & v, std::string_view expected, A... args)
|
||||
void test(Value v, std::string_view expected, A... args)
|
||||
{
|
||||
std::stringstream out;
|
||||
v.print(state, out, args...);
|
||||
@@ -110,8 +110,9 @@ TEST_F(ValuePrintingTests, vLambda)
|
||||
PosTable::Origin origin = state.positions.addOrigin(std::monostate(), 1);
|
||||
auto posIdx = state.positions.add(origin, 0);
|
||||
auto body = ExprInt(0);
|
||||
auto formals = Formals{};
|
||||
|
||||
ExprLambda eLambda(posIdx, createSymbol("a"), &body);
|
||||
ExprLambda eLambda(posIdx, createSymbol("a"), &formals, &body);
|
||||
|
||||
Value vLambda;
|
||||
vLambda.mkLambda(&env, &eLambda);
|
||||
@@ -499,8 +500,9 @@ TEST_F(ValuePrintingTests, ansiColorsLambda)
|
||||
PosTable::Origin origin = state.positions.addOrigin(std::monostate(), 1);
|
||||
auto posIdx = state.positions.add(origin, 0);
|
||||
auto body = ExprInt(0);
|
||||
auto formals = Formals{};
|
||||
|
||||
ExprLambda eLambda(posIdx, createSymbol("a"), &body);
|
||||
ExprLambda eLambda(posIdx, createSymbol("a"), &formals, &body);
|
||||
|
||||
Value vLambda;
|
||||
vLambda.mkLambda(&env, &eLambda);
|
||||
@@ -623,11 +625,10 @@ TEST_F(ValuePrintingTests, ansiColorsAttrsElided)
|
||||
vThree.mkInt(3);
|
||||
|
||||
builder.insert(state.symbols.create("three"), &vThree);
|
||||
Value vAttrs2;
|
||||
vAttrs2.mkAttrs(builder.finish());
|
||||
vAttrs.mkAttrs(builder.finish());
|
||||
|
||||
test(
|
||||
vAttrs2,
|
||||
vAttrs,
|
||||
"{ one = " ANSI_CYAN "1" ANSI_NORMAL "; " ANSI_FAINT "«2 attributes elided»" ANSI_NORMAL " }",
|
||||
PrintOptions{.ansiColors = true, .maxAttrs = 1});
|
||||
}
|
||||
|
||||
+65
-58
@@ -1496,13 +1496,15 @@ void EvalState::callFunction(Value & fun, std::span<Value *> args, Value & vRes,
|
||||
|
||||
ExprLambda & lambda(*vCur.lambda().fun);
|
||||
|
||||
auto size = (!lambda.arg ? 0 : 1) + (lambda.getFormals() ? lambda.getFormals()->formals.size() : 0);
|
||||
auto size = (!lambda.arg ? 0 : 1) + (lambda.hasFormals() ? lambda.formals->formals.size() : 0);
|
||||
Env & env2(mem.allocEnv(size));
|
||||
env2.up = vCur.lambda().env;
|
||||
|
||||
Displacement displ = 0;
|
||||
|
||||
if (auto formals = lambda.getFormals()) {
|
||||
if (!lambda.hasFormals())
|
||||
env2.values[displ++] = args[0];
|
||||
else {
|
||||
try {
|
||||
forceAttrs(*args[0], lambda.pos, "while evaluating the value passed for the lambda argument");
|
||||
} catch (Error & e) {
|
||||
@@ -1518,7 +1520,7 @@ void EvalState::callFunction(Value & fun, std::span<Value *> args, Value & vRes,
|
||||
there is no matching actual argument but the formal
|
||||
argument has a default, use the default. */
|
||||
size_t attrsUsed = 0;
|
||||
for (auto & i : formals->formals) {
|
||||
for (auto & i : lambda.formals->formals) {
|
||||
auto j = args[0]->attrs()->get(i.name);
|
||||
if (!j) {
|
||||
if (!i.def) {
|
||||
@@ -1540,13 +1542,13 @@ void EvalState::callFunction(Value & fun, std::span<Value *> args, Value & vRes,
|
||||
|
||||
/* Check that each actual argument is listed as a formal
|
||||
argument (unless the attribute match specifies a `...'). */
|
||||
if (!formals->ellipsis && attrsUsed != args[0]->attrs()->size()) {
|
||||
if (!lambda.formals->ellipsis && attrsUsed != args[0]->attrs()->size()) {
|
||||
/* Nope, so show the first unexpected argument to the
|
||||
user. */
|
||||
for (auto & i : *args[0]->attrs())
|
||||
if (!formals->has(i.name)) {
|
||||
if (!lambda.formals->has(i.name)) {
|
||||
StringSet formalNames;
|
||||
for (auto & formal : formals->formals)
|
||||
for (auto & formal : lambda.formals->formals)
|
||||
formalNames.insert(std::string(symbols[formal.name]));
|
||||
auto suggestions = Suggestions::bestMatches(formalNames, symbols[i.name]);
|
||||
error<TypeError>(
|
||||
@@ -1561,8 +1563,6 @@ void EvalState::callFunction(Value & fun, std::span<Value *> args, Value & vRes,
|
||||
}
|
||||
unreachable();
|
||||
}
|
||||
} else {
|
||||
env2.values[displ++] = args[0];
|
||||
}
|
||||
|
||||
nrFunctionCalls++;
|
||||
@@ -1747,15 +1747,14 @@ void EvalState::autoCallFunction(const Bindings & args, Value & fun, Value & res
|
||||
}
|
||||
}
|
||||
|
||||
if (!fun.isLambda() || !fun.lambda().fun->getFormals()) {
|
||||
if (!fun.isLambda() || !fun.lambda().fun->hasFormals()) {
|
||||
res = fun;
|
||||
return;
|
||||
}
|
||||
auto formals = fun.lambda().fun->getFormals();
|
||||
|
||||
auto attrs = buildBindings(std::max(static_cast<uint32_t>(formals->formals.size()), args.size()));
|
||||
auto attrs = buildBindings(std::max(static_cast<uint32_t>(fun.lambda().fun->formals->formals.size()), args.size()));
|
||||
|
||||
if (formals->ellipsis) {
|
||||
if (fun.lambda().fun->formals->ellipsis) {
|
||||
// If the formals have an ellipsis (eg the function accepts extra args) pass
|
||||
// all available automatic arguments (which includes arguments specified on
|
||||
// the command line via --arg/--argstr)
|
||||
@@ -1763,7 +1762,7 @@ void EvalState::autoCallFunction(const Bindings & args, Value & fun, Value & res
|
||||
attrs.insert(v);
|
||||
} else {
|
||||
// Otherwise, only pass the arguments that the function accepts
|
||||
for (auto & i : formals->formals) {
|
||||
for (auto & i : fun.lambda().fun->formals->formals) {
|
||||
auto j = args.get(i.name);
|
||||
if (j) {
|
||||
attrs.insert(*j);
|
||||
@@ -2021,7 +2020,7 @@ void EvalState::concatLists(
|
||||
void ExprConcatStrings::eval(EvalState & state, Env & env, Value & v)
|
||||
{
|
||||
NixStringContext context;
|
||||
std::vector<BackedStringView> strings;
|
||||
std::vector<BackedStringView> s;
|
||||
size_t sSize = 0;
|
||||
NixInt n{0};
|
||||
NixFloat nf = 0;
|
||||
@@ -2029,11 +2028,32 @@ void ExprConcatStrings::eval(EvalState & state, Env & env, Value & v)
|
||||
bool first = !forceString;
|
||||
ValueType firstType = nString;
|
||||
|
||||
const auto str = [&] {
|
||||
std::string result;
|
||||
result.reserve(sSize);
|
||||
for (const auto & part : s)
|
||||
result += *part;
|
||||
return result;
|
||||
};
|
||||
/* c_str() is not str().c_str() because we want to create a string
|
||||
Value. allocating a GC'd string directly and moving it into a
|
||||
Value lets us avoid an allocation and copy. */
|
||||
const auto c_str = [&] {
|
||||
char * result = allocString(sSize + 1);
|
||||
char * tmp = result;
|
||||
for (const auto & part : s) {
|
||||
memcpy(tmp, part->data(), part->size());
|
||||
tmp += part->size();
|
||||
}
|
||||
*tmp = 0;
|
||||
return result;
|
||||
};
|
||||
|
||||
// List of returned strings. References to these Values must NOT be persisted.
|
||||
SmallTemporaryValueVector<conservativeStackReservation> values(es.size());
|
||||
SmallTemporaryValueVector<conservativeStackReservation> values(es->size());
|
||||
Value * vTmpP = values.data();
|
||||
|
||||
for (auto & [i_pos, i] : es) {
|
||||
for (auto & [i_pos, i] : *es) {
|
||||
Value & vTmp = *vTmpP++;
|
||||
i->eval(state, env, vTmp);
|
||||
|
||||
@@ -2076,46 +2096,33 @@ void ExprConcatStrings::eval(EvalState & state, Env & env, Value & v)
|
||||
.withFrame(env, *this)
|
||||
.debugThrow();
|
||||
} else {
|
||||
if (strings.empty())
|
||||
strings.reserve(es.size());
|
||||
if (s.empty())
|
||||
s.reserve(es->size());
|
||||
/* skip canonization of first path, which would only be not
|
||||
canonized in the first place if it's coming from a ./${foo} type
|
||||
path */
|
||||
auto part = state.coerceToString(
|
||||
i_pos, vTmp, context, "while evaluating a path segment", false, firstType == nString, !first);
|
||||
sSize += part->size();
|
||||
strings.emplace_back(std::move(part));
|
||||
s.emplace_back(std::move(part));
|
||||
}
|
||||
|
||||
first = false;
|
||||
}
|
||||
|
||||
if (firstType == nInt) {
|
||||
if (firstType == nInt)
|
||||
v.mkInt(n);
|
||||
} else if (firstType == nFloat) {
|
||||
else if (firstType == nFloat)
|
||||
v.mkFloat(nf);
|
||||
} else if (firstType == nPath) {
|
||||
else if (firstType == nPath) {
|
||||
if (!context.empty())
|
||||
state.error<EvalError>("a string that refers to a store path cannot be appended to a path")
|
||||
.atPos(pos)
|
||||
.withFrame(env, *this)
|
||||
.debugThrow();
|
||||
std::string result_str;
|
||||
result_str.reserve(sSize);
|
||||
for (const auto & part : strings) {
|
||||
result_str += *part;
|
||||
}
|
||||
v.mkPath(state.rootPath(CanonPath(result_str)));
|
||||
} else {
|
||||
char * result_str = allocString(sSize + 1);
|
||||
char * tmp = result_str;
|
||||
for (const auto & part : strings) {
|
||||
memcpy(tmp, part->data(), part->size());
|
||||
tmp += part->size();
|
||||
}
|
||||
*tmp = 0;
|
||||
v.mkStringMove(result_str, context);
|
||||
}
|
||||
v.mkPath(state.rootPath(CanonPath(str())));
|
||||
} else
|
||||
v.mkStringMove(c_str(), context);
|
||||
}
|
||||
|
||||
void ExprPos::eval(EvalState & state, Env & env, Value & v)
|
||||
@@ -2153,28 +2160,30 @@ void EvalState::forceValueDeep(Value & v)
|
||||
{
|
||||
std::set<const Value *> seen;
|
||||
|
||||
[&, &state(*this)](this const auto & recurse, Value & v) {
|
||||
std::function<void(Value & v)> recurse;
|
||||
|
||||
recurse = [&](Value & v) {
|
||||
if (!seen.insert(&v).second)
|
||||
return;
|
||||
|
||||
state.forceValue(v, v.determinePos(noPos));
|
||||
forceValue(v, v.determinePos(noPos));
|
||||
|
||||
if (v.type() == nAttrs) {
|
||||
for (auto & i : *v.attrs())
|
||||
try {
|
||||
// If the value is a thunk, we're evaling. Otherwise no trace necessary.
|
||||
auto dts = state.debugRepl && i.value->isThunk() ? makeDebugTraceStacker(
|
||||
state,
|
||||
*i.value->thunk().expr,
|
||||
*i.value->thunk().env,
|
||||
i.pos,
|
||||
"while evaluating the attribute '%1%'",
|
||||
state.symbols[i.name])
|
||||
: nullptr;
|
||||
auto dts = debugRepl && i.value->isThunk() ? makeDebugTraceStacker(
|
||||
*this,
|
||||
*i.value->thunk().expr,
|
||||
*i.value->thunk().env,
|
||||
i.pos,
|
||||
"while evaluating the attribute '%1%'",
|
||||
symbols[i.name])
|
||||
: nullptr;
|
||||
|
||||
recurse(*i.value);
|
||||
} catch (Error & e) {
|
||||
state.addErrorTrace(e, i.pos, "while evaluating the attribute '%1%'", state.symbols[i.name]);
|
||||
addErrorTrace(e, i.pos, "while evaluating the attribute '%1%'", symbols[i.name]);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@@ -2183,7 +2192,9 @@ void EvalState::forceValueDeep(Value & v)
|
||||
for (auto v2 : v.listView())
|
||||
recurse(*v2);
|
||||
}
|
||||
}(v);
|
||||
};
|
||||
|
||||
recurse(v);
|
||||
}
|
||||
|
||||
NixInt EvalState::forceInt(Value & v, const PosIdx pos, std::string_view errorCtx)
|
||||
@@ -3056,7 +3067,7 @@ Expr * EvalState::parseExprFromFile(const SourcePath & path)
|
||||
return parseExprFromFile(path, staticBaseEnv);
|
||||
}
|
||||
|
||||
Expr * EvalState::parseExprFromFile(const SourcePath & path, const std::shared_ptr<StaticEnv> & staticEnv)
|
||||
Expr * EvalState::parseExprFromFile(const SourcePath & path, std::shared_ptr<StaticEnv> & staticEnv)
|
||||
{
|
||||
auto buffer = path.resolveSymlinks().readFile();
|
||||
// readFile hopefully have left some extra space for terminators
|
||||
@@ -3064,8 +3075,8 @@ Expr * EvalState::parseExprFromFile(const SourcePath & path, const std::shared_p
|
||||
return parse(buffer.data(), buffer.size(), Pos::Origin(path), path.parent(), staticEnv);
|
||||
}
|
||||
|
||||
Expr * EvalState::parseExprFromString(
|
||||
std::string s_, const SourcePath & basePath, const std::shared_ptr<StaticEnv> & staticEnv)
|
||||
Expr *
|
||||
EvalState::parseExprFromString(std::string s_, const SourcePath & basePath, std::shared_ptr<StaticEnv> & staticEnv)
|
||||
{
|
||||
// NOTE this method (and parseStdin) must take care to *fully copy* their input
|
||||
// into their respective Pos::Origin until the parser stops overwriting its input
|
||||
@@ -3199,11 +3210,7 @@ std::optional<SourcePath> EvalState::resolveLookupPathPath(const LookupPath::Pat
|
||||
}
|
||||
|
||||
Expr * EvalState::parse(
|
||||
char * text,
|
||||
size_t length,
|
||||
Pos::Origin origin,
|
||||
const SourcePath & basePath,
|
||||
const std::shared_ptr<StaticEnv> & staticEnv)
|
||||
char * text, size_t length, Pos::Origin origin, const SourcePath & basePath, std::shared_ptr<StaticEnv> & staticEnv)
|
||||
{
|
||||
DocCommentMap tmpDocComments; // Only used when not origin is not a SourcePath
|
||||
DocCommentMap * docComments = &tmpDocComments;
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "nix/expr/symbol-table.hh"
|
||||
|
||||
#include <boost/container/static_vector.hpp>
|
||||
#include <boost/iterator/function_output_iterator.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
@@ -464,48 +463,12 @@ private:
|
||||
return bindings->baseLayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the bindings gets "layered" on top of another we need to recalculate
|
||||
* the number of unique attributes in the chain.
|
||||
*
|
||||
* This is done by either iterating over the base "layer" and the newly added
|
||||
* attributes and counting duplicates. If the base "layer" is big this approach
|
||||
* is inefficient and we fall back to doing per-element binary search in the base
|
||||
* "layer".
|
||||
*/
|
||||
void finishSizeIfNecessary()
|
||||
{
|
||||
if (!hasBaseLayer())
|
||||
return;
|
||||
|
||||
auto & base = *bindings->baseLayer;
|
||||
auto attrs = std::span(bindings->attrs, bindings->numAttrs);
|
||||
|
||||
Bindings::size_type duplicates = 0;
|
||||
|
||||
/* If the base bindings is smaller than the newly added attributes
|
||||
iterate using std::set_intersection to run in O(|base| + |attrs|) =
|
||||
O(|attrs|). Otherwise use an O(|attrs| * log(|base|)) per-attr binary
|
||||
search to check for duplicates. Note that if we are in this code path then
|
||||
|attrs| <= bindingsUpdateLayerRhsSizeThreshold, which 16 by default. We are
|
||||
optimizing for the case when a small attribute set gets "layered" on top of
|
||||
a much larger one. When attrsets are already small it's fine to do a linear
|
||||
scan, but we should avoid expensive iterations over large "base" attrsets. */
|
||||
if (attrs.size() > base.size()) {
|
||||
std::set_intersection(
|
||||
base.begin(),
|
||||
base.end(),
|
||||
attrs.begin(),
|
||||
attrs.end(),
|
||||
boost::make_function_output_iterator([&]([[maybe_unused]] auto && _) { ++duplicates; }));
|
||||
} else {
|
||||
for (const auto & attr : attrs) {
|
||||
if (base.get(attr.name))
|
||||
++duplicates;
|
||||
}
|
||||
}
|
||||
|
||||
bindings->numAttrsInChain = base.numAttrsInChain + attrs.size() - duplicates;
|
||||
if (hasBaseLayer())
|
||||
/* NOTE: Do not use std::ranges::distance, since Bindings is a sized
|
||||
range, but we are calculating this size here. */
|
||||
bindings->numAttrsInChain = std::distance(bindings->begin(), bindings->end());
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
@@ -191,7 +191,7 @@ std::ostream & operator<<(std::ostream & os, const ValueType t);
|
||||
|
||||
struct RegexCache;
|
||||
|
||||
ref<RegexCache> makeRegexCache();
|
||||
std::shared_ptr<RegexCache> makeRegexCache();
|
||||
|
||||
struct DebugTrace
|
||||
{
|
||||
@@ -372,7 +372,6 @@ public:
|
||||
|
||||
const fetchers::Settings & fetchSettings;
|
||||
const EvalSettings & settings;
|
||||
|
||||
SymbolTable symbols;
|
||||
PosTable positions;
|
||||
|
||||
@@ -419,7 +418,7 @@ public:
|
||||
|
||||
RootValue vImportedDrvToDerivation = nullptr;
|
||||
|
||||
const ref<fetchers::InputCache> inputCache;
|
||||
ref<fetchers::InputCache> inputCache;
|
||||
|
||||
/**
|
||||
* Debugger
|
||||
@@ -472,18 +471,18 @@ private:
|
||||
|
||||
/* Cache for calls to addToStore(); maps source paths to the store
|
||||
paths. */
|
||||
const ref<boost::concurrent_flat_map<SourcePath, StorePath>> srcToStore;
|
||||
ref<boost::concurrent_flat_map<SourcePath, StorePath>> srcToStore;
|
||||
|
||||
/**
|
||||
* A cache that maps paths to "resolved" paths for importing Nix
|
||||
* expressions, i.e. `/foo` to `/foo/default.nix`.
|
||||
*/
|
||||
const ref<boost::concurrent_flat_map<SourcePath, SourcePath>> importResolutionCache;
|
||||
ref<boost::concurrent_flat_map<SourcePath, SourcePath>> importResolutionCache;
|
||||
|
||||
/**
|
||||
* A cache from resolved paths to values.
|
||||
*/
|
||||
const ref<boost::concurrent_flat_map<
|
||||
ref<boost::concurrent_flat_map<
|
||||
SourcePath,
|
||||
Value *,
|
||||
std::hash<SourcePath>,
|
||||
@@ -505,7 +504,7 @@ private:
|
||||
/**
|
||||
* Cache used by prim_match().
|
||||
*/
|
||||
const ref<RegexCache> regexCache;
|
||||
std::shared_ptr<RegexCache> regexCache;
|
||||
|
||||
public:
|
||||
|
||||
@@ -593,13 +592,12 @@ public:
|
||||
* Parse a Nix expression from the specified file.
|
||||
*/
|
||||
Expr * parseExprFromFile(const SourcePath & path);
|
||||
Expr * parseExprFromFile(const SourcePath & path, const std::shared_ptr<StaticEnv> & staticEnv);
|
||||
Expr * parseExprFromFile(const SourcePath & path, std::shared_ptr<StaticEnv> & staticEnv);
|
||||
|
||||
/**
|
||||
* Parse a Nix expression from the specified string.
|
||||
*/
|
||||
Expr *
|
||||
parseExprFromString(std::string s, const SourcePath & basePath, const std::shared_ptr<StaticEnv> & staticEnv);
|
||||
Expr * parseExprFromString(std::string s, const SourcePath & basePath, std::shared_ptr<StaticEnv> & staticEnv);
|
||||
Expr * parseExprFromString(std::string s, const SourcePath & basePath);
|
||||
|
||||
Expr * parseStdin();
|
||||
@@ -768,7 +766,7 @@ public:
|
||||
|
||||
#if NIX_USE_BOEHMGC
|
||||
/** A GC root for the baseEnv reference. */
|
||||
const std::shared_ptr<Env *> baseEnvP;
|
||||
std::shared_ptr<Env *> baseEnvP;
|
||||
#endif
|
||||
|
||||
public:
|
||||
@@ -782,7 +780,7 @@ public:
|
||||
/**
|
||||
* The same, but used during parsing to resolve variables.
|
||||
*/
|
||||
const std::shared_ptr<StaticEnv> staticBaseEnv; // !!! should be private
|
||||
std::shared_ptr<StaticEnv> staticBaseEnv; // !!! should be private
|
||||
|
||||
/**
|
||||
* Internal primops not exposed to the user.
|
||||
@@ -864,7 +862,7 @@ private:
|
||||
size_t length,
|
||||
Pos::Origin origin,
|
||||
const SourcePath & basePath,
|
||||
const std::shared_ptr<StaticEnv> & staticEnv);
|
||||
std::shared_ptr<StaticEnv> & staticEnv);
|
||||
|
||||
/**
|
||||
* Current Nix call stack depth, used with `max-call-depth` setting to throw stack overflow hopefully before we run
|
||||
|
||||
@@ -13,8 +13,6 @@
|
||||
#include "nix/expr/eval-error.hh"
|
||||
#include "nix/util/pos-idx.hh"
|
||||
#include "nix/expr/counter.hh"
|
||||
#include "nix/util/pos-table.hh"
|
||||
#include "nix/util/error.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
@@ -444,14 +442,8 @@ struct ExprAttrs : Expr
|
||||
|
||||
struct ExprList : Expr
|
||||
{
|
||||
std::span<Expr *> elems;
|
||||
|
||||
ExprList(std::pmr::polymorphic_allocator<char> & alloc, std::vector<Expr *> exprs)
|
||||
: elems({alloc.allocate_object<Expr *>(exprs.size()), exprs.size()})
|
||||
{
|
||||
std::ranges::copy(exprs, elems.begin());
|
||||
};
|
||||
|
||||
std::vector<Expr *> elems;
|
||||
ExprList() {};
|
||||
COMMON_METHODS
|
||||
Value * maybeThunk(EvalState & state, Env & env) override;
|
||||
|
||||
@@ -468,7 +460,7 @@ struct Formal
|
||||
Expr * def;
|
||||
};
|
||||
|
||||
struct FormalsBuilder
|
||||
struct Formals
|
||||
{
|
||||
typedef std::vector<Formal> Formals_;
|
||||
/**
|
||||
@@ -483,23 +475,6 @@ struct FormalsBuilder
|
||||
formals.begin(), formals.end(), arg, [](const Formal & f, const Symbol & sym) { return f.name < sym; });
|
||||
return it != formals.end() && it->name == arg;
|
||||
}
|
||||
};
|
||||
|
||||
struct Formals
|
||||
{
|
||||
std::span<Formal> formals;
|
||||
bool ellipsis;
|
||||
|
||||
Formals(std::span<Formal> formals, bool ellipsis)
|
||||
: formals(formals)
|
||||
, ellipsis(ellipsis) {};
|
||||
|
||||
bool has(Symbol arg) const
|
||||
{
|
||||
auto it = std::lower_bound(
|
||||
formals.begin(), formals.end(), arg, [](const Formal & f, const Symbol & sym) { return f.name < sym; });
|
||||
return it != formals.end() && it->name == arg;
|
||||
}
|
||||
|
||||
std::vector<Formal> lexicographicOrder(const SymbolTable & symbols) const
|
||||
{
|
||||
@@ -517,71 +492,31 @@ struct ExprLambda : Expr
|
||||
PosIdx pos;
|
||||
Symbol name;
|
||||
Symbol arg;
|
||||
|
||||
private:
|
||||
bool hasFormals;
|
||||
bool ellipsis;
|
||||
uint16_t nFormals;
|
||||
Formal * formalsStart;
|
||||
public:
|
||||
|
||||
std::optional<Formals> getFormals() const
|
||||
{
|
||||
if (hasFormals)
|
||||
return Formals{{formalsStart, nFormals}, ellipsis};
|
||||
else
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
Formals * formals;
|
||||
Expr * body;
|
||||
DocComment docComment;
|
||||
|
||||
ExprLambda(
|
||||
const PosTable & positions,
|
||||
std::pmr::polymorphic_allocator<char> & alloc,
|
||||
PosIdx pos,
|
||||
Symbol arg,
|
||||
const FormalsBuilder & formals,
|
||||
Expr * body)
|
||||
ExprLambda(PosIdx pos, Symbol arg, Formals * formals, Expr * body)
|
||||
: pos(pos)
|
||||
, arg(arg)
|
||||
, hasFormals(true)
|
||||
, ellipsis(formals.ellipsis)
|
||||
, nFormals(formals.formals.size())
|
||||
, formalsStart(alloc.allocate_object<Formal>(nFormals))
|
||||
, body(body)
|
||||
{
|
||||
if (formals.formals.size() > nFormals) [[unlikely]] {
|
||||
auto err = Error(
|
||||
"too many formal arguments, implementation supports at most %1%",
|
||||
std::numeric_limits<decltype(nFormals)>::max());
|
||||
if (pos)
|
||||
err.atPos(positions[pos]);
|
||||
throw err;
|
||||
}
|
||||
std::uninitialized_copy_n(formals.formals.begin(), nFormals, formalsStart);
|
||||
};
|
||||
|
||||
ExprLambda(PosIdx pos, Symbol arg, Expr * body)
|
||||
: pos(pos)
|
||||
, arg(arg)
|
||||
, hasFormals(false)
|
||||
, ellipsis(false)
|
||||
, nFormals(0)
|
||||
, formalsStart(nullptr)
|
||||
, formals(formals)
|
||||
, body(body) {};
|
||||
|
||||
ExprLambda(
|
||||
const PosTable & positions,
|
||||
std::pmr::polymorphic_allocator<char> & alloc,
|
||||
PosIdx pos,
|
||||
FormalsBuilder formals,
|
||||
Expr * body)
|
||||
: ExprLambda(positions, alloc, pos, Symbol(), formals, body) {};
|
||||
ExprLambda(PosIdx pos, Formals * formals, Expr * body)
|
||||
: pos(pos)
|
||||
, formals(formals)
|
||||
, body(body)
|
||||
{
|
||||
}
|
||||
|
||||
void setName(Symbol name) override;
|
||||
std::string showNamePos(const EvalState & state) const;
|
||||
|
||||
inline bool hasFormals() const
|
||||
{
|
||||
return formals != nullptr;
|
||||
}
|
||||
|
||||
PosIdx getPos() const override
|
||||
{
|
||||
return pos;
|
||||
@@ -760,11 +695,11 @@ struct ExprConcatStrings : Expr
|
||||
{
|
||||
PosIdx pos;
|
||||
bool forceString;
|
||||
std::vector<std::pair<PosIdx, Expr *>> es;
|
||||
ExprConcatStrings(const PosIdx & pos, bool forceString, std::vector<std::pair<PosIdx, Expr *>> && es)
|
||||
std::vector<std::pair<PosIdx, Expr *>> * es;
|
||||
ExprConcatStrings(const PosIdx & pos, bool forceString, std::vector<std::pair<PosIdx, Expr *>> * es)
|
||||
: pos(pos)
|
||||
, forceString(forceString)
|
||||
, es(std::move(es)) {};
|
||||
, es(es) {};
|
||||
|
||||
PosIdx getPos() const override
|
||||
{
|
||||
|
||||
@@ -93,7 +93,7 @@ struct ParserState
|
||||
void addAttr(
|
||||
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 validateFormals(FormalsBuilder & formals, PosIdx pos = noPos, Symbol arg = {});
|
||||
Formals * validateFormals(Formals * formals, PosIdx pos = noPos, Symbol arg = {});
|
||||
Expr * stripIndentation(const PosIdx pos, std::vector<std::pair<PosIdx, std::variant<Expr *, StringToken>>> && es);
|
||||
PosIdx at(const ParserLocation & loc);
|
||||
};
|
||||
@@ -213,17 +213,17 @@ ParserState::addAttr(ExprAttrs * attrs, AttrPath & attrPath, const Symbol & symb
|
||||
}
|
||||
}
|
||||
|
||||
inline void ParserState::validateFormals(FormalsBuilder & formals, PosIdx pos, Symbol arg)
|
||||
inline Formals * ParserState::validateFormals(Formals * formals, PosIdx pos, Symbol arg)
|
||||
{
|
||||
std::sort(formals.formals.begin(), formals.formals.end(), [](const auto & a, const auto & b) {
|
||||
std::sort(formals->formals.begin(), formals->formals.end(), [](const auto & a, const auto & b) {
|
||||
return std::tie(a.name, a.pos) < std::tie(b.name, b.pos);
|
||||
});
|
||||
|
||||
std::optional<std::pair<Symbol, PosIdx>> duplicate;
|
||||
for (size_t i = 0; i + 1 < formals.formals.size(); i++) {
|
||||
if (formals.formals[i].name != formals.formals[i + 1].name)
|
||||
for (size_t i = 0; i + 1 < formals->formals.size(); i++) {
|
||||
if (formals->formals[i].name != formals->formals[i + 1].name)
|
||||
continue;
|
||||
std::pair thisDup{formals.formals[i].name, formals.formals[i + 1].pos};
|
||||
std::pair thisDup{formals->formals[i].name, formals->formals[i + 1].pos};
|
||||
duplicate = std::min(thisDup, duplicate.value_or(thisDup));
|
||||
}
|
||||
if (duplicate)
|
||||
@@ -231,9 +231,11 @@ inline void ParserState::validateFormals(FormalsBuilder & formals, PosIdx pos, S
|
||||
{.msg = HintFmt("duplicate formal function argument '%1%'", symbols[duplicate->first]),
|
||||
.pos = positions[duplicate->second]});
|
||||
|
||||
if (arg && formals.has(arg))
|
||||
if (arg && formals->has(arg))
|
||||
throw ParseError(
|
||||
{.msg = HintFmt("duplicate formal function argument '%1%'", symbols[arg]), .pos = positions[pos]});
|
||||
|
||||
return formals;
|
||||
}
|
||||
|
||||
inline Expr *
|
||||
@@ -280,7 +282,7 @@ ParserState::stripIndentation(const PosIdx pos, std::vector<std::pair<PosIdx, st
|
||||
}
|
||||
|
||||
/* Strip spaces from each line. */
|
||||
std::vector<std::pair<PosIdx, Expr *>> es2{};
|
||||
auto * es2 = new std::vector<std::pair<PosIdx, Expr *>>;
|
||||
atStartOfLine = true;
|
||||
size_t curDropped = 0;
|
||||
size_t n = es.size();
|
||||
@@ -288,7 +290,7 @@ ParserState::stripIndentation(const PosIdx pos, std::vector<std::pair<PosIdx, st
|
||||
const auto trimExpr = [&](Expr * e) {
|
||||
atStartOfLine = false;
|
||||
curDropped = 0;
|
||||
es2.emplace_back(i->first, e);
|
||||
es2->emplace_back(i->first, e);
|
||||
};
|
||||
const auto trimString = [&](const StringToken & t) {
|
||||
std::string s2;
|
||||
@@ -322,7 +324,7 @@ ParserState::stripIndentation(const PosIdx pos, std::vector<std::pair<PosIdx, st
|
||||
|
||||
// Ignore empty strings for a minor optimisation and AST simplification
|
||||
if (s2 != "") {
|
||||
es2.emplace_back(i->first, new ExprString(alloc, s2));
|
||||
es2->emplace_back(i->first, new ExprString(alloc, s2));
|
||||
}
|
||||
};
|
||||
for (; i != es.end(); ++i, --n) {
|
||||
@@ -331,17 +333,19 @@ ParserState::stripIndentation(const PosIdx pos, std::vector<std::pair<PosIdx, st
|
||||
|
||||
// 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.
|
||||
if (es2.size() == 0) {
|
||||
if (es2->size() == 0) {
|
||||
auto * const result = new ExprString("");
|
||||
delete es2;
|
||||
return result;
|
||||
}
|
||||
|
||||
/* If this is a single string, then don't do a concatenation. */
|
||||
if (es2.size() == 1 && dynamic_cast<ExprString *>((es2)[0].second)) {
|
||||
auto * const result = (es2)[0].second;
|
||||
if (es2->size() == 1 && dynamic_cast<ExprString *>((*es2)[0].second)) {
|
||||
auto * const result = (*es2)[0].second;
|
||||
delete es2;
|
||||
return result;
|
||||
}
|
||||
return new ExprConcatStrings(pos, true, std::move(es2));
|
||||
return new ExprConcatStrings(pos, true, es2);
|
||||
}
|
||||
|
||||
inline PosIdx LexerState::at(const ParserLocation & loc)
|
||||
|
||||
+17
-25
@@ -142,11 +142,11 @@ or { return OR_KW; }
|
||||
return PIPE_INTO;
|
||||
}
|
||||
|
||||
{ID} { yylval->emplace<StringToken>(yytext, (size_t) yyleng); return ID; }
|
||||
{ID} { yylval->id = {yytext, (size_t) yyleng}; return ID; }
|
||||
{INT} { errno = 0;
|
||||
std::optional<int64_t> numMay = string2Int<int64_t>(yytext);
|
||||
if (numMay.has_value()) {
|
||||
yylval->emplace<NixInt>(*numMay);
|
||||
yylval->n = NixInt{*numMay};
|
||||
} else {
|
||||
throw ParseError(ErrorInfo{
|
||||
.msg = HintFmt("invalid integer '%1%'", yytext),
|
||||
@@ -156,7 +156,7 @@ or { return OR_KW; }
|
||||
return INT_LIT;
|
||||
}
|
||||
{FLOAT} { errno = 0;
|
||||
yylval->emplace<NixFloat>(strtod(yytext, 0));
|
||||
yylval->nf = strtod(yytext, 0);
|
||||
if (errno != 0)
|
||||
throw ParseError(ErrorInfo{
|
||||
.msg = HintFmt("invalid float '%1%'", yytext),
|
||||
@@ -183,7 +183,7 @@ or { return OR_KW; }
|
||||
/* It is impossible to match strings ending with '$' with one
|
||||
regex because trailing contexts are only valid at the end
|
||||
of a rule. (A sane but undocumented limitation.) */
|
||||
yylval->emplace<StringToken>(unescapeStr(yytext, yyleng, [&]() { return state->positions[CUR_POS]; }));
|
||||
yylval->str = unescapeStr(yytext, yyleng, [&]() { return state->positions[CUR_POS]; });
|
||||
return STR;
|
||||
}
|
||||
<STRING>\$\{ { PUSH_STATE(DEFAULT); return DOLLAR_CURLY; }
|
||||
@@ -198,27 +198,27 @@ or { return OR_KW; }
|
||||
|
||||
\'\'(\ *\n)? { PUSH_STATE(IND_STRING); return IND_STRING_OPEN; }
|
||||
<IND_STRING>([^\$\']|\$[^\{\']|\'[^\'\$])+ {
|
||||
yylval->emplace<StringToken>(yytext, (size_t) yyleng, true);
|
||||
forceNoNullByte(yylval->as<StringToken>(), [&]() { return state->positions[CUR_POS]; });
|
||||
yylval->str = {yytext, (size_t) yyleng, true};
|
||||
forceNoNullByte(yylval->str, [&]() { return state->positions[CUR_POS]; });
|
||||
return IND_STR;
|
||||
}
|
||||
<IND_STRING>\'\'\$ |
|
||||
<IND_STRING>\$ {
|
||||
yylval->emplace<StringToken>("$", 1);
|
||||
yylval->str = {"$", 1};
|
||||
return IND_STR;
|
||||
}
|
||||
<IND_STRING>\'\'\' {
|
||||
yylval->emplace<StringToken>("''", 2);
|
||||
yylval->str = {"''", 2};
|
||||
return IND_STR;
|
||||
}
|
||||
<IND_STRING>\'\'\\{ANY} {
|
||||
yylval->emplace<StringToken>(unescapeStr(yytext + 2, yyleng - 2, [&]() { return state->positions[CUR_POS]; }));
|
||||
yylval->str = unescapeStr(yytext + 2, yyleng - 2, [&]() { return state->positions[CUR_POS]; });
|
||||
return IND_STR;
|
||||
}
|
||||
<IND_STRING>\$\{ { PUSH_STATE(DEFAULT); return DOLLAR_CURLY; }
|
||||
<IND_STRING>\'\' { POP_STATE(); return IND_STRING_CLOSE; }
|
||||
<IND_STRING>\' {
|
||||
yylval->emplace<StringToken>("'", 1);
|
||||
yylval->str = {"'", 1};
|
||||
return IND_STR;
|
||||
}
|
||||
|
||||
@@ -232,31 +232,23 @@ or { return OR_KW; }
|
||||
<PATH_START>{PATH_SEG} {
|
||||
POP_STATE();
|
||||
PUSH_STATE(INPATH_SLASH);
|
||||
yylval->emplace<StringToken>(yytext, (size_t) yyleng);
|
||||
yylval->path = {yytext, (size_t) yyleng};
|
||||
return PATH;
|
||||
}
|
||||
|
||||
<PATH_START>{HPATH_START} {
|
||||
POP_STATE();
|
||||
PUSH_STATE(INPATH_SLASH);
|
||||
yylval->emplace<StringToken>(yytext, (size_t) yyleng);
|
||||
yylval->path = {yytext, (size_t) yyleng};
|
||||
return HPATH;
|
||||
}
|
||||
|
||||
<PATH_START>{ANY} |
|
||||
<PATH_START><<EOF>> {
|
||||
/* This should be unreachable: PATH_START is only entered after matching
|
||||
PATH_SEG or HPATH_START, and we rewind to re-parse those same patterns.
|
||||
This rule exists to satisfy flex's %option nodefault requirement. */
|
||||
unreachable();
|
||||
}
|
||||
|
||||
{PATH} {
|
||||
if (yytext[yyleng-1] == '/')
|
||||
PUSH_STATE(INPATH_SLASH);
|
||||
else
|
||||
PUSH_STATE(INPATH);
|
||||
yylval->emplace<StringToken>(yytext, (size_t) yyleng);
|
||||
yylval->path = {yytext, (size_t) yyleng};
|
||||
return PATH;
|
||||
}
|
||||
{HPATH} {
|
||||
@@ -264,7 +256,7 @@ or { return OR_KW; }
|
||||
PUSH_STATE(INPATH_SLASH);
|
||||
else
|
||||
PUSH_STATE(INPATH);
|
||||
yylval->emplace<StringToken>(yytext, (size_t) yyleng);
|
||||
yylval->path = {yytext, (size_t) yyleng};
|
||||
return HPATH;
|
||||
}
|
||||
|
||||
@@ -280,7 +272,7 @@ or { return OR_KW; }
|
||||
PUSH_STATE(INPATH_SLASH);
|
||||
else
|
||||
PUSH_STATE(INPATH);
|
||||
yylval->emplace<StringToken>(yytext, (size_t) yyleng);
|
||||
yylval->str = {yytext, (size_t) yyleng};
|
||||
return STR;
|
||||
}
|
||||
<INPATH>{ANY} |
|
||||
@@ -302,8 +294,8 @@ or { return OR_KW; }
|
||||
});
|
||||
}
|
||||
|
||||
{SPATH} { yylval->emplace<StringToken>(yytext, (size_t) yyleng); return SPATH; }
|
||||
{URI} { yylval->emplace<StringToken>(yytext, (size_t) yyleng); return URI; }
|
||||
{SPATH} { yylval->path = {yytext, (size_t) yyleng}; return SPATH; }
|
||||
{URI} { yylval->uri = {yytext, (size_t) yyleng}; return URI; }
|
||||
|
||||
%{
|
||||
// Doc comment rule
|
||||
|
||||
+2
-47
@@ -183,62 +183,17 @@ subdir('primops')
|
||||
subdir('nix-meson-build-support/export-all-symbols')
|
||||
subdir('nix-meson-build-support/windows-version')
|
||||
|
||||
# Turns out that Bison/Flex are particularly sensitive to compilers
|
||||
# failing to inline functions. For that reason we crank up the inlining
|
||||
# threshold manually for optimized builds. Yes, this can be considered 'ricing'
|
||||
# the compiler, but it does pay off.
|
||||
#
|
||||
# NOTE: missed inlining can be spotted (for Clang) using -Rpass-missed=inline
|
||||
# and -fdump-ipa-inline-missed (for GCC).
|
||||
parser_library_cpp_args = []
|
||||
|
||||
if not get_option('debug')
|
||||
if cxx.get_id() == 'clang'
|
||||
# The default as of LLVM 21 is 225:
|
||||
# llc --help-hidden | grep inline-threshold
|
||||
parser_library_cpp_args += [
|
||||
'-mllvm',
|
||||
'-inline-threshold=5000',
|
||||
]
|
||||
elif cxx.get_id() == 'gcc'
|
||||
parser_library_cpp_args += [
|
||||
'--param=max-inline-insns-single=1000',
|
||||
'--param=max-inline-insns-auto=1000',
|
||||
'--param=inline-unit-growth=400',
|
||||
]
|
||||
endif
|
||||
endif
|
||||
|
||||
# Working around https://github.com/mesonbuild/meson/issues/1367.
|
||||
parser_library = static_library(
|
||||
'nixexpr-parser',
|
||||
parser_tab,
|
||||
lexer_tab,
|
||||
cpp_args : parser_library_cpp_args,
|
||||
dependencies : deps_public + deps_private + deps_other,
|
||||
include_directories : include_dirs,
|
||||
# 1. Stdlib and regular assertions regress parser performance significantly, so build without
|
||||
# them for this one library when building in a release configuration.
|
||||
# 2. Disable LTO for GCC because then inlining flags won't apply, since LTO in GCC is done
|
||||
# by plonking down GIMPLE in the archive.
|
||||
override_options : [
|
||||
'b_ndebug=@0@'.format(not get_option('debug')),
|
||||
'b_lto=@0@'.format(get_option('b_lto') and cxx.get_id() != 'gcc'),
|
||||
],
|
||||
)
|
||||
|
||||
this_library = library(
|
||||
'nixexpr',
|
||||
sources,
|
||||
config_priv_h,
|
||||
parser_tab[1],
|
||||
lexer_tab[1],
|
||||
parser_tab,
|
||||
lexer_tab,
|
||||
generated_headers,
|
||||
soversion : nix_soversion,
|
||||
dependencies : deps_public + deps_private + deps_other,
|
||||
include_directories : include_dirs,
|
||||
link_args : linker_export_flags,
|
||||
link_whole : [ parser_library ],
|
||||
prelink : true, # For C++ static initializers
|
||||
install : true,
|
||||
cpp_pch : do_pch ? [ 'pch/precompiled-headers.hh' ] : [],
|
||||
|
||||
@@ -154,7 +154,7 @@ void ExprList::show(const SymbolTable & symbols, std::ostream & str) const
|
||||
void ExprLambda::show(const SymbolTable & symbols, std::ostream & str) const
|
||||
{
|
||||
str << "(";
|
||||
if (auto formals = getFormals()) {
|
||||
if (hasFormals()) {
|
||||
str << "{ ";
|
||||
bool first = true;
|
||||
// the natural Symbol ordering is by creation time, which can lead to the
|
||||
@@ -171,7 +171,7 @@ void ExprLambda::show(const SymbolTable & symbols, std::ostream & str) const
|
||||
i.def->show(symbols, str);
|
||||
}
|
||||
}
|
||||
if (ellipsis) {
|
||||
if (formals->ellipsis) {
|
||||
if (!first)
|
||||
str << ", ";
|
||||
str << "...";
|
||||
@@ -246,7 +246,7 @@ void ExprConcatStrings::show(const SymbolTable & symbols, std::ostream & str) co
|
||||
{
|
||||
bool first = true;
|
||||
str << "(";
|
||||
for (auto & i : es) {
|
||||
for (auto & i : *es) {
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
@@ -452,14 +452,14 @@ void ExprLambda::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv>
|
||||
es.exprEnvs.insert(std::make_pair(this, env));
|
||||
|
||||
auto newEnv =
|
||||
std::make_shared<StaticEnv>(nullptr, env, (getFormals() ? getFormals()->formals.size() : 0) + (!arg ? 0 : 1));
|
||||
std::make_shared<StaticEnv>(nullptr, env, (hasFormals() ? formals->formals.size() : 0) + (!arg ? 0 : 1));
|
||||
|
||||
Displacement displ = 0;
|
||||
|
||||
if (arg)
|
||||
newEnv->vars.emplace_back(arg, displ++);
|
||||
|
||||
if (auto formals = getFormals()) {
|
||||
if (hasFormals()) {
|
||||
for (auto & i : formals->formals)
|
||||
newEnv->vars.emplace_back(i.name, displ++);
|
||||
|
||||
@@ -564,7 +564,7 @@ void ExprConcatStrings::bindVars(EvalState & es, const std::shared_ptr<const Sta
|
||||
if (es.debugRepl)
|
||||
es.exprEnvs.insert(std::make_pair(this, env));
|
||||
|
||||
for (auto & i : this->es)
|
||||
for (auto & i : *this->es)
|
||||
i.second->bindVars(es, env);
|
||||
}
|
||||
|
||||
|
||||
+107
-87
@@ -14,10 +14,6 @@
|
||||
|
||||
%code requires {
|
||||
|
||||
// bison adds a bunch of switch statements with default:
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wswitch-enum"
|
||||
|
||||
#ifndef BISON_HEADER
|
||||
#define BISON_HEADER
|
||||
|
||||
@@ -124,28 +120,46 @@ static Expr * makeCall(PosIdx pos, Expr * fn, Expr * arg) {
|
||||
|
||||
%}
|
||||
|
||||
%define api.value.type variant
|
||||
%union {
|
||||
// !!! We're probably leaking stuff here.
|
||||
nix::Expr * e;
|
||||
nix::ExprList * list;
|
||||
nix::ExprAttrs * attrs;
|
||||
nix::Formals * formals;
|
||||
nix::Formal * formal;
|
||||
nix::NixInt n;
|
||||
nix::NixFloat nf;
|
||||
nix::StringToken id; // !!! -> Symbol
|
||||
nix::StringToken path;
|
||||
nix::StringToken uri;
|
||||
nix::StringToken str;
|
||||
std::vector<nix::AttrName> * attrNames;
|
||||
std::vector<std::pair<nix::AttrName, nix::PosIdx>> * inheritAttrs;
|
||||
std::vector<std::pair<nix::PosIdx, nix::Expr *>> * string_parts;
|
||||
std::variant<nix::Expr *, std::string_view> * to_be_string;
|
||||
std::vector<std::pair<nix::PosIdx, std::variant<nix::Expr *, nix::StringToken>>> * ind_string_parts;
|
||||
}
|
||||
|
||||
%type <nix::Expr *> start expr expr_function expr_if expr_op
|
||||
%type <nix::Expr *> expr_select expr_simple expr_app
|
||||
%type <nix::Expr *> expr_pipe_from expr_pipe_into
|
||||
%type <std::vector<Expr *>> list
|
||||
%type <nix::ExprAttrs *> binds binds1
|
||||
%type <nix::FormalsBuilder> formals formal_set
|
||||
%type <nix::Formal> formal
|
||||
%type <std::vector<nix::AttrName>> attrpath
|
||||
%type <std::vector<std::pair<nix::AttrName, nix::PosIdx>>> attrs
|
||||
%type <std::vector<std::pair<nix::PosIdx, nix::Expr *>>> string_parts_interpolated
|
||||
%type <std::vector<std::pair<nix::PosIdx, std::variant<nix::Expr *, nix::StringToken>>>> ind_string_parts
|
||||
%type <nix::Expr *> path_start
|
||||
%type <std::variant<nix::Expr *, std::string_view>> string_parts string_attr
|
||||
%type <nix::StringToken> attr
|
||||
%token <nix::StringToken> ID
|
||||
%token <nix::StringToken> STR IND_STR
|
||||
%token <nix::NixInt> INT_LIT
|
||||
%token <nix::NixFloat> FLOAT_LIT
|
||||
%token <nix::StringToken> PATH HPATH SPATH PATH_END
|
||||
%token <nix::StringToken> URI
|
||||
%type <e> start expr expr_function expr_if expr_op
|
||||
%type <e> expr_select expr_simple expr_app
|
||||
%type <e> expr_pipe_from expr_pipe_into
|
||||
%type <list> expr_list
|
||||
%type <attrs> binds binds1
|
||||
%type <formals> formals formal_set
|
||||
%type <formal> formal
|
||||
%type <attrNames> attrpath
|
||||
%type <inheritAttrs> attrs
|
||||
%type <string_parts> string_parts_interpolated
|
||||
%type <ind_string_parts> ind_string_parts
|
||||
%type <e> path_start
|
||||
%type <to_be_string> string_parts string_attr
|
||||
%type <id> attr
|
||||
%token <id> ID
|
||||
%token <str> STR IND_STR
|
||||
%token <n> INT_LIT
|
||||
%token <nf> FLOAT_LIT
|
||||
%token <path> PATH HPATH SPATH PATH_END
|
||||
%token <uri> URI
|
||||
%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 DOLLAR_CURLY /* == ${ */
|
||||
@@ -179,30 +193,26 @@ expr: expr_function;
|
||||
|
||||
expr_function
|
||||
: ID ':' expr_function
|
||||
{ auto me = new ExprLambda(CUR_POS, state->symbols.create($1), $3);
|
||||
{ auto me = new ExprLambda(CUR_POS, state->symbols.create($1), 0, $3);
|
||||
$$ = me;
|
||||
SET_DOC_POS(me, @1);
|
||||
}
|
||||
| formal_set ':' expr_function[body]
|
||||
{
|
||||
state->validateFormals($formal_set);
|
||||
auto me = new ExprLambda(state->positions, state->alloc, CUR_POS, std::move($formal_set), $body);
|
||||
{ auto me = new ExprLambda(CUR_POS, state->validateFormals($formal_set), $body);
|
||||
$$ = me;
|
||||
SET_DOC_POS(me, @1);
|
||||
}
|
||||
| formal_set '@' ID ':' expr_function[body]
|
||||
{
|
||||
auto arg = state->symbols.create($ID);
|
||||
state->validateFormals($formal_set, CUR_POS, arg);
|
||||
auto me = new ExprLambda(state->positions, state->alloc, CUR_POS, arg, std::move($formal_set), $body);
|
||||
auto me = new ExprLambda(CUR_POS, arg, state->validateFormals($formal_set, CUR_POS, arg), $body);
|
||||
$$ = me;
|
||||
SET_DOC_POS(me, @1);
|
||||
}
|
||||
| ID '@' formal_set ':' expr_function[body]
|
||||
{
|
||||
auto arg = state->symbols.create($ID);
|
||||
state->validateFormals($formal_set, CUR_POS, arg);
|
||||
auto me = new ExprLambda(state->positions, state->alloc, CUR_POS, arg, std::move($formal_set), $body);
|
||||
auto me = new ExprLambda(CUR_POS, arg, state->validateFormals($formal_set, CUR_POS, arg), $body);
|
||||
$$ = me;
|
||||
SET_DOC_POS(me, @1);
|
||||
}
|
||||
@@ -251,9 +261,9 @@ expr_op
|
||||
| expr_op OR expr_op { $$ = new ExprOpOr(state->at(@2), $1, $3); }
|
||||
| expr_op IMPL expr_op { $$ = new ExprOpImpl(state->at(@2), $1, $3); }
|
||||
| expr_op UPDATE expr_op { $$ = new ExprOpUpdate(state->at(@2), $1, $3); }
|
||||
| expr_op '?' attrpath { $$ = new ExprOpHasAttr(state->alloc, $1, std::move($3)); }
|
||||
| expr_op '?' attrpath { $$ = new ExprOpHasAttr(state->alloc, $1, std::move(*$3)); delete $3; }
|
||||
| expr_op '+' expr_op
|
||||
{ $$ = new ExprConcatStrings(state->at(@2), false, {{state->at(@1), $1}, {state->at(@3), $3}}); }
|
||||
{ $$ = new ExprConcatStrings(state->at(@2), false, new std::vector<std::pair<PosIdx, Expr *> >({{state->at(@1), $1}, {state->at(@3), $3}})); }
|
||||
| expr_op '-' expr_op { $$ = new ExprCall(state->at(@2), new ExprVar(state->s.sub), {$1, $3}); }
|
||||
| expr_op '*' expr_op { $$ = new ExprCall(state->at(@2), new ExprVar(state->s.mul), {$1, $3}); }
|
||||
| expr_op '/' expr_op { $$ = new ExprCall(state->at(@2), new ExprVar(state->s.div), {$1, $3}); }
|
||||
@@ -272,9 +282,9 @@ expr_app
|
||||
|
||||
expr_select
|
||||
: expr_simple '.' attrpath
|
||||
{ $$ = new ExprSelect(state->alloc, CUR_POS, $1, std::move($3), nullptr); }
|
||||
{ $$ = new ExprSelect(state->alloc, CUR_POS, $1, std::move(*$3), nullptr); delete $3; }
|
||||
| expr_simple '.' attrpath OR_KW expr_select
|
||||
{ $$ = new ExprSelect(state->alloc, CUR_POS, $1, std::move($3), $5); $5->warnIfCursedOr(state->symbols, state->positions); }
|
||||
{ $$ = new ExprSelect(state->alloc, CUR_POS, $1, std::move(*$3), $5); delete $3; $5->warnIfCursedOr(state->symbols, state->positions); }
|
||||
| /* Backwards compatibility: because Nixpkgs has a function named ‘or’,
|
||||
allow stuff like ‘map or [...]’. This production is problematic (see
|
||||
https://github.com/NixOS/nix/issues/11118) and will be refactored in the
|
||||
@@ -301,15 +311,17 @@ expr_simple
|
||||
std::visit(overloaded{
|
||||
[&](std::string_view str) { $$ = new ExprString(state->alloc, str); },
|
||||
[&](Expr * expr) { $$ = expr; }},
|
||||
$2);
|
||||
*$2);
|
||||
delete $2;
|
||||
}
|
||||
| IND_STRING_OPEN ind_string_parts IND_STRING_CLOSE {
|
||||
$$ = state->stripIndentation(CUR_POS, std::move($2));
|
||||
$$ = state->stripIndentation(CUR_POS, std::move(*$2));
|
||||
delete $2;
|
||||
}
|
||||
| path_start PATH_END
|
||||
| path_start string_parts_interpolated PATH_END {
|
||||
$2.insert($2.begin(), {state->at(@1), $1});
|
||||
$$ = new ExprConcatStrings(CUR_POS, false, std::move($2));
|
||||
$2->insert($2->begin(), {state->at(@1), $1});
|
||||
$$ = new ExprConcatStrings(CUR_POS, false, $2);
|
||||
}
|
||||
| SPATH {
|
||||
std::string_view path($1.p + 1, $1.l - 2);
|
||||
@@ -338,23 +350,24 @@ expr_simple
|
||||
{ $2->pos = CUR_POS; $$ = $2; }
|
||||
| '{' '}'
|
||||
{ $$ = new ExprAttrs(CUR_POS); }
|
||||
| '[' list ']' { $$ = new ExprList(state->alloc, std::move($2)); }
|
||||
| '[' expr_list ']' { $$ = $2; }
|
||||
;
|
||||
|
||||
string_parts
|
||||
: STR { $$ = $1; }
|
||||
| string_parts_interpolated { $$ = new ExprConcatStrings(CUR_POS, true, std::move($1)); }
|
||||
| { $$ = std::string_view(); }
|
||||
: STR { $$ = new std::variant<Expr *, std::string_view>($1); }
|
||||
| string_parts_interpolated { $$ = new std::variant<Expr *, std::string_view>(new ExprConcatStrings(CUR_POS, true, $1)); }
|
||||
| { $$ = new std::variant<Expr *, std::string_view>(std::string_view()); }
|
||||
;
|
||||
|
||||
string_parts_interpolated
|
||||
: string_parts_interpolated STR
|
||||
{ $$ = std::move($1); $$.emplace_back(state->at(@2), new ExprString(state->alloc, $2)); }
|
||||
| string_parts_interpolated DOLLAR_CURLY expr '}' { $$ = std::move($1); $$.emplace_back(state->at(@2), $3); }
|
||||
| DOLLAR_CURLY expr '}' { $$.emplace_back(state->at(@1), $2); }
|
||||
{ $$ = $1; $1->emplace_back(state->at(@2), new ExprString(state->alloc, $2)); }
|
||||
| string_parts_interpolated DOLLAR_CURLY expr '}' { $$ = $1; $1->emplace_back(state->at(@2), $3); }
|
||||
| DOLLAR_CURLY expr '}' { $$ = new std::vector<std::pair<PosIdx, Expr *>>; $$->emplace_back(state->at(@1), $2); }
|
||||
| STR DOLLAR_CURLY expr '}' {
|
||||
$$.emplace_back(state->at(@1), new ExprString(state->alloc, $1));
|
||||
$$.emplace_back(state->at(@2), $3);
|
||||
$$ = new std::vector<std::pair<PosIdx, Expr *>>;
|
||||
$$->emplace_back(state->at(@1), new ExprString(state->alloc, $1));
|
||||
$$->emplace_back(state->at(@2), $3);
|
||||
}
|
||||
;
|
||||
|
||||
@@ -395,9 +408,9 @@ path_start
|
||||
;
|
||||
|
||||
ind_string_parts
|
||||
: ind_string_parts IND_STR { $$ = std::move($1); $$.emplace_back(state->at(@2), $2); }
|
||||
| ind_string_parts DOLLAR_CURLY expr '}' { $$ = std::move($1); $$.emplace_back(state->at(@2), $3); }
|
||||
| { }
|
||||
: ind_string_parts IND_STR { $$ = $1; $1->emplace_back(state->at(@2), $2); }
|
||||
| ind_string_parts DOLLAR_CURLY expr '}' { $$ = $1; $1->emplace_back(state->at(@2), $3); }
|
||||
| { $$ = new std::vector<std::pair<PosIdx, std::variant<Expr *, StringToken>>>; }
|
||||
;
|
||||
|
||||
binds
|
||||
@@ -408,17 +421,19 @@ binds
|
||||
binds1
|
||||
: binds1[accum] attrpath '=' expr ';'
|
||||
{ $$ = $accum;
|
||||
state->addAttr($$, std::move($attrpath), @attrpath, $expr, @expr);
|
||||
state->addAttr($$, std::move(*$attrpath), @attrpath, $expr, @expr);
|
||||
delete $attrpath;
|
||||
}
|
||||
| binds[accum] INHERIT attrs ';'
|
||||
{ $$ = $accum;
|
||||
for (auto & [i, iPos] : $attrs) {
|
||||
for (auto & [i, iPos] : *$attrs) {
|
||||
if ($accum->attrs.find(i.symbol) != $accum->attrs.end())
|
||||
state->dupAttr(i.symbol, iPos, $accum->attrs[i.symbol].pos);
|
||||
$accum->attrs.emplace(
|
||||
i.symbol,
|
||||
ExprAttrs::AttrDef(new ExprVar(iPos, i.symbol), iPos, ExprAttrs::AttrDef::Kind::Inherited));
|
||||
}
|
||||
delete $attrs;
|
||||
}
|
||||
| binds[accum] INHERIT '(' expr ')' attrs ';'
|
||||
{ $$ = $accum;
|
||||
@@ -426,7 +441,7 @@ binds1
|
||||
$accum->inheritFromExprs = std::make_unique<std::vector<Expr *>>();
|
||||
$accum->inheritFromExprs->push_back($expr);
|
||||
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())
|
||||
state->dupAttr(i.symbol, iPos, $accum->attrs[i.symbol].pos);
|
||||
$accum->attrs.emplace(
|
||||
@@ -436,45 +451,51 @@ binds1
|
||||
iPos,
|
||||
ExprAttrs::AttrDef::Kind::InheritedFrom));
|
||||
}
|
||||
delete $attrs;
|
||||
}
|
||||
| attrpath '=' expr ';'
|
||||
{ $$ = new ExprAttrs;
|
||||
state->addAttr($$, std::move($attrpath), @attrpath, $expr, @expr);
|
||||
state->addAttr($$, std::move(*$attrpath), @attrpath, $expr, @expr);
|
||||
delete $attrpath;
|
||||
}
|
||||
;
|
||||
|
||||
attrs
|
||||
: attrs attr { $$ = std::move($1); $$.emplace_back(state->symbols.create($2), state->at(@2)); }
|
||||
: attrs attr { $$ = $1; $1->emplace_back(AttrName(state->symbols.create($2)), state->at(@2)); }
|
||||
| attrs string_attr
|
||||
{ $$ = std::move($1);
|
||||
{ $$ = $1;
|
||||
std::visit(overloaded {
|
||||
[&](std::string_view str) { $$.emplace_back(state->symbols.create(str), state->at(@2)); },
|
||||
[&](std::string_view str) { $$->emplace_back(AttrName(state->symbols.create(str)), state->at(@2)); },
|
||||
[&](Expr * expr) {
|
||||
throw ParseError({
|
||||
.msg = HintFmt("dynamic attributes not allowed in inherit"),
|
||||
.pos = state->positions[state->at(@2)]
|
||||
});
|
||||
}
|
||||
}, $2);
|
||||
}, *$2);
|
||||
delete $2;
|
||||
}
|
||||
| { }
|
||||
| { $$ = new std::vector<std::pair<AttrName, PosIdx>>; }
|
||||
;
|
||||
|
||||
attrpath
|
||||
: attrpath '.' attr { $$ = std::move($1); $$.emplace_back(state->symbols.create($3)); }
|
||||
: attrpath '.' attr { $$ = $1; $1->push_back(AttrName(state->symbols.create($3))); }
|
||||
| attrpath '.' string_attr
|
||||
{ $$ = std::move($1);
|
||||
{ $$ = $1;
|
||||
std::visit(overloaded {
|
||||
[&](std::string_view str) { $$.emplace_back(state->symbols.create(str)); },
|
||||
[&](Expr * expr) { $$.emplace_back(expr); }
|
||||
}, std::move($3));
|
||||
[&](std::string_view str) { $$->push_back(AttrName(state->symbols.create(str))); },
|
||||
[&](Expr * expr) { $$->push_back(AttrName(expr)); }
|
||||
}, *$3);
|
||||
delete $3;
|
||||
}
|
||||
| attr { $$.emplace_back(state->symbols.create($1)); }
|
||||
| attr { $$ = new std::vector<AttrName>; $$->push_back(AttrName(state->symbols.create($1))); }
|
||||
| string_attr
|
||||
{ std::visit(overloaded {
|
||||
[&](std::string_view str) { $$.emplace_back(state->symbols.create(str)); },
|
||||
[&](Expr * expr) { $$.emplace_back(expr); }
|
||||
}, std::move($1));
|
||||
{ $$ = new std::vector<AttrName>;
|
||||
std::visit(overloaded {
|
||||
[&](std::string_view str) { $$->push_back(AttrName(state->symbols.create(str))); },
|
||||
[&](Expr * expr) { $$->push_back(AttrName(expr)); }
|
||||
}, *$1);
|
||||
delete $1;
|
||||
}
|
||||
;
|
||||
|
||||
@@ -484,33 +505,33 @@ attr
|
||||
;
|
||||
|
||||
string_attr
|
||||
: '"' string_parts '"' { $$ = std::move($2); }
|
||||
| DOLLAR_CURLY expr '}' { $$ = $2; }
|
||||
: '"' string_parts '"' { $$ = $2; }
|
||||
| DOLLAR_CURLY expr '}' { $$ = new std::variant<Expr *, std::string_view>($2); }
|
||||
;
|
||||
|
||||
list
|
||||
: list expr_select { $$ = std::move($1); $$.push_back($2); /* !!! dangerous */; $2->warnIfCursedOr(state->symbols, state->positions); }
|
||||
| { }
|
||||
expr_list
|
||||
: expr_list expr_select { $$ = $1; $1->elems.push_back($2); /* !!! dangerous */; $2->warnIfCursedOr(state->symbols, state->positions); }
|
||||
| { $$ = new ExprList; }
|
||||
;
|
||||
|
||||
formal_set
|
||||
: '{' formals ',' ELLIPSIS '}' { $$ = std::move($formals); $$.ellipsis = true; }
|
||||
| '{' ELLIPSIS '}' { $$.ellipsis = true; }
|
||||
| '{' formals ',' '}' { $$ = std::move($formals); $$.ellipsis = false; }
|
||||
| '{' formals '}' { $$ = std::move($formals); $$.ellipsis = false; }
|
||||
| '{' '}' { $$.ellipsis = false; }
|
||||
: '{' formals ',' ELLIPSIS '}' { $$ = $formals; $$->ellipsis = true; }
|
||||
| '{' ELLIPSIS '}' { $$ = new Formals; $$->ellipsis = true; }
|
||||
| '{' formals ',' '}' { $$ = $formals; $$->ellipsis = false; }
|
||||
| '{' formals '}' { $$ = $formals; $$->ellipsis = false; }
|
||||
| '{' '}' { $$ = new Formals; $$->ellipsis = false; }
|
||||
;
|
||||
|
||||
formals
|
||||
: formals[accum] ',' formal
|
||||
{ $$ = std::move($accum); $$.formals.emplace_back(std::move($formal)); }
|
||||
{ $$ = $accum; $$->formals.emplace_back(*$formal); delete $formal; }
|
||||
| formal
|
||||
{ $$.formals.emplace_back(std::move($formal)); }
|
||||
{ $$ = new Formals; $$->formals.emplace_back(*$formal); delete $formal; }
|
||||
;
|
||||
|
||||
formal
|
||||
: ID { $$ = Formal{CUR_POS, state->symbols.create($1), 0}; }
|
||||
| ID '?' expr { $$ = Formal{CUR_POS, state->symbols.create($1), $3}; }
|
||||
: ID { $$ = new Formal{CUR_POS, state->symbols.create($1), 0}; }
|
||||
| ID '?' expr { $$ = new Formal{CUR_POS, state->symbols.create($1), $3}; }
|
||||
;
|
||||
|
||||
%%
|
||||
@@ -561,4 +582,3 @@ Expr * parseExprFromBuf(
|
||||
|
||||
|
||||
}
|
||||
#pragma GCC diagnostic pop // end ignored "-Wswitch-enum"
|
||||
+15
-14
@@ -1374,7 +1374,7 @@ static void derivationStrictInternal(EvalState & state, std::string_view drvName
|
||||
pos,
|
||||
"while evaluating the `__structuredAttrs` "
|
||||
"attribute passed to builtins.derivationStrict"))
|
||||
jsonObject = StructuredAttrs{};
|
||||
jsonObject = StructuredAttrs{.structuredAttrs = json::object()};
|
||||
|
||||
/* Check whether null attributes should be ignored. */
|
||||
bool ignoreNulls = false;
|
||||
@@ -3363,20 +3363,21 @@ static void prim_functionArgs(EvalState & state, const PosIdx pos, Value ** args
|
||||
if (!args[0]->isLambda())
|
||||
state.error<TypeError>("'functionArgs' requires a function").atPos(pos).debugThrow();
|
||||
|
||||
if (const auto & formals = args[0]->lambda().fun->getFormals()) {
|
||||
auto attrs = state.buildBindings(formals->formals.size());
|
||||
for (auto & i : formals->formals)
|
||||
attrs.insert(i.name, state.getBool(i.def), i.pos);
|
||||
/* Optimization: avoid sorting bindings. `formals` must already be sorted according to
|
||||
(std::tie(a.name, a.pos) < std::tie(b.name, b.pos)) predicate, so the following assertion
|
||||
always holds:
|
||||
assert(std::is_sorted(attrs.alreadySorted()->begin(), attrs.alreadySorted()->end()));
|
||||
.*/
|
||||
v.mkAttrs(attrs.alreadySorted());
|
||||
} else {
|
||||
if (!args[0]->lambda().fun->hasFormals()) {
|
||||
v.mkAttrs(&Bindings::emptyBindings);
|
||||
return;
|
||||
}
|
||||
|
||||
const auto & formals = args[0]->lambda().fun->formals->formals;
|
||||
auto attrs = state.buildBindings(formals.size());
|
||||
for (auto & i : formals)
|
||||
attrs.insert(i.name, state.getBool(i.def), i.pos);
|
||||
/* Optimization: avoid sorting bindings. `formals` must already be sorted according to
|
||||
(std::tie(a.name, a.pos) < std::tie(b.name, b.pos)) predicate, so the following assertion
|
||||
always holds:
|
||||
assert(std::is_sorted(attrs.alreadySorted()->begin(), attrs.alreadySorted()->end()));
|
||||
.*/
|
||||
v.mkAttrs(attrs.alreadySorted());
|
||||
}
|
||||
|
||||
static RegisterPrimOp primop_functionArgs({
|
||||
@@ -4610,9 +4611,9 @@ struct RegexCache
|
||||
}
|
||||
};
|
||||
|
||||
ref<RegexCache> makeRegexCache()
|
||||
std::shared_ptr<RegexCache> makeRegexCache()
|
||||
{
|
||||
return make_ref<RegexCache>();
|
||||
return std::make_shared<RegexCache>();
|
||||
}
|
||||
|
||||
void prim_match(EvalState & state, const PosIdx pos, Value ** args, Value & v)
|
||||
|
||||
@@ -64,8 +64,6 @@ static void runFetchClosureWithRewrite(
|
||||
.pos = state.positions[pos]});
|
||||
}
|
||||
|
||||
state.allowClosure(toPath);
|
||||
|
||||
state.mkStorePathString(toPath, v);
|
||||
}
|
||||
|
||||
@@ -93,8 +91,6 @@ static void runFetchClosureWithContentAddressedPath(
|
||||
.pos = state.positions[pos]});
|
||||
}
|
||||
|
||||
state.allowClosure(fromPath);
|
||||
|
||||
state.mkStorePathString(fromPath, v);
|
||||
}
|
||||
|
||||
@@ -119,8 +115,6 @@ static void runFetchClosureWithInputAddressedPath(
|
||||
.pos = state.positions[pos]});
|
||||
}
|
||||
|
||||
state.allowClosure(fromPath);
|
||||
|
||||
state.mkStorePathString(fromPath, v);
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ static void prim_fromTOML(EvalState & state, const PosIdx pos, Value ** args, Va
|
||||
|
||||
std::istringstream tomlStream(std::string{toml});
|
||||
|
||||
auto visit = [&](this auto & self, Value & v, toml::value t) -> void {
|
||||
auto visit = [&](auto & self, Value & v, toml::value t) -> void {
|
||||
switch (t.type()) {
|
||||
case toml::value_t::table: {
|
||||
auto table = toml::get<toml::table>(t);
|
||||
@@ -100,7 +100,7 @@ static void prim_fromTOML(EvalState & state, const PosIdx pos, Value ** args, Va
|
||||
|
||||
for (auto & elem : table) {
|
||||
forceNoNullByte(elem.first);
|
||||
self(attrs.alloc(elem.first), elem.second);
|
||||
self(self, attrs.alloc(elem.first), elem.second);
|
||||
}
|
||||
|
||||
v.mkAttrs(attrs);
|
||||
@@ -110,7 +110,7 @@ static void prim_fromTOML(EvalState & state, const PosIdx pos, Value ** args, Va
|
||||
|
||||
auto list = state.buildList(array.size());
|
||||
for (const auto & [n, v] : enumerate(list))
|
||||
self(*(v = state.allocValue()), array[n]);
|
||||
self(self, *(v = state.allocValue()), array[n]);
|
||||
v.mkList(list);
|
||||
} break;
|
||||
case toml::value_t::boolean:
|
||||
@@ -155,6 +155,7 @@ static void prim_fromTOML(EvalState & state, const PosIdx pos, Value ** args, Va
|
||||
|
||||
try {
|
||||
visit(
|
||||
visit,
|
||||
val,
|
||||
toml::parse(
|
||||
tomlStream,
|
||||
|
||||
@@ -145,14 +145,14 @@ static void printValueAsXML(
|
||||
posToXML(state, xmlAttrs, state.positions[v.lambda().fun->pos]);
|
||||
XMLOpenElement _(doc, "function", xmlAttrs);
|
||||
|
||||
if (auto formals = v.lambda().fun->getFormals()) {
|
||||
if (v.lambda().fun->hasFormals()) {
|
||||
XMLAttrs attrs;
|
||||
if (v.lambda().fun->arg)
|
||||
attrs["name"] = state.symbols[v.lambda().fun->arg];
|
||||
if (formals->ellipsis)
|
||||
if (v.lambda().fun->formals->ellipsis)
|
||||
attrs["ellipsis"] = "1";
|
||||
XMLOpenElement _(doc, "attrspat", attrs);
|
||||
for (auto & i : formals->lexicographicOrder(state.symbols))
|
||||
for (auto & i : v.lambda().fun->formals->lexicographicOrder(state.symbols))
|
||||
doc.writeEmptyElement("attr", singletonAttrs("name", state.symbols[i.name]));
|
||||
} else
|
||||
doc.writeEmptyElement("varpat", singletonAttrs("name", state.symbols[v.lambda().fun->arg]));
|
||||
|
||||
@@ -9,7 +9,8 @@ NixStringContextElem NixStringContextElem::parse(std::string_view s0, const Expe
|
||||
{
|
||||
std::string_view s = s0;
|
||||
|
||||
auto parseRest = [&](this auto & parseRest) -> SingleDerivedPath {
|
||||
std::function<SingleDerivedPath()> parseRest;
|
||||
parseRest = [&]() -> SingleDerivedPath {
|
||||
// Case on whether there is a '!'
|
||||
size_t index = s.find("!");
|
||||
if (index == std::string_view::npos) {
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "nix/util/json-utils.hh"
|
||||
#include "nix/fetchers/fetch-settings.hh"
|
||||
#include "nix/fetchers/fetch-to-store.hh"
|
||||
#include "nix/util/url.hh"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
@@ -66,12 +65,6 @@ Input Input::fromURL(const Settings & settings, const ParsedURL & url, bool requ
|
||||
}
|
||||
}
|
||||
|
||||
// Provide a helpful hint when user tries file+git instead of git+file
|
||||
auto parsedScheme = parseUrlScheme(url.scheme);
|
||||
if (parsedScheme.application == "file" && parsedScheme.transport == "git") {
|
||||
throw Error("input '%s' is unsupported; did you mean 'git+file' instead of 'file+git'?", url);
|
||||
}
|
||||
|
||||
throw Error("input '%s' is unsupported", url);
|
||||
}
|
||||
|
||||
@@ -519,11 +512,10 @@ using namespace nix;
|
||||
fetchers::PublicKey adl_serializer<fetchers::PublicKey>::from_json(const json & json)
|
||||
{
|
||||
fetchers::PublicKey res = {};
|
||||
auto & obj = getObject(json);
|
||||
if (auto * type = optionalValueAt(obj, "type"))
|
||||
if (auto type = optionalValueAt(json, "type"))
|
||||
res.type = getString(*type);
|
||||
|
||||
res.key = getString(valueAt(obj, "key"));
|
||||
res.key = getString(valueAt(json, "key"));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ std::vector<nlohmann::json> Fetch::fetchUrls(const std::vector<Pointer> & pointe
|
||||
auto url = api.endpoint + "/objects/batch";
|
||||
const auto & authHeader = api.authHeader;
|
||||
FileTransferRequest request(parseURL(url));
|
||||
request.method = HttpMethod::POST;
|
||||
request.post = true;
|
||||
Headers headers;
|
||||
if (authHeader.has_value())
|
||||
headers.push_back({"Authorization", *authHeader});
|
||||
@@ -219,9 +219,7 @@ std::vector<nlohmann::json> Fetch::fetchUrls(const std::vector<Pointer> & pointe
|
||||
nlohmann::json oidList = pointerToPayload(pointers);
|
||||
nlohmann::json data = {{"operation", "download"}};
|
||||
data["objects"] = oidList;
|
||||
auto payload = data.dump();
|
||||
StringSource source{payload};
|
||||
request.data = {source};
|
||||
request.data = data.dump();
|
||||
|
||||
FileTransferResult result = getFileTransfer()->upload(request);
|
||||
auto responseString = result.data;
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include "nix/util/users.hh"
|
||||
#include "nix/util/fs-sink.hh"
|
||||
#include "nix/util/sync.hh"
|
||||
#include "nix/util/util.hh"
|
||||
|
||||
#include <git2/attr.h>
|
||||
#include <git2/blob.h>
|
||||
@@ -531,12 +530,12 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
|
||||
auto act = (Activity *) payload;
|
||||
act->result(
|
||||
resFetchStatus,
|
||||
fmt("%d/%d objects received, %d/%d deltas indexed, %s",
|
||||
fmt("%d/%d objects received, %d/%d deltas indexed, %.1f MiB",
|
||||
stats->received_objects,
|
||||
stats->total_objects,
|
||||
stats->indexed_deltas,
|
||||
stats->total_deltas,
|
||||
renderSize(stats->received_bytes)));
|
||||
stats->received_bytes / (1024.0 * 1024.0)));
|
||||
return getInterrupted() ? -1 : 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -164,7 +164,8 @@ struct GitInputScheme : InputScheme
|
||||
{
|
||||
std::optional<Input> inputFromURL(const Settings & settings, const ParsedURL & url, bool requireTree) const override
|
||||
{
|
||||
if (url.scheme != "git" && parseUrlScheme(url.scheme).application != "git")
|
||||
auto parsedScheme = parseUrlScheme(url.scheme);
|
||||
if (parsedScheme.application != "git")
|
||||
return {};
|
||||
|
||||
auto url2(url);
|
||||
|
||||
@@ -206,28 +206,6 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
.description = "flake_id_ref_branch_ignore_empty_segments_ref_rev",
|
||||
.expectedUrl = "flake:nixpkgs/branch/2aae6c35c94fcfb415dbe95f408b9ce91ee846ed",
|
||||
},
|
||||
InputFromURLTestCase{
|
||||
.url = "git://somewhere/repo?ref=branch",
|
||||
.attrs =
|
||||
{
|
||||
{"type", Attr("git")},
|
||||
{"ref", Attr("branch")},
|
||||
{"url", Attr("git://somewhere/repo")},
|
||||
},
|
||||
.description = "plain_git_with_ref",
|
||||
.expectedUrl = "git://somewhere/repo?ref=branch",
|
||||
},
|
||||
InputFromURLTestCase{
|
||||
.url = "git+https://somewhere.aaaaaaa/repo?ref=branch",
|
||||
.attrs =
|
||||
{
|
||||
{"type", Attr("git")},
|
||||
{"ref", Attr("branch")},
|
||||
{"url", Attr("https://somewhere.aaaaaaa/repo")},
|
||||
},
|
||||
.description = "git_https_with_ref",
|
||||
.expectedUrl = "git+https://somewhere.aaaaaaa/repo?ref=branch",
|
||||
},
|
||||
InputFromURLTestCase{
|
||||
// Note that this is different from above because the "flake id" shorthand
|
||||
// doesn't allow this.
|
||||
|
||||
+8
-11
@@ -281,15 +281,12 @@ static Flake readFlake(
|
||||
if (auto outputs = vInfo.attrs()->get(sOutputs)) {
|
||||
expectType(state, nFunction, *outputs->value, outputs->pos);
|
||||
|
||||
if (outputs->value->isLambda()) {
|
||||
if (auto formals = outputs->value->lambda().fun->getFormals()) {
|
||||
for (auto & formal : formals->formals) {
|
||||
if (formal.name != state.s.self)
|
||||
flake.inputs.emplace(
|
||||
state.symbols[formal.name],
|
||||
FlakeInput{
|
||||
.ref = parseFlakeRef(state.fetchSettings, std::string(state.symbols[formal.name]))});
|
||||
}
|
||||
if (outputs->value->isLambda() && outputs->value->lambda().fun->hasFormals()) {
|
||||
for (auto & formal : outputs->value->lambda().fun->formals->formals) {
|
||||
if (formal.name != state.s.self)
|
||||
flake.inputs.emplace(
|
||||
state.symbols[formal.name],
|
||||
FlakeInput{.ref = parseFlakeRef(state.fetchSettings, std::string(state.symbols[formal.name]))});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -505,8 +502,8 @@ lockFlake(const Settings & settings, EvalState & state, const FlakeRef & topRef,
|
||||
|
||||
/* Get the overrides (i.e. attributes of the form
|
||||
'inputs.nixops.inputs.nixpkgs.url = ...'). */
|
||||
auto addOverrides =
|
||||
[&](this const auto & addOverrides, const FlakeInput & input, const InputAttrPath & prefix) -> void {
|
||||
std::function<void(const FlakeInput & input, const InputAttrPath & prefix)> addOverrides;
|
||||
addOverrides = [&](const FlakeInput & input, const InputAttrPath & prefix) {
|
||||
for (auto & [idOverride, inputOverride] : input.overrides) {
|
||||
auto inputAttrPath(prefix);
|
||||
inputAttrPath.push_back(idOverride);
|
||||
|
||||
@@ -147,10 +147,11 @@ LockFile::LockFile(const fetchers::Settings & fetchSettings, std::string_view co
|
||||
if (version < 5 || version > 7)
|
||||
throw Error("lock file '%s' has unsupported version %d", path, version);
|
||||
|
||||
std::string rootKey = json["root"];
|
||||
std::map<std::string, ref<Node>> nodeMap{{rootKey, root}};
|
||||
std::map<std::string, ref<Node>> nodeMap;
|
||||
|
||||
[&](this const auto & getInputs, Node & node, const nlohmann::json & jsonNode) {
|
||||
std::function<void(Node & node, const nlohmann::json & jsonNode)> getInputs;
|
||||
|
||||
getInputs = [&](Node & node, const nlohmann::json & jsonNode) {
|
||||
if (jsonNode.find("inputs") == jsonNode.end())
|
||||
return;
|
||||
for (auto & i : jsonNode["inputs"].items()) {
|
||||
@@ -178,7 +179,11 @@ LockFile::LockFile(const fetchers::Settings & fetchSettings, std::string_view co
|
||||
throw Error("lock file contains cycle to root node");
|
||||
}
|
||||
}
|
||||
}(*root, json["nodes"][rootKey]);
|
||||
};
|
||||
|
||||
std::string rootKey = json["root"];
|
||||
nodeMap.insert_or_assign(rootKey, root);
|
||||
getInputs(*root, json["nodes"][rootKey]);
|
||||
|
||||
// FIXME: check that there are no cycles in version >= 7. Cycles
|
||||
// between inputs are only possible using 'follows' indirections.
|
||||
@@ -192,7 +197,9 @@ std::pair<nlohmann::json, LockFile::KeyMap> LockFile::toJSON() const
|
||||
KeyMap nodeKeys;
|
||||
boost::unordered_flat_set<std::string> keys;
|
||||
|
||||
auto dumpNode = [&](this auto & dumpNode, std::string key, ref<const Node> node) -> std::string {
|
||||
std::function<std::string(const std::string & key, ref<const Node> node)> dumpNode;
|
||||
|
||||
dumpNode = [&](std::string key, ref<const Node> node) -> std::string {
|
||||
auto k = nodeKeys.find(node);
|
||||
if (k != nodeKeys.end())
|
||||
return k->second;
|
||||
@@ -269,13 +276,17 @@ std::optional<FlakeRef> LockFile::isUnlocked(const fetchers::Settings & fetchSet
|
||||
{
|
||||
std::set<ref<const Node>> nodes;
|
||||
|
||||
[&](this const auto & visit, ref<const Node> node) {
|
||||
std::function<void(ref<const Node> node)> visit;
|
||||
|
||||
visit = [&](ref<const Node> node) {
|
||||
if (!nodes.insert(node).second)
|
||||
return;
|
||||
for (auto & i : node->inputs)
|
||||
if (auto child = std::get_if<0>(&i.second))
|
||||
visit(*child);
|
||||
}(root);
|
||||
};
|
||||
|
||||
visit(root);
|
||||
|
||||
/* Return whether the input is either locked, or, if
|
||||
`allow-dirty-locks` is enabled, it has a NAR hash. In the
|
||||
@@ -321,7 +332,9 @@ std::map<InputAttrPath, Node::Edge> LockFile::getAllInputs() const
|
||||
std::set<ref<Node>> done;
|
||||
std::map<InputAttrPath, Node::Edge> res;
|
||||
|
||||
[&](this const auto & recurse, const InputAttrPath & prefix, ref<Node> node) {
|
||||
std::function<void(const InputAttrPath & prefix, ref<Node> node)> recurse;
|
||||
|
||||
recurse = [&](const InputAttrPath & prefix, ref<Node> node) {
|
||||
if (!done.insert(node).second)
|
||||
return;
|
||||
|
||||
@@ -332,7 +345,9 @@ std::map<InputAttrPath, Node::Edge> LockFile::getAllInputs() const
|
||||
if (auto child = std::get_if<0>(&input))
|
||||
recurse(inputAttrPath, *child);
|
||||
}
|
||||
}({}, root);
|
||||
};
|
||||
|
||||
recurse({}, root);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -89,6 +89,8 @@ extern volatile ::sig_atomic_t blockInt;
|
||||
|
||||
/* GC helpers. */
|
||||
|
||||
std::string showBytes(uint64_t bytes);
|
||||
|
||||
struct GCResults;
|
||||
|
||||
struct PrintFreed
|
||||
|
||||
+34
-31
@@ -6,7 +6,6 @@
|
||||
#include "nix/main/loggers.hh"
|
||||
#include "nix/main/progress-bar.hh"
|
||||
#include "nix/util/signals.hh"
|
||||
#include "nix/util/util.hh"
|
||||
|
||||
#include <algorithm>
|
||||
#include <exception>
|
||||
@@ -65,19 +64,18 @@ void printMissing(ref<Store> store, const MissingPaths & missing, Verbosity lvl)
|
||||
}
|
||||
|
||||
if (!missing.willSubstitute.empty()) {
|
||||
const float downloadSizeMiB = missing.downloadSize / (1024.f * 1024.f);
|
||||
const float narSizeMiB = missing.narSize / (1024.f * 1024.f);
|
||||
if (missing.willSubstitute.size() == 1) {
|
||||
printMsg(
|
||||
lvl,
|
||||
"this path will be fetched (%s download, %s unpacked):",
|
||||
renderSize(missing.downloadSize),
|
||||
renderSize(missing.narSize));
|
||||
lvl, "this path will be fetched (%.2f MiB download, %.2f MiB unpacked):", downloadSizeMiB, narSizeMiB);
|
||||
} else {
|
||||
printMsg(
|
||||
lvl,
|
||||
"these %d paths will be fetched (%s download, %s unpacked):",
|
||||
"these %d paths will be fetched (%.2f MiB download, %.2f MiB unpacked):",
|
||||
missing.willSubstitute.size(),
|
||||
renderSize(missing.downloadSize),
|
||||
renderSize(missing.narSize));
|
||||
downloadSizeMiB,
|
||||
narSizeMiB);
|
||||
}
|
||||
std::vector<const StorePath *> willSubstituteSorted = {};
|
||||
std::for_each(missing.willSubstitute.begin(), missing.willSubstitute.end(), [&](const StorePath & p) {
|
||||
@@ -322,29 +320,34 @@ int handleExceptions(const std::string & programName, std::function<void()> fun)
|
||||
std::string error = ANSI_RED "error:" ANSI_NORMAL " ";
|
||||
try {
|
||||
try {
|
||||
fun();
|
||||
} catch (...) {
|
||||
/* Subtle: we have to make sure that any `interrupted'
|
||||
condition is discharged before we reach printMsg()
|
||||
below, since otherwise it will throw an (uncaught)
|
||||
exception. */
|
||||
setInterruptThrown();
|
||||
throw;
|
||||
try {
|
||||
fun();
|
||||
} catch (...) {
|
||||
/* Subtle: we have to make sure that any `interrupted'
|
||||
condition is discharged before we reach printMsg()
|
||||
below, since otherwise it will throw an (uncaught)
|
||||
exception. */
|
||||
setInterruptThrown();
|
||||
throw;
|
||||
}
|
||||
} catch (Exit & e) {
|
||||
return e.status;
|
||||
} catch (UsageError & e) {
|
||||
logError(e.info());
|
||||
printError("Try '%1% --help' for more information.", programName);
|
||||
return 1;
|
||||
} catch (BaseError & e) {
|
||||
logError(e.info());
|
||||
return e.info().status;
|
||||
} catch (std::bad_alloc & e) {
|
||||
printError(error + "out of memory");
|
||||
return 1;
|
||||
} catch (std::exception & e) {
|
||||
printError(error + e.what());
|
||||
return 1;
|
||||
}
|
||||
} catch (Exit & e) {
|
||||
return e.status;
|
||||
} catch (UsageError & e) {
|
||||
logError(e.info());
|
||||
printError("Try '%1% --help' for more information.", programName);
|
||||
return 1;
|
||||
} catch (BaseError & e) {
|
||||
logError(e.info());
|
||||
return e.info().status;
|
||||
} catch (std::bad_alloc & e) {
|
||||
printError(error + "out of memory");
|
||||
return 1;
|
||||
} catch (std::exception & e) {
|
||||
printError(error + e.what());
|
||||
} catch (...) {
|
||||
/* In case logger also throws just give up. */
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -408,7 +411,7 @@ RunPager::~RunPager()
|
||||
PrintFreed::~PrintFreed()
|
||||
{
|
||||
if (show)
|
||||
std::cout << fmt("%d store paths deleted, %s freed\n", results.paths.size(), renderSize(results.bytesFreed));
|
||||
std::cout << fmt("%d store paths deleted, %s freed\n", results.paths.size(), showBytes(results.bytesFreed));
|
||||
}
|
||||
|
||||
} // namespace nix
|
||||
@@ -126,36 +126,6 @@ StorePath * nix_store_parse_path(nix_c_context * context, Store * store, const c
|
||||
NIXC_CATCH_ERRS_NULL
|
||||
}
|
||||
|
||||
nix_err nix_store_get_fs_closure(
|
||||
nix_c_context * context,
|
||||
Store * store,
|
||||
const StorePath * store_path,
|
||||
bool flip_direction,
|
||||
bool include_outputs,
|
||||
bool include_derivers,
|
||||
void * userdata,
|
||||
void (*callback)(nix_c_context * context, void * userdata, const StorePath * store_path))
|
||||
{
|
||||
if (context)
|
||||
context->last_err_code = NIX_OK;
|
||||
try {
|
||||
const auto nixStore = store->ptr;
|
||||
|
||||
nix::StorePathSet set;
|
||||
nixStore->computeFSClosure(store_path->path, set, flip_direction, include_outputs, include_derivers);
|
||||
|
||||
if (callback) {
|
||||
for (const auto & path : set) {
|
||||
const StorePath tmp{path};
|
||||
callback(context, userdata, &tmp);
|
||||
if (context && context->last_err_code != NIX_OK)
|
||||
return context->last_err_code;
|
||||
}
|
||||
}
|
||||
}
|
||||
NIXC_CATCH_ERRS
|
||||
}
|
||||
|
||||
nix_err nix_store_realise(
|
||||
nix_c_context * context,
|
||||
Store * store,
|
||||
@@ -173,14 +143,6 @@ nix_err nix_store_realise(
|
||||
const auto nixStore = store->ptr;
|
||||
auto results = nixStore->buildPathsWithResults(paths, nix::bmNormal, nixStore);
|
||||
|
||||
assert(results.size() == 1);
|
||||
|
||||
// Check if any builds failed
|
||||
for (auto & result : results) {
|
||||
if (auto * failureP = result.tryGetFailure())
|
||||
failureP->rethrow();
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
for (const auto & result : results) {
|
||||
if (auto * success = result.tryGetSuccess()) {
|
||||
|
||||
@@ -186,8 +186,6 @@ nix_err nix_store_real_path(
|
||||
* @param[in] path Path to build
|
||||
* @param[in] userdata data to pass to every callback invocation
|
||||
* @param[in] callback called for every realised output
|
||||
* @return NIX_OK if the build succeeded, or an error code if the build/scheduling/outputs/copying/etc failed.
|
||||
* On error, the callback is never invoked and error information is stored in context.
|
||||
*/
|
||||
nix_err nix_store_realise(
|
||||
nix_c_context * context,
|
||||
@@ -247,35 +245,6 @@ void nix_derivation_free(nix_derivation * drv);
|
||||
*/
|
||||
nix_err nix_store_copy_closure(nix_c_context * context, Store * srcStore, Store * dstStore, StorePath * path);
|
||||
|
||||
/**
|
||||
* @brief Gets the closure of a specific store path
|
||||
*
|
||||
* @note The callback borrows each StorePath only for the duration of the call.
|
||||
*
|
||||
* @param[out] context Optional, stores error information
|
||||
* @param[in] store nix store reference
|
||||
* @param[in] store_path The path to compute from
|
||||
* @param[in] flip_direction If false, compute the forward closure (paths referenced by any store path in the closure).
|
||||
* If true, compute the backward closure (paths that reference any store path in the closure).
|
||||
* @param[in] include_outputs If flip_direction is false: for any derivation in the closure, include its outputs.
|
||||
* If flip_direction is true: for any output in the closure, include derivations that produce
|
||||
* it.
|
||||
* @param[in] include_derivers If flip_direction is false: for any output in the closure, include the derivation that
|
||||
* produced it.
|
||||
* If flip_direction is true: for any derivation in the closure, include its outputs.
|
||||
* @param[in] callback The function to call for every store path, in no particular order
|
||||
* @param[in] userdata The userdata to pass to the callback
|
||||
*/
|
||||
nix_err nix_store_get_fs_closure(
|
||||
nix_c_context * context,
|
||||
Store * store,
|
||||
const StorePath * store_path,
|
||||
bool flip_direction,
|
||||
bool include_outputs,
|
||||
bool include_derivers,
|
||||
void * userdata,
|
||||
void (*callback)(nix_c_context * context, void * userdata, const StorePath * store_path));
|
||||
|
||||
// cffi end
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "nix/store/content-address.hh"
|
||||
#include "nix/util/tests/json-characterization.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
@@ -9,93 +8,33 @@ namespace nix {
|
||||
* ContentAddressMethod::parse, ContentAddressMethod::render
|
||||
* --------------------------------------------------------------------------*/
|
||||
|
||||
static auto methods = ::testing::Values(
|
||||
std::pair{ContentAddressMethod::Raw::Text, "text"},
|
||||
std::pair{ContentAddressMethod::Raw::Flat, "flat"},
|
||||
std::pair{ContentAddressMethod::Raw::NixArchive, "nar"},
|
||||
std::pair{ContentAddressMethod::Raw::Git, "git"});
|
||||
|
||||
struct ContentAddressMethodTest : ::testing::Test,
|
||||
::testing::WithParamInterface<std::pair<ContentAddressMethod, std::string_view>>
|
||||
{};
|
||||
|
||||
TEST_P(ContentAddressMethodTest, testRoundTripPrintParse_1)
|
||||
TEST(ContentAddressMethod, testRoundTripPrintParse_1)
|
||||
{
|
||||
auto & [cam, _] = GetParam();
|
||||
EXPECT_EQ(ContentAddressMethod::parse(cam.render()), cam);
|
||||
for (ContentAddressMethod cam : {
|
||||
ContentAddressMethod::Raw::Text,
|
||||
ContentAddressMethod::Raw::Flat,
|
||||
ContentAddressMethod::Raw::NixArchive,
|
||||
ContentAddressMethod::Raw::Git,
|
||||
}) {
|
||||
EXPECT_EQ(ContentAddressMethod::parse(cam.render()), cam);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(ContentAddressMethodTest, testRoundTripPrintParse_2)
|
||||
TEST(ContentAddressMethod, testRoundTripPrintParse_2)
|
||||
{
|
||||
auto & [cam, camS] = GetParam();
|
||||
EXPECT_EQ(ContentAddressMethod::parse(camS).render(), camS);
|
||||
for (const std::string_view camS : {
|
||||
"text",
|
||||
"flat",
|
||||
"nar",
|
||||
"git",
|
||||
}) {
|
||||
EXPECT_EQ(ContentAddressMethod::parse(camS).render(), camS);
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(ContentAddressMethod, ContentAddressMethodTest, methods);
|
||||
|
||||
TEST(ContentAddressMethod, testParseContentAddressMethodOptException)
|
||||
{
|
||||
EXPECT_THROW(ContentAddressMethod::parse("narwhal"), UsageError);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* JSON
|
||||
* --------------------------------------------------------------------------*/
|
||||
|
||||
class ContentAddressTest : public virtual CharacterizationTest
|
||||
{
|
||||
std::filesystem::path unitTestData = getUnitTestData() / "content-address";
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* We set these in tests rather than the regular globals so we don't have
|
||||
* to worry about race conditions if the tests run concurrently.
|
||||
*/
|
||||
ExperimentalFeatureSettings mockXpSettings;
|
||||
|
||||
std::filesystem::path goldenMaster(std::string_view testStem) const override
|
||||
{
|
||||
return unitTestData / testStem;
|
||||
}
|
||||
};
|
||||
|
||||
using nlohmann::json;
|
||||
|
||||
struct ContentAddressJsonTest : ContentAddressTest,
|
||||
JsonCharacterizationTest<ContentAddress>,
|
||||
::testing::WithParamInterface<std::pair<std::string_view, ContentAddress>>
|
||||
{};
|
||||
|
||||
TEST_P(ContentAddressJsonTest, from_json)
|
||||
{
|
||||
auto & [name, expected] = GetParam();
|
||||
readJsonTest(name, expected);
|
||||
}
|
||||
|
||||
TEST_P(ContentAddressJsonTest, to_json)
|
||||
{
|
||||
auto & [name, value] = GetParam();
|
||||
writeJsonTest(name, value);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
ContentAddressJSON,
|
||||
ContentAddressJsonTest,
|
||||
::testing::Values(
|
||||
std::pair{
|
||||
"text",
|
||||
ContentAddress{
|
||||
.method = ContentAddressMethod::Raw::Text,
|
||||
.hash = hashString(HashAlgorithm::SHA256, "asdf"),
|
||||
},
|
||||
},
|
||||
std::pair{
|
||||
"nar",
|
||||
ContentAddress{
|
||||
.method = ContentAddressMethod::Raw::NixArchive,
|
||||
.hash = hashString(HashAlgorithm::SHA256, "qwer"),
|
||||
},
|
||||
}));
|
||||
|
||||
} // namespace nix
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"hash": {
|
||||
"algorithm": "sha256",
|
||||
"format": "base64",
|
||||
"hash": "9vLqj0XYoFfJVmoz+ZR02i5camYE1zYSFlDicwxvsKM="
|
||||
},
|
||||
"method": "nar"
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"hash": {
|
||||
"algorithm": "sha256",
|
||||
"format": "base64",
|
||||
"hash": "8OTC92xYkW7CWPJGhRvqCR0U1CR6L8PhhpRGGxgW4Ts="
|
||||
},
|
||||
"method": "text"
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
local://?root=/foo%20bar/baz
|
||||
local://?root=/foo bar/baz
|
||||
@@ -1 +0,0 @@
|
||||
local://?root=/foo bar/baz
|
||||
@@ -1 +0,0 @@
|
||||
ssh://userinfo@[fea5:23e1:3916:fc24:cb52:2837:2ecb:ea8e%eth0]?a=b&c=d
|
||||
@@ -1 +0,0 @@
|
||||
ssh://userinfo@[fea5:23e1:3916:fc24:cb52:2837:2ecb:ea8e%25eth0]?a=b&c=d
|
||||
@@ -1 +0,0 @@
|
||||
ssh://userinfo@fea5:23e1:3916:fc24:cb52:2837:2ecb:ea8e%25?a=b&c=d
|
||||
@@ -1 +0,0 @@
|
||||
ssh://userinfo@fea5:23e1:3916:fc24:cb52:2837:2ecb:ea8e%eth0?a=b&c=d
|
||||
@@ -1 +0,0 @@
|
||||
ssh://fea5:23e1:3916:fc24:cb52:2837:2ecb:ea8e%eth0?a=b&c=d
|
||||
@@ -1 +0,0 @@
|
||||
ssh://fea5:23e1:3916:fc24:cb52:2837:2ecb:ea8e%eth0
|
||||
@@ -218,70 +218,6 @@ struct LambdaAdapter
|
||||
}
|
||||
};
|
||||
|
||||
class NixApiStoreTestWithRealisedPath : public nix_api_store_test_base
|
||||
{
|
||||
public:
|
||||
StorePath * drvPath = nullptr;
|
||||
nix_derivation * drv = nullptr;
|
||||
Store * store = nullptr;
|
||||
StorePath * outPath = nullptr;
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
nix_api_store_test_base::SetUp();
|
||||
|
||||
nix::experimentalFeatureSettings.set("extra-experimental-features", "ca-derivations");
|
||||
nix::settings.substituters = {};
|
||||
|
||||
store = open_local_store();
|
||||
|
||||
std::filesystem::path unitTestData{getenv("_NIX_TEST_UNIT_DATA")};
|
||||
std::ifstream t{unitTestData / "derivation/ca/self-contained.json"};
|
||||
std::stringstream buffer;
|
||||
buffer << t.rdbuf();
|
||||
|
||||
// Replace the hardcoded system with the current system
|
||||
std::string jsonStr = nix::replaceStrings(buffer.str(), "x86_64-linux", nix::settings.thisSystem.get());
|
||||
|
||||
drv = nix_derivation_from_json(ctx, store, jsonStr.c_str());
|
||||
assert_ctx_ok();
|
||||
ASSERT_NE(drv, nullptr);
|
||||
|
||||
drvPath = nix_add_derivation(ctx, store, drv);
|
||||
assert_ctx_ok();
|
||||
ASSERT_NE(drvPath, nullptr);
|
||||
|
||||
auto cb = LambdaAdapter{.fun = [&](const char * outname, const StorePath * outPath_) {
|
||||
ASSERT_NE(outname, nullptr) << "Output name should not be NULL";
|
||||
auto is_valid_path = nix_store_is_valid_path(ctx, store, outPath_);
|
||||
ASSERT_EQ(is_valid_path, true);
|
||||
ASSERT_STREQ(outname, "out") << "Expected single 'out' output";
|
||||
ASSERT_EQ(outPath, nullptr) << "Output path callback should only be called once";
|
||||
outPath = nix_store_path_clone(outPath_);
|
||||
}};
|
||||
|
||||
auto ret = nix_store_realise(
|
||||
ctx, store, drvPath, static_cast<void *>(&cb), decltype(cb)::call_void<const char *, const StorePath *>);
|
||||
assert_ctx_ok();
|
||||
ASSERT_EQ(ret, NIX_OK);
|
||||
ASSERT_NE(outPath, nullptr) << "Derivation should have produced an output";
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
if (drvPath)
|
||||
nix_store_path_free(drvPath);
|
||||
if (outPath)
|
||||
nix_store_path_free(outPath);
|
||||
if (drv)
|
||||
nix_derivation_free(drv);
|
||||
if (store)
|
||||
nix_store_free(store);
|
||||
|
||||
nix_api_store_test_base::TearDown();
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(nix_api_store_test_base, build_from_json)
|
||||
{
|
||||
// FIXME get rid of these
|
||||
@@ -296,10 +232,7 @@ TEST_F(nix_api_store_test_base, build_from_json)
|
||||
std::stringstream buffer;
|
||||
buffer << t.rdbuf();
|
||||
|
||||
// Replace the hardcoded system with the current system
|
||||
std::string jsonStr = nix::replaceStrings(buffer.str(), "x86_64-linux", nix::settings.thisSystem.get());
|
||||
|
||||
auto * drv = nix_derivation_from_json(ctx, store, jsonStr.c_str());
|
||||
auto * drv = nix_derivation_from_json(ctx, store, buffer.str().c_str());
|
||||
assert_ctx_ok();
|
||||
ASSERT_NE(drv, nullptr);
|
||||
|
||||
@@ -307,21 +240,15 @@ TEST_F(nix_api_store_test_base, build_from_json)
|
||||
assert_ctx_ok();
|
||||
ASSERT_NE(drv, nullptr);
|
||||
|
||||
int callbackCount = 0;
|
||||
auto cb = LambdaAdapter{.fun = [&](const char * outname, const StorePath * outPath) {
|
||||
ASSERT_NE(outname, nullptr);
|
||||
ASSERT_STREQ(outname, "out");
|
||||
ASSERT_NE(outPath, nullptr);
|
||||
auto is_valid_path = nix_store_is_valid_path(ctx, store, outPath);
|
||||
ASSERT_EQ(is_valid_path, true);
|
||||
callbackCount++;
|
||||
}};
|
||||
|
||||
auto ret = nix_store_realise(
|
||||
ctx, store, drvPath, static_cast<void *>(&cb), decltype(cb)::call_void<const char *, const StorePath *>);
|
||||
assert_ctx_ok();
|
||||
ASSERT_EQ(ret, NIX_OK);
|
||||
ASSERT_EQ(callbackCount, 1) << "Callback should have been invoked exactly once";
|
||||
|
||||
// Clean up
|
||||
nix_store_path_free(drvPath);
|
||||
@@ -329,468 +256,4 @@ TEST_F(nix_api_store_test_base, build_from_json)
|
||||
nix_store_free(store);
|
||||
}
|
||||
|
||||
TEST_F(nix_api_store_test_base, nix_store_realise_invalid_system)
|
||||
{
|
||||
// Test that nix_store_realise properly reports errors when the system is invalid
|
||||
nix::experimentalFeatureSettings.set("extra-experimental-features", "ca-derivations");
|
||||
nix::settings.substituters = {};
|
||||
|
||||
auto * store = open_local_store();
|
||||
|
||||
std::filesystem::path unitTestData{getenv("_NIX_TEST_UNIT_DATA")};
|
||||
std::ifstream t{unitTestData / "derivation/ca/self-contained.json"};
|
||||
std::stringstream buffer;
|
||||
buffer << t.rdbuf();
|
||||
|
||||
// Use an invalid system that cannot be built
|
||||
std::string jsonStr = nix::replaceStrings(buffer.str(), "x86_64-linux", "bogus65-bogusos");
|
||||
|
||||
auto * drv = nix_derivation_from_json(ctx, store, jsonStr.c_str());
|
||||
assert_ctx_ok();
|
||||
ASSERT_NE(drv, nullptr);
|
||||
|
||||
auto * drvPath = nix_add_derivation(ctx, store, drv);
|
||||
assert_ctx_ok();
|
||||
ASSERT_NE(drvPath, nullptr);
|
||||
|
||||
int callbackCount = 0;
|
||||
auto cb = LambdaAdapter{.fun = [&](const char * outname, const StorePath * outPath) { callbackCount++; }};
|
||||
|
||||
auto ret = nix_store_realise(
|
||||
ctx, store, drvPath, static_cast<void *>(&cb), decltype(cb)::call_void<const char *, const StorePath *>);
|
||||
|
||||
// Should fail with an error
|
||||
ASSERT_NE(ret, NIX_OK);
|
||||
ASSERT_EQ(callbackCount, 0) << "Callback should not be invoked when build fails";
|
||||
|
||||
// Check that error message is set
|
||||
std::string errMsg = nix_err_msg(nullptr, ctx, nullptr);
|
||||
ASSERT_FALSE(errMsg.empty()) << "Error message should be set";
|
||||
ASSERT_NE(errMsg.find("system"), std::string::npos) << "Error should mention system";
|
||||
|
||||
// Clean up
|
||||
nix_store_path_free(drvPath);
|
||||
nix_derivation_free(drv);
|
||||
nix_store_free(store);
|
||||
}
|
||||
|
||||
TEST_F(nix_api_store_test_base, nix_store_realise_builder_fails)
|
||||
{
|
||||
// Test that nix_store_realise properly reports errors when the builder fails
|
||||
nix::experimentalFeatureSettings.set("extra-experimental-features", "ca-derivations");
|
||||
nix::settings.substituters = {};
|
||||
|
||||
auto * store = open_local_store();
|
||||
|
||||
std::filesystem::path unitTestData{getenv("_NIX_TEST_UNIT_DATA")};
|
||||
std::ifstream t{unitTestData / "derivation/ca/self-contained.json"};
|
||||
std::stringstream buffer;
|
||||
buffer << t.rdbuf();
|
||||
|
||||
// Replace with current system and make builder command fail
|
||||
std::string jsonStr = nix::replaceStrings(buffer.str(), "x86_64-linux", nix::settings.thisSystem.get());
|
||||
jsonStr = nix::replaceStrings(jsonStr, "echo $name foo > $out", "exit 1");
|
||||
|
||||
auto * drv = nix_derivation_from_json(ctx, store, jsonStr.c_str());
|
||||
assert_ctx_ok();
|
||||
ASSERT_NE(drv, nullptr);
|
||||
|
||||
auto * drvPath = nix_add_derivation(ctx, store, drv);
|
||||
assert_ctx_ok();
|
||||
ASSERT_NE(drvPath, nullptr);
|
||||
|
||||
int callbackCount = 0;
|
||||
auto cb = LambdaAdapter{.fun = [&](const char * outname, const StorePath * outPath) { callbackCount++; }};
|
||||
|
||||
auto ret = nix_store_realise(
|
||||
ctx, store, drvPath, static_cast<void *>(&cb), decltype(cb)::call_void<const char *, const StorePath *>);
|
||||
|
||||
// Should fail with an error
|
||||
ASSERT_NE(ret, NIX_OK);
|
||||
ASSERT_EQ(callbackCount, 0) << "Callback should not be invoked when build fails";
|
||||
|
||||
// Check that error message is set
|
||||
std::string errMsg = nix_err_msg(nullptr, ctx, nullptr);
|
||||
ASSERT_FALSE(errMsg.empty()) << "Error message should be set";
|
||||
|
||||
// Clean up
|
||||
nix_store_path_free(drvPath);
|
||||
nix_derivation_free(drv);
|
||||
nix_store_free(store);
|
||||
}
|
||||
|
||||
TEST_F(nix_api_store_test_base, nix_store_realise_builder_no_output)
|
||||
{
|
||||
// Test that nix_store_realise properly reports errors when builder succeeds but produces no output
|
||||
nix::experimentalFeatureSettings.set("extra-experimental-features", "ca-derivations");
|
||||
nix::settings.substituters = {};
|
||||
|
||||
auto * store = open_local_store();
|
||||
|
||||
std::filesystem::path unitTestData{getenv("_NIX_TEST_UNIT_DATA")};
|
||||
std::ifstream t{unitTestData / "derivation/ca/self-contained.json"};
|
||||
std::stringstream buffer;
|
||||
buffer << t.rdbuf();
|
||||
|
||||
// Replace with current system and make builder succeed but not produce output
|
||||
std::string jsonStr = nix::replaceStrings(buffer.str(), "x86_64-linux", nix::settings.thisSystem.get());
|
||||
jsonStr = nix::replaceStrings(jsonStr, "echo $name foo > $out", "true");
|
||||
|
||||
auto * drv = nix_derivation_from_json(ctx, store, jsonStr.c_str());
|
||||
assert_ctx_ok();
|
||||
ASSERT_NE(drv, nullptr);
|
||||
|
||||
auto * drvPath = nix_add_derivation(ctx, store, drv);
|
||||
assert_ctx_ok();
|
||||
ASSERT_NE(drvPath, nullptr);
|
||||
|
||||
int callbackCount = 0;
|
||||
auto cb = LambdaAdapter{.fun = [&](const char * outname, const StorePath * outPath) { callbackCount++; }};
|
||||
|
||||
auto ret = nix_store_realise(
|
||||
ctx, store, drvPath, static_cast<void *>(&cb), decltype(cb)::call_void<const char *, const StorePath *>);
|
||||
|
||||
// Should fail with an error
|
||||
ASSERT_NE(ret, NIX_OK);
|
||||
ASSERT_EQ(callbackCount, 0) << "Callback should not be invoked when build produces no output";
|
||||
|
||||
// Check that error message is set
|
||||
std::string errMsg = nix_err_msg(nullptr, ctx, nullptr);
|
||||
ASSERT_FALSE(errMsg.empty()) << "Error message should be set";
|
||||
|
||||
// Clean up
|
||||
nix_store_path_free(drvPath);
|
||||
nix_derivation_free(drv);
|
||||
nix_store_free(store);
|
||||
}
|
||||
|
||||
TEST_F(NixApiStoreTestWithRealisedPath, nix_store_get_fs_closure_with_outputs)
|
||||
{
|
||||
// Test closure computation with include_outputs on a derivation path
|
||||
struct CallbackData
|
||||
{
|
||||
std::set<std::string> * paths;
|
||||
};
|
||||
|
||||
std::set<std::string> closure_paths;
|
||||
CallbackData data{&closure_paths};
|
||||
|
||||
auto ret = nix_store_get_fs_closure(
|
||||
ctx,
|
||||
store,
|
||||
drvPath, // Use derivation path
|
||||
false, // flip_direction
|
||||
true, // include_outputs - include the outputs in the closure
|
||||
false, // include_derivers
|
||||
&data,
|
||||
[](nix_c_context * context, void * userdata, const StorePath * path) {
|
||||
auto * data = static_cast<CallbackData *>(userdata);
|
||||
std::string path_str;
|
||||
nix_store_path_name(path, OBSERVE_STRING(path_str));
|
||||
auto [it, inserted] = data->paths->insert(path_str);
|
||||
ASSERT_TRUE(inserted) << "Duplicate path in closure: " << path_str;
|
||||
});
|
||||
assert_ctx_ok();
|
||||
ASSERT_EQ(ret, NIX_OK);
|
||||
|
||||
// The closure should contain the derivation and its outputs
|
||||
ASSERT_GE(closure_paths.size(), 2);
|
||||
|
||||
// Verify the output path is in the closure
|
||||
std::string outPathName;
|
||||
nix_store_path_name(outPath, OBSERVE_STRING(outPathName));
|
||||
ASSERT_EQ(closure_paths.count(outPathName), 1);
|
||||
}
|
||||
|
||||
TEST_F(NixApiStoreTestWithRealisedPath, nix_store_get_fs_closure_without_outputs)
|
||||
{
|
||||
// Test closure computation WITHOUT include_outputs on a derivation path
|
||||
struct CallbackData
|
||||
{
|
||||
std::set<std::string> * paths;
|
||||
};
|
||||
|
||||
std::set<std::string> closure_paths;
|
||||
CallbackData data{&closure_paths};
|
||||
|
||||
auto ret = nix_store_get_fs_closure(
|
||||
ctx,
|
||||
store,
|
||||
drvPath, // Use derivation path
|
||||
false, // flip_direction
|
||||
false, // include_outputs - do NOT include the outputs
|
||||
false, // include_derivers
|
||||
&data,
|
||||
[](nix_c_context * context, void * userdata, const StorePath * path) {
|
||||
auto * data = static_cast<CallbackData *>(userdata);
|
||||
std::string path_str;
|
||||
nix_store_path_name(path, OBSERVE_STRING(path_str));
|
||||
auto [it, inserted] = data->paths->insert(path_str);
|
||||
ASSERT_TRUE(inserted) << "Duplicate path in closure: " << path_str;
|
||||
});
|
||||
assert_ctx_ok();
|
||||
ASSERT_EQ(ret, NIX_OK);
|
||||
|
||||
// Verify the output path is NOT in the closure
|
||||
std::string outPathName;
|
||||
nix_store_path_name(outPath, OBSERVE_STRING(outPathName));
|
||||
ASSERT_EQ(closure_paths.count(outPathName), 0) << "Output path should not be in closure when includeOutputs=false";
|
||||
}
|
||||
|
||||
TEST_F(NixApiStoreTestWithRealisedPath, nix_store_get_fs_closure_flip_direction)
|
||||
{
|
||||
// Test closure computation with flip_direction on a derivation path
|
||||
// When flip_direction=true, we get the reverse dependencies (what depends on this path)
|
||||
// For a derivation, this should NOT include outputs even with include_outputs=true
|
||||
struct CallbackData
|
||||
{
|
||||
std::set<std::string> * paths;
|
||||
};
|
||||
|
||||
std::set<std::string> closure_paths;
|
||||
CallbackData data{&closure_paths};
|
||||
|
||||
auto ret = nix_store_get_fs_closure(
|
||||
ctx,
|
||||
store,
|
||||
drvPath, // Use derivation path
|
||||
true, // flip_direction - get reverse dependencies
|
||||
true, // include_outputs
|
||||
false, // include_derivers
|
||||
&data,
|
||||
[](nix_c_context * context, void * userdata, const StorePath * path) {
|
||||
auto * data = static_cast<CallbackData *>(userdata);
|
||||
std::string path_str;
|
||||
nix_store_path_name(path, OBSERVE_STRING(path_str));
|
||||
auto [it, inserted] = data->paths->insert(path_str);
|
||||
ASSERT_TRUE(inserted) << "Duplicate path in closure: " << path_str;
|
||||
});
|
||||
assert_ctx_ok();
|
||||
ASSERT_EQ(ret, NIX_OK);
|
||||
|
||||
// Verify the output path is NOT in the closure when direction is flipped
|
||||
std::string outPathName;
|
||||
nix_store_path_name(outPath, OBSERVE_STRING(outPathName));
|
||||
ASSERT_EQ(closure_paths.count(outPathName), 0) << "Output path should not be in closure when flip_direction=true";
|
||||
}
|
||||
|
||||
TEST_F(NixApiStoreTestWithRealisedPath, nix_store_get_fs_closure_include_derivers)
|
||||
{
|
||||
// Test closure computation with include_derivers on an output path
|
||||
// This should include the derivation that produced the output
|
||||
struct CallbackData
|
||||
{
|
||||
std::set<std::string> * paths;
|
||||
};
|
||||
|
||||
std::set<std::string> closure_paths;
|
||||
CallbackData data{&closure_paths};
|
||||
|
||||
auto ret = nix_store_get_fs_closure(
|
||||
ctx,
|
||||
store,
|
||||
outPath, // Use output path (not derivation)
|
||||
false, // flip_direction
|
||||
false, // include_outputs
|
||||
true, // include_derivers - include the derivation
|
||||
&data,
|
||||
[](nix_c_context * context, void * userdata, const StorePath * path) {
|
||||
auto * data = static_cast<CallbackData *>(userdata);
|
||||
std::string path_str;
|
||||
nix_store_path_name(path, OBSERVE_STRING(path_str));
|
||||
auto [it, inserted] = data->paths->insert(path_str);
|
||||
ASSERT_TRUE(inserted) << "Duplicate path in closure: " << path_str;
|
||||
});
|
||||
assert_ctx_ok();
|
||||
ASSERT_EQ(ret, NIX_OK);
|
||||
|
||||
// Verify the derivation path is in the closure
|
||||
// Deriver is nasty stateful, and this assertion is only guaranteed because
|
||||
// we're using an empty store as our starting point. Otherwise, if the
|
||||
// output happens to exist, the deriver could be anything.
|
||||
std::string drvPathName;
|
||||
nix_store_path_name(drvPath, OBSERVE_STRING(drvPathName));
|
||||
ASSERT_EQ(closure_paths.count(drvPathName), 1) << "Derivation should be in closure when include_derivers=true";
|
||||
}
|
||||
|
||||
TEST_F(NixApiStoreTestWithRealisedPath, nix_store_realise_output_ordering)
|
||||
{
|
||||
// Test that nix_store_realise returns outputs in alphabetical order by output name.
|
||||
// This test uses a CA derivation with 10 outputs in randomized input order
|
||||
// to verify that the callback order is deterministic and alphabetical.
|
||||
nix::experimentalFeatureSettings.set("extra-experimental-features", "ca-derivations");
|
||||
nix::settings.substituters = {};
|
||||
|
||||
auto * store = open_local_store();
|
||||
|
||||
// Create a CA derivation with 10 outputs using proper placeholders
|
||||
auto outa_ph = nix::hashPlaceholder("outa");
|
||||
auto outb_ph = nix::hashPlaceholder("outb");
|
||||
auto outc_ph = nix::hashPlaceholder("outc");
|
||||
auto outd_ph = nix::hashPlaceholder("outd");
|
||||
auto oute_ph = nix::hashPlaceholder("oute");
|
||||
auto outf_ph = nix::hashPlaceholder("outf");
|
||||
auto outg_ph = nix::hashPlaceholder("outg");
|
||||
auto outh_ph = nix::hashPlaceholder("outh");
|
||||
auto outi_ph = nix::hashPlaceholder("outi");
|
||||
auto outj_ph = nix::hashPlaceholder("outj");
|
||||
|
||||
std::string drvJson = R"({
|
||||
"version": 3,
|
||||
"name": "multi-output-test",
|
||||
"system": ")" + nix::settings.thisSystem.get()
|
||||
+ R"(",
|
||||
"builder": "/bin/sh",
|
||||
"args": ["-c", "echo a > $outa; echo b > $outb; echo c > $outc; echo d > $outd; echo e > $oute; echo f > $outf; echo g > $outg; echo h > $outh; echo i > $outi; echo j > $outj"],
|
||||
"env": {
|
||||
"builder": "/bin/sh",
|
||||
"name": "multi-output-test",
|
||||
"system": ")" + nix::settings.thisSystem.get()
|
||||
+ R"(",
|
||||
"outf": ")" + outf_ph
|
||||
+ R"(",
|
||||
"outd": ")" + outd_ph
|
||||
+ R"(",
|
||||
"outi": ")" + outi_ph
|
||||
+ R"(",
|
||||
"oute": ")" + oute_ph
|
||||
+ R"(",
|
||||
"outh": ")" + outh_ph
|
||||
+ R"(",
|
||||
"outc": ")" + outc_ph
|
||||
+ R"(",
|
||||
"outb": ")" + outb_ph
|
||||
+ R"(",
|
||||
"outg": ")" + outg_ph
|
||||
+ R"(",
|
||||
"outj": ")" + outj_ph
|
||||
+ R"(",
|
||||
"outa": ")" + outa_ph
|
||||
+ R"("
|
||||
},
|
||||
"inputDrvs": {},
|
||||
"inputSrcs": [],
|
||||
"outputs": {
|
||||
"outd": { "hashAlgo": "sha256", "method": "nar" },
|
||||
"outf": { "hashAlgo": "sha256", "method": "nar" },
|
||||
"outg": { "hashAlgo": "sha256", "method": "nar" },
|
||||
"outb": { "hashAlgo": "sha256", "method": "nar" },
|
||||
"outc": { "hashAlgo": "sha256", "method": "nar" },
|
||||
"outi": { "hashAlgo": "sha256", "method": "nar" },
|
||||
"outj": { "hashAlgo": "sha256", "method": "nar" },
|
||||
"outh": { "hashAlgo": "sha256", "method": "nar" },
|
||||
"outa": { "hashAlgo": "sha256", "method": "nar" },
|
||||
"oute": { "hashAlgo": "sha256", "method": "nar" }
|
||||
}
|
||||
})";
|
||||
|
||||
auto * drv = nix_derivation_from_json(ctx, store, drvJson.c_str());
|
||||
assert_ctx_ok();
|
||||
ASSERT_NE(drv, nullptr);
|
||||
|
||||
auto * drvPath = nix_add_derivation(ctx, store, drv);
|
||||
assert_ctx_ok();
|
||||
ASSERT_NE(drvPath, nullptr);
|
||||
|
||||
// Realise the derivation - capture the order outputs are returned
|
||||
std::map<std::string, nix::StorePath> outputs;
|
||||
std::vector<std::string> output_order;
|
||||
auto cb = LambdaAdapter{.fun = [&](const char * outname, const StorePath * outPath) {
|
||||
ASSERT_NE(outname, nullptr);
|
||||
ASSERT_NE(outPath, nullptr);
|
||||
output_order.push_back(outname);
|
||||
outputs.emplace(outname, outPath->path);
|
||||
}};
|
||||
|
||||
auto ret = nix_store_realise(
|
||||
ctx, store, drvPath, static_cast<void *>(&cb), decltype(cb)::call_void<const char *, const StorePath *>);
|
||||
assert_ctx_ok();
|
||||
ASSERT_EQ(ret, NIX_OK);
|
||||
ASSERT_EQ(outputs.size(), 10);
|
||||
|
||||
// Verify outputs are returned in alphabetical order by output name
|
||||
std::vector<std::string> expected_order = {
|
||||
"outa", "outb", "outc", "outd", "oute", "outf", "outg", "outh", "outi", "outj"};
|
||||
ASSERT_EQ(output_order, expected_order) << "Outputs should be returned in alphabetical order by output name";
|
||||
|
||||
// Now compute closure with include_outputs and collect paths in order
|
||||
struct CallbackData
|
||||
{
|
||||
std::vector<std::string> * paths;
|
||||
};
|
||||
|
||||
std::vector<std::string> closure_paths;
|
||||
CallbackData data{&closure_paths};
|
||||
|
||||
ret = nix_store_get_fs_closure(
|
||||
ctx,
|
||||
store,
|
||||
drvPath,
|
||||
false, // flip_direction
|
||||
true, // include_outputs - include the outputs in the closure
|
||||
false, // include_derivers
|
||||
&data,
|
||||
[](nix_c_context * context, void * userdata, const StorePath * path) {
|
||||
auto * data = static_cast<CallbackData *>(userdata);
|
||||
std::string path_str;
|
||||
nix_store_path_name(path, OBSERVE_STRING(path_str));
|
||||
data->paths->push_back(path_str);
|
||||
});
|
||||
assert_ctx_ok();
|
||||
ASSERT_EQ(ret, NIX_OK);
|
||||
|
||||
// Should contain at least the derivation and 10 outputs
|
||||
ASSERT_GE(closure_paths.size(), 11);
|
||||
|
||||
// Verify all outputs are present in the closure
|
||||
for (const auto & [outname, outPath] : outputs) {
|
||||
std::string outPathName = store->ptr->printStorePath(outPath);
|
||||
|
||||
bool found = false;
|
||||
for (const auto & p : closure_paths) {
|
||||
// nix_store_path_name returns just the name part, so match against full path name
|
||||
if (outPathName.find(p) != std::string::npos) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(found) << "Output " << outname << " (" << outPathName << ") not found in closure";
|
||||
}
|
||||
|
||||
nix_store_path_free(drvPath);
|
||||
nix_derivation_free(drv);
|
||||
nix_store_free(store);
|
||||
}
|
||||
|
||||
TEST_F(NixApiStoreTestWithRealisedPath, nix_store_get_fs_closure_error_propagation)
|
||||
{
|
||||
// Test that errors in the callback abort the closure computation
|
||||
struct CallbackData
|
||||
{
|
||||
int * count;
|
||||
};
|
||||
|
||||
int call_count = 0;
|
||||
CallbackData data{&call_count};
|
||||
|
||||
auto ret = nix_store_get_fs_closure(
|
||||
ctx,
|
||||
store,
|
||||
drvPath, // Use derivation path
|
||||
false, // flip_direction
|
||||
true, // include_outputs
|
||||
false, // include_derivers
|
||||
&data,
|
||||
[](nix_c_context * context, void * userdata, const StorePath * path) {
|
||||
auto * data = static_cast<CallbackData *>(userdata);
|
||||
(*data->count)++;
|
||||
// Set an error immediately
|
||||
nix_set_err_msg(context, NIX_ERR_UNKNOWN, "Test error");
|
||||
});
|
||||
|
||||
// Should have aborted with error
|
||||
ASSERT_EQ(ret, NIX_ERR_UNKNOWN);
|
||||
ASSERT_EQ(call_count, 1); // Should have been called exactly once, then aborted
|
||||
}
|
||||
|
||||
} // namespace nixC
|
||||
@@ -1,6 +1,4 @@
|
||||
#include "nix/store/references.hh"
|
||||
#include "nix/store/path-references.hh"
|
||||
#include "nix/util/memory-source-accessor.hh"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@@ -81,145 +79,4 @@ TEST(references, scan)
|
||||
}
|
||||
}
|
||||
|
||||
TEST(references, scanForReferencesDeep)
|
||||
{
|
||||
using File = MemorySourceAccessor::File;
|
||||
|
||||
// Create store paths to search for
|
||||
StorePath path1{"dc04vv14dak1c1r48qa0m23vr9jy8sm0-foo"};
|
||||
StorePath path2{"zc842j0rz61mjsp3h3wp5ly71ak6qgdn-bar"};
|
||||
StorePath path3{"a5cn2i4b83gnsm60d38l3kgb8qfplm11-baz"};
|
||||
|
||||
StorePathSet refs{path1, path2, path3};
|
||||
|
||||
std::string_view hash1 = path1.hashPart();
|
||||
std::string_view hash2 = path2.hashPart();
|
||||
std::string_view hash3 = path3.hashPart();
|
||||
|
||||
// Create an in-memory file system with various reference patterns
|
||||
auto accessor = make_ref<MemorySourceAccessor>();
|
||||
accessor->root = File::Directory{
|
||||
.contents{
|
||||
{
|
||||
// file1.txt: contains hash1
|
||||
"file1.txt",
|
||||
File::Regular{
|
||||
.contents = "This file references " + hash1 + " in its content",
|
||||
},
|
||||
},
|
||||
{
|
||||
// file2.txt: contains hash2 and hash3
|
||||
"file2.txt",
|
||||
File::Regular{
|
||||
.contents = "Multiple refs: " + hash2 + " and also " + hash3,
|
||||
},
|
||||
},
|
||||
{
|
||||
// file3.txt: contains no references
|
||||
"file3.txt",
|
||||
File::Regular{
|
||||
.contents = "This file has no store path references at all",
|
||||
},
|
||||
},
|
||||
{
|
||||
// subdir: a subdirectory
|
||||
"subdir",
|
||||
File::Directory{
|
||||
.contents{
|
||||
{
|
||||
// subdir/file4.txt: contains hash1 again
|
||||
"file4.txt",
|
||||
File::Regular{
|
||||
.contents = "Subdirectory file with " + hash1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
// link1: a symlink that contains a reference in its target
|
||||
"link1",
|
||||
File::Symlink{
|
||||
.target = hash2 + "-target",
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// Test the callback-based API
|
||||
{
|
||||
std::map<CanonPath, StorePathSet> foundRefs;
|
||||
|
||||
scanForReferencesDeep(*accessor, CanonPath::root, refs, [&](FileRefScanResult result) {
|
||||
foundRefs[std::move(result.filePath)] = std::move(result.foundRefs);
|
||||
});
|
||||
|
||||
// Verify we found the expected references
|
||||
EXPECT_EQ(foundRefs.size(), 4); // file1, file2, file4, link1
|
||||
|
||||
// Check file1.txt found path1
|
||||
{
|
||||
CanonPath f1Path("/file1.txt");
|
||||
auto it = foundRefs.find(f1Path);
|
||||
ASSERT_TRUE(it != foundRefs.end());
|
||||
EXPECT_EQ(it->second.size(), 1);
|
||||
EXPECT_TRUE(it->second.count(path1));
|
||||
}
|
||||
|
||||
// Check file2.txt found path2 and path3
|
||||
{
|
||||
CanonPath f2Path("/file2.txt");
|
||||
auto it = foundRefs.find(f2Path);
|
||||
ASSERT_TRUE(it != foundRefs.end());
|
||||
EXPECT_EQ(it->second.size(), 2);
|
||||
EXPECT_TRUE(it->second.count(path2));
|
||||
EXPECT_TRUE(it->second.count(path3));
|
||||
}
|
||||
|
||||
// Check file3.txt is not in results (no refs)
|
||||
{
|
||||
CanonPath f3Path("/file3.txt");
|
||||
EXPECT_FALSE(foundRefs.count(f3Path));
|
||||
}
|
||||
|
||||
// Check subdir/file4.txt found path1
|
||||
{
|
||||
CanonPath f4Path("/subdir/file4.txt");
|
||||
auto it = foundRefs.find(f4Path);
|
||||
ASSERT_TRUE(it != foundRefs.end());
|
||||
EXPECT_EQ(it->second.size(), 1);
|
||||
EXPECT_TRUE(it->second.count(path1));
|
||||
}
|
||||
|
||||
// Check symlink found path2
|
||||
{
|
||||
CanonPath linkPath("/link1");
|
||||
auto it = foundRefs.find(linkPath);
|
||||
ASSERT_TRUE(it != foundRefs.end());
|
||||
EXPECT_EQ(it->second.size(), 1);
|
||||
EXPECT_TRUE(it->second.count(path2));
|
||||
}
|
||||
}
|
||||
|
||||
// Test the map-based convenience API
|
||||
{
|
||||
auto results = scanForReferencesDeep(*accessor, CanonPath::root, refs);
|
||||
|
||||
EXPECT_EQ(results.size(), 4); // file1, file2, file4, link1
|
||||
|
||||
// Verify all expected files are in the results
|
||||
EXPECT_TRUE(results.count(CanonPath("/file1.txt")));
|
||||
EXPECT_TRUE(results.count(CanonPath("/file2.txt")));
|
||||
EXPECT_TRUE(results.count(CanonPath("/subdir/file4.txt")));
|
||||
EXPECT_TRUE(results.count(CanonPath("/link1")));
|
||||
EXPECT_FALSE(results.count(CanonPath("/file3.txt")));
|
||||
|
||||
// Verify the references found in each file are correct
|
||||
EXPECT_EQ(results.at(CanonPath("/file1.txt")), StorePathSet{path1});
|
||||
EXPECT_EQ(results.at(CanonPath("/file2.txt")), StorePathSet({path2, path3}));
|
||||
EXPECT_EQ(results.at(CanonPath("/subdir/file4.txt")), StorePathSet{path1});
|
||||
EXPECT_EQ(results.at(CanonPath("/link1")), StorePathSet{path2});
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace nix
|
||||
@@ -70,25 +70,6 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
},
|
||||
"with_profile_and_region",
|
||||
},
|
||||
ParsedS3URLTestCase{
|
||||
"s3://my-bucket/my-key.txt?versionId=abc123xyz",
|
||||
{
|
||||
.bucket = "my-bucket",
|
||||
.key = {"my-key.txt"},
|
||||
.versionId = "abc123xyz",
|
||||
},
|
||||
"with_versionId",
|
||||
},
|
||||
ParsedS3URLTestCase{
|
||||
"s3://bucket/path/to/object?region=eu-west-1&versionId=version456",
|
||||
{
|
||||
.bucket = "bucket",
|
||||
.key = {"path", "to", "object"},
|
||||
.region = "eu-west-1",
|
||||
.versionId = "version456",
|
||||
},
|
||||
"with_region_and_versionId",
|
||||
},
|
||||
ParsedS3URLTestCase{
|
||||
"s3://bucket/key?endpoint=https://minio.local&scheme=http",
|
||||
{
|
||||
@@ -241,37 +222,6 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
},
|
||||
"https://s3.ap-southeast-2.amazonaws.com/bucket/path/to/file.txt",
|
||||
"complex_path_and_region",
|
||||
},
|
||||
S3ToHttpsConversionTestCase{
|
||||
ParsedS3URL{
|
||||
.bucket = "my-bucket",
|
||||
.key = {"my-key.txt"},
|
||||
.versionId = "abc123xyz",
|
||||
},
|
||||
ParsedURL{
|
||||
.scheme = "https",
|
||||
.authority = ParsedURL::Authority{.host = "s3.us-east-1.amazonaws.com"},
|
||||
.path = {"", "my-bucket", "my-key.txt"},
|
||||
.query = {{"versionId", "abc123xyz"}},
|
||||
},
|
||||
"https://s3.us-east-1.amazonaws.com/my-bucket/my-key.txt?versionId=abc123xyz",
|
||||
"with_versionId",
|
||||
},
|
||||
S3ToHttpsConversionTestCase{
|
||||
ParsedS3URL{
|
||||
.bucket = "versioned-bucket",
|
||||
.key = {"path", "to", "object"},
|
||||
.region = "eu-west-1",
|
||||
.versionId = "version456",
|
||||
},
|
||||
ParsedURL{
|
||||
.scheme = "https",
|
||||
.authority = ParsedURL::Authority{.host = "s3.eu-west-1.amazonaws.com"},
|
||||
.path = {"", "versioned-bucket", "path", "to", "object"},
|
||||
.query = {{"versionId", "version456"}},
|
||||
},
|
||||
"https://s3.eu-west-1.amazonaws.com/versioned-bucket/path/to/object?versionId=version456",
|
||||
"with_region_and_versionId",
|
||||
}),
|
||||
[](const ::testing::TestParamInfo<S3ToHttpsConversionTestCase> & info) { return info.param.description; });
|
||||
|
||||
|
||||
@@ -100,12 +100,9 @@ URI_TEST(local_1, localExample_1)
|
||||
|
||||
URI_TEST(local_2, localExample_2)
|
||||
|
||||
/* Test path with encoded spaces */
|
||||
/* Test path with spaces */
|
||||
URI_TEST(local_3, localExample_3)
|
||||
|
||||
/* Test path with spaces that are improperly not encoded */
|
||||
URI_TEST_READ(local_3_no_percent, localExample_3)
|
||||
|
||||
URI_TEST_READ(local_shorthand_1, localExample_1)
|
||||
|
||||
URI_TEST_READ(local_shorthand_2, localExample_2)
|
||||
@@ -186,64 +183,4 @@ static StoreReference sshIPv6AuthorityWithUserinfoAndParams{
|
||||
|
||||
URI_TEST_READ(ssh_unbracketed_ipv6_3, sshIPv6AuthorityWithUserinfoAndParams)
|
||||
|
||||
static const StoreReference sshIPv6AuthorityWithUserinfoAndParamsAndZoneId{
|
||||
.variant =
|
||||
StoreReference::Specified{
|
||||
.scheme = "ssh",
|
||||
.authority = "userinfo@[fea5:23e1:3916:fc24:cb52:2837:2ecb:ea8e%25eth0]",
|
||||
},
|
||||
.params =
|
||||
{
|
||||
{"a", "b"},
|
||||
{"c", "d"},
|
||||
},
|
||||
};
|
||||
|
||||
URI_TEST_READ(ssh_unbracketed_ipv6_4, sshIPv6AuthorityWithUserinfoAndParamsAndZoneId)
|
||||
URI_TEST_READ(ssh_unbracketed_ipv6_5, sshIPv6AuthorityWithUserinfoAndParamsAndZoneId)
|
||||
|
||||
static const StoreReference sshIPv6AuthorityWithUserinfoAndParamsAndZoneIdTricky{
|
||||
.variant =
|
||||
StoreReference::Specified{
|
||||
.scheme = "ssh",
|
||||
.authority = "userinfo@[fea5:23e1:3916:fc24:cb52:2837:2ecb:ea8e%2525]",
|
||||
},
|
||||
.params =
|
||||
{
|
||||
{"a", "b"},
|
||||
{"c", "d"},
|
||||
},
|
||||
};
|
||||
|
||||
// Non-standard syntax where the IPv6 literal appears without brackets. In
|
||||
// this case don't considering %25 to be a pct-encoded % and just take it as a
|
||||
// literal value. 25 is a perfectly legal ZoneId value in theory.
|
||||
URI_TEST_READ(ssh_unbracketed_ipv6_6, sshIPv6AuthorityWithUserinfoAndParamsAndZoneIdTricky)
|
||||
URI_TEST_READ(ssh_unbracketed_ipv6_7, sshIPv6AuthorityWithUserinfoAndParamsAndZoneId)
|
||||
|
||||
static const StoreReference sshIPv6AuthorityWithParamsAndZoneId{
|
||||
.variant =
|
||||
StoreReference::Specified{
|
||||
.scheme = "ssh",
|
||||
.authority = "[fea5:23e1:3916:fc24:cb52:2837:2ecb:ea8e%25eth0]",
|
||||
},
|
||||
.params =
|
||||
{
|
||||
{"a", "b"},
|
||||
{"c", "d"},
|
||||
},
|
||||
};
|
||||
|
||||
URI_TEST_READ(ssh_unbracketed_ipv6_8, sshIPv6AuthorityWithParamsAndZoneId)
|
||||
|
||||
static const StoreReference sshIPv6AuthorityWithZoneId{
|
||||
.variant =
|
||||
StoreReference::Specified{
|
||||
.scheme = "ssh",
|
||||
.authority = "[fea5:23e1:3916:fc24:cb52:2837:2ecb:ea8e%25eth0]",
|
||||
},
|
||||
};
|
||||
|
||||
URI_TEST_READ(ssh_unbracketed_ipv6_9, sshIPv6AuthorityWithZoneId)
|
||||
|
||||
} // namespace nix
|
||||
@@ -76,11 +76,9 @@ std::optional<std::string> BinaryCacheStore::getNixCacheInfo()
|
||||
return getFile(cacheInfoFile);
|
||||
}
|
||||
|
||||
void BinaryCacheStore::upsertFile(
|
||||
const std::string & path, std::string && data, const std::string & mimeType, uint64_t sizeHint)
|
||||
void BinaryCacheStore::upsertFile(const std::string & path, std::string && data, const std::string & mimeType)
|
||||
{
|
||||
auto source = restartableSourceFromFactory([data = std::move(data)]() { return make_unique<StringSource>(data); });
|
||||
upsertFile(path, *source, mimeType, sizeHint);
|
||||
upsertFile(path, std::make_shared<std::stringstream>(std::move(data)), mimeType);
|
||||
}
|
||||
|
||||
void BinaryCacheStore::getFile(const std::string & path, Callback<std::optional<std::string>> callback) noexcept
|
||||
@@ -272,19 +270,11 @@ ref<const ValidPathInfo> BinaryCacheStore::addToStoreCommon(
|
||||
|
||||
/* Atomically write the NAR file. */
|
||||
if (repair || !fileExists(narInfo->url)) {
|
||||
auto source = restartableSourceFromFactory([fnTemp]() {
|
||||
struct AutoCloseFDSource : AutoCloseFD, FdSource
|
||||
{
|
||||
AutoCloseFDSource(AutoCloseFD fd)
|
||||
: AutoCloseFD(std::move(fd))
|
||||
, FdSource(get())
|
||||
{
|
||||
}
|
||||
};
|
||||
return std::make_unique<AutoCloseFDSource>(toDescriptor(open(fnTemp.c_str(), O_RDONLY)));
|
||||
});
|
||||
stats.narWrite++;
|
||||
upsertFile(narInfo->url, *source, "application/x-nix-nar", narInfo->fileSize);
|
||||
upsertFile(
|
||||
narInfo->url,
|
||||
std::make_shared<std::fstream>(fnTemp, std::ios_base::in | std::ios_base::binary),
|
||||
"application/x-nix-nar");
|
||||
} else
|
||||
stats.narWriteAverted++;
|
||||
|
||||
|
||||
@@ -239,6 +239,7 @@ Goal::Co DerivationBuildingGoal::tryToBuild()
|
||||
: buildMode == bmCheck ? "checking outputs of '%s'"
|
||||
: "building '%s'",
|
||||
worker.store.printStorePath(drvPath));
|
||||
fmt("building '%s'", worker.store.printStorePath(drvPath));
|
||||
#ifndef _WIN32 // TODO enable build hook on Windows
|
||||
if (hook)
|
||||
msg += fmt(" on '%s'", hook->machineName);
|
||||
@@ -677,15 +678,7 @@ Goal::Co DerivationBuildingGoal::tryToBuild()
|
||||
{
|
||||
builder.reset();
|
||||
StorePathSet outputPaths;
|
||||
/* In the check case we install no store objects, and so
|
||||
`builtOutputs` is empty. However, per issue #14287, there is
|
||||
an expectation that the post-build hook is still executed.
|
||||
(This is useful for e.g. logging successful deterministic rebuilds.)
|
||||
|
||||
In order to make that work, in the check case just load the
|
||||
(preexisting) infos from scratch, rather than relying on what
|
||||
`DerivationBuilder` returned to us. */
|
||||
for (auto & [_, output] : buildMode == bmCheck ? checkPathValidity(initialOutputs).second : builtOutputs) {
|
||||
for (auto & [_, output] : builtOutputs) {
|
||||
// for sake of `bmRepair`
|
||||
worker.markContentsGood(output.outPath);
|
||||
outputPaths.insert(output.outPath);
|
||||
|
||||
@@ -25,7 +25,7 @@ DesugaredEnv DesugaredEnv::create(
|
||||
if (drv.structuredAttrs) {
|
||||
auto json = drv.structuredAttrs->prepareStructuredAttrs(store, drvOptions, inputPaths, drv.outputs);
|
||||
res.atFileEnvPair("NIX_ATTRS_SH_FILE", ".attrs.sh") = StructuredAttrs::writeShell(json);
|
||||
res.atFileEnvPair("NIX_ATTRS_JSON_FILE", ".attrs.json") = static_cast<nlohmann::json>(std::move(json)).dump();
|
||||
res.atFileEnvPair("NIX_ATTRS_JSON_FILE", ".attrs.json") = json.dump();
|
||||
} else {
|
||||
/* In non-structured mode, set all bindings either directory in the
|
||||
environment or via a file, as specified by
|
||||
|
||||
@@ -147,7 +147,7 @@ Goal::Co DerivationGoal::haveDerivation(bool storeDerivation)
|
||||
co_await await(std::move(waitees));
|
||||
}
|
||||
if (nrFailed != 0) {
|
||||
co_return doneFailure({BuildResult::Failure::DependencyFailed, "Build failed due to failed dependency"});
|
||||
co_return doneFailure({BuildResult::Failure::DependencyFailed, "resolution failed"});
|
||||
}
|
||||
|
||||
if (resolutionGoal->resolvedDrv) {
|
||||
@@ -278,23 +278,7 @@ Goal::Co DerivationGoal::haveDerivation(bool storeDerivation)
|
||||
}
|
||||
}
|
||||
|
||||
/* If the wanted output is not in builtOutputs (e.g., because it
|
||||
was already valid and therefore not re-registered), we need to
|
||||
add it ourselves to ensure we return the correct information. */
|
||||
if (success.builtOutputs.count(wantedOutput) == 0) {
|
||||
debug(
|
||||
"BUG! wanted output '%s' not in builtOutputs, working around by adding it manually", wantedOutput);
|
||||
success.builtOutputs = {{
|
||||
wantedOutput,
|
||||
{
|
||||
assertPathValidity(),
|
||||
{
|
||||
.drvHash = outputHash,
|
||||
.outputName = wantedOutput,
|
||||
},
|
||||
},
|
||||
}};
|
||||
}
|
||||
assert(success.builtOutputs.count(wantedOutput) > 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -268,18 +268,16 @@ Goal::Co PathSubstitutionGoal::tryToRun(
|
||||
try {
|
||||
promise.get_future().get();
|
||||
} catch (std::exception & e) {
|
||||
printError(e.what());
|
||||
|
||||
/* Cause the parent build to fail unless --fallback is given,
|
||||
or the substitute has disappeared. The latter case behaves
|
||||
the same as the substitute never having existed in the
|
||||
first place. */
|
||||
try {
|
||||
throw;
|
||||
} catch (SubstituteGone & sg) {
|
||||
/* Missing NARs are expected when they've been garbage collected.
|
||||
This is not a failure, so log as a warning instead of an error. */
|
||||
logWarning({.msg = sg.info().msg});
|
||||
} catch (SubstituteGone &) {
|
||||
} catch (...) {
|
||||
printError(e.what());
|
||||
substituterFailed = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "nix/util/args.hh"
|
||||
#include "nix/store/content-address.hh"
|
||||
#include "nix/util/split.hh"
|
||||
#include "nix/util/json-utils.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
@@ -301,36 +300,3 @@ Hash ContentAddressWithReferences::getHash() const
|
||||
}
|
||||
|
||||
} // namespace nix
|
||||
|
||||
namespace nlohmann {
|
||||
|
||||
using namespace nix;
|
||||
|
||||
ContentAddressMethod adl_serializer<ContentAddressMethod>::from_json(const json & json)
|
||||
{
|
||||
return ContentAddressMethod::parse(getString(json));
|
||||
}
|
||||
|
||||
void adl_serializer<ContentAddressMethod>::to_json(json & json, const ContentAddressMethod & m)
|
||||
{
|
||||
json = m.render();
|
||||
}
|
||||
|
||||
ContentAddress adl_serializer<ContentAddress>::from_json(const json & json)
|
||||
{
|
||||
auto obj = getObject(json);
|
||||
return {
|
||||
.method = adl_serializer<ContentAddressMethod>::from_json(valueAt(obj, "method")),
|
||||
.hash = valueAt(obj, "hash"),
|
||||
};
|
||||
}
|
||||
|
||||
void adl_serializer<ContentAddress>::to_json(json & json, const ContentAddress & ca)
|
||||
{
|
||||
json = {
|
||||
{"method", ca.method},
|
||||
{"hash", ca.hash},
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace nlohmann
|
||||
@@ -1031,7 +1031,7 @@ void processConnection(ref<Store> store, FdSource && from, FdSink && to, Trusted
|
||||
auto [protoVersion, features] =
|
||||
WorkerProto::BasicServerConnection::handshake(to, from, PROTOCOL_VERSION, WorkerProto::allFeatures);
|
||||
|
||||
if (protoVersion < MINIMUM_PROTOCOL_VERSION)
|
||||
if (protoVersion < 256 + 18)
|
||||
throw Error("the Nix client version is too old");
|
||||
|
||||
WorkerProto::BasicServerConnection conn;
|
||||
|
||||
@@ -22,9 +22,9 @@ getStringAttr(const StringMap & env, const StructuredAttrs * parsed, const std::
|
||||
if (i == parsed->structuredAttrs.end())
|
||||
return {};
|
||||
else {
|
||||
if (!i->second.is_string())
|
||||
if (!i->is_string())
|
||||
throw Error("attribute '%s' of must be a string", name);
|
||||
return i->second.get<std::string>();
|
||||
return i->get<std::string>();
|
||||
}
|
||||
} else {
|
||||
auto i = env.find(name);
|
||||
@@ -42,9 +42,9 @@ static bool getBoolAttr(const StringMap & env, const StructuredAttrs * parsed, c
|
||||
if (i == parsed->structuredAttrs.end())
|
||||
return def;
|
||||
else {
|
||||
if (!i->second.is_boolean())
|
||||
if (!i->is_boolean())
|
||||
throw Error("attribute '%s' must be a Boolean", name);
|
||||
return i->second.get<bool>();
|
||||
return i->get<bool>();
|
||||
}
|
||||
} else {
|
||||
auto i = env.find(name);
|
||||
@@ -63,11 +63,10 @@ getStringsAttr(const StringMap & env, const StructuredAttrs * parsed, const std:
|
||||
if (i == parsed->structuredAttrs.end())
|
||||
return {};
|
||||
else {
|
||||
if (!i->second.is_array())
|
||||
if (!i->is_array())
|
||||
throw Error("attribute '%s' must be a list of strings", name);
|
||||
auto & a = getArray(i->second);
|
||||
Strings res;
|
||||
for (auto j = a.begin(); j != a.end(); ++j) {
|
||||
for (auto j = i->begin(); j != i->end(); ++j) {
|
||||
if (!j->is_string())
|
||||
throw Error("attribute '%s' must be a list of strings", name);
|
||||
res.push_back(j->get<std::string>());
|
||||
@@ -117,29 +116,27 @@ DerivationOptions::fromStructuredAttrs(const StringMap & env, const StructuredAt
|
||||
DerivationOptions defaults = {};
|
||||
|
||||
if (shouldWarn && parsed) {
|
||||
auto & structuredAttrs = parsed->structuredAttrs;
|
||||
|
||||
if (get(structuredAttrs, "allowedReferences")) {
|
||||
if (get(parsed->structuredAttrs, "allowedReferences")) {
|
||||
warn(
|
||||
"'structuredAttrs' disables the effect of the top-level attribute 'allowedReferences'; use 'outputChecks' instead");
|
||||
}
|
||||
if (get(structuredAttrs, "allowedRequisites")) {
|
||||
if (get(parsed->structuredAttrs, "allowedRequisites")) {
|
||||
warn(
|
||||
"'structuredAttrs' disables the effect of the top-level attribute 'allowedRequisites'; use 'outputChecks' instead");
|
||||
}
|
||||
if (get(structuredAttrs, "disallowedRequisites")) {
|
||||
if (get(parsed->structuredAttrs, "disallowedRequisites")) {
|
||||
warn(
|
||||
"'structuredAttrs' disables the effect of the top-level attribute 'disallowedRequisites'; use 'outputChecks' instead");
|
||||
}
|
||||
if (get(structuredAttrs, "disallowedReferences")) {
|
||||
if (get(parsed->structuredAttrs, "disallowedReferences")) {
|
||||
warn(
|
||||
"'structuredAttrs' disables the effect of the top-level attribute 'disallowedReferences'; use 'outputChecks' instead");
|
||||
}
|
||||
if (get(structuredAttrs, "maxSize")) {
|
||||
if (get(parsed->structuredAttrs, "maxSize")) {
|
||||
warn(
|
||||
"'structuredAttrs' disables the effect of the top-level attribute 'maxSize'; use 'outputChecks' instead");
|
||||
}
|
||||
if (get(structuredAttrs, "maxClosureSize")) {
|
||||
if (get(parsed->structuredAttrs, "maxClosureSize")) {
|
||||
warn(
|
||||
"'structuredAttrs' disables the effect of the top-level attribute 'maxClosureSize'; use 'outputChecks' instead");
|
||||
}
|
||||
@@ -148,15 +145,11 @@ DerivationOptions::fromStructuredAttrs(const StringMap & env, const StructuredAt
|
||||
return {
|
||||
.outputChecks = [&]() -> OutputChecksVariant {
|
||||
if (parsed) {
|
||||
auto & structuredAttrs = parsed->structuredAttrs;
|
||||
|
||||
std::map<std::string, OutputChecks> res;
|
||||
if (auto * outputChecks = get(structuredAttrs, "outputChecks")) {
|
||||
for (auto & [outputName, output_] : getObject(*outputChecks)) {
|
||||
if (auto outputChecks = get(parsed->structuredAttrs, "outputChecks")) {
|
||||
for (auto & [outputName, output] : getObject(*outputChecks)) {
|
||||
OutputChecks checks;
|
||||
|
||||
auto & output = getObject(output_);
|
||||
|
||||
if (auto maxSize = get(output, "maxSize"))
|
||||
checks.maxSize = maxSize->get<uint64_t>();
|
||||
|
||||
@@ -202,9 +195,7 @@ DerivationOptions::fromStructuredAttrs(const StringMap & env, const StructuredAt
|
||||
std::map<std::string, bool> res;
|
||||
|
||||
if (parsed) {
|
||||
auto & structuredAttrs = parsed->structuredAttrs;
|
||||
|
||||
if (auto * udr = get(structuredAttrs, "unsafeDiscardReferences")) {
|
||||
if (auto udr = get(parsed->structuredAttrs, "unsafeDiscardReferences")) {
|
||||
for (auto & [outputName, output] : getObject(*udr)) {
|
||||
if (!output.is_boolean())
|
||||
throw Error("attribute 'unsafeDiscardReferences.\"%s\"' must be a Boolean", outputName);
|
||||
@@ -235,7 +226,7 @@ DerivationOptions::fromStructuredAttrs(const StringMap & env, const StructuredAt
|
||||
std::map<std::string, StringSet> ret;
|
||||
|
||||
if (parsed) {
|
||||
auto * e = optionalValueAt(parsed->structuredAttrs, "exportReferencesGraph");
|
||||
auto e = optionalValueAt(parsed->structuredAttrs, "exportReferencesGraph");
|
||||
if (!e || !e->is_object())
|
||||
return ret;
|
||||
for (auto & [key, value] : getObject(*e)) {
|
||||
@@ -342,10 +333,8 @@ namespace nlohmann {
|
||||
|
||||
using namespace nix;
|
||||
|
||||
DerivationOptions adl_serializer<DerivationOptions>::from_json(const json & json_)
|
||||
DerivationOptions adl_serializer<DerivationOptions>::from_json(const json & json)
|
||||
{
|
||||
auto & json = getObject(json_);
|
||||
|
||||
return {
|
||||
.outputChecks = [&]() -> OutputChecksVariant {
|
||||
auto outputChecks = getObject(valueAt(json, "outputChecks"));
|
||||
@@ -408,24 +397,13 @@ void adl_serializer<DerivationOptions>::to_json(json & json, const DerivationOpt
|
||||
json["allowSubstitutes"] = o.allowSubstitutes;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static inline std::optional<T> ptrToOwned(const json * ptr)
|
||||
DerivationOptions::OutputChecks adl_serializer<DerivationOptions::OutputChecks>::from_json(const json & json)
|
||||
{
|
||||
if (ptr)
|
||||
return std::optional{*ptr};
|
||||
else
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
DerivationOptions::OutputChecks adl_serializer<DerivationOptions::OutputChecks>::from_json(const json & json_)
|
||||
{
|
||||
auto & json = getObject(json_);
|
||||
|
||||
return {
|
||||
.ignoreSelfRefs = getBoolean(valueAt(json, "ignoreSelfRefs")),
|
||||
.allowedReferences = ptrToOwned<StringSet>(getNullable(valueAt(json, "allowedReferences"))),
|
||||
.allowedReferences = nullableValueAt(json, "allowedReferences"),
|
||||
.disallowedReferences = getStringSet(valueAt(json, "disallowedReferences")),
|
||||
.allowedRequisites = ptrToOwned<StringSet>(getNullable(valueAt(json, "allowedRequisites"))),
|
||||
.allowedRequisites = nullableValueAt(json, "allowedRequisites"),
|
||||
.disallowedRequisites = getStringSet(valueAt(json, "disallowedRequisites")),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1391,7 +1391,8 @@ void adl_serializer<Derivation>::to_json(json & res, const Derivation & d)
|
||||
}
|
||||
|
||||
{
|
||||
auto doInput = [&](this const auto & doInput, const auto & inputNode) -> nlohmann::json {
|
||||
std::function<nlohmann::json(const DerivedPathMap<StringSet>::ChildNode &)> doInput;
|
||||
doInput = [&](const auto & inputNode) {
|
||||
auto value = nlohmann::json::object();
|
||||
value["outputs"] = inputNode.value;
|
||||
{
|
||||
@@ -1453,7 +1454,8 @@ Derivation adl_serializer<Derivation>::from_json(const json & _json, const Exper
|
||||
}
|
||||
|
||||
try {
|
||||
auto doInput = [&](this const auto & doInput, const auto & _json) -> DerivedPathMap<StringSet>::ChildNode {
|
||||
std::function<DerivedPathMap<StringSet>::ChildNode(const nlohmann::json &)> doInput;
|
||||
doInput = [&](const auto & _json) {
|
||||
auto & json = getObject(_json);
|
||||
DerivedPathMap<StringSet>::ChildNode node;
|
||||
node.value = getStringSet(valueAt(json, "outputs"));
|
||||
|
||||
@@ -148,7 +148,7 @@ struct DummyStoreImpl : DummyStore
|
||||
/**
|
||||
* The dummy store is incapable of *not* trusting! :)
|
||||
*/
|
||||
std::optional<TrustedFlag> isTrustedClient() override
|
||||
virtual std::optional<TrustedFlag> isTrustedClient() override
|
||||
{
|
||||
return Trusted;
|
||||
}
|
||||
@@ -258,6 +258,18 @@ struct DummyStoreImpl : DummyStore
|
||||
});
|
||||
}
|
||||
|
||||
void narFromPath(const StorePath & path, Sink & sink) override
|
||||
{
|
||||
bool visited = contents.cvisit(path, [&](const auto & kv) {
|
||||
const auto & [info, accessor] = kv.second;
|
||||
SourcePath sourcePath(accessor);
|
||||
dumpPath(sourcePath, sink, FileSerialisationMethod::NixArchive);
|
||||
});
|
||||
|
||||
if (!visited)
|
||||
throw Error("path '%s' is not valid", printStorePath(path));
|
||||
}
|
||||
|
||||
void queryRealisationUncached(
|
||||
const DrvOutput & drvOutput, Callback<std::shared_ptr<const UnkeyedRealisation>> callback) noexcept override
|
||||
{
|
||||
|
||||
@@ -295,17 +295,20 @@ struct curlFileTransfer : public FileTransfer
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t readCallback(char * buffer, size_t size, size_t nitems) noexcept
|
||||
try {
|
||||
auto data = request.data;
|
||||
return data->source->read(buffer, nitems * size);
|
||||
} catch (EndOfFile &) {
|
||||
return 0;
|
||||
} catch (...) {
|
||||
return CURL_READFUNC_ABORT;
|
||||
size_t readOffset = 0;
|
||||
|
||||
size_t readCallback(char * buffer, size_t size, size_t nitems)
|
||||
{
|
||||
if (readOffset == request.data->length())
|
||||
return 0;
|
||||
auto count = std::min(size * nitems, request.data->length() - readOffset);
|
||||
assert(count);
|
||||
memcpy(buffer, request.data->data() + readOffset, count);
|
||||
readOffset += count;
|
||||
return count;
|
||||
}
|
||||
|
||||
static size_t readCallbackWrapper(char * buffer, size_t size, size_t nitems, void * userp) noexcept
|
||||
static size_t readCallbackWrapper(char * buffer, size_t size, size_t nitems, void * userp)
|
||||
{
|
||||
return ((TransferItem *) userp)->readCallback(buffer, size, nitems);
|
||||
}
|
||||
@@ -319,24 +322,19 @@ struct curlFileTransfer : public FileTransfer
|
||||
}
|
||||
#endif
|
||||
|
||||
size_t seekCallback(curl_off_t offset, int origin) noexcept
|
||||
try {
|
||||
auto source = request.data->source;
|
||||
size_t seekCallback(curl_off_t offset, int origin)
|
||||
{
|
||||
if (origin == SEEK_SET) {
|
||||
source->restart();
|
||||
source->skip(offset);
|
||||
readOffset = offset;
|
||||
} else if (origin == SEEK_CUR) {
|
||||
source->skip(offset);
|
||||
readOffset += offset;
|
||||
} else if (origin == SEEK_END) {
|
||||
NullSink sink{};
|
||||
source->drainInto(sink);
|
||||
readOffset = request.data->length() + offset;
|
||||
}
|
||||
return CURL_SEEKFUNC_OK;
|
||||
} catch (...) {
|
||||
return CURL_SEEKFUNC_FAIL;
|
||||
}
|
||||
|
||||
static size_t seekCallbackWrapper(void * clientp, curl_off_t offset, int origin) noexcept
|
||||
static size_t seekCallbackWrapper(void * clientp, curl_off_t offset, int origin)
|
||||
{
|
||||
return ((TransferItem *) clientp)->seekCallback(offset, origin);
|
||||
}
|
||||
@@ -386,30 +384,28 @@ struct curlFileTransfer : public FileTransfer
|
||||
if (settings.downloadSpeed.get() > 0)
|
||||
curl_easy_setopt(req, CURLOPT_MAX_RECV_SPEED_LARGE, (curl_off_t) (settings.downloadSpeed.get() * 1024));
|
||||
|
||||
if (request.method == HttpMethod::HEAD)
|
||||
if (request.head)
|
||||
curl_easy_setopt(req, CURLOPT_NOBODY, 1);
|
||||
|
||||
if (request.method == HttpMethod::DELETE)
|
||||
curl_easy_setopt(req, CURLOPT_CUSTOMREQUEST, "DELETE");
|
||||
|
||||
if (request.data) {
|
||||
if (request.method == HttpMethod::POST) {
|
||||
if (request.post)
|
||||
curl_easy_setopt(req, CURLOPT_POST, 1L);
|
||||
curl_easy_setopt(req, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t) request.data->sizeHint);
|
||||
} else if (request.method == HttpMethod::PUT) {
|
||||
else
|
||||
curl_easy_setopt(req, CURLOPT_UPLOAD, 1L);
|
||||
curl_easy_setopt(req, CURLOPT_INFILESIZE_LARGE, (curl_off_t) request.data->sizeHint);
|
||||
} else {
|
||||
unreachable();
|
||||
}
|
||||
curl_easy_setopt(req, CURLOPT_READFUNCTION, readCallbackWrapper);
|
||||
curl_easy_setopt(req, CURLOPT_READDATA, this);
|
||||
curl_easy_setopt(req, CURLOPT_INFILESIZE_LARGE, (curl_off_t) request.data->length());
|
||||
curl_easy_setopt(req, CURLOPT_SEEKFUNCTION, seekCallbackWrapper);
|
||||
curl_easy_setopt(req, CURLOPT_SEEKDATA, this);
|
||||
}
|
||||
|
||||
if (settings.caFile != "")
|
||||
curl_easy_setopt(req, CURLOPT_CAINFO, settings.caFile.get().c_str());
|
||||
if (request.verifyTLS) {
|
||||
if (settings.caFile != "")
|
||||
curl_easy_setopt(req, CURLOPT_CAINFO, settings.caFile.get().c_str());
|
||||
} else {
|
||||
curl_easy_setopt(req, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
curl_easy_setopt(req, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
}
|
||||
|
||||
#if !defined(_WIN32) && LIBCURL_VERSION_NUM >= 0x071000
|
||||
curl_easy_setopt(req, CURLOPT_SOCKOPTFUNCTION, cloexec_callback);
|
||||
@@ -600,14 +596,7 @@ struct curlFileTransfer : public FileTransfer
|
||||
decompressionSink.reset();
|
||||
errorSink.reset();
|
||||
embargo = std::chrono::steady_clock::now() + std::chrono::milliseconds(ms);
|
||||
try {
|
||||
fileTransfer.enqueueItem(shared_from_this());
|
||||
} catch (const nix::Error & e) {
|
||||
// If enqueue fails (e.g., during shutdown), fail the transfer properly
|
||||
// instead of letting the exception propagate, which would leave done=false
|
||||
// and cause the destructor to attempt a second callback invocation
|
||||
fail(std::move(exc));
|
||||
}
|
||||
fileTransfer.enqueueItem(shared_from_this());
|
||||
} else
|
||||
fail(std::move(exc));
|
||||
}
|
||||
@@ -633,7 +622,7 @@ struct curlFileTransfer : public FileTransfer
|
||||
void quit()
|
||||
{
|
||||
quitting = true;
|
||||
/* We wil not be processing any more incoming requests */
|
||||
/* We wil not be processing any more incomming requests */
|
||||
while (!incoming.empty())
|
||||
incoming.pop();
|
||||
}
|
||||
@@ -933,11 +922,6 @@ FileTransferResult FileTransfer::upload(const FileTransferRequest & request)
|
||||
return enqueueFileTransfer(request).get();
|
||||
}
|
||||
|
||||
FileTransferResult FileTransfer::deleteResource(const FileTransferRequest & request)
|
||||
{
|
||||
return enqueueFileTransfer(request).get();
|
||||
}
|
||||
|
||||
void FileTransfer::download(
|
||||
FileTransferRequest && request, Sink & sink, std::function<void(FileTransferResult)> resultCallback)
|
||||
{
|
||||
|
||||
Loaded 100 of 182 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user