mirror of
https://github.com/NixOS/nix.git
synced 2025-11-24 03:09:35 +01:00
Merge commit '2805439335' into progress-bar
This commit is contained in:
commit
28c6225110
159 changed files with 4997 additions and 1395 deletions
9
.github/stale.yml
vendored
9
.github/stale.yml
vendored
|
|
@ -1,10 +1,9 @@
|
||||||
# Configuration for probot-stale - https://github.com/probot/stale
|
# Configuration for probot-stale - https://github.com/probot/stale
|
||||||
daysUntilStale: 180
|
daysUntilStale: 180
|
||||||
daysUntilClose: 365
|
daysUntilClose: false
|
||||||
exemptLabels:
|
exemptLabels:
|
||||||
- "critical"
|
- "critical"
|
||||||
|
- "never-stale"
|
||||||
staleLabel: "stale"
|
staleLabel: "stale"
|
||||||
markComment: |
|
markComment: false
|
||||||
I marked this as stale due to inactivity. → [More info](https://github.com/NixOS/nix/blob/master/.github/STALE-BOT.md)
|
closeComment: false
|
||||||
closeComment: |
|
|
||||||
I closed this issue due to inactivity. → [More info](https://github.com/NixOS/nix/blob/master/.github/STALE-BOT.md)
|
|
||||||
|
|
|
||||||
2
.github/workflows/backport.yml
vendored
2
.github/workflows/backport.yml
vendored
|
|
@ -15,7 +15,7 @@ jobs:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: Create backport PRs
|
- name: Create backport PRs
|
||||||
# should be kept in sync with `version`
|
# should be kept in sync with `version`
|
||||||
uses: zeebe-io/backport-action@v0.0.7
|
uses: zeebe-io/backport-action@v0.0.8
|
||||||
with:
|
with:
|
||||||
# Config README: https://github.com/zeebe-io/backport-action#backport-action
|
# Config README: https://github.com/zeebe-io/backport-action#backport-action
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
|
||||||
8
.github/workflows/ci.yml
vendored
8
.github/workflows/ci.yml
vendored
|
|
@ -4,6 +4,8 @@ on:
|
||||||
pull_request:
|
pull_request:
|
||||||
push:
|
push:
|
||||||
|
|
||||||
|
permissions: read-all
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
tests:
|
tests:
|
||||||
|
|
@ -28,6 +30,8 @@ jobs:
|
||||||
- run: nix --experimental-features 'nix-command flakes' flake check -L
|
- run: nix --experimental-features 'nix-command flakes' flake check -L
|
||||||
|
|
||||||
check_cachix:
|
check_cachix:
|
||||||
|
permissions:
|
||||||
|
contents: none
|
||||||
name: Cachix secret present for installer tests
|
name: Cachix secret present for installer tests
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
outputs:
|
||||||
|
|
@ -88,7 +92,7 @@ jobs:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- uses: cachix/install-nix-action@v17
|
- uses: cachix/install-nix-action@v17
|
||||||
- run: echo CACHIX_NAME="$(echo $GITHUB_REPOSITORY-install-tests | tr "[A-Z]/" "[a-z]-")" >> $GITHUB_ENV
|
- run: echo CACHIX_NAME="$(echo $GITHUB_REPOSITORY-install-tests | tr "[A-Z]/" "[a-z]-")" >> $GITHUB_ENV
|
||||||
- run: echo NIX_VERSION="$(nix-instantiate --eval -E '(import ./default.nix).defaultPackage.${builtins.currentSystem}.version' | tr -d \")" >> $GITHUB_ENV
|
- run: echo NIX_VERSION="$(nix --experimental-features 'nix-command flakes' eval .\#default.version | tr -d \")" >> $GITHUB_ENV
|
||||||
- uses: cachix/cachix-action@v10
|
- uses: cachix/cachix-action@v10
|
||||||
if: needs.check_cachix.outputs.secret == 'true'
|
if: needs.check_cachix.outputs.secret == 'true'
|
||||||
with:
|
with:
|
||||||
|
|
@ -100,7 +104,7 @@ jobs:
|
||||||
- run: docker tag nix:$NIX_VERSION nixos/nix:$NIX_VERSION
|
- run: docker tag nix:$NIX_VERSION nixos/nix:$NIX_VERSION
|
||||||
- run: docker tag nix:$NIX_VERSION nixos/nix:master
|
- run: docker tag nix:$NIX_VERSION nixos/nix:master
|
||||||
- name: Login to Docker Hub
|
- name: Login to Docker Hub
|
||||||
uses: docker/login-action@v1
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
|
||||||
4
.github/workflows/hydra_status.yml
vendored
4
.github/workflows/hydra_status.yml
vendored
|
|
@ -1,8 +1,12 @@
|
||||||
name: Hydra status
|
name: Hydra status
|
||||||
|
|
||||||
|
permissions: read-all
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: "12,42 * * * *"
|
- cron: "12,42 * * * *"
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check_hydra_status:
|
check_hydra_status:
|
||||||
name: Check Hydra status
|
name: Check Hydra status
|
||||||
|
|
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -35,6 +35,7 @@ perl/Makefile.config
|
||||||
/src/libexpr/parser-tab.hh
|
/src/libexpr/parser-tab.hh
|
||||||
/src/libexpr/parser-tab.output
|
/src/libexpr/parser-tab.output
|
||||||
/src/libexpr/nix.tbl
|
/src/libexpr/nix.tbl
|
||||||
|
/src/libexpr/tests/libexpr-tests
|
||||||
|
|
||||||
# /src/libstore/
|
# /src/libstore/
|
||||||
*.gen.*
|
*.gen.*
|
||||||
|
|
|
||||||
2
.version
2
.version
|
|
@ -1 +1 @@
|
||||||
2.9.0
|
2.10.0
|
||||||
4
Makefile
4
Makefile
|
|
@ -8,6 +8,7 @@ makefiles = \
|
||||||
src/libfetchers/local.mk \
|
src/libfetchers/local.mk \
|
||||||
src/libmain/local.mk \
|
src/libmain/local.mk \
|
||||||
src/libexpr/local.mk \
|
src/libexpr/local.mk \
|
||||||
|
src/libexpr/tests/local.mk \
|
||||||
src/libcmd/local.mk \
|
src/libcmd/local.mk \
|
||||||
src/nix/local.mk \
|
src/nix/local.mk \
|
||||||
src/resolve-system-dependencies/local.mk \
|
src/resolve-system-dependencies/local.mk \
|
||||||
|
|
@ -27,7 +28,8 @@ makefiles = \
|
||||||
OPTIMIZE = 1
|
OPTIMIZE = 1
|
||||||
|
|
||||||
ifeq ($(OPTIMIZE), 1)
|
ifeq ($(OPTIMIZE), 1)
|
||||||
GLOBAL_CXXFLAGS += -O3
|
GLOBAL_CXXFLAGS += -O3 $(CXXLTO)
|
||||||
|
GLOBAL_LDFLAGS += $(CXXLTO)
|
||||||
else
|
else
|
||||||
GLOBAL_CXXFLAGS += -O0 -U_FORTIFY_SOURCE
|
GLOBAL_CXXFLAGS += -O0 -U_FORTIFY_SOURCE
|
||||||
endif
|
endif
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
HOST_OS = @host_os@
|
|
||||||
AR = @AR@
|
AR = @AR@
|
||||||
BDW_GC_LIBS = @BDW_GC_LIBS@
|
BDW_GC_LIBS = @BDW_GC_LIBS@
|
||||||
BOOST_LDFLAGS = @BOOST_LDFLAGS@
|
BOOST_LDFLAGS = @BOOST_LDFLAGS@
|
||||||
|
|
@ -7,18 +6,20 @@ CC = @CC@
|
||||||
CFLAGS = @CFLAGS@
|
CFLAGS = @CFLAGS@
|
||||||
CXX = @CXX@
|
CXX = @CXX@
|
||||||
CXXFLAGS = @CXXFLAGS@
|
CXXFLAGS = @CXXFLAGS@
|
||||||
|
CXXLTO = @CXXLTO@
|
||||||
EDITLINE_LIBS = @EDITLINE_LIBS@
|
EDITLINE_LIBS = @EDITLINE_LIBS@
|
||||||
ENABLE_S3 = @ENABLE_S3@
|
ENABLE_S3 = @ENABLE_S3@
|
||||||
GTEST_LIBS = @GTEST_LIBS@
|
GTEST_LIBS = @GTEST_LIBS@
|
||||||
HAVE_LIBCPUID = @HAVE_LIBCPUID@
|
HAVE_LIBCPUID = @HAVE_LIBCPUID@
|
||||||
HAVE_SECCOMP = @HAVE_SECCOMP@
|
HAVE_SECCOMP = @HAVE_SECCOMP@
|
||||||
|
HOST_OS = @host_os@
|
||||||
LDFLAGS = @LDFLAGS@
|
LDFLAGS = @LDFLAGS@
|
||||||
LIBARCHIVE_LIBS = @LIBARCHIVE_LIBS@
|
LIBARCHIVE_LIBS = @LIBARCHIVE_LIBS@
|
||||||
LIBBROTLI_LIBS = @LIBBROTLI_LIBS@
|
LIBBROTLI_LIBS = @LIBBROTLI_LIBS@
|
||||||
LIBCURL_LIBS = @LIBCURL_LIBS@
|
LIBCURL_LIBS = @LIBCURL_LIBS@
|
||||||
|
LIBSECCOMP_LIBS = @LIBSECCOMP_LIBS@
|
||||||
LOWDOWN_LIBS = @LOWDOWN_LIBS@
|
LOWDOWN_LIBS = @LOWDOWN_LIBS@
|
||||||
OPENSSL_LIBS = @OPENSSL_LIBS@
|
OPENSSL_LIBS = @OPENSSL_LIBS@
|
||||||
LIBSECCOMP_LIBS = @LIBSECCOMP_LIBS@
|
|
||||||
PACKAGE_NAME = @PACKAGE_NAME@
|
PACKAGE_NAME = @PACKAGE_NAME@
|
||||||
PACKAGE_VERSION = @PACKAGE_VERSION@
|
PACKAGE_VERSION = @PACKAGE_VERSION@
|
||||||
SHELL = @bash@
|
SHELL = @bash@
|
||||||
|
|
@ -30,6 +31,7 @@ datadir = @datadir@
|
||||||
datarootdir = @datarootdir@
|
datarootdir = @datarootdir@
|
||||||
doc_generate = @doc_generate@
|
doc_generate = @doc_generate@
|
||||||
docdir = @docdir@
|
docdir = @docdir@
|
||||||
|
embedded_sandbox_shell = @embedded_sandbox_shell@
|
||||||
exec_prefix = @exec_prefix@
|
exec_prefix = @exec_prefix@
|
||||||
includedir = @includedir@
|
includedir = @includedir@
|
||||||
libdir = @libdir@
|
libdir = @libdir@
|
||||||
|
|
|
||||||
33
configure.ac
33
configure.ac
|
|
@ -147,6 +147,20 @@ if test "x$GCC_ATOMIC_BUILTINS_NEED_LIBATOMIC" = xyes; then
|
||||||
LDFLAGS="-latomic $LDFLAGS"
|
LDFLAGS="-latomic $LDFLAGS"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# LTO is currently broken with clang for unknown reasons; ld segfaults in the llvm plugin
|
||||||
|
AC_ARG_ENABLE(lto, AS_HELP_STRING([--enable-lto],[Enable LTO (only supported with GCC) [default=no]]),
|
||||||
|
lto=$enableval, lto=no)
|
||||||
|
if test "$lto" = yes; then
|
||||||
|
if $CXX --version | grep -q GCC; then
|
||||||
|
AC_SUBST(CXXLTO, [-flto=jobserver])
|
||||||
|
else
|
||||||
|
echo "error: LTO is only supported with GCC at the moment" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
AC_SUBST(CXXLTO, [""])
|
||||||
|
fi
|
||||||
|
|
||||||
PKG_PROG_PKG_CONFIG
|
PKG_PROG_PKG_CONFIG
|
||||||
|
|
||||||
AC_ARG_ENABLE(shared, AS_HELP_STRING([--enable-shared],[Build shared libraries for Nix [default=yes]]),
|
AC_ARG_ENABLE(shared, AS_HELP_STRING([--enable-shared],[Build shared libraries for Nix [default=yes]]),
|
||||||
|
|
@ -294,6 +308,25 @@ esac
|
||||||
AC_ARG_WITH(sandbox-shell, AS_HELP_STRING([--with-sandbox-shell=PATH],[path of a statically-linked shell to use as /bin/sh in sandboxes]),
|
AC_ARG_WITH(sandbox-shell, AS_HELP_STRING([--with-sandbox-shell=PATH],[path of a statically-linked shell to use as /bin/sh in sandboxes]),
|
||||||
sandbox_shell=$withval)
|
sandbox_shell=$withval)
|
||||||
AC_SUBST(sandbox_shell)
|
AC_SUBST(sandbox_shell)
|
||||||
|
if test ${cross_compiling:-no} = no && ! test -z ${sandbox_shell+x}; then
|
||||||
|
AC_MSG_CHECKING([whether sandbox-shell has the standalone feature])
|
||||||
|
# busybox shell sometimes allows executing other busybox applets,
|
||||||
|
# even if they are not in the path, breaking our sandbox
|
||||||
|
if PATH= $sandbox_shell -c "busybox" 2>&1 | grep -qv "not found"; then
|
||||||
|
AC_MSG_RESULT(enabled)
|
||||||
|
AC_MSG_ERROR([Please disable busybox FEATURE_SH_STANDALONE])
|
||||||
|
else
|
||||||
|
AC_MSG_RESULT(disabled)
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
AC_ARG_ENABLE(embedded-sandbox-shell, AS_HELP_STRING([--enable-embedded-sandbox-shell],[include the sandbox shell in the Nix binary [default=no]]),
|
||||||
|
embedded_sandbox_shell=$enableval, embedded_sandbox_shell=no)
|
||||||
|
AC_SUBST(embedded_sandbox_shell)
|
||||||
|
if test "$embedded_sandbox_shell" = yes; then
|
||||||
|
AC_DEFINE(HAVE_EMBEDDED_SANDBOX_SHELL, 1, [Include the sandbox shell in the Nix binary.])
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Expand all variables in config.status.
|
# Expand all variables in config.status.
|
||||||
test "$prefix" = NONE && prefix=$ac_default_prefix
|
test "$prefix" = NONE && prefix=$ac_default_prefix
|
||||||
|
|
|
||||||
31
doc/manual/anchors.jq
Executable file
31
doc/manual/anchors.jq
Executable file
|
|
@ -0,0 +1,31 @@
|
||||||
|
"\\[\\]\\{#(?<anchor>[^\\}]+?)\\}" as $empty_anchor_regex |
|
||||||
|
"\\[(?<text>[^\\]]+?)\\]\\{#(?<anchor>[^\\}]+?)\\}" as $anchor_regex |
|
||||||
|
|
||||||
|
|
||||||
|
def transform_anchors_html:
|
||||||
|
. | gsub($empty_anchor_regex; "<a name=\"" + .anchor + "\"></a>")
|
||||||
|
| gsub($anchor_regex; "<a href=\"#" + .anchor + "\" id=\"" + .anchor + "\">" + .text + "</a>");
|
||||||
|
|
||||||
|
|
||||||
|
def transform_anchors_strip:
|
||||||
|
. | gsub($empty_anchor_regex; "")
|
||||||
|
| gsub($anchor_regex; .text);
|
||||||
|
|
||||||
|
|
||||||
|
def map_contents_recursively(transformer):
|
||||||
|
. + {
|
||||||
|
Chapter: (.Chapter + {
|
||||||
|
content: .Chapter.content | transformer,
|
||||||
|
sub_items: .Chapter.sub_items | map(map_contents_recursively(transformer)),
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
def process_command:
|
||||||
|
.[0] as $context |
|
||||||
|
.[1] as $body |
|
||||||
|
$body + {
|
||||||
|
sections: $body.sections | map(map_contents_recursively(if $context.renderer == "html" then transform_anchors_html else transform_anchors_strip end)),
|
||||||
|
};
|
||||||
|
|
||||||
|
process_command
|
||||||
|
|
@ -1,2 +1,7 @@
|
||||||
[output.html]
|
[output.html]
|
||||||
additional-css = ["custom.css"]
|
additional-css = ["custom.css"]
|
||||||
|
additional-js = ["redirects.js"]
|
||||||
|
|
||||||
|
[preprocessor.anchors]
|
||||||
|
renderers = ["html"]
|
||||||
|
command = "jq --from-file doc/manual/anchors.jq"
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ doc/manual/generated/man1/nix3-manpages: $(d)/src/command-ref/new-cli
|
||||||
done
|
done
|
||||||
@touch $@
|
@touch $@
|
||||||
|
|
||||||
$(docdir)/manual/index.html: $(MANUAL_SRCS) $(d)/book.toml $(d)/custom.css $(d)/src/SUMMARY.md $(d)/src/command-ref/new-cli $(d)/src/command-ref/conf-file.md $(d)/src/expressions/builtins.md $(call rwildcard, $(d)/src, *.md)
|
$(docdir)/manual/index.html: $(MANUAL_SRCS) $(d)/book.toml $(d)/anchors.jq $(d)/custom.css $(d)/src/SUMMARY.md $(d)/src/command-ref/new-cli $(d)/src/command-ref/conf-file.md $(d)/src/expressions/builtins.md $(call rwildcard, $(d)/src, *.md)
|
||||||
$(trace-gen) RUST_LOG=warn mdbook build doc/manual -d $(DESTDIR)$(docdir)/manual
|
$(trace-gen) RUST_LOG=warn mdbook build doc/manual -d $(DESTDIR)$(docdir)/manual
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
|
||||||
337
doc/manual/redirects.js
Normal file
337
doc/manual/redirects.js
Normal file
|
|
@ -0,0 +1,337 @@
|
||||||
|
// Redirects from old DocBook manual.
|
||||||
|
var redirects = {
|
||||||
|
"#part-advanced-topics": "advanced-topics/advanced-topics.html",
|
||||||
|
"#chap-tuning-cores-and-jobs": "advanced-topics/cores-vs-jobs.html",
|
||||||
|
"#chap-diff-hook": "advanced-topics/diff-hook.html",
|
||||||
|
"#check-dirs-are-unregistered": "advanced-topics/diff-hook.html#check-dirs-are-unregistered",
|
||||||
|
"#chap-distributed-builds": "advanced-topics/distributed-builds.html",
|
||||||
|
"#chap-post-build-hook": "advanced-topics/post-build-hook.html",
|
||||||
|
"#chap-post-build-hook-caveats": "advanced-topics/post-build-hook.html#implementation-caveats",
|
||||||
|
"#part-command-ref": "command-ref/command-ref.html",
|
||||||
|
"#conf-allow-import-from-derivation": "command-ref/conf-file.html#conf-allow-import-from-derivation",
|
||||||
|
"#conf-allow-new-privileges": "command-ref/conf-file.html#conf-allow-new-privileges",
|
||||||
|
"#conf-allowed-uris": "command-ref/conf-file.html#conf-allowed-uris",
|
||||||
|
"#conf-allowed-users": "command-ref/conf-file.html#conf-allowed-users",
|
||||||
|
"#conf-auto-optimise-store": "command-ref/conf-file.html#conf-auto-optimise-store",
|
||||||
|
"#conf-binary-cache-public-keys": "command-ref/conf-file.html#conf-binary-cache-public-keys",
|
||||||
|
"#conf-binary-caches": "command-ref/conf-file.html#conf-binary-caches",
|
||||||
|
"#conf-build-compress-log": "command-ref/conf-file.html#conf-build-compress-log",
|
||||||
|
"#conf-build-cores": "command-ref/conf-file.html#conf-build-cores",
|
||||||
|
"#conf-build-extra-chroot-dirs": "command-ref/conf-file.html#conf-build-extra-chroot-dirs",
|
||||||
|
"#conf-build-extra-sandbox-paths": "command-ref/conf-file.html#conf-build-extra-sandbox-paths",
|
||||||
|
"#conf-build-fallback": "command-ref/conf-file.html#conf-build-fallback",
|
||||||
|
"#conf-build-max-jobs": "command-ref/conf-file.html#conf-build-max-jobs",
|
||||||
|
"#conf-build-max-log-size": "command-ref/conf-file.html#conf-build-max-log-size",
|
||||||
|
"#conf-build-max-silent-time": "command-ref/conf-file.html#conf-build-max-silent-time",
|
||||||
|
"#conf-build-repeat": "command-ref/conf-file.html#conf-build-repeat",
|
||||||
|
"#conf-build-timeout": "command-ref/conf-file.html#conf-build-timeout",
|
||||||
|
"#conf-build-use-chroot": "command-ref/conf-file.html#conf-build-use-chroot",
|
||||||
|
"#conf-build-use-sandbox": "command-ref/conf-file.html#conf-build-use-sandbox",
|
||||||
|
"#conf-build-use-substitutes": "command-ref/conf-file.html#conf-build-use-substitutes",
|
||||||
|
"#conf-build-users-group": "command-ref/conf-file.html#conf-build-users-group",
|
||||||
|
"#conf-builders": "command-ref/conf-file.html#conf-builders",
|
||||||
|
"#conf-builders-use-substitutes": "command-ref/conf-file.html#conf-builders-use-substitutes",
|
||||||
|
"#conf-compress-build-log": "command-ref/conf-file.html#conf-compress-build-log",
|
||||||
|
"#conf-connect-timeout": "command-ref/conf-file.html#conf-connect-timeout",
|
||||||
|
"#conf-cores": "command-ref/conf-file.html#conf-cores",
|
||||||
|
"#conf-diff-hook": "command-ref/conf-file.html#conf-diff-hook",
|
||||||
|
"#conf-enforce-determinism": "command-ref/conf-file.html#conf-enforce-determinism",
|
||||||
|
"#conf-env-keep-derivations": "command-ref/conf-file.html#conf-env-keep-derivations",
|
||||||
|
"#conf-extra-binary-caches": "command-ref/conf-file.html#conf-extra-binary-caches",
|
||||||
|
"#conf-extra-platforms": "command-ref/conf-file.html#conf-extra-platforms",
|
||||||
|
"#conf-extra-sandbox-paths": "command-ref/conf-file.html#conf-extra-sandbox-paths",
|
||||||
|
"#conf-extra-substituters": "command-ref/conf-file.html#conf-extra-substituters",
|
||||||
|
"#conf-fallback": "command-ref/conf-file.html#conf-fallback",
|
||||||
|
"#conf-fsync-metadata": "command-ref/conf-file.html#conf-fsync-metadata",
|
||||||
|
"#conf-gc-keep-derivations": "command-ref/conf-file.html#conf-gc-keep-derivations",
|
||||||
|
"#conf-gc-keep-outputs": "command-ref/conf-file.html#conf-gc-keep-outputs",
|
||||||
|
"#conf-hashed-mirrors": "command-ref/conf-file.html#conf-hashed-mirrors",
|
||||||
|
"#conf-http-connections": "command-ref/conf-file.html#conf-http-connections",
|
||||||
|
"#conf-keep-build-log": "command-ref/conf-file.html#conf-keep-build-log",
|
||||||
|
"#conf-keep-derivations": "command-ref/conf-file.html#conf-keep-derivations",
|
||||||
|
"#conf-keep-env-derivations": "command-ref/conf-file.html#conf-keep-env-derivations",
|
||||||
|
"#conf-keep-outputs": "command-ref/conf-file.html#conf-keep-outputs",
|
||||||
|
"#conf-max-build-log-size": "command-ref/conf-file.html#conf-max-build-log-size",
|
||||||
|
"#conf-max-free": "command-ref/conf-file.html#conf-max-free",
|
||||||
|
"#conf-max-jobs": "command-ref/conf-file.html#conf-max-jobs",
|
||||||
|
"#conf-max-silent-time": "command-ref/conf-file.html#conf-max-silent-time",
|
||||||
|
"#conf-min-free": "command-ref/conf-file.html#conf-min-free",
|
||||||
|
"#conf-narinfo-cache-negative-ttl": "command-ref/conf-file.html#conf-narinfo-cache-negative-ttl",
|
||||||
|
"#conf-narinfo-cache-positive-ttl": "command-ref/conf-file.html#conf-narinfo-cache-positive-ttl",
|
||||||
|
"#conf-netrc-file": "command-ref/conf-file.html#conf-netrc-file",
|
||||||
|
"#conf-plugin-files": "command-ref/conf-file.html#conf-plugin-files",
|
||||||
|
"#conf-post-build-hook": "command-ref/conf-file.html#conf-post-build-hook",
|
||||||
|
"#conf-pre-build-hook": "command-ref/conf-file.html#conf-pre-build-hook",
|
||||||
|
"#conf-repeat": "command-ref/conf-file.html#conf-repeat",
|
||||||
|
"#conf-require-sigs": "command-ref/conf-file.html#conf-require-sigs",
|
||||||
|
"#conf-restrict-eval": "command-ref/conf-file.html#conf-restrict-eval",
|
||||||
|
"#conf-run-diff-hook": "command-ref/conf-file.html#conf-run-diff-hook",
|
||||||
|
"#conf-sandbox": "command-ref/conf-file.html#conf-sandbox",
|
||||||
|
"#conf-sandbox-dev-shm-size": "command-ref/conf-file.html#conf-sandbox-dev-shm-size",
|
||||||
|
"#conf-sandbox-paths": "command-ref/conf-file.html#conf-sandbox-paths",
|
||||||
|
"#conf-secret-key-files": "command-ref/conf-file.html#conf-secret-key-files",
|
||||||
|
"#conf-show-trace": "command-ref/conf-file.html#conf-show-trace",
|
||||||
|
"#conf-stalled-download-timeout": "command-ref/conf-file.html#conf-stalled-download-timeout",
|
||||||
|
"#conf-substitute": "command-ref/conf-file.html#conf-substitute",
|
||||||
|
"#conf-substituters": "command-ref/conf-file.html#conf-substituters",
|
||||||
|
"#conf-system": "command-ref/conf-file.html#conf-system",
|
||||||
|
"#conf-system-features": "command-ref/conf-file.html#conf-system-features",
|
||||||
|
"#conf-tarball-ttl": "command-ref/conf-file.html#conf-tarball-ttl",
|
||||||
|
"#conf-timeout": "command-ref/conf-file.html#conf-timeout",
|
||||||
|
"#conf-trace-function-calls": "command-ref/conf-file.html#conf-trace-function-calls",
|
||||||
|
"#conf-trusted-binary-caches": "command-ref/conf-file.html#conf-trusted-binary-caches",
|
||||||
|
"#conf-trusted-public-keys": "command-ref/conf-file.html#conf-trusted-public-keys",
|
||||||
|
"#conf-trusted-substituters": "command-ref/conf-file.html#conf-trusted-substituters",
|
||||||
|
"#conf-trusted-users": "command-ref/conf-file.html#conf-trusted-users",
|
||||||
|
"#extra-sandbox-paths": "command-ref/conf-file.html#extra-sandbox-paths",
|
||||||
|
"#sec-conf-file": "command-ref/conf-file.html",
|
||||||
|
"#env-NIX_PATH": "command-ref/env-common.html#env-NIX_PATH",
|
||||||
|
"#env-common": "command-ref/env-common.html",
|
||||||
|
"#envar-remote": "command-ref/env-common.html#env-NIX_REMOTE",
|
||||||
|
"#sec-common-env": "command-ref/env-common.html",
|
||||||
|
"#ch-files": "command-ref/files.html",
|
||||||
|
"#ch-main-commands": "command-ref/main-commands.html",
|
||||||
|
"#opt-out-link": "command-ref/nix-build.html#opt-out-link",
|
||||||
|
"#sec-nix-build": "command-ref/nix-build.html",
|
||||||
|
"#sec-nix-channel": "command-ref/nix-channel.html",
|
||||||
|
"#sec-nix-collect-garbage": "command-ref/nix-collect-garbage.html",
|
||||||
|
"#sec-nix-copy-closure": "command-ref/nix-copy-closure.html",
|
||||||
|
"#sec-nix-daemon": "command-ref/nix-daemon.html",
|
||||||
|
"#refsec-nix-env-install-examples": "command-ref/nix-env.html#examples",
|
||||||
|
"#rsec-nix-env-install": "command-ref/nix-env.html#operation---install",
|
||||||
|
"#rsec-nix-env-set": "command-ref/nix-env.html#operation---set",
|
||||||
|
"#rsec-nix-env-set-flag": "command-ref/nix-env.html#operation---set-flag",
|
||||||
|
"#rsec-nix-env-upgrade": "command-ref/nix-env.html#operation---upgrade",
|
||||||
|
"#sec-nix-env": "command-ref/nix-env.html",
|
||||||
|
"#ssec-version-comparisons": "command-ref/nix-env.html#versions",
|
||||||
|
"#sec-nix-hash": "command-ref/nix-hash.html",
|
||||||
|
"#sec-nix-instantiate": "command-ref/nix-instantiate.html",
|
||||||
|
"#sec-nix-prefetch-url": "command-ref/nix-prefetch-url.html",
|
||||||
|
"#sec-nix-shell": "command-ref/nix-shell.html",
|
||||||
|
"#ssec-nix-shell-shebang": "command-ref/nix-shell.html#use-as-a--interpreter",
|
||||||
|
"#nixref-queries": "command-ref/nix-store.html#queries",
|
||||||
|
"#opt-add-root": "command-ref/nix-store.html#opt-add-root",
|
||||||
|
"#refsec-nix-store-dump": "command-ref/nix-store.html#operation---dump",
|
||||||
|
"#refsec-nix-store-export": "command-ref/nix-store.html#operation---export",
|
||||||
|
"#refsec-nix-store-import": "command-ref/nix-store.html#operation---import",
|
||||||
|
"#refsec-nix-store-query": "command-ref/nix-store.html#operation---query",
|
||||||
|
"#refsec-nix-store-verify": "command-ref/nix-store.html#operation---verify",
|
||||||
|
"#rsec-nix-store-gc": "command-ref/nix-store.html#operation---gc",
|
||||||
|
"#rsec-nix-store-generate-binary-cache-key": "command-ref/nix-store.html#operation---generate-binary-cache-key",
|
||||||
|
"#rsec-nix-store-realise": "command-ref/nix-store.html#operation---realise",
|
||||||
|
"#rsec-nix-store-serve": "command-ref/nix-store.html#operation---serve",
|
||||||
|
"#sec-nix-store": "command-ref/nix-store.html",
|
||||||
|
"#opt-I": "command-ref/opt-common.html#opt-I",
|
||||||
|
"#opt-attr": "command-ref/opt-common.html#opt-attr",
|
||||||
|
"#opt-common": "command-ref/opt-common.html",
|
||||||
|
"#opt-cores": "command-ref/opt-common.html#opt-cores",
|
||||||
|
"#opt-log-format": "command-ref/opt-common.html#opt-log-format",
|
||||||
|
"#opt-max-jobs": "command-ref/opt-common.html#opt-max-jobs",
|
||||||
|
"#opt-max-silent-time": "command-ref/opt-common.html#opt-max-silent-time",
|
||||||
|
"#opt-timeout": "command-ref/opt-common.html#opt-timeout",
|
||||||
|
"#sec-common-options": "command-ref/opt-common.html",
|
||||||
|
"#ch-utilities": "command-ref/utilities.html",
|
||||||
|
"#chap-hacking": "contributing/hacking.html",
|
||||||
|
"#adv-attr-allowSubstitutes": "expressions/advanced-attributes.html#adv-attr-allowSubstitutes",
|
||||||
|
"#adv-attr-allowedReferences": "expressions/advanced-attributes.html#adv-attr-allowedReferences",
|
||||||
|
"#adv-attr-allowedRequisites": "expressions/advanced-attributes.html#adv-attr-allowedRequisites",
|
||||||
|
"#adv-attr-disallowedReferences": "expressions/advanced-attributes.html#adv-attr-disallowedReferences",
|
||||||
|
"#adv-attr-disallowedRequisites": "expressions/advanced-attributes.html#adv-attr-disallowedRequisites",
|
||||||
|
"#adv-attr-exportReferencesGraph": "expressions/advanced-attributes.html#adv-attr-exportReferencesGraph",
|
||||||
|
"#adv-attr-impureEnvVars": "expressions/advanced-attributes.html#adv-attr-impureEnvVars",
|
||||||
|
"#adv-attr-outputHash": "expressions/advanced-attributes.html#adv-attr-outputHash",
|
||||||
|
"#adv-attr-outputHashAlgo": "expressions/advanced-attributes.html#adv-attr-outputHashAlgo",
|
||||||
|
"#adv-attr-outputHashMode": "expressions/advanced-attributes.html#adv-attr-outputHashMode",
|
||||||
|
"#adv-attr-passAsFile": "expressions/advanced-attributes.html#adv-attr-passAsFile",
|
||||||
|
"#adv-attr-preferLocalBuild": "expressions/advanced-attributes.html#adv-attr-preferLocalBuild",
|
||||||
|
"#fixed-output-drvs": "expressions/advanced-attributes.html#adv-attr-outputHash",
|
||||||
|
"#sec-advanced-attributes": "expressions/advanced-attributes.html",
|
||||||
|
"#sec-arguments": "expressions/arguments-variables.html",
|
||||||
|
"#sec-build-script": "expressions/build-script.html",
|
||||||
|
"#builtin-abort": "expressions/builtins.html#builtins-abort",
|
||||||
|
"#builtin-add": "expressions/builtins.html#builtins-add",
|
||||||
|
"#builtin-all": "expressions/builtins.html#builtins-all",
|
||||||
|
"#builtin-any": "expressions/builtins.html#builtins-any",
|
||||||
|
"#builtin-attrNames": "expressions/builtins.html#builtins-attrNames",
|
||||||
|
"#builtin-attrValues": "expressions/builtins.html#builtins-attrValues",
|
||||||
|
"#builtin-baseNameOf": "expressions/builtins.html#builtins-baseNameOf",
|
||||||
|
"#builtin-bitAnd": "expressions/builtins.html#builtins-bitAnd",
|
||||||
|
"#builtin-bitOr": "expressions/builtins.html#builtins-bitOr",
|
||||||
|
"#builtin-bitXor": "expressions/builtins.html#builtins-bitXor",
|
||||||
|
"#builtin-builtins": "expressions/builtins.html#builtins-builtins",
|
||||||
|
"#builtin-compareVersions": "expressions/builtins.html#builtins-compareVersions",
|
||||||
|
"#builtin-concatLists": "expressions/builtins.html#builtins-concatLists",
|
||||||
|
"#builtin-concatStringsSep": "expressions/builtins.html#builtins-concatStringsSep",
|
||||||
|
"#builtin-currentSystem": "expressions/builtins.html#builtins-currentSystem",
|
||||||
|
"#builtin-deepSeq": "expressions/builtins.html#builtins-deepSeq",
|
||||||
|
"#builtin-derivation": "expressions/builtins.html#builtins-derivation",
|
||||||
|
"#builtin-dirOf": "expressions/builtins.html#builtins-dirOf",
|
||||||
|
"#builtin-div": "expressions/builtins.html#builtins-div",
|
||||||
|
"#builtin-elem": "expressions/builtins.html#builtins-elem",
|
||||||
|
"#builtin-elemAt": "expressions/builtins.html#builtins-elemAt",
|
||||||
|
"#builtin-fetchGit": "expressions/builtins.html#builtins-fetchGit",
|
||||||
|
"#builtin-fetchTarball": "expressions/builtins.html#builtins-fetchTarball",
|
||||||
|
"#builtin-fetchurl": "expressions/builtins.html#builtins-fetchurl",
|
||||||
|
"#builtin-filterSource": "expressions/builtins.html#builtins-filterSource",
|
||||||
|
"#builtin-foldl-prime": "expressions/builtins.html#builtins-foldl-prime",
|
||||||
|
"#builtin-fromJSON": "expressions/builtins.html#builtins-fromJSON",
|
||||||
|
"#builtin-functionArgs": "expressions/builtins.html#builtins-functionArgs",
|
||||||
|
"#builtin-genList": "expressions/builtins.html#builtins-genList",
|
||||||
|
"#builtin-getAttr": "expressions/builtins.html#builtins-getAttr",
|
||||||
|
"#builtin-getEnv": "expressions/builtins.html#builtins-getEnv",
|
||||||
|
"#builtin-hasAttr": "expressions/builtins.html#builtins-hasAttr",
|
||||||
|
"#builtin-hashFile": "expressions/builtins.html#builtins-hashFile",
|
||||||
|
"#builtin-hashString": "expressions/builtins.html#builtins-hashString",
|
||||||
|
"#builtin-head": "expressions/builtins.html#builtins-head",
|
||||||
|
"#builtin-import": "expressions/builtins.html#builtins-import",
|
||||||
|
"#builtin-intersectAttrs": "expressions/builtins.html#builtins-intersectAttrs",
|
||||||
|
"#builtin-isAttrs": "expressions/builtins.html#builtins-isAttrs",
|
||||||
|
"#builtin-isBool": "expressions/builtins.html#builtins-isBool",
|
||||||
|
"#builtin-isFloat": "expressions/builtins.html#builtins-isFloat",
|
||||||
|
"#builtin-isFunction": "expressions/builtins.html#builtins-isFunction",
|
||||||
|
"#builtin-isInt": "expressions/builtins.html#builtins-isInt",
|
||||||
|
"#builtin-isList": "expressions/builtins.html#builtins-isList",
|
||||||
|
"#builtin-isNull": "expressions/builtins.html#builtins-isNull",
|
||||||
|
"#builtin-isString": "expressions/builtins.html#builtins-isString",
|
||||||
|
"#builtin-length": "expressions/builtins.html#builtins-length",
|
||||||
|
"#builtin-lessThan": "expressions/builtins.html#builtins-lessThan",
|
||||||
|
"#builtin-listToAttrs": "expressions/builtins.html#builtins-listToAttrs",
|
||||||
|
"#builtin-map": "expressions/builtins.html#builtins-map",
|
||||||
|
"#builtin-match": "expressions/builtins.html#builtins-match",
|
||||||
|
"#builtin-mul": "expressions/builtins.html#builtins-mul",
|
||||||
|
"#builtin-parseDrvName": "expressions/builtins.html#builtins-parseDrvName",
|
||||||
|
"#builtin-path": "expressions/builtins.html#builtins-path",
|
||||||
|
"#builtin-pathExists": "expressions/builtins.html#builtins-pathExists",
|
||||||
|
"#builtin-placeholder": "expressions/builtins.html#builtins-placeholder",
|
||||||
|
"#builtin-readDir": "expressions/builtins.html#builtins-readDir",
|
||||||
|
"#builtin-readFile": "expressions/builtins.html#builtins-readFile",
|
||||||
|
"#builtin-removeAttrs": "expressions/builtins.html#builtins-removeAttrs",
|
||||||
|
"#builtin-replaceStrings": "expressions/builtins.html#builtins-replaceStrings",
|
||||||
|
"#builtin-seq": "expressions/builtins.html#builtins-seq",
|
||||||
|
"#builtin-sort": "expressions/builtins.html#builtins-sort",
|
||||||
|
"#builtin-split": "expressions/builtins.html#builtins-split",
|
||||||
|
"#builtin-splitVersion": "expressions/builtins.html#builtins-splitVersion",
|
||||||
|
"#builtin-stringLength": "expressions/builtins.html#builtins-stringLength",
|
||||||
|
"#builtin-sub": "expressions/builtins.html#builtins-sub",
|
||||||
|
"#builtin-substring": "expressions/builtins.html#builtins-substring",
|
||||||
|
"#builtin-tail": "expressions/builtins.html#builtins-tail",
|
||||||
|
"#builtin-throw": "expressions/builtins.html#builtins-throw",
|
||||||
|
"#builtin-toFile": "expressions/builtins.html#builtins-toFile",
|
||||||
|
"#builtin-toJSON": "expressions/builtins.html#builtins-toJSON",
|
||||||
|
"#builtin-toPath": "expressions/builtins.html#builtins-toPath",
|
||||||
|
"#builtin-toString": "expressions/builtins.html#builtins-toString",
|
||||||
|
"#builtin-toXML": "expressions/builtins.html#builtins-toXML",
|
||||||
|
"#builtin-trace": "expressions/builtins.html#builtins-trace",
|
||||||
|
"#builtin-tryEval": "expressions/builtins.html#builtins-tryEval",
|
||||||
|
"#builtin-typeOf": "expressions/builtins.html#builtins-typeOf",
|
||||||
|
"#ssec-builtins": "expressions/builtins.html",
|
||||||
|
"#attr-system": "expressions/derivations.html#attr-system",
|
||||||
|
"#ssec-derivation": "expressions/derivations.html",
|
||||||
|
"#ch-expression-language": "expressions/expression-language.html",
|
||||||
|
"#sec-expression-syntax": "expressions/expression-syntax.html",
|
||||||
|
"#sec-generic-builder": "expressions/generic-builder.html",
|
||||||
|
"#sec-constructs": "expressions/language-constructs.html",
|
||||||
|
"#sect-let-expressions": "expressions/language-constructs.html#let-expressions",
|
||||||
|
"#ss-functions": "expressions/language-constructs.html#functions",
|
||||||
|
"#sec-language-operators": "expressions/language-operators.html",
|
||||||
|
"#table-operators": "expressions/language-operators.html",
|
||||||
|
"#ssec-values": "expressions/language-values.html",
|
||||||
|
"#sec-building-simple": "expressions/simple-building-testing.html",
|
||||||
|
"#ch-simple-expression": "expressions/simple-expression.html",
|
||||||
|
"#chap-writing-nix-expressions": "expressions/writing-nix-expressions.html",
|
||||||
|
"#gloss-closure": "glossary.html#gloss-closure",
|
||||||
|
"#gloss-derivation": "glossary.html#gloss-derivation",
|
||||||
|
"#gloss-deriver": "glossary.html#gloss-deriver",
|
||||||
|
"#gloss-nar": "glossary.html#gloss-nar",
|
||||||
|
"#gloss-output-path": "glossary.html#gloss-output-path",
|
||||||
|
"#gloss-profile": "glossary.html#gloss-profile",
|
||||||
|
"#gloss-reachable": "glossary.html#gloss-reachable",
|
||||||
|
"#gloss-reference": "glossary.html#gloss-reference",
|
||||||
|
"#gloss-substitute": "glossary.html#gloss-substitute",
|
||||||
|
"#gloss-user-env": "glossary.html#gloss-user-env",
|
||||||
|
"#gloss-validity": "glossary.html#gloss-validity",
|
||||||
|
"#part-glossary": "glossary.html",
|
||||||
|
"#sec-building-source": "installation/building-source.html",
|
||||||
|
"#ch-env-variables": "installation/env-variables.html",
|
||||||
|
"#sec-installer-proxy-settings": "installation/env-variables.html#proxy-environment-variables",
|
||||||
|
"#sec-nix-ssl-cert-file": "installation/env-variables.html#nix_ssl_cert_file",
|
||||||
|
"#sec-nix-ssl-cert-file-with-nix-daemon-and-macos": "installation/env-variables.html#nix_ssl_cert_file-with-macos-and-the-nix-daemon",
|
||||||
|
"#chap-installation": "installation/installation.html",
|
||||||
|
"#ch-installing-binary": "installation/installing-binary.html",
|
||||||
|
"#sect-macos-installation": "installation/installing-binary.html#macos-installation",
|
||||||
|
"#sect-macos-installation-change-store-prefix": "installation/installing-binary.html#macos-installation",
|
||||||
|
"#sect-macos-installation-encrypted-volume": "installation/installing-binary.html#macos-installation",
|
||||||
|
"#sect-macos-installation-recommended-notes": "installation/installing-binary.html#macos-installation",
|
||||||
|
"#sect-macos-installation-symlink": "installation/installing-binary.html#macos-installation",
|
||||||
|
"#sect-multi-user-installation": "installation/installing-binary.html#multi-user-installation",
|
||||||
|
"#sect-nix-install-binary-tarball": "installation/installing-binary.html#installing-from-a-binary-tarball",
|
||||||
|
"#sect-nix-install-pinned-version-url": "installation/installing-binary.html#installing-a-pinned-nix-version-from-a-url",
|
||||||
|
"#sect-single-user-installation": "installation/installing-binary.html#single-user-installation",
|
||||||
|
"#ch-installing-source": "installation/installing-source.html",
|
||||||
|
"#ssec-multi-user": "installation/multi-user.html",
|
||||||
|
"#ch-nix-security": "installation/nix-security.html",
|
||||||
|
"#sec-obtaining-source": "installation/obtaining-source.html",
|
||||||
|
"#sec-prerequisites-source": "installation/prerequisites-source.html",
|
||||||
|
"#sec-single-user": "installation/single-user.html",
|
||||||
|
"#ch-supported-platforms": "installation/supported-platforms.html",
|
||||||
|
"#ch-upgrading-nix": "installation/upgrading.html",
|
||||||
|
"#ch-about-nix": "introduction.html",
|
||||||
|
"#chap-introduction": "introduction.html",
|
||||||
|
"#ch-basic-package-mgmt": "package-management/basic-package-mgmt.html",
|
||||||
|
"#ssec-binary-cache-substituter": "package-management/binary-cache-substituter.html",
|
||||||
|
"#sec-channels": "package-management/channels.html",
|
||||||
|
"#ssec-copy-closure": "package-management/copy-closure.html",
|
||||||
|
"#sec-garbage-collection": "package-management/garbage-collection.html",
|
||||||
|
"#ssec-gc-roots": "package-management/garbage-collector-roots.html",
|
||||||
|
"#chap-package-management": "package-management/package-management.html",
|
||||||
|
"#sec-profiles": "package-management/profiles.html",
|
||||||
|
"#ssec-s3-substituter": "package-management/s3-substituter.html",
|
||||||
|
"#ssec-s3-substituter-anonymous-reads": "package-management/s3-substituter.html#anonymous-reads-to-your-s3-compatible-binary-cache",
|
||||||
|
"#ssec-s3-substituter-authenticated-reads": "package-management/s3-substituter.html#authenticated-reads-to-your-s3-binary-cache",
|
||||||
|
"#ssec-s3-substituter-authenticated-writes": "package-management/s3-substituter.html#authenticated-writes-to-your-s3-compatible-binary-cache",
|
||||||
|
"#sec-sharing-packages": "package-management/sharing-packages.html",
|
||||||
|
"#ssec-ssh-substituter": "package-management/ssh-substituter.html",
|
||||||
|
"#chap-quick-start": "quick-start.html",
|
||||||
|
"#sec-relnotes": "release-notes/release-notes.html",
|
||||||
|
"#ch-relnotes-0.10.1": "release-notes/rl-0.10.1.html",
|
||||||
|
"#ch-relnotes-0.10": "release-notes/rl-0.10.html",
|
||||||
|
"#ssec-relnotes-0.11": "release-notes/rl-0.11.html",
|
||||||
|
"#ssec-relnotes-0.12": "release-notes/rl-0.12.html",
|
||||||
|
"#ssec-relnotes-0.13": "release-notes/rl-0.13.html",
|
||||||
|
"#ssec-relnotes-0.14": "release-notes/rl-0.14.html",
|
||||||
|
"#ssec-relnotes-0.15": "release-notes/rl-0.15.html",
|
||||||
|
"#ssec-relnotes-0.16": "release-notes/rl-0.16.html",
|
||||||
|
"#ch-relnotes-0.5": "release-notes/rl-0.5.html",
|
||||||
|
"#ch-relnotes-0.6": "release-notes/rl-0.6.html",
|
||||||
|
"#ch-relnotes-0.7": "release-notes/rl-0.7.html",
|
||||||
|
"#ch-relnotes-0.8.1": "release-notes/rl-0.8.1.html",
|
||||||
|
"#ch-relnotes-0.8": "release-notes/rl-0.8.html",
|
||||||
|
"#ch-relnotes-0.9.1": "release-notes/rl-0.9.1.html",
|
||||||
|
"#ch-relnotes-0.9.2": "release-notes/rl-0.9.2.html",
|
||||||
|
"#ch-relnotes-0.9": "release-notes/rl-0.9.html",
|
||||||
|
"#ssec-relnotes-1.0": "release-notes/rl-1.0.html",
|
||||||
|
"#ssec-relnotes-1.1": "release-notes/rl-1.1.html",
|
||||||
|
"#ssec-relnotes-1.10": "release-notes/rl-1.10.html",
|
||||||
|
"#ssec-relnotes-1.11.10": "release-notes/rl-1.11.10.html",
|
||||||
|
"#ssec-relnotes-1.11": "release-notes/rl-1.11.html",
|
||||||
|
"#ssec-relnotes-1.2": "release-notes/rl-1.2.html",
|
||||||
|
"#ssec-relnotes-1.3": "release-notes/rl-1.3.html",
|
||||||
|
"#ssec-relnotes-1.4": "release-notes/rl-1.4.html",
|
||||||
|
"#ssec-relnotes-1.5.1": "release-notes/rl-1.5.1.html",
|
||||||
|
"#ssec-relnotes-1.5.2": "release-notes/rl-1.5.2.html",
|
||||||
|
"#ssec-relnotes-1.5": "release-notes/rl-1.5.html",
|
||||||
|
"#ssec-relnotes-1.6.1": "release-notes/rl-1.6.1.html",
|
||||||
|
"#ssec-relnotes-1.6.0": "release-notes/rl-1.6.html",
|
||||||
|
"#ssec-relnotes-1.7": "release-notes/rl-1.7.html",
|
||||||
|
"#ssec-relnotes-1.8": "release-notes/rl-1.8.html",
|
||||||
|
"#ssec-relnotes-1.9": "release-notes/rl-1.9.html",
|
||||||
|
"#ssec-relnotes-2.0": "release-notes/rl-2.0.html",
|
||||||
|
"#ssec-relnotes-2.1": "release-notes/rl-2.1.html",
|
||||||
|
"#ssec-relnotes-2.2": "release-notes/rl-2.2.html",
|
||||||
|
"#ssec-relnotes-2.3": "release-notes/rl-2.3.html"
|
||||||
|
};
|
||||||
|
|
||||||
|
var isRoot = (document.location.pathname.endsWith('/') || document.location.pathname.endsWith('/index.html')) && path_to_root === '';
|
||||||
|
if (isRoot && redirects[document.location.hash]) {
|
||||||
|
document.location.href = path_to_root + redirects[document.location.hash];
|
||||||
|
}
|
||||||
|
|
@ -72,6 +72,8 @@
|
||||||
- [CLI guideline](contributing/cli-guideline.md)
|
- [CLI guideline](contributing/cli-guideline.md)
|
||||||
- [Release Notes](release-notes/release-notes.md)
|
- [Release Notes](release-notes/release-notes.md)
|
||||||
- [Release X.Y (202?-??-??)](release-notes/rl-next.md)
|
- [Release X.Y (202?-??-??)](release-notes/rl-next.md)
|
||||||
|
- [Release 2.10 (2022-07-11)](release-notes/rl-2.10.md)
|
||||||
|
- [Release 2.9 (2022-05-30)](release-notes/rl-2.9.md)
|
||||||
- [Release 2.8 (2022-04-19)](release-notes/rl-2.8.md)
|
- [Release 2.8 (2022-04-19)](release-notes/rl-2.8.md)
|
||||||
- [Release 2.7 (2022-03-07)](release-notes/rl-2.7.md)
|
- [Release 2.7 (2022-03-07)](release-notes/rl-2.7.md)
|
||||||
- [Release 2.6 (2022-01-24)](release-notes/rl-2.6.md)
|
- [Release 2.6 (2022-01-24)](release-notes/rl-2.6.md)
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ In particular, notice the
|
||||||
`/nix/store/krpqk0l9ib0ibi1d2w52z293zw455cap-unstable.check` output. Nix
|
`/nix/store/krpqk0l9ib0ibi1d2w52z293zw455cap-unstable.check` output. Nix
|
||||||
has copied the build results to that directory where you can examine it.
|
has copied the build results to that directory where you can examine it.
|
||||||
|
|
||||||
> **Note**
|
> []{#check-dirs-are-unregistered} **Note**
|
||||||
>
|
>
|
||||||
> Check paths are not protected against garbage collection, and this
|
> Check paths are not protected against garbage collection, and this
|
||||||
> path will be deleted on the next garbage collection.
|
> path will be deleted on the next garbage collection.
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
Most Nix commands interpret the following environment variables:
|
Most Nix commands interpret the following environment variables:
|
||||||
|
|
||||||
- `IN_NIX_SHELL`\
|
- [`IN_NIX_SHELL`]{#env-IN_NIX_SHELL}\
|
||||||
Indicator that tells if the current environment was set up by
|
Indicator that tells if the current environment was set up by
|
||||||
`nix-shell`. Since Nix 2.0 the values are `"pure"` and `"impure"`
|
`nix-shell`. It can have the values `pure` or `impure`.
|
||||||
|
|
||||||
- `NIX_PATH`\
|
- [`NIX_PATH`]{#env-NIX_PATH}\
|
||||||
A colon-separated list of directories used to look up Nix
|
A colon-separated list of directories used to look up Nix
|
||||||
expressions enclosed in angle brackets (i.e., `<path>`). For
|
expressions enclosed in angle brackets (i.e., `<path>`). For
|
||||||
instance, the value
|
instance, the value
|
||||||
|
|
@ -44,7 +44,7 @@ Most Nix commands interpret the following environment variables:
|
||||||
The Nix search path can also be extended using the `-I` option to
|
The Nix search path can also be extended using the `-I` option to
|
||||||
many Nix commands, which takes precedence over `NIX_PATH`.
|
many Nix commands, which takes precedence over `NIX_PATH`.
|
||||||
|
|
||||||
- `NIX_IGNORE_SYMLINK_STORE`\
|
- [`NIX_IGNORE_SYMLINK_STORE`]{#env-NIX_IGNORE_SYMLINK_STORE}\
|
||||||
Normally, the Nix store directory (typically `/nix/store`) is not
|
Normally, the Nix store directory (typically `/nix/store`) is not
|
||||||
allowed to contain any symlink components. This is to prevent
|
allowed to contain any symlink components. This is to prevent
|
||||||
“impure” builds. Builders sometimes “canonicalise” paths by
|
“impure” builds. Builders sometimes “canonicalise” paths by
|
||||||
|
|
@ -66,41 +66,41 @@ Most Nix commands interpret the following environment variables:
|
||||||
|
|
||||||
Consult the mount 8 manual page for details.
|
Consult the mount 8 manual page for details.
|
||||||
|
|
||||||
- `NIX_STORE_DIR`\
|
- [`NIX_STORE_DIR`]{#env-NIX_STORE_DIR}\
|
||||||
Overrides the location of the Nix store (default `prefix/store`).
|
Overrides the location of the Nix store (default `prefix/store`).
|
||||||
|
|
||||||
- `NIX_DATA_DIR`\
|
- [`NIX_DATA_DIR`]{#env-NIX_DATA_DIR}\
|
||||||
Overrides the location of the Nix static data directory (default
|
Overrides the location of the Nix static data directory (default
|
||||||
`prefix/share`).
|
`prefix/share`).
|
||||||
|
|
||||||
- `NIX_LOG_DIR`\
|
- [`NIX_LOG_DIR`]{#env-NIX_LOG_DIR}\
|
||||||
Overrides the location of the Nix log directory (default
|
Overrides the location of the Nix log directory (default
|
||||||
`prefix/var/log/nix`).
|
`prefix/var/log/nix`).
|
||||||
|
|
||||||
- `NIX_STATE_DIR`\
|
- [`NIX_STATE_DIR`]{#env-NIX_STATE_DIR}\
|
||||||
Overrides the location of the Nix state directory (default
|
Overrides the location of the Nix state directory (default
|
||||||
`prefix/var/nix`).
|
`prefix/var/nix`).
|
||||||
|
|
||||||
- `NIX_CONF_DIR`\
|
- [`NIX_CONF_DIR`]{#env-NIX_CONF_DIR}\
|
||||||
Overrides the location of the system Nix configuration directory
|
Overrides the location of the system Nix configuration directory
|
||||||
(default `prefix/etc/nix`).
|
(default `prefix/etc/nix`).
|
||||||
|
|
||||||
- `NIX_CONFIG`\
|
- [`NIX_CONFIG`]{#env-NIX_CONFIG}\
|
||||||
Applies settings from Nix configuration from the environment.
|
Applies settings from Nix configuration from the environment.
|
||||||
The content is treated as if it was read from a Nix configuration file.
|
The content is treated as if it was read from a Nix configuration file.
|
||||||
Settings are separated by the newline character.
|
Settings are separated by the newline character.
|
||||||
|
|
||||||
- `NIX_USER_CONF_FILES`\
|
- [`NIX_USER_CONF_FILES`]{#env-NIX_USER_CONF_FILES}\
|
||||||
Overrides the location of the user Nix configuration files to load
|
Overrides the location of the user Nix configuration files to load
|
||||||
from (defaults to the XDG spec locations). The variable is treated
|
from (defaults to the XDG spec locations). The variable is treated
|
||||||
as a list separated by the `:` token.
|
as a list separated by the `:` token.
|
||||||
|
|
||||||
- `TMPDIR`\
|
- [`TMPDIR`]{#env-TMPDIR}\
|
||||||
Use the specified directory to store temporary files. In particular,
|
Use the specified directory to store temporary files. In particular,
|
||||||
this includes temporary build directories; these can take up
|
this includes temporary build directories; these can take up
|
||||||
substantial amounts of disk space. The default is `/tmp`.
|
substantial amounts of disk space. The default is `/tmp`.
|
||||||
|
|
||||||
- `NIX_REMOTE`\
|
- [`NIX_REMOTE`]{#env-NIX_REMOTE}\
|
||||||
This variable should be set to `daemon` if you want to use the Nix
|
This variable should be set to `daemon` if you want to use the Nix
|
||||||
daemon to execute Nix operations. This is necessary in [multi-user
|
daemon to execute Nix operations. This is necessary in [multi-user
|
||||||
Nix installations](../installation/multi-user.md). If the Nix
|
Nix installations](../installation/multi-user.md). If the Nix
|
||||||
|
|
@ -108,16 +108,16 @@ Most Nix commands interpret the following environment variables:
|
||||||
should be set to `unix://path/to/socket`. Otherwise, it should be
|
should be set to `unix://path/to/socket`. Otherwise, it should be
|
||||||
left unset.
|
left unset.
|
||||||
|
|
||||||
- `NIX_SHOW_STATS`\
|
- [`NIX_SHOW_STATS`]{#env-NIX_SHOW_STATS}\
|
||||||
If set to `1`, Nix will print some evaluation statistics, such as
|
If set to `1`, Nix will print some evaluation statistics, such as
|
||||||
the number of values allocated.
|
the number of values allocated.
|
||||||
|
|
||||||
- `NIX_COUNT_CALLS`\
|
- [`NIX_COUNT_CALLS`]{#env-NIX_COUNT_CALLS}\
|
||||||
If set to `1`, Nix will print how often functions were called during
|
If set to `1`, Nix will print how often functions were called during
|
||||||
Nix expression evaluation. This is useful for profiling your Nix
|
Nix expression evaluation. This is useful for profiling your Nix
|
||||||
expressions.
|
expressions.
|
||||||
|
|
||||||
- `GC_INITIAL_HEAP_SIZE`\
|
- [`GC_INITIAL_HEAP_SIZE`]{#env-GC_INITIAL_HEAP_SIZE}\
|
||||||
If Nix has been configured to use the Boehm garbage collector, this
|
If Nix has been configured to use the Boehm garbage collector, this
|
||||||
variable sets the initial size of the heap in bytes. It defaults to
|
variable sets the initial size of the heap in bytes. It defaults to
|
||||||
384 MiB. Setting it to a low value reduces memory consumption, but
|
384 MiB. Setting it to a low value reduces memory consumption, but
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,12 @@
|
||||||
[`--dry-run`]
|
[`--dry-run`]
|
||||||
[{`--out-link` | `-o`} *outlink*]
|
[{`--out-link` | `-o`} *outlink*]
|
||||||
|
|
||||||
|
# Disambiguation
|
||||||
|
|
||||||
|
This man page describes the command `nix-build`, which is distinct from `nix
|
||||||
|
build`. For documentation on the latter, run `nix build --help` or see `man
|
||||||
|
nix3-build`.
|
||||||
|
|
||||||
# Description
|
# Description
|
||||||
|
|
||||||
The `nix-build` command builds the derivations described by the Nix
|
The `nix-build` command builds the derivations described by the Nix
|
||||||
|
|
@ -47,16 +53,16 @@ All options not listed here are passed to `nix-store
|
||||||
--realise`, except for `--arg` and `--attr` / `-A` which are passed to
|
--realise`, except for `--arg` and `--attr` / `-A` which are passed to
|
||||||
`nix-instantiate`.
|
`nix-instantiate`.
|
||||||
|
|
||||||
- `--no-out-link`\
|
- [`--no-out-link`]{#opt-no-out-link}\
|
||||||
Do not create a symlink to the output path. Note that as a result
|
Do not create a symlink to the output path. Note that as a result
|
||||||
the output does not become a root of the garbage collector, and so
|
the output does not become a root of the garbage collector, and so
|
||||||
might be deleted by `nix-store
|
might be deleted by `nix-store
|
||||||
--gc`.
|
--gc`.
|
||||||
|
|
||||||
- `--dry-run`\
|
- [`--dry-run`]{#opt-dry-run}\
|
||||||
Show what store paths would be built or downloaded.
|
Show what store paths would be built or downloaded.
|
||||||
|
|
||||||
- `--out-link` / `-o` *outlink*\
|
- [`--out-link`]{#opt-out-link} / `-o` *outlink*\
|
||||||
Change the name of the symlink to the output path created from
|
Change the name of the symlink to the output path created from
|
||||||
`result` to *outlink*.
|
`result` to *outlink*.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ subcommand to be performed. These are documented below.
|
||||||
Several commands, such as `nix-env -q` and `nix-env -i`, take a list of
|
Several commands, such as `nix-env -q` and `nix-env -i`, take a list of
|
||||||
arguments that specify the packages on which to operate. These are
|
arguments that specify the packages on which to operate. These are
|
||||||
extended regular expressions that must match the entire name of the
|
extended regular expressions that must match the entire name of the
|
||||||
package. (For details on regular expressions, see regex7.) The match is
|
package. (For details on regular expressions, see **regex**(7).) The match is
|
||||||
case-sensitive. The regular expression can optionally be followed by a
|
case-sensitive. The regular expression can optionally be followed by a
|
||||||
dash and a version number; if omitted, any version of the package will
|
dash and a version number; if omitted, any version of the package will
|
||||||
match. Here are some examples:
|
match. Here are some examples:
|
||||||
|
|
@ -412,7 +412,7 @@ The upgrade operation determines whether a derivation `y` is an upgrade
|
||||||
of a derivation `x` by looking at their respective `name` attributes.
|
of a derivation `x` by looking at their respective `name` attributes.
|
||||||
The names (e.g., `gcc-3.3.1` are split into two parts: the package name
|
The names (e.g., `gcc-3.3.1` are split into two parts: the package name
|
||||||
(`gcc`), and the version (`3.3.1`). The version part starts after the
|
(`gcc`), and the version (`3.3.1`). The version part starts after the
|
||||||
first dash not followed by a letter. `x` is considered an upgrade of `y`
|
first dash not followed by a letter. `y` is considered an upgrade of `x`
|
||||||
if their package names match, and the version of `y` is higher than that
|
if their package names match, and the version of `y` is higher than that
|
||||||
of `x`.
|
of `x`.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,12 @@
|
||||||
[`--keep` *name*]
|
[`--keep` *name*]
|
||||||
{{`--packages` | `-p`} {*packages* | *expressions*} … | [*path*]}
|
{{`--packages` | `-p`} {*packages* | *expressions*} … | [*path*]}
|
||||||
|
|
||||||
|
# Disambiguation
|
||||||
|
|
||||||
|
This man page describes the command `nix-shell`, which is distinct from `nix
|
||||||
|
shell`. For documentation on the latter, run `nix shell --help` or see `man
|
||||||
|
nix3-shell`.
|
||||||
|
|
||||||
# Description
|
# Description
|
||||||
|
|
||||||
The command `nix-shell` will build the dependencies of the specified
|
The command `nix-shell` will build the dependencies of the specified
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ This section lists the options that are common to all operations. These
|
||||||
options are allowed for every subcommand, though they may not always
|
options are allowed for every subcommand, though they may not always
|
||||||
have an effect.
|
have an effect.
|
||||||
|
|
||||||
- `--add-root` *path*\
|
- [`--add-root`]{#opt-add-root} *path*\
|
||||||
Causes the result of a realisation (`--realise` and
|
Causes the result of a realisation (`--realise` and
|
||||||
`--force-realise`) to be registered as a root of the garbage
|
`--force-realise`) to be registered as a root of the garbage
|
||||||
collector. *path* will be created as a symlink to the resulting
|
collector. *path* will be created as a symlink to the resulting
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@
|
||||||
|
|
||||||
Most Nix commands accept the following command-line options:
|
Most Nix commands accept the following command-line options:
|
||||||
|
|
||||||
- `--help`\
|
- [`--help`]{#opt-help}\
|
||||||
Prints out a summary of the command syntax and exits.
|
Prints out a summary of the command syntax and exits.
|
||||||
|
|
||||||
- `--version`\
|
- [`--version`]{#opt-version}\
|
||||||
Prints out the Nix version number on standard output and exits.
|
Prints out the Nix version number on standard output and exits.
|
||||||
|
|
||||||
- `--verbose` / `-v`\
|
- [`--verbose`]{#opt-verbose} / `-v`\
|
||||||
Increases the level of verbosity of diagnostic messages printed on
|
Increases the level of verbosity of diagnostic messages printed on
|
||||||
standard error. For each Nix operation, the information printed on
|
standard error. For each Nix operation, the information printed on
|
||||||
standard output is well-defined; any diagnostic information is
|
standard output is well-defined; any diagnostic information is
|
||||||
|
|
@ -37,14 +37,14 @@ Most Nix commands accept the following command-line options:
|
||||||
- 5\
|
- 5\
|
||||||
“Vomit”: print vast amounts of debug information.
|
“Vomit”: print vast amounts of debug information.
|
||||||
|
|
||||||
- `--quiet`\
|
- [`--quiet`]{#opt-quiet}\
|
||||||
Decreases the level of verbosity of diagnostic messages printed on
|
Decreases the level of verbosity of diagnostic messages printed on
|
||||||
standard error. This is the inverse option to `-v` / `--verbose`.
|
standard error. This is the inverse option to `-v` / `--verbose`.
|
||||||
|
|
||||||
This option may be specified repeatedly. See the previous verbosity
|
This option may be specified repeatedly. See the previous verbosity
|
||||||
levels list.
|
levels list.
|
||||||
|
|
||||||
- `--log-format` *format*\
|
- [`--log-format`]{#opt-log-format} *format*\
|
||||||
This option can be used to change the output of the log format, with
|
This option can be used to change the output of the log format, with
|
||||||
*format* being one of:
|
*format* being one of:
|
||||||
|
|
||||||
|
|
@ -66,14 +66,14 @@ Most Nix commands accept the following command-line options:
|
||||||
- bar-with-logs\
|
- bar-with-logs\
|
||||||
Display the raw logs, with the progress bar at the bottom.
|
Display the raw logs, with the progress bar at the bottom.
|
||||||
|
|
||||||
- `--no-build-output` / `-Q`\
|
- [`--no-build-output`]{#opt-no-build-output} / `-Q`\
|
||||||
By default, output written by builders to standard output and
|
By default, output written by builders to standard output and
|
||||||
standard error is echoed to the Nix command's standard error. This
|
standard error is echoed to the Nix command's standard error. This
|
||||||
option suppresses this behaviour. Note that the builder's standard
|
option suppresses this behaviour. Note that the builder's standard
|
||||||
output and error are always written to a log file in
|
output and error are always written to a log file in
|
||||||
`prefix/nix/var/log/nix`.
|
`prefix/nix/var/log/nix`.
|
||||||
|
|
||||||
- `--max-jobs` / `-j` *number*\
|
- [`--max-jobs`]{#opt-max-jobs} / `-j` *number*\
|
||||||
Sets the maximum number of build jobs that Nix will perform in
|
Sets the maximum number of build jobs that Nix will perform in
|
||||||
parallel to the specified number. Specify `auto` to use the number
|
parallel to the specified number. Specify `auto` to use the number
|
||||||
of CPUs in the system. The default is specified by the `max-jobs`
|
of CPUs in the system. The default is specified by the `max-jobs`
|
||||||
|
|
@ -83,7 +83,7 @@ Most Nix commands accept the following command-line options:
|
||||||
Setting it to `0` disallows building on the local machine, which is
|
Setting it to `0` disallows building on the local machine, which is
|
||||||
useful when you want builds to happen only on remote builders.
|
useful when you want builds to happen only on remote builders.
|
||||||
|
|
||||||
- `--cores`\
|
- [`--cores`]{#opt-cores}\
|
||||||
Sets the value of the `NIX_BUILD_CORES` environment variable in
|
Sets the value of the `NIX_BUILD_CORES` environment variable in
|
||||||
the invocation of builders. Builders can use this variable at
|
the invocation of builders. Builders can use this variable at
|
||||||
their discretion to control the maximum amount of parallelism. For
|
their discretion to control the maximum amount of parallelism. For
|
||||||
|
|
@ -94,18 +94,18 @@ Most Nix commands accept the following command-line options:
|
||||||
means that the builder should use all available CPU cores in the
|
means that the builder should use all available CPU cores in the
|
||||||
system.
|
system.
|
||||||
|
|
||||||
- `--max-silent-time`\
|
- [`--max-silent-time`]{#opt-max-silent-time}\
|
||||||
Sets the maximum number of seconds that a builder can go without
|
Sets the maximum number of seconds that a builder can go without
|
||||||
producing any data on standard output or standard error. The
|
producing any data on standard output or standard error. The
|
||||||
default is specified by the `max-silent-time` configuration
|
default is specified by the `max-silent-time` configuration
|
||||||
setting. `0` means no time-out.
|
setting. `0` means no time-out.
|
||||||
|
|
||||||
- `--timeout`\
|
- [`--timeout`]{#opt-timeout}\
|
||||||
Sets the maximum number of seconds that a builder can run. The
|
Sets the maximum number of seconds that a builder can run. The
|
||||||
default is specified by the `timeout` configuration setting. `0`
|
default is specified by the `timeout` configuration setting. `0`
|
||||||
means no timeout.
|
means no timeout.
|
||||||
|
|
||||||
- `--keep-going` / `-k`\
|
- [`--keep-going`]{#opt-keep-going} / `-k`\
|
||||||
Keep going in case of failed builds, to the greatest extent
|
Keep going in case of failed builds, to the greatest extent
|
||||||
possible. That is, if building an input of some derivation fails,
|
possible. That is, if building an input of some derivation fails,
|
||||||
Nix will still build the other inputs, but not the derivation
|
Nix will still build the other inputs, but not the derivation
|
||||||
|
|
@ -113,13 +113,13 @@ Most Nix commands accept the following command-line options:
|
||||||
for builds of substitutes), possibly killing builds in progress (in
|
for builds of substitutes), possibly killing builds in progress (in
|
||||||
case of parallel or distributed builds).
|
case of parallel or distributed builds).
|
||||||
|
|
||||||
- `--keep-failed` / `-K`\
|
- [`--keep-failed`]{#opt-keep-failed} / `-K`\
|
||||||
Specifies that in case of a build failure, the temporary directory
|
Specifies that in case of a build failure, the temporary directory
|
||||||
(usually in `/tmp`) in which the build takes place should not be
|
(usually in `/tmp`) in which the build takes place should not be
|
||||||
deleted. The path of the build directory is printed as an
|
deleted. The path of the build directory is printed as an
|
||||||
informational message.
|
informational message.
|
||||||
|
|
||||||
- `--fallback`\
|
- [`--fallback`]{#opt-fallback}\
|
||||||
Whenever Nix attempts to build a derivation for which substitutes
|
Whenever Nix attempts to build a derivation for which substitutes
|
||||||
are known for each output path, but realising the output paths
|
are known for each output path, but realising the output paths
|
||||||
through the substitutes fails, fall back on building the derivation.
|
through the substitutes fails, fall back on building the derivation.
|
||||||
|
|
@ -134,12 +134,12 @@ Most Nix commands accept the following command-line options:
|
||||||
failure in obtaining the substitutes to lead to a full build from
|
failure in obtaining the substitutes to lead to a full build from
|
||||||
source (with the related consumption of resources).
|
source (with the related consumption of resources).
|
||||||
|
|
||||||
- `--readonly-mode`\
|
- [`--readonly-mode`]{#opt-readonly-mode}\
|
||||||
When this option is used, no attempt is made to open the Nix
|
When this option is used, no attempt is made to open the Nix
|
||||||
database. Most Nix operations do need database access, so those
|
database. Most Nix operations do need database access, so those
|
||||||
operations will fail.
|
operations will fail.
|
||||||
|
|
||||||
- `--arg` *name* *value*\
|
- [`--arg`]{#opt-arg} *name* *value*\
|
||||||
This option is accepted by `nix-env`, `nix-instantiate`,
|
This option is accepted by `nix-env`, `nix-instantiate`,
|
||||||
`nix-shell` and `nix-build`. When evaluating Nix expressions, the
|
`nix-shell` and `nix-build`. When evaluating Nix expressions, the
|
||||||
expression evaluator will automatically try to call functions that
|
expression evaluator will automatically try to call functions that
|
||||||
|
|
@ -170,13 +170,13 @@ Most Nix commands accept the following command-line options:
|
||||||
since the argument is a Nix string literal, you have to escape the
|
since the argument is a Nix string literal, you have to escape the
|
||||||
quotes.)
|
quotes.)
|
||||||
|
|
||||||
- `--argstr` *name* *value*\
|
- [`--argstr`]{#opt-argstr} *name* *value*\
|
||||||
This option is like `--arg`, only the value is not a Nix
|
This option is like `--arg`, only the value is not a Nix
|
||||||
expression but a string. So instead of `--arg system
|
expression but a string. So instead of `--arg system
|
||||||
\"i686-linux\"` (the outer quotes are to keep the shell happy) you
|
\"i686-linux\"` (the outer quotes are to keep the shell happy) you
|
||||||
can say `--argstr system i686-linux`.
|
can say `--argstr system i686-linux`.
|
||||||
|
|
||||||
- `--attr` / `-A` *attrPath*\
|
- [`--attr`]{#opt-attr} / `-A` *attrPath*\
|
||||||
Select an attribute from the top-level Nix expression being
|
Select an attribute from the top-level Nix expression being
|
||||||
evaluated. (`nix-env`, `nix-instantiate`, `nix-build` and
|
evaluated. (`nix-env`, `nix-instantiate`, `nix-build` and
|
||||||
`nix-shell` only.) The *attribute path* *attrPath* is a sequence
|
`nix-shell` only.) The *attribute path* *attrPath* is a sequence
|
||||||
|
|
@ -191,7 +191,7 @@ Most Nix commands accept the following command-line options:
|
||||||
attribute of the fourth element of the array in the `foo` attribute
|
attribute of the fourth element of the array in the `foo` attribute
|
||||||
of the top-level expression.
|
of the top-level expression.
|
||||||
|
|
||||||
- `--expr` / `-E`\
|
- [`--expr`]{#opt-expr} / `-E`\
|
||||||
Interpret the command line arguments as a list of Nix expressions to
|
Interpret the command line arguments as a list of Nix expressions to
|
||||||
be parsed and evaluated, rather than as a list of file names of Nix
|
be parsed and evaluated, rather than as a list of file names of Nix
|
||||||
expressions. (`nix-instantiate`, `nix-build` and `nix-shell` only.)
|
expressions. (`nix-instantiate`, `nix-build` and `nix-shell` only.)
|
||||||
|
|
@ -202,17 +202,17 @@ Most Nix commands accept the following command-line options:
|
||||||
use, give your expression to the `nix-shell -p` convenience flag
|
use, give your expression to the `nix-shell -p` convenience flag
|
||||||
instead.
|
instead.
|
||||||
|
|
||||||
- `-I` *path*\
|
- [`-I`]{#opt-I} *path*\
|
||||||
Add a path to the Nix expression search path. This option may be
|
Add a path to the Nix expression search path. This option may be
|
||||||
given multiple times. See the `NIX_PATH` environment variable for
|
given multiple times. See the `NIX_PATH` environment variable for
|
||||||
information on the semantics of the Nix search path. Paths added
|
information on the semantics of the Nix search path. Paths added
|
||||||
through `-I` take precedence over `NIX_PATH`.
|
through `-I` take precedence over `NIX_PATH`.
|
||||||
|
|
||||||
- `--option` *name* *value*\
|
- [`--option`]{#opt-option} *name* *value*\
|
||||||
Set the Nix configuration option *name* to *value*. This overrides
|
Set the Nix configuration option *name* to *value*. This overrides
|
||||||
settings in the Nix configuration file (see nix.conf5).
|
settings in the Nix configuration file (see nix.conf5).
|
||||||
|
|
||||||
- `--repair`\
|
- [`--repair`]{#opt-repair}\
|
||||||
Fix corrupted or missing store paths by redownloading or rebuilding
|
Fix corrupted or missing store paths by redownloading or rebuilding
|
||||||
them. Note that this is slow because it requires computing a
|
them. Note that this is slow because it requires computing a
|
||||||
cryptographic hash of the contents of every path in the closure of
|
cryptographic hash of the contents of every path in the closure of
|
||||||
|
|
|
||||||
|
|
@ -71,18 +71,6 @@ To install it in `$(pwd)/outputs` and test it:
|
||||||
nix (Nix) 3.0
|
nix (Nix) 3.0
|
||||||
```
|
```
|
||||||
|
|
||||||
To run a functional test:
|
|
||||||
|
|
||||||
```console
|
|
||||||
make tests/test-name-should-auto-complete.sh.test
|
|
||||||
```
|
|
||||||
|
|
||||||
To run the unit-tests for C++ code:
|
|
||||||
|
|
||||||
```
|
|
||||||
make check
|
|
||||||
```
|
|
||||||
|
|
||||||
If you have a flakes-enabled Nix you can replace:
|
If you have a flakes-enabled Nix you can replace:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
|
|
@ -94,3 +82,29 @@ by:
|
||||||
```console
|
```console
|
||||||
$ nix develop
|
$ nix develop
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
Nix comes with three different flavors of tests: unit, functional and integration.
|
||||||
|
|
||||||
|
### Unit-tests
|
||||||
|
|
||||||
|
The unit-tests for each Nix library (`libexpr`, `libstore`, etc..) are defined
|
||||||
|
under `src/{library_name}/tests` using the
|
||||||
|
[googletest](https://google.github.io/googletest/) framework.
|
||||||
|
|
||||||
|
You can run the whole testsuite with `make check`, or the tests for a specific component with `make libfoo-tests_RUN`. Finer-grained filtering is also possible using the [--gtest_filter](https://google.github.io/googletest/advanced.html#running-a-subset-of-the-tests) command-line option.
|
||||||
|
|
||||||
|
### Functional tests
|
||||||
|
|
||||||
|
The functional tests reside under the `tests` directory and are listed in `tests/local.mk`.
|
||||||
|
The whole testsuite can be run with `make install && make installcheck`.
|
||||||
|
Individual tests can be run with `make tests/{testName}.sh.test`.
|
||||||
|
|
||||||
|
### Integration tests
|
||||||
|
|
||||||
|
The integration tests are defined in the Nix flake under the `hydraJobs.tests` attribute.
|
||||||
|
These tests include everything that needs to interact with external services or run Nix in a non-trivial distributed setup.
|
||||||
|
Because these tests are expensive and require more than what the standard github-actions setup provides, they only run on the master branch (on <https://hydra.nixos.org/jobset/nix/master>).
|
||||||
|
|
||||||
|
You can run them manually with `nix build .#hydraJobs.tests.{testName}` or `nix-build -A hydraJobs.tests.{testName}`
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
Derivations can declare some infrequently used optional attributes.
|
Derivations can declare some infrequently used optional attributes.
|
||||||
|
|
||||||
- `allowedReferences`\
|
- [`allowedReferences`]{#adv-attr-allowedReferences}\
|
||||||
The optional attribute `allowedReferences` specifies a list of legal
|
The optional attribute `allowedReferences` specifies a list of legal
|
||||||
references (dependencies) of the output of the builder. For example,
|
references (dependencies) of the output of the builder. For example,
|
||||||
|
|
||||||
|
|
@ -17,7 +17,7 @@ Derivations can declare some infrequently used optional attributes.
|
||||||
booting Linux don’t have accidental dependencies on other paths in
|
booting Linux don’t have accidental dependencies on other paths in
|
||||||
the Nix store.
|
the Nix store.
|
||||||
|
|
||||||
- `allowedRequisites`\
|
- [`allowedRequisites`]{#adv-attr-allowedRequisites}\
|
||||||
This attribute is similar to `allowedReferences`, but it specifies
|
This attribute is similar to `allowedReferences`, but it specifies
|
||||||
the legal requisites of the whole closure, so all the dependencies
|
the legal requisites of the whole closure, so all the dependencies
|
||||||
recursively. For example,
|
recursively. For example,
|
||||||
|
|
@ -30,7 +30,7 @@ Derivations can declare some infrequently used optional attributes.
|
||||||
runtime dependency than `foobar`, and in addition it enforces that
|
runtime dependency than `foobar`, and in addition it enforces that
|
||||||
`foobar` itself doesn't introduce any other dependency itself.
|
`foobar` itself doesn't introduce any other dependency itself.
|
||||||
|
|
||||||
- `disallowedReferences`\
|
- [`disallowedReferences`]{#adv-attr-disallowedReferences}\
|
||||||
The optional attribute `disallowedReferences` specifies a list of
|
The optional attribute `disallowedReferences` specifies a list of
|
||||||
illegal references (dependencies) of the output of the builder. For
|
illegal references (dependencies) of the output of the builder. For
|
||||||
example,
|
example,
|
||||||
|
|
@ -42,7 +42,7 @@ Derivations can declare some infrequently used optional attributes.
|
||||||
enforces that the output of a derivation cannot have a direct
|
enforces that the output of a derivation cannot have a direct
|
||||||
runtime dependencies on the derivation `foo`.
|
runtime dependencies on the derivation `foo`.
|
||||||
|
|
||||||
- `disallowedRequisites`\
|
- [`disallowedRequisites`]{#adv-attr-disallowedRequisites}\
|
||||||
This attribute is similar to `disallowedReferences`, but it
|
This attribute is similar to `disallowedReferences`, but it
|
||||||
specifies illegal requisites for the whole closure, so all the
|
specifies illegal requisites for the whole closure, so all the
|
||||||
dependencies recursively. For example,
|
dependencies recursively. For example,
|
||||||
|
|
@ -55,7 +55,7 @@ Derivations can declare some infrequently used optional attributes.
|
||||||
dependency on `foobar` or any other derivation depending recursively
|
dependency on `foobar` or any other derivation depending recursively
|
||||||
on `foobar`.
|
on `foobar`.
|
||||||
|
|
||||||
- `exportReferencesGraph`\
|
- [`exportReferencesGraph`]{#adv-attr-exportReferencesGraph}\
|
||||||
This attribute allows builders access to the references graph of
|
This attribute allows builders access to the references graph of
|
||||||
their inputs. The attribute is a list of inputs in the Nix store
|
their inputs. The attribute is a list of inputs in the Nix store
|
||||||
whose references graph the builder needs to know. The value of
|
whose references graph the builder needs to know. The value of
|
||||||
|
|
@ -84,7 +84,7 @@ Derivations can declare some infrequently used optional attributes.
|
||||||
with a Nix store containing the closure of a bootable NixOS
|
with a Nix store containing the closure of a bootable NixOS
|
||||||
configuration).
|
configuration).
|
||||||
|
|
||||||
- `impureEnvVars`\
|
- [`impureEnvVars`]{#adv-attr-impureEnvVars}\
|
||||||
This attribute allows you to specify a list of environment variables
|
This attribute allows you to specify a list of environment variables
|
||||||
that should be passed from the environment of the calling user to
|
that should be passed from the environment of the calling user to
|
||||||
the builder. Usually, the environment is cleared completely when the
|
the builder. Usually, the environment is cleared completely when the
|
||||||
|
|
@ -112,7 +112,7 @@ Derivations can declare some infrequently used optional attributes.
|
||||||
> environmental variables come from the environment of the
|
> environmental variables come from the environment of the
|
||||||
> `nix-build`.
|
> `nix-build`.
|
||||||
|
|
||||||
- `outputHash`; `outputHashAlgo`; `outputHashMode`\
|
- [`outputHash`]{#adv-attr-outputHash}; [`outputHashAlgo`]{#adv-attr-outputHashAlgo}; [`outputHashMode`]{#adv-attr-outputHashMode}\
|
||||||
These attributes declare that the derivation is a so-called
|
These attributes declare that the derivation is a so-called
|
||||||
*fixed-output derivation*, which means that a cryptographic hash of
|
*fixed-output derivation*, which means that a cryptographic hash of
|
||||||
the output is already known in advance. When the build of a
|
the output is already known in advance. When the build of a
|
||||||
|
|
@ -208,7 +208,7 @@ Derivations can declare some infrequently used optional attributes.
|
||||||
[`nix-hash` command](../command-ref/nix-hash.md) for information
|
[`nix-hash` command](../command-ref/nix-hash.md) for information
|
||||||
about converting to and from base-32 notation.)
|
about converting to and from base-32 notation.)
|
||||||
|
|
||||||
- `__contentAddressed`
|
- [`__contentAddressed`]{#adv-attr-__contentAddressed}
|
||||||
If this **experimental** attribute is set to true, then the derivation
|
If this **experimental** attribute is set to true, then the derivation
|
||||||
outputs will be stored in a content-addressed location rather than the
|
outputs will be stored in a content-addressed location rather than the
|
||||||
traditional input-addressed one.
|
traditional input-addressed one.
|
||||||
|
|
@ -216,7 +216,7 @@ Derivations can declare some infrequently used optional attributes.
|
||||||
|
|
||||||
Setting this attribute also requires setting `outputHashMode` and `outputHashAlgo` like for *fixed-output derivations* (see above).
|
Setting this attribute also requires setting `outputHashMode` and `outputHashAlgo` like for *fixed-output derivations* (see above).
|
||||||
|
|
||||||
- `passAsFile`\
|
- [`passAsFile`]{#adv-attr-passAsFile}\
|
||||||
A list of names of attributes that should be passed via files rather
|
A list of names of attributes that should be passed via files rather
|
||||||
than environment variables. For example, if you have
|
than environment variables. For example, if you have
|
||||||
|
|
||||||
|
|
@ -234,7 +234,7 @@ Derivations can declare some infrequently used optional attributes.
|
||||||
builder, since most operating systems impose a limit on the size
|
builder, since most operating systems impose a limit on the size
|
||||||
of the environment (typically, a few hundred kilobyte).
|
of the environment (typically, a few hundred kilobyte).
|
||||||
|
|
||||||
- `preferLocalBuild`\
|
- [`preferLocalBuild`]{#adv-attr-preferLocalBuild}\
|
||||||
If this attribute is set to `true` and [distributed building is
|
If this attribute is set to `true` and [distributed building is
|
||||||
enabled](../advanced-topics/distributed-builds.md), then, if
|
enabled](../advanced-topics/distributed-builds.md), then, if
|
||||||
possible, the derivation will be built locally instead of forwarded
|
possible, the derivation will be built locally instead of forwarded
|
||||||
|
|
@ -242,7 +242,7 @@ Derivations can declare some infrequently used optional attributes.
|
||||||
where the cost of doing a download or remote build would exceed
|
where the cost of doing a download or remote build would exceed
|
||||||
the cost of building locally.
|
the cost of building locally.
|
||||||
|
|
||||||
- `allowSubstitutes`\
|
- [`allowSubstitutes`]{#adv-attr-allowSubstitutes}\
|
||||||
If this attribute is set to `false`, then Nix will always build this
|
If this attribute is set to `false`, then Nix will always build this
|
||||||
derivation; it will not try to substitute its outputs. This is
|
derivation; it will not try to substitute its outputs. This is
|
||||||
useful for very trivial derivations (such as `writeText` in Nixpkgs)
|
useful for very trivial derivations (such as `writeText` in Nixpkgs)
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ Here are the constants built into the Nix expression evaluator:
|
||||||
This allows a Nix expression to fall back gracefully on older Nix
|
This allows a Nix expression to fall back gracefully on older Nix
|
||||||
installations that don’t have the desired built-in function.
|
installations that don’t have the desired built-in function.
|
||||||
|
|
||||||
- `builtins.currentSystem`\
|
- [`builtins.currentSystem`]{#builtins-currentSystem}\
|
||||||
The built-in value `currentSystem` evaluates to the Nix platform
|
The built-in value `currentSystem` evaluates to the Nix platform
|
||||||
identifier for the Nix installation on which the expression is being
|
identifier for the Nix installation on which the expression is being
|
||||||
evaluated, such as `"i686-linux"` or `"x86_64-darwin"`.
|
evaluated, such as `"i686-linux"` or `"x86_64-darwin"`.
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ The most important built-in function is `derivation`, which is used to
|
||||||
describe a single derivation (a build action). It takes as input a set,
|
describe a single derivation (a build action). It takes as input a set,
|
||||||
the attributes of which specify the inputs of the build.
|
the attributes of which specify the inputs of the build.
|
||||||
|
|
||||||
- There must be an attribute named `system` whose value must be a
|
- There must be an attribute named [`system`]{#attr-system} whose value must be a
|
||||||
string specifying a Nix system type, such as `"i686-linux"` or
|
string specifying a Nix system type, such as `"i686-linux"` or
|
||||||
`"x86_64-darwin"`. (To figure out your system type, run `nix -vv
|
`"x86_64-darwin"`. (To figure out your system type, run `nix -vv
|
||||||
--version`.) The build can only be performed on a machine and
|
--version`.) The build can only be performed on a machine and
|
||||||
|
|
|
||||||
|
|
@ -1,48 +1,48 @@
|
||||||
# Glossary
|
# Glossary
|
||||||
|
|
||||||
- derivation\
|
- [derivation]{#gloss-derivation}\
|
||||||
A description of a build action. The result of a derivation is a
|
A description of a build action. The result of a derivation is a
|
||||||
store object. Derivations are typically specified in Nix expressions
|
store object. Derivations are typically specified in Nix expressions
|
||||||
using the [`derivation` primitive](expressions/derivations.md). These are
|
using the [`derivation` primitive](expressions/derivations.md). These are
|
||||||
translated into low-level *store derivations* (implicitly by
|
translated into low-level *store derivations* (implicitly by
|
||||||
`nix-env` and `nix-build`, or explicitly by `nix-instantiate`).
|
`nix-env` and `nix-build`, or explicitly by `nix-instantiate`).
|
||||||
|
|
||||||
- store\
|
- [store]{#gloss-store}\
|
||||||
The location in the file system where store objects live. Typically
|
The location in the file system where store objects live. Typically
|
||||||
`/nix/store`.
|
`/nix/store`.
|
||||||
|
|
||||||
- store path\
|
- [store path]{#gloss-store-path}\
|
||||||
The location in the file system of a store object, i.e., an
|
The location in the file system of a store object, i.e., an
|
||||||
immediate child of the Nix store directory.
|
immediate child of the Nix store directory.
|
||||||
|
|
||||||
- store object\
|
- [store object]{#gloss-store-object}\
|
||||||
A file that is an immediate child of the Nix store directory. These
|
A file that is an immediate child of the Nix store directory. These
|
||||||
can be regular files, but also entire directory trees. Store objects
|
can be regular files, but also entire directory trees. Store objects
|
||||||
can be sources (objects copied from outside of the store),
|
can be sources (objects copied from outside of the store),
|
||||||
derivation outputs (objects produced by running a build action), or
|
derivation outputs (objects produced by running a build action), or
|
||||||
derivations (files describing a build action).
|
derivations (files describing a build action).
|
||||||
|
|
||||||
- substitute\
|
- [substitute]{#gloss-substitute}\
|
||||||
A substitute is a command invocation stored in the Nix database that
|
A substitute is a command invocation stored in the Nix database that
|
||||||
describes how to build a store object, bypassing the normal build
|
describes how to build a store object, bypassing the normal build
|
||||||
mechanism (i.e., derivations). Typically, the substitute builds the
|
mechanism (i.e., derivations). Typically, the substitute builds the
|
||||||
store object by downloading a pre-built version of the store object
|
store object by downloading a pre-built version of the store object
|
||||||
from some server.
|
from some server.
|
||||||
|
|
||||||
- purity\
|
- [purity]{#gloss-purity}\
|
||||||
The assumption that equal Nix derivations when run always produce
|
The assumption that equal Nix derivations when run always produce
|
||||||
the same output. This cannot be guaranteed in general (e.g., a
|
the same output. This cannot be guaranteed in general (e.g., a
|
||||||
builder can rely on external inputs such as the network or the
|
builder can rely on external inputs such as the network or the
|
||||||
system time) but the Nix model assumes it.
|
system time) but the Nix model assumes it.
|
||||||
|
|
||||||
- Nix expression\
|
- [Nix expression]{#gloss-nix-expression}\
|
||||||
A high-level description of software packages and compositions
|
A high-level description of software packages and compositions
|
||||||
thereof. Deploying software using Nix entails writing Nix
|
thereof. Deploying software using Nix entails writing Nix
|
||||||
expressions for your packages. Nix expressions are translated to
|
expressions for your packages. Nix expressions are translated to
|
||||||
derivations that are stored in the Nix store. These derivations can
|
derivations that are stored in the Nix store. These derivations can
|
||||||
then be built.
|
then be built.
|
||||||
|
|
||||||
- reference\
|
- [reference]{#gloss-reference}\
|
||||||
A store path `P` is said to have a reference to a store path `Q` if
|
A store path `P` is said to have a reference to a store path `Q` if
|
||||||
the store object at `P` contains the path `Q` somewhere. The
|
the store object at `P` contains the path `Q` somewhere. The
|
||||||
*references* of a store path are the set of store paths to which it
|
*references* of a store path are the set of store paths to which it
|
||||||
|
|
@ -52,11 +52,11 @@
|
||||||
output paths), whereas an output path only references other output
|
output paths), whereas an output path only references other output
|
||||||
paths.
|
paths.
|
||||||
|
|
||||||
- reachable\
|
- [reachable]{#gloss-reachable}\
|
||||||
A store path `Q` is reachable from another store path `P` if `Q`
|
A store path `Q` is reachable from another store path `P` if `Q`
|
||||||
is in the *closure* of the *references* relation.
|
is in the *closure* of the *references* relation.
|
||||||
|
|
||||||
- closure\
|
- [closure]{#gloss-closure}\
|
||||||
The closure of a store path is the set of store paths that are
|
The closure of a store path is the set of store paths that are
|
||||||
directly or indirectly “reachable” from that store path; that is,
|
directly or indirectly “reachable” from that store path; that is,
|
||||||
it’s the closure of the path under the *references* relation. For
|
it’s the closure of the path under the *references* relation. For
|
||||||
|
|
@ -71,34 +71,34 @@
|
||||||
to path `Q`, then `Q` is in the closure of `P`. Further, if `Q`
|
to path `Q`, then `Q` is in the closure of `P`. Further, if `Q`
|
||||||
references `R` then `R` is also in the closure of `P`.
|
references `R` then `R` is also in the closure of `P`.
|
||||||
|
|
||||||
- output path\
|
- [output path]{#gloss-output-path}\
|
||||||
A store path produced by a derivation.
|
A store path produced by a derivation.
|
||||||
|
|
||||||
- deriver\
|
- [deriver]{#gloss-deriver}\
|
||||||
The deriver of an *output path* is the store
|
The deriver of an *output path* is the store
|
||||||
derivation that built it.
|
derivation that built it.
|
||||||
|
|
||||||
- validity\
|
- [validity]{#gloss-validity}\
|
||||||
A store path is considered *valid* if it exists in the file system,
|
A store path is considered *valid* if it exists in the file system,
|
||||||
is listed in the Nix database as being valid, and if all paths in
|
is listed in the Nix database as being valid, and if all paths in
|
||||||
its closure are also valid.
|
its closure are also valid.
|
||||||
|
|
||||||
- user environment\
|
- [user environment]{#gloss-user-env}\
|
||||||
An automatically generated store object that consists of a set of
|
An automatically generated store object that consists of a set of
|
||||||
symlinks to “active” applications, i.e., other store paths. These
|
symlinks to “active” applications, i.e., other store paths. These
|
||||||
are generated automatically by
|
are generated automatically by
|
||||||
[`nix-env`](command-ref/nix-env.md). See *profiles*.
|
[`nix-env`](command-ref/nix-env.md). See *profiles*.
|
||||||
|
|
||||||
- profile\
|
- [profile]{#gloss-profile}\
|
||||||
A symlink to the current *user environment* of a user, e.g.,
|
A symlink to the current *user environment* of a user, e.g.,
|
||||||
`/nix/var/nix/profiles/default`.
|
`/nix/var/nix/profiles/default`.
|
||||||
|
|
||||||
- NAR\
|
- [NAR]{#gloss-nar}\
|
||||||
A *N*ix *AR*chive. This is a serialisation of a path in the Nix
|
A *N*ix *AR*chive. This is a serialisation of a path in the Nix
|
||||||
store. It can contain regular files, directories and symbolic
|
store. It can contain regular files, directories and symbolic
|
||||||
links. NARs are generated and unpacked using `nix-store --dump`
|
links. NARs are generated and unpacked using `nix-store --dump`
|
||||||
and `nix-store --restore`.
|
and `nix-store --restore`.
|
||||||
- `∅` \
|
- [`∅`]{#gloss-emtpy-set}\
|
||||||
The empty set symbol. In the context of profile history, this denotes a package is not present in a particular version of the profile.
|
The empty set symbol. In the context of profile history, this denotes a package is not present in a particular version of the profile.
|
||||||
- `ε` \
|
- [`ε`]{#gloss-epsilon}\
|
||||||
The epsilon symbol. In the context of a package, this means the version is empty. More precisely, the derivation does not have a version attribute.
|
The epsilon symbol. In the context of a package, this means the version is empty. More precisely, the derivation does not have a version attribute.
|
||||||
|
|
|
||||||
|
|
@ -186,7 +186,8 @@ and `/etc/zshrc` which you may remove.
|
||||||
> read-only root will prevent you from manually deleting the empty `/nix`
|
> read-only root will prevent you from manually deleting the empty `/nix`
|
||||||
> mountpoint.
|
> mountpoint.
|
||||||
|
|
||||||
# macOS Installation <a name="sect-macos-installation-change-store-prefix"></a><a name="sect-macos-installation-encrypted-volume"></a><a name="sect-macos-installation-symlink"></a><a name="sect-macos-installation-recommended-notes"></a>
|
# macOS Installation
|
||||||
|
[]{#sect-macos-installation-change-store-prefix}[]{#sect-macos-installation-encrypted-volume}[]{#sect-macos-installation-symlink}[]{#sect-macos-installation-recommended-notes}
|
||||||
<!-- Note: anchors above to catch permalinks to old explanations -->
|
<!-- Note: anchors above to catch permalinks to old explanations -->
|
||||||
|
|
||||||
We believe we have ironed out how to cleanly support the read-only root
|
We believe we have ironed out how to cleanly support the read-only root
|
||||||
|
|
|
||||||
31
doc/manual/src/release-notes/rl-2.10.md
Normal file
31
doc/manual/src/release-notes/rl-2.10.md
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
# Release 2.10 (2022-07-11)
|
||||||
|
|
||||||
|
* `nix repl` now takes installables on the command line, unifying the usage
|
||||||
|
with other commands that use `--file` and `--expr`. Primary breaking change
|
||||||
|
is for the common usage of `nix repl '<nixpkgs>'` which can be recovered with
|
||||||
|
`nix repl --file '<nixpkgs>'` or `nix repl --expr 'import <nixpkgs>{}'`.
|
||||||
|
|
||||||
|
This is currently guarded by the `repl-flake` experimental feature.
|
||||||
|
|
||||||
|
* A new function `builtins.traceVerbose` is available. It is similar
|
||||||
|
to `builtins.trace` if the `trace-verbose` setting is set to true,
|
||||||
|
and it is a no-op otherwise.
|
||||||
|
|
||||||
|
* `nix search` has a new flag `--exclude` to filter out packages.
|
||||||
|
|
||||||
|
* On Linux, if `/nix` doesn't exist and cannot be created and you're
|
||||||
|
not running as root, Nix will automatically use
|
||||||
|
`~/.local/share/nix/root` as a chroot store. This enables non-root
|
||||||
|
users to download the statically linked Nix binary and have it work
|
||||||
|
out of the box, e.g.
|
||||||
|
|
||||||
|
```
|
||||||
|
# ~/nix run nixpkgs#hello
|
||||||
|
warning: '/nix' does not exists, so Nix will use '/home/ubuntu/.local/share/nix/root' as a chroot store
|
||||||
|
Hello, world!
|
||||||
|
```
|
||||||
|
|
||||||
|
* `flake-registry.json` is now fetched from `channels.nixos.org`.
|
||||||
|
|
||||||
|
* Nix can now be built with LTO by passing `--enable-lto` to `configure`.
|
||||||
|
LTO is currently only supported when building with GCC.
|
||||||
47
doc/manual/src/release-notes/rl-2.9.md
Normal file
47
doc/manual/src/release-notes/rl-2.9.md
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
# Release 2.9 (2022-05-30)
|
||||||
|
|
||||||
|
* Running Nix with the new `--debugger` flag will cause it to start a
|
||||||
|
repl session if an exception is thrown during evaluation, or if
|
||||||
|
`builtins.break` is called. From there you can inspect the values
|
||||||
|
of variables and evaluate Nix expressions. In debug mode, the
|
||||||
|
following new repl commands are available:
|
||||||
|
|
||||||
|
```
|
||||||
|
:env Show env stack
|
||||||
|
:bt Show trace stack
|
||||||
|
:st Show current trace
|
||||||
|
:st <idx> Change to another trace in the stack
|
||||||
|
:c Go until end of program, exception, or builtins.break().
|
||||||
|
:s Go one step
|
||||||
|
```
|
||||||
|
|
||||||
|
Read more about the debugger
|
||||||
|
[here](https://www.zknotes.com/note/5970).
|
||||||
|
|
||||||
|
* Nix now provides better integration with zsh's `run-help`
|
||||||
|
feature. It is now included in the Nix installation in the form of
|
||||||
|
an autoloadable shell function, `run-help-nix`. It picks up Nix
|
||||||
|
subcommands from the currently typed in command and directs the user
|
||||||
|
to the associated man pages.
|
||||||
|
|
||||||
|
* `nix repl` has a new build-and-link (`:bl`) command that builds a
|
||||||
|
derivation while creating GC root symlinks.
|
||||||
|
|
||||||
|
* The path produced by `builtins.toFile` is now allowed to be imported
|
||||||
|
or read even with restricted evaluation. Note that this will not
|
||||||
|
work with a read-only store.
|
||||||
|
|
||||||
|
* `nix build` has a new `--print-out-paths` flag to print the
|
||||||
|
resulting output paths. This matches the default behaviour of
|
||||||
|
`nix-build`.
|
||||||
|
|
||||||
|
* You can now specify which outputs of a derivation `nix` should
|
||||||
|
operate on using the syntax `installable^outputs`,
|
||||||
|
e.g. `nixpkgs#glibc^dev,static` or `nixpkgs#glibc^*`. By default,
|
||||||
|
`nix` will use the outputs specified by the derivation's
|
||||||
|
`meta.outputsToInstall` attribute if it exists, or all outputs
|
||||||
|
otherwise.
|
||||||
|
|
||||||
|
* `builtins.fetchTree` (and flake inputs) can now be used to fetch
|
||||||
|
plain files over the `http(s)` and `file` protocols in addition to
|
||||||
|
directory tarballs.
|
||||||
|
|
@ -1,26 +1,2 @@
|
||||||
# Release X.Y (202?-??-??)
|
# Release X.Y (202?-??-??)
|
||||||
|
|
||||||
* Nix now provides better integration with zsh's run-help feature. It is now
|
|
||||||
included in the Nix installation in the form of an autoloadable shell
|
|
||||||
function, run-help-nix. It picks up Nix subcommands from the currently typed
|
|
||||||
in command and directs the user to the associated man pages.
|
|
||||||
|
|
||||||
* `nix repl` has a new build-'n-link (`:bl`) command that builds a derivation
|
|
||||||
while creating GC root symlinks.
|
|
||||||
|
|
||||||
* The path produced by `builtins.toFile` is now allowed to be imported or read
|
|
||||||
even with restricted evaluation. Note that this will not work with a
|
|
||||||
read-only store.
|
|
||||||
|
|
||||||
* `nix build` has a new `--print-out-paths` flag to print the resulting output paths.
|
|
||||||
This matches the default behaviour of `nix-build`.
|
|
||||||
|
|
||||||
* You can now specify which outputs of a derivation `nix` should
|
|
||||||
operate on using the syntax `installable^outputs`,
|
|
||||||
e.g. `nixpkgs#glibc^dev,static` or `nixpkgs#glibc^*`. By default,
|
|
||||||
`nix` will use the outputs specified by the derivation's
|
|
||||||
`meta.outputsToInstall` attribute if it exists, or all outputs
|
|
||||||
otherwise.
|
|
||||||
|
|
||||||
Selecting derivation outputs using the attribute selection syntax
|
|
||||||
(e.g. `nixpkgs#glibc.dev`) no longer works.
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@
|
||||||
, tag ? "latest"
|
, tag ? "latest"
|
||||||
, channelName ? "nixpkgs"
|
, channelName ? "nixpkgs"
|
||||||
, channelURL ? "https://nixos.org/channels/nixpkgs-unstable"
|
, channelURL ? "https://nixos.org/channels/nixpkgs-unstable"
|
||||||
|
, extraPkgs ? []
|
||||||
|
, maxLayers ? 100
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
defaultPkgs = with pkgs; [
|
defaultPkgs = with pkgs; [
|
||||||
|
|
@ -23,7 +25,7 @@ let
|
||||||
iana-etc
|
iana-etc
|
||||||
git
|
git
|
||||||
openssh
|
openssh
|
||||||
];
|
] ++ extraPkgs;
|
||||||
|
|
||||||
users = {
|
users = {
|
||||||
|
|
||||||
|
|
@ -229,7 +231,7 @@ let
|
||||||
in
|
in
|
||||||
pkgs.dockerTools.buildLayeredImageWithNixDb {
|
pkgs.dockerTools.buildLayeredImageWithNixDb {
|
||||||
|
|
||||||
inherit name tag;
|
inherit name tag maxLayers;
|
||||||
|
|
||||||
contents = [ baseSystem ];
|
contents = [ baseSystem ];
|
||||||
|
|
||||||
|
|
|
||||||
18
flake.lock
generated
18
flake.lock
generated
|
|
@ -18,17 +18,18 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1645296114,
|
"lastModified": 1657693803,
|
||||||
"narHash": "sha256-y53N7TyIkXsjMpOG7RhvqJFGDacLs9HlyHeSTBioqYU=",
|
"narHash": "sha256-G++2CJ9u0E7NNTAi9n5G8TdDmGJXcIjkJ3NF8cetQB8=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "530a53dcbc9437363471167a5e4762c5fcfa34a1",
|
"rev": "365e1b3a859281cf11b94f87231adeabbdd878a2",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"id": "nixpkgs",
|
"owner": "NixOS",
|
||||||
"ref": "nixos-21.05-small",
|
"ref": "nixos-22.05-small",
|
||||||
"type": "indirect"
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixpkgs-regression": {
|
"nixpkgs-regression": {
|
||||||
|
|
@ -41,9 +42,10 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"id": "nixpkgs",
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
"rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2",
|
"rev": "215d4d0fd80ca5163643b03a33fde804a29cc1e2",
|
||||||
"type": "indirect"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
|
|
|
||||||
110
flake.nix
110
flake.nix
|
|
@ -1,8 +1,8 @@
|
||||||
{
|
{
|
||||||
description = "The purely functional package manager";
|
description = "The purely functional package manager";
|
||||||
|
|
||||||
inputs.nixpkgs.url = "nixpkgs/nixos-21.05-small";
|
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05-small";
|
||||||
inputs.nixpkgs-regression.url = "nixpkgs/215d4d0fd80ca5163643b03a33fde804a29cc1e2";
|
inputs.nixpkgs-regression.url = "github:NixOS/nixpkgs/215d4d0fd80ca5163643b03a33fde804a29cc1e2";
|
||||||
inputs.lowdown-src = { url = "github:kristapsdz/lowdown"; flake = false; };
|
inputs.lowdown-src = { url = "github:kristapsdz/lowdown"; flake = false; };
|
||||||
|
|
||||||
outputs = { self, nixpkgs, nixpkgs-regression, lowdown-src }:
|
outputs = { self, nixpkgs, nixpkgs-regression, lowdown-src }:
|
||||||
|
|
@ -36,7 +36,7 @@
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
forAllStdenvs = stdenvs: f: nixpkgs.lib.genAttrs stdenvs (stdenv: f stdenv);
|
forAllStdenvs = f: nixpkgs.lib.genAttrs stdenvs (stdenv: f stdenv);
|
||||||
|
|
||||||
# Memoize nixpkgs for different platforms for efficiency.
|
# Memoize nixpkgs for different platforms for efficiency.
|
||||||
nixpkgsFor =
|
nixpkgsFor =
|
||||||
|
|
@ -54,7 +54,7 @@
|
||||||
# we want most of the time and for backwards compatibility
|
# we want most of the time and for backwards compatibility
|
||||||
forAllSystems (system: stdenvsPackages.${system} // stdenvsPackages.${system}.stdenvPackages);
|
forAllSystems (system: stdenvsPackages.${system} // stdenvsPackages.${system}.stdenvPackages);
|
||||||
|
|
||||||
commonDeps = pkgs: with pkgs; rec {
|
commonDeps = { pkgs, isStatic ? false }: with pkgs; rec {
|
||||||
# Use "busybox-sandbox-shell" if present,
|
# Use "busybox-sandbox-shell" if present,
|
||||||
# if not (legacy) fallback and hope it's sufficient.
|
# if not (legacy) fallback and hope it's sufficient.
|
||||||
sh = pkgs.busybox-sandbox-shell or (busybox.override {
|
sh = pkgs.busybox-sandbox-shell or (busybox.override {
|
||||||
|
|
@ -85,10 +85,11 @@
|
||||||
lib.optionals stdenv.isLinux [
|
lib.optionals stdenv.isLinux [
|
||||||
"--with-boost=${boost}/lib"
|
"--with-boost=${boost}/lib"
|
||||||
"--with-sandbox-shell=${sh}/bin/busybox"
|
"--with-sandbox-shell=${sh}/bin/busybox"
|
||||||
|
]
|
||||||
|
++ lib.optionals (stdenv.isLinux && !(isStatic && stdenv.system == "aarch64-linux")) [
|
||||||
"LDFLAGS=-fuse-ld=gold"
|
"LDFLAGS=-fuse-ld=gold"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
nativeBuildDeps =
|
nativeBuildDeps =
|
||||||
[
|
[
|
||||||
buildPackages.bison
|
buildPackages.bison
|
||||||
|
|
@ -102,12 +103,12 @@
|
||||||
# Tests
|
# Tests
|
||||||
buildPackages.git
|
buildPackages.git
|
||||||
buildPackages.mercurial # FIXME: remove? only needed for tests
|
buildPackages.mercurial # FIXME: remove? only needed for tests
|
||||||
buildPackages.jq
|
buildPackages.jq # Also for custom mdBook preprocessor.
|
||||||
]
|
]
|
||||||
++ lib.optionals stdenv.hostPlatform.isLinux [(buildPackages.util-linuxMinimal or buildPackages.utillinuxMinimal)];
|
++ lib.optionals stdenv.hostPlatform.isLinux [(buildPackages.util-linuxMinimal or buildPackages.utillinuxMinimal)];
|
||||||
|
|
||||||
buildDeps =
|
buildDeps =
|
||||||
[ curl
|
[ (curl.override { patchNetrcRegression = true; })
|
||||||
bzip2 xz brotli editline
|
bzip2 xz brotli editline
|
||||||
openssl sqlite
|
openssl sqlite
|
||||||
libarchive
|
libarchive
|
||||||
|
|
@ -135,11 +136,6 @@
|
||||||
}))
|
}))
|
||||||
nlohmann_json
|
nlohmann_json
|
||||||
];
|
];
|
||||||
|
|
||||||
perlDeps =
|
|
||||||
[ perl
|
|
||||||
perlPackages.DBDSQLite
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
installScriptFor = systems:
|
installScriptFor = systems:
|
||||||
|
|
@ -176,7 +172,7 @@
|
||||||
echo "file installer $out/install" >> $out/nix-support/hydra-build-products
|
echo "file installer $out/install" >> $out/nix-support/hydra-build-products
|
||||||
'';
|
'';
|
||||||
|
|
||||||
testNixVersions = pkgs: client: daemon: with commonDeps pkgs; with pkgs.lib; pkgs.stdenv.mkDerivation {
|
testNixVersions = pkgs: client: daemon: with commonDeps { inherit pkgs; }; with pkgs.lib; pkgs.stdenv.mkDerivation {
|
||||||
NIX_DAEMON_PACKAGE = daemon;
|
NIX_DAEMON_PACKAGE = daemon;
|
||||||
NIX_CLIENT_PACKAGE = client;
|
NIX_CLIENT_PACKAGE = client;
|
||||||
name =
|
name =
|
||||||
|
|
@ -287,7 +283,7 @@
|
||||||
# Forward from the previous stage as we don’t want it to pick the lowdown override
|
# Forward from the previous stage as we don’t want it to pick the lowdown override
|
||||||
nixUnstable = prev.nixUnstable;
|
nixUnstable = prev.nixUnstable;
|
||||||
|
|
||||||
nix = with final; with commonDeps pkgs; currentStdenv.mkDerivation {
|
nix = with final; with commonDeps { inherit pkgs; }; currentStdenv.mkDerivation {
|
||||||
name = "nix-${version}";
|
name = "nix-${version}";
|
||||||
inherit version;
|
inherit version;
|
||||||
|
|
||||||
|
|
@ -319,6 +315,7 @@
|
||||||
for LIB in $out/lib/*.dylib; do
|
for LIB in $out/lib/*.dylib; do
|
||||||
chmod u+w $LIB
|
chmod u+w $LIB
|
||||||
install_name_tool -id $LIB $LIB
|
install_name_tool -id $LIB $LIB
|
||||||
|
install_name_tool -delete_rpath ${boost}/lib/ $LIB || true
|
||||||
done
|
done
|
||||||
install_name_tool -change ${boost}/lib/libboost_system.dylib $out/lib/libboost_system.dylib $out/lib/libboost_thread.dylib
|
install_name_tool -change ${boost}/lib/libboost_system.dylib $out/lib/libboost_system.dylib $out/lib/libboost_thread.dylib
|
||||||
''}
|
''}
|
||||||
|
|
@ -353,7 +350,7 @@
|
||||||
|
|
||||||
strictDeps = true;
|
strictDeps = true;
|
||||||
|
|
||||||
passthru.perl-bindings = with final; currentStdenv.mkDerivation {
|
passthru.perl-bindings = with final; perl.pkgs.toPerlModule (currentStdenv.mkDerivation {
|
||||||
name = "nix-perl-${version}";
|
name = "nix-perl-${version}";
|
||||||
|
|
||||||
src = self;
|
src = self;
|
||||||
|
|
@ -366,7 +363,7 @@
|
||||||
|
|
||||||
buildInputs =
|
buildInputs =
|
||||||
[ nix
|
[ nix
|
||||||
curl
|
(curl.override { patchNetrcRegression = true; })
|
||||||
bzip2
|
bzip2
|
||||||
xz
|
xz
|
||||||
pkgs.perl
|
pkgs.perl
|
||||||
|
|
@ -375,16 +372,17 @@
|
||||||
++ lib.optional (currentStdenv.isLinux || currentStdenv.isDarwin) libsodium
|
++ lib.optional (currentStdenv.isLinux || currentStdenv.isDarwin) libsodium
|
||||||
++ lib.optional currentStdenv.isDarwin darwin.apple_sdk.frameworks.Security;
|
++ lib.optional currentStdenv.isDarwin darwin.apple_sdk.frameworks.Security;
|
||||||
|
|
||||||
configureFlags = ''
|
configureFlags = [
|
||||||
--with-dbi=${perlPackages.DBI}/${pkgs.perl.libPrefix}
|
"--with-dbi=${perlPackages.DBI}/${pkgs.perl.libPrefix}"
|
||||||
--with-dbd-sqlite=${perlPackages.DBDSQLite}/${pkgs.perl.libPrefix}
|
"--with-dbd-sqlite=${perlPackages.DBDSQLite}/${pkgs.perl.libPrefix}"
|
||||||
'';
|
];
|
||||||
|
|
||||||
enableParallelBuilding = true;
|
enableParallelBuilding = true;
|
||||||
|
|
||||||
postUnpack = "sourceRoot=$sourceRoot/perl";
|
postUnpack = "sourceRoot=$sourceRoot/perl";
|
||||||
};
|
});
|
||||||
|
|
||||||
|
meta.platforms = systems;
|
||||||
};
|
};
|
||||||
|
|
||||||
lowdown-nix = with final; currentStdenv.mkDerivation rec {
|
lowdown-nix = with final; currentStdenv.mkDerivation rec {
|
||||||
|
|
@ -409,7 +407,7 @@
|
||||||
|
|
||||||
# A Nixpkgs overlay that overrides the 'nix' and
|
# A Nixpkgs overlay that overrides the 'nix' and
|
||||||
# 'nix.perl-bindings' packages.
|
# 'nix.perl-bindings' packages.
|
||||||
overlay = overlayFor (p: p.stdenv);
|
overlays.default = overlayFor (p: p.stdenv);
|
||||||
|
|
||||||
hydraJobs = {
|
hydraJobs = {
|
||||||
|
|
||||||
|
|
@ -434,7 +432,7 @@
|
||||||
value = let
|
value = let
|
||||||
nixpkgsCross = import nixpkgs {
|
nixpkgsCross = import nixpkgs {
|
||||||
inherit system crossSystem;
|
inherit system crossSystem;
|
||||||
overlays = [ self.overlay ];
|
overlays = [ self.overlays.default ];
|
||||||
};
|
};
|
||||||
in binaryTarball nixpkgsFor.${system} self.packages.${system}."nix-${crossSystem}" nixpkgsCross;
|
in binaryTarball nixpkgsFor.${system} self.packages.${system}."nix-${crossSystem}" nixpkgsCross;
|
||||||
}) crossSystems));
|
}) crossSystems));
|
||||||
|
|
@ -452,7 +450,7 @@
|
||||||
# Line coverage analysis.
|
# Line coverage analysis.
|
||||||
coverage =
|
coverage =
|
||||||
with nixpkgsFor.x86_64-linux;
|
with nixpkgsFor.x86_64-linux;
|
||||||
with commonDeps pkgs;
|
with commonDeps { inherit pkgs; };
|
||||||
|
|
||||||
releaseTools.coverageAnalysis {
|
releaseTools.coverageAnalysis {
|
||||||
name = "nix-coverage-${version}";
|
name = "nix-coverage-${version}";
|
||||||
|
|
@ -480,31 +478,31 @@
|
||||||
tests.remoteBuilds = import ./tests/remote-builds.nix {
|
tests.remoteBuilds = import ./tests/remote-builds.nix {
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
inherit nixpkgs;
|
inherit nixpkgs;
|
||||||
inherit (self) overlay;
|
overlay = self.overlays.default;
|
||||||
};
|
};
|
||||||
|
|
||||||
tests.nix-copy-closure = import ./tests/nix-copy-closure.nix {
|
tests.nix-copy-closure = import ./tests/nix-copy-closure.nix {
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
inherit nixpkgs;
|
inherit nixpkgs;
|
||||||
inherit (self) overlay;
|
overlay = self.overlays.default;
|
||||||
};
|
};
|
||||||
|
|
||||||
tests.nssPreload = (import ./tests/nss-preload.nix rec {
|
tests.nssPreload = (import ./tests/nss-preload.nix rec {
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
inherit nixpkgs;
|
inherit nixpkgs;
|
||||||
inherit (self) overlay;
|
overlay = self.overlays.default;
|
||||||
});
|
});
|
||||||
|
|
||||||
tests.githubFlakes = (import ./tests/github-flakes.nix rec {
|
tests.githubFlakes = (import ./tests/github-flakes.nix rec {
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
inherit nixpkgs;
|
inherit nixpkgs;
|
||||||
inherit (self) overlay;
|
overlay = self.overlays.default;
|
||||||
});
|
});
|
||||||
|
|
||||||
tests.sourcehutFlakes = (import ./tests/sourcehut-flakes.nix rec {
|
tests.sourcehutFlakes = (import ./tests/sourcehut-flakes.nix rec {
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
inherit nixpkgs;
|
inherit nixpkgs;
|
||||||
inherit (self) overlay;
|
overlay = self.overlays.default;
|
||||||
});
|
});
|
||||||
|
|
||||||
tests.setuid = nixpkgs.lib.genAttrs
|
tests.setuid = nixpkgs.lib.genAttrs
|
||||||
|
|
@ -512,7 +510,7 @@
|
||||||
(system:
|
(system:
|
||||||
import ./tests/setuid.nix rec {
|
import ./tests/setuid.nix rec {
|
||||||
inherit nixpkgs system;
|
inherit nixpkgs system;
|
||||||
inherit (self) overlay;
|
overlay = self.overlays.default;
|
||||||
});
|
});
|
||||||
|
|
||||||
# Make sure that nix-env still produces the exact same result
|
# Make sure that nix-env still produces the exact same result
|
||||||
|
|
@ -557,12 +555,13 @@
|
||||||
dockerImage = self.hydraJobs.dockerImage.${system};
|
dockerImage = self.hydraJobs.dockerImage.${system};
|
||||||
});
|
});
|
||||||
|
|
||||||
packages = forAllSystems (system: {
|
packages = forAllSystems (system: rec {
|
||||||
inherit (nixpkgsFor.${system}) nix;
|
inherit (nixpkgsFor.${system}) nix;
|
||||||
|
default = nix;
|
||||||
} // (nixpkgs.lib.optionalAttrs (builtins.elem system linux64BitSystems) {
|
} // (nixpkgs.lib.optionalAttrs (builtins.elem system linux64BitSystems) {
|
||||||
nix-static = let
|
nix-static = let
|
||||||
nixpkgs = nixpkgsFor.${system}.pkgsStatic;
|
nixpkgs = nixpkgsFor.${system}.pkgsStatic;
|
||||||
in with commonDeps nixpkgs; nixpkgs.stdenv.mkDerivation {
|
in with commonDeps { pkgs = nixpkgs; isStatic = true; }; nixpkgs.stdenv.mkDerivation {
|
||||||
name = "nix-${version}";
|
name = "nix-${version}";
|
||||||
|
|
||||||
src = self;
|
src = self;
|
||||||
|
|
@ -574,14 +573,24 @@
|
||||||
nativeBuildInputs = nativeBuildDeps;
|
nativeBuildInputs = nativeBuildDeps;
|
||||||
buildInputs = buildDeps ++ propagatedDeps;
|
buildInputs = buildDeps ++ propagatedDeps;
|
||||||
|
|
||||||
configureFlags = [ "--sysconfdir=/etc" ];
|
# Work around pkgsStatic disabling all tests.
|
||||||
|
# Remove in NixOS 22.11, see https://github.com/NixOS/nixpkgs/pull/140271.
|
||||||
|
preHook =
|
||||||
|
''
|
||||||
|
doCheck=1
|
||||||
|
doInstallCheck=1
|
||||||
|
'';
|
||||||
|
|
||||||
|
configureFlags =
|
||||||
|
configureFlags ++
|
||||||
|
[ "--sysconfdir=/etc"
|
||||||
|
"--enable-embedded-sandbox-shell"
|
||||||
|
];
|
||||||
|
|
||||||
enableParallelBuilding = true;
|
enableParallelBuilding = true;
|
||||||
|
|
||||||
makeFlags = "profiledir=$(out)/etc/profile.d";
|
makeFlags = "profiledir=$(out)/etc/profile.d";
|
||||||
|
|
||||||
doCheck = true;
|
|
||||||
|
|
||||||
installFlags = "sysconfdir=$(out)/etc";
|
installFlags = "sysconfdir=$(out)/etc";
|
||||||
|
|
||||||
postInstall = ''
|
postInstall = ''
|
||||||
|
|
@ -591,7 +600,6 @@
|
||||||
echo "file binary-dist $out/bin/nix" >> $out/nix-support/hydra-build-products
|
echo "file binary-dist $out/bin/nix" >> $out/nix-support/hydra-build-products
|
||||||
'';
|
'';
|
||||||
|
|
||||||
doInstallCheck = true;
|
|
||||||
installCheckFlags = "sysconfdir=$(out)/etc";
|
installCheckFlags = "sysconfdir=$(out)/etc";
|
||||||
|
|
||||||
stripAllList = ["bin"];
|
stripAllList = ["bin"];
|
||||||
|
|
@ -600,6 +608,7 @@
|
||||||
|
|
||||||
hardeningDisable = [ "pie" ];
|
hardeningDisable = [ "pie" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
dockerImage =
|
dockerImage =
|
||||||
let
|
let
|
||||||
pkgs = nixpkgsFor.${system};
|
pkgs = nixpkgsFor.${system};
|
||||||
|
|
@ -614,14 +623,16 @@
|
||||||
ln -s ${image} $image
|
ln -s ${image} $image
|
||||||
echo "file binary-dist $image" >> $out/nix-support/hydra-build-products
|
echo "file binary-dist $image" >> $out/nix-support/hydra-build-products
|
||||||
'';
|
'';
|
||||||
} // builtins.listToAttrs (map (crossSystem: {
|
}
|
||||||
|
|
||||||
|
// builtins.listToAttrs (map (crossSystem: {
|
||||||
name = "nix-${crossSystem}";
|
name = "nix-${crossSystem}";
|
||||||
value = let
|
value = let
|
||||||
nixpkgsCross = import nixpkgs {
|
nixpkgsCross = import nixpkgs {
|
||||||
inherit system crossSystem;
|
inherit system crossSystem;
|
||||||
overlays = [ self.overlay ];
|
overlays = [ self.overlays.default ];
|
||||||
};
|
};
|
||||||
in with commonDeps nixpkgsCross; nixpkgsCross.stdenv.mkDerivation {
|
in with commonDeps { pkgs = nixpkgsCross; }; nixpkgsCross.stdenv.mkDerivation {
|
||||||
name = "nix-${version}";
|
name = "nix-${version}";
|
||||||
|
|
||||||
src = self;
|
src = self;
|
||||||
|
|
@ -653,27 +664,25 @@
|
||||||
doInstallCheck = true;
|
doInstallCheck = true;
|
||||||
installCheckFlags = "sysconfdir=$(out)/etc";
|
installCheckFlags = "sysconfdir=$(out)/etc";
|
||||||
};
|
};
|
||||||
}) crossSystems)) // (builtins.listToAttrs (map (stdenvName:
|
}) (if system == "x86_64-linux" then crossSystems else [])))
|
||||||
|
|
||||||
|
// (builtins.listToAttrs (map (stdenvName:
|
||||||
nixpkgsFor.${system}.lib.nameValuePair
|
nixpkgsFor.${system}.lib.nameValuePair
|
||||||
"nix-${stdenvName}"
|
"nix-${stdenvName}"
|
||||||
nixpkgsFor.${system}."${stdenvName}Packages".nix
|
nixpkgsFor.${system}."${stdenvName}Packages".nix
|
||||||
) stdenvs)));
|
) stdenvs)));
|
||||||
|
|
||||||
defaultPackage = forAllSystems (system: self.packages.${system}.nix);
|
devShells = forAllSystems (system:
|
||||||
|
forAllStdenvs (stdenv:
|
||||||
devShell = forAllSystems (system: self.devShells.${system}.stdenvPackages);
|
|
||||||
|
|
||||||
devShells = forAllSystemsAndStdenvs (system: stdenv:
|
|
||||||
with nixpkgsFor.${system};
|
with nixpkgsFor.${system};
|
||||||
with commonDeps pkgs;
|
with commonDeps { inherit pkgs; };
|
||||||
|
|
||||||
nixpkgsFor.${system}.${stdenv}.mkDerivation {
|
nixpkgsFor.${system}.${stdenv}.mkDerivation {
|
||||||
name = "nix";
|
name = "nix";
|
||||||
|
|
||||||
outputs = [ "out" "dev" "doc" ];
|
outputs = [ "out" "dev" "doc" ];
|
||||||
|
|
||||||
nativeBuildInputs = nativeBuildDeps;
|
nativeBuildInputs = nativeBuildDeps;
|
||||||
buildInputs = buildDeps ++ propagatedDeps ++ awsDeps ++ perlDeps;
|
buildInputs = buildDeps ++ propagatedDeps ++ awsDeps;
|
||||||
|
|
||||||
inherit configureFlags;
|
inherit configureFlags;
|
||||||
|
|
||||||
|
|
@ -690,7 +699,10 @@
|
||||||
# Make bash completion work.
|
# Make bash completion work.
|
||||||
XDG_DATA_DIRS+=:$out/share
|
XDG_DATA_DIRS+=:$out/share
|
||||||
'';
|
'';
|
||||||
});
|
}
|
||||||
|
)
|
||||||
|
// { default = self.devShells.${system}.stdenv; }
|
||||||
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ ConditionPathIsReadWrite=@localstatedir@/nix/daemon-socket
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=@@bindir@/nix-daemon nix-daemon --daemon
|
ExecStart=@@bindir@/nix-daemon nix-daemon --daemon
|
||||||
KillMode=process
|
KillMode=process
|
||||||
|
LimitNOFILE=4096
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ define build-library
|
||||||
$(1)_PATH := $$(_d)/$$($(1)_NAME).$(SO_EXT)
|
$(1)_PATH := $$(_d)/$$($(1)_NAME).$(SO_EXT)
|
||||||
|
|
||||||
$$($(1)_PATH): $$($(1)_OBJS) $$(_libs) | $$(_d)/
|
$$($(1)_PATH): $$($(1)_OBJS) $$(_libs) | $$(_d)/
|
||||||
$$(trace-ld) $(CXX) -o $$(abspath $$@) -shared $$(LDFLAGS) $$(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$($(1)_LDFLAGS_PROPAGATED) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE)) $$($(1)_LDFLAGS_UNINSTALLED)
|
+$$(trace-ld) $(CXX) -o $$(abspath $$@) -shared $$(LDFLAGS) $$(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$($(1)_LDFLAGS_PROPAGATED) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE)) $$($(1)_LDFLAGS_UNINSTALLED)
|
||||||
|
|
||||||
ifndef HOST_DARWIN
|
ifndef HOST_DARWIN
|
||||||
$(1)_LDFLAGS_USE += -Wl,-rpath,$$(abspath $$(_d))
|
$(1)_LDFLAGS_USE += -Wl,-rpath,$$(abspath $$(_d))
|
||||||
|
|
@ -105,7 +105,7 @@ define build-library
|
||||||
$$(eval $$(call create-dir, $$($(1)_INSTALL_DIR)))
|
$$(eval $$(call create-dir, $$($(1)_INSTALL_DIR)))
|
||||||
|
|
||||||
$$($(1)_INSTALL_PATH): $$($(1)_OBJS) $$(_libs_final) | $(DESTDIR)$$($(1)_INSTALL_DIR)/
|
$$($(1)_INSTALL_PATH): $$($(1)_OBJS) $$(_libs_final) | $(DESTDIR)$$($(1)_INSTALL_DIR)/
|
||||||
$$(trace-ld) $(CXX) -o $$@ -shared $$(LDFLAGS) $$(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$($(1)_LDFLAGS_PROPAGATED) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE_INSTALLED))
|
+$$(trace-ld) $(CXX) -o $$@ -shared $$(LDFLAGS) $$(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$($(1)_LDFLAGS_PROPAGATED) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE_INSTALLED))
|
||||||
|
|
||||||
$(1)_LDFLAGS_USE_INSTALLED += -L$$(DESTDIR)$$($(1)_INSTALL_DIR) -l$$(patsubst lib%,%,$$(strip $$($(1)_NAME)))
|
$(1)_LDFLAGS_USE_INSTALLED += -L$$(DESTDIR)$$($(1)_INSTALL_DIR) -l$$(patsubst lib%,%,$$(strip $$($(1)_NAME)))
|
||||||
ifndef HOST_DARWIN
|
ifndef HOST_DARWIN
|
||||||
|
|
@ -125,7 +125,7 @@ define build-library
|
||||||
$(1)_PATH := $$(_d)/$$($(1)_NAME).a
|
$(1)_PATH := $$(_d)/$$($(1)_NAME).a
|
||||||
|
|
||||||
$$($(1)_PATH): $$($(1)_OBJS) | $$(_d)/
|
$$($(1)_PATH): $$($(1)_OBJS) | $$(_d)/
|
||||||
$$(trace-ld) $(LD) -Ur -o $$(_d)/$$($(1)_NAME).o $$?
|
+$$(trace-ld) $(LD) -Ur -o $$(_d)/$$($(1)_NAME).o $$^
|
||||||
$$(trace-ar) $(AR) crs $$@ $$(_d)/$$($(1)_NAME).o
|
$$(trace-ar) $(AR) crs $$@ $$(_d)/$$($(1)_NAME).o
|
||||||
|
|
||||||
$(1)_LDFLAGS_USE += $$($(1)_PATH) $$($(1)_LDFLAGS)
|
$(1)_LDFLAGS_USE += $$($(1)_PATH) $$($(1)_LDFLAGS)
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ define build-program
|
||||||
$$(eval $$(call create-dir, $$(_d)))
|
$$(eval $$(call create-dir, $$(_d)))
|
||||||
|
|
||||||
$$($(1)_PATH): $$($(1)_OBJS) $$(_libs) | $$(_d)/
|
$$($(1)_PATH): $$($(1)_OBJS) $$(_libs) | $$(_d)/
|
||||||
$$(trace-ld) $(CXX) -o $$@ $$(LDFLAGS) $$(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE))
|
+$$(trace-ld) $(CXX) -o $$@ $$(LDFLAGS) $$(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE))
|
||||||
|
|
||||||
$(1)_INSTALL_DIR ?= $$(bindir)
|
$(1)_INSTALL_DIR ?= $$(bindir)
|
||||||
|
|
||||||
|
|
@ -49,7 +49,7 @@ define build-program
|
||||||
_libs_final := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_INSTALL_PATH))
|
_libs_final := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_INSTALL_PATH))
|
||||||
|
|
||||||
$(DESTDIR)$$($(1)_INSTALL_PATH): $$($(1)_OBJS) $$(_libs_final) | $(DESTDIR)$$($(1)_INSTALL_DIR)/
|
$(DESTDIR)$$($(1)_INSTALL_PATH): $$($(1)_OBJS) $$(_libs_final) | $(DESTDIR)$$($(1)_INSTALL_DIR)/
|
||||||
$$(trace-ld) $(CXX) -o $$@ $$(LDFLAGS) $$(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE_INSTALLED))
|
+$$(trace-ld) $(CXX) -o $$@ $$(LDFLAGS) $$(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE_INSTALLED))
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -442,9 +442,14 @@ add_nix_vol_fstab_line() {
|
||||||
local escaped_mountpoint="${NIX_ROOT/ /'\\\'040}"
|
local escaped_mountpoint="${NIX_ROOT/ /'\\\'040}"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
# wrap `ex` to work around a problem with vim plugins breaking exit codes;
|
# wrap `ex` to work around problems w/ vim features breaking exit codes
|
||||||
# (see https://github.com/NixOS/nix/issues/5468)
|
# - plugins (see github.com/NixOS/nix/issues/5468): -u NONE
|
||||||
# we'd prefer EDITOR="/usr/bin/ex --noplugin" but vifs doesn't word-split
|
# - swap file: -n
|
||||||
|
#
|
||||||
|
# the first draft used `--noplugin`, but github.com/NixOS/nix/issues/6462
|
||||||
|
# suggests we need the less-semantic `-u NONE`
|
||||||
|
#
|
||||||
|
# we'd prefer EDITOR="/usr/bin/ex -u NONE" but vifs doesn't word-split
|
||||||
# the EDITOR env.
|
# the EDITOR env.
|
||||||
#
|
#
|
||||||
# TODO: at some point we should switch to `--clean`, but it wasn't added
|
# TODO: at some point we should switch to `--clean`, but it wasn't added
|
||||||
|
|
@ -452,7 +457,7 @@ add_nix_vol_fstab_line() {
|
||||||
# minver 10.12.6 seems to have released with vim 7.4
|
# minver 10.12.6 seems to have released with vim 7.4
|
||||||
cat > "$SCRATCH/ex_cleanroom_wrapper" <<EOF
|
cat > "$SCRATCH/ex_cleanroom_wrapper" <<EOF
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
/usr/bin/ex --noplugin "\$@"
|
/usr/bin/ex -u NONE -n "\$@"
|
||||||
EOF
|
EOF
|
||||||
chmod 755 "$SCRATCH/ex_cleanroom_wrapper"
|
chmod 755 "$SCRATCH/ex_cleanroom_wrapper"
|
||||||
|
|
||||||
|
|
@ -646,8 +651,9 @@ EOF
|
||||||
task "Configuring /etc/synthetic.conf to make a mount-point at $NIX_ROOT" >&2
|
task "Configuring /etc/synthetic.conf to make a mount-point at $NIX_ROOT" >&2
|
||||||
# technically /etc/synthetic.d/nix is supported in Big Sur+
|
# technically /etc/synthetic.d/nix is supported in Big Sur+
|
||||||
# but handling both takes even more code...
|
# but handling both takes even more code...
|
||||||
|
# See earlier note; `-u NONE` disables vim plugins/rc, `-n` skips swapfile
|
||||||
_sudo "to add Nix to /etc/synthetic.conf" \
|
_sudo "to add Nix to /etc/synthetic.conf" \
|
||||||
/usr/bin/ex --noplugin /etc/synthetic.conf <<EOF
|
/usr/bin/ex -u NONE -n /etc/synthetic.conf <<EOF
|
||||||
:a
|
:a
|
||||||
${NIX_ROOT:1}
|
${NIX_ROOT:1}
|
||||||
.
|
.
|
||||||
|
|
@ -815,7 +821,8 @@ setup_volume_daemon() {
|
||||||
local volume_uuid="$2"
|
local volume_uuid="$2"
|
||||||
if ! test_voldaemon; then
|
if ! test_voldaemon; then
|
||||||
task "Configuring LaunchDaemon to mount '$NIX_VOLUME_LABEL'" >&2
|
task "Configuring LaunchDaemon to mount '$NIX_VOLUME_LABEL'" >&2
|
||||||
_sudo "to install the Nix volume mounter" /usr/bin/ex --noplugin "$NIX_VOLUME_MOUNTD_DEST" <<EOF
|
# See earlier note; `-u NONE` disables vim plugins/rc, `-n` skips swapfile
|
||||||
|
_sudo "to install the Nix volume mounter" /usr/bin/ex -u NONE -n "$NIX_VOLUME_MOUNTD_DEST" <<EOF
|
||||||
:a
|
:a
|
||||||
$(generate_mount_daemon "$cmd_type" "$volume_uuid")
|
$(generate_mount_daemon "$cmd_type" "$volume_uuid")
|
||||||
.
|
.
|
||||||
|
|
|
||||||
|
|
@ -638,6 +638,17 @@ place_channel_configuration() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_selinux() {
|
||||||
|
if command -v getenforce > /dev/null 2>&1; then
|
||||||
|
if ! [ "$(getenforce)" = "Disabled" ]; then
|
||||||
|
failure <<EOF
|
||||||
|
Nix does not work with selinux enabled yet!
|
||||||
|
see https://github.com/NixOS/nix/issues/2374
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
welcome_to_nix() {
|
welcome_to_nix() {
|
||||||
ok "Welcome to the Multi-User Nix Installation"
|
ok "Welcome to the Multi-User Nix Installation"
|
||||||
|
|
||||||
|
|
@ -866,6 +877,8 @@ when I need to.
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
check_selinux
|
||||||
|
|
||||||
if [ "$(uname -s)" = "Darwin" ]; then
|
if [ "$(uname -s)" = "Darwin" ]; then
|
||||||
# shellcheck source=./install-darwin-multi-user.sh
|
# shellcheck source=./install-darwin-multi-user.sh
|
||||||
. "$EXTRACTED_NIX_PATH/install-darwin-multi-user.sh"
|
. "$EXTRACTED_NIX_PATH/install-darwin-multi-user.sh"
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,9 @@ if ! [ -w "$dest" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -p "$dest/store"
|
# The auto-chroot code in openFromNonUri() checks for the
|
||||||
|
# non-existence of /nix/var/nix, so we need to create it here.
|
||||||
|
mkdir -p "$dest/store" "$dest/var/nix"
|
||||||
|
|
||||||
printf "copying Nix to %s..." "${dest}/store" >&2
|
printf "copying Nix to %s..." "${dest}/store" >&2
|
||||||
# Insert a newline if no progress is shown.
|
# Insert a newline if no progress is shown.
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,11 @@ ref<Store> CopyCommand::getDstStore()
|
||||||
|
|
||||||
EvalCommand::EvalCommand()
|
EvalCommand::EvalCommand()
|
||||||
{
|
{
|
||||||
|
addFlag({
|
||||||
|
.longName = "debugger",
|
||||||
|
.description = "start an interactive environment if evaluation fails",
|
||||||
|
.handler = {&startReplOnEvalErrors, true},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
EvalCommand::~EvalCommand()
|
EvalCommand::~EvalCommand()
|
||||||
|
|
@ -103,7 +108,7 @@ ref<Store> EvalCommand::getEvalStore()
|
||||||
|
|
||||||
ref<EvalState> EvalCommand::getEvalState()
|
ref<EvalState> EvalCommand::getEvalState()
|
||||||
{
|
{
|
||||||
if (!evalState)
|
if (!evalState) {
|
||||||
evalState =
|
evalState =
|
||||||
#if HAVE_BOEHMGC
|
#if HAVE_BOEHMGC
|
||||||
std::allocate_shared<EvalState>(traceable_allocator<EvalState>(),
|
std::allocate_shared<EvalState>(traceable_allocator<EvalState>(),
|
||||||
|
|
@ -113,6 +118,11 @@ ref<EvalState> EvalCommand::getEvalState()
|
||||||
searchPath, getEvalStore(), getStore())
|
searchPath, getEvalStore(), getStore())
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
|
|
||||||
|
if (startReplOnEvalErrors) {
|
||||||
|
evalState->debugRepl = &runRepl;
|
||||||
|
};
|
||||||
|
}
|
||||||
return ref<EvalState>(evalState);
|
return ref<EvalState>(evalState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,9 @@ struct CopyCommand : virtual StoreCommand
|
||||||
|
|
||||||
struct EvalCommand : virtual StoreCommand, MixEvalArgs
|
struct EvalCommand : virtual StoreCommand, MixEvalArgs
|
||||||
{
|
{
|
||||||
|
bool startReplOnEvalErrors = false;
|
||||||
|
bool ignoreExceptionsDuringTry = false;
|
||||||
|
|
||||||
EvalCommand();
|
EvalCommand();
|
||||||
|
|
||||||
~EvalCommand();
|
~EvalCommand();
|
||||||
|
|
@ -75,10 +78,16 @@ struct MixFlakeOptions : virtual Args, EvalCommand
|
||||||
{
|
{
|
||||||
flake::LockFlags lockFlags;
|
flake::LockFlags lockFlags;
|
||||||
|
|
||||||
|
std::optional<std::string> needsFlakeInputCompletion = {};
|
||||||
|
|
||||||
MixFlakeOptions();
|
MixFlakeOptions();
|
||||||
|
|
||||||
virtual std::optional<FlakeRef> getFlakeRefForCompletion()
|
virtual std::vector<std::string> getFlakesForCompletion()
|
||||||
{ return {}; }
|
{ return {}; }
|
||||||
|
|
||||||
|
void completeFlakeInput(std::string_view prefix);
|
||||||
|
|
||||||
|
void completionHook() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SourceExprCommand : virtual Args, MixFlakeOptions
|
struct SourceExprCommand : virtual Args, MixFlakeOptions
|
||||||
|
|
@ -114,12 +123,13 @@ struct InstallablesCommand : virtual Args, SourceExprCommand
|
||||||
InstallablesCommand();
|
InstallablesCommand();
|
||||||
|
|
||||||
void prepare() override;
|
void prepare() override;
|
||||||
|
Installables load();
|
||||||
|
|
||||||
virtual bool useDefaultInstallables() { return true; }
|
virtual bool useDefaultInstallables() { return true; }
|
||||||
|
|
||||||
std::optional<FlakeRef> getFlakeRefForCompletion() override;
|
std::vector<std::string> getFlakesForCompletion() override;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
|
|
||||||
std::vector<std::string> _installables;
|
std::vector<std::string> _installables;
|
||||||
};
|
};
|
||||||
|
|
@ -133,9 +143,9 @@ struct InstallableCommand : virtual Args, SourceExprCommand
|
||||||
|
|
||||||
void prepare() override;
|
void prepare() override;
|
||||||
|
|
||||||
std::optional<FlakeRef> getFlakeRefForCompletion() override
|
std::vector<std::string> getFlakesForCompletion() override
|
||||||
{
|
{
|
||||||
return parseFlakeRefWithFragment(_installable, absPath(".")).first;
|
return {_installable};
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -270,4 +280,8 @@ void printClosureDiff(
|
||||||
const StorePath & afterPath,
|
const StorePath & afterPath,
|
||||||
std::string_view indent);
|
std::string_view indent);
|
||||||
|
|
||||||
|
|
||||||
|
void runRepl(
|
||||||
|
ref<EvalState> evalState,
|
||||||
|
const ValMap & extraEnv);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,17 +23,6 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
void completeFlakeInputPath(
|
|
||||||
ref<EvalState> evalState,
|
|
||||||
const FlakeRef & flakeRef,
|
|
||||||
std::string_view prefix)
|
|
||||||
{
|
|
||||||
auto flake = flake::getFlake(*evalState, flakeRef, true);
|
|
||||||
for (auto & input : flake.inputs)
|
|
||||||
if (hasPrefix(input.first, prefix))
|
|
||||||
completions->add(input.first);
|
|
||||||
}
|
|
||||||
|
|
||||||
MixFlakeOptions::MixFlakeOptions()
|
MixFlakeOptions::MixFlakeOptions()
|
||||||
{
|
{
|
||||||
auto category = "Common flake-related options";
|
auto category = "Common flake-related options";
|
||||||
|
|
@ -86,8 +75,7 @@ MixFlakeOptions::MixFlakeOptions()
|
||||||
lockFlags.inputUpdates.insert(flake::parseInputPath(s));
|
lockFlags.inputUpdates.insert(flake::parseInputPath(s));
|
||||||
}},
|
}},
|
||||||
.completer = {[&](size_t, std::string_view prefix) {
|
.completer = {[&](size_t, std::string_view prefix) {
|
||||||
if (auto flakeRef = getFlakeRefForCompletion())
|
needsFlakeInputCompletion = {std::string(prefix)};
|
||||||
completeFlakeInputPath(getEvalState(), *flakeRef, prefix);
|
|
||||||
}}
|
}}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -103,12 +91,10 @@ MixFlakeOptions::MixFlakeOptions()
|
||||||
parseFlakeRef(flakeRef, absPath("."), true));
|
parseFlakeRef(flakeRef, absPath("."), true));
|
||||||
}},
|
}},
|
||||||
.completer = {[&](size_t n, std::string_view prefix) {
|
.completer = {[&](size_t n, std::string_view prefix) {
|
||||||
if (n == 0) {
|
if (n == 0)
|
||||||
if (auto flakeRef = getFlakeRefForCompletion())
|
needsFlakeInputCompletion = {std::string(prefix)};
|
||||||
completeFlakeInputPath(getEvalState(), *flakeRef, prefix);
|
else if (n == 1)
|
||||||
} else if (n == 1) {
|
|
||||||
completeFlakeRef(getEvalState()->store, prefix);
|
completeFlakeRef(getEvalState()->store, prefix);
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -139,6 +125,24 @@ MixFlakeOptions::MixFlakeOptions()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MixFlakeOptions::completeFlakeInput(std::string_view prefix)
|
||||||
|
{
|
||||||
|
auto evalState = getEvalState();
|
||||||
|
for (auto & flakeRefS : getFlakesForCompletion()) {
|
||||||
|
auto flakeRef = parseFlakeRefWithFragment(expandTilde(flakeRefS), absPath(".")).first;
|
||||||
|
auto flake = flake::getFlake(*evalState, flakeRef, true);
|
||||||
|
for (auto & input : flake.inputs)
|
||||||
|
if (hasPrefix(input.first, prefix))
|
||||||
|
completions->add(input.first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MixFlakeOptions::completionHook()
|
||||||
|
{
|
||||||
|
if (auto & prefix = needsFlakeInputCompletion)
|
||||||
|
completeFlakeInput(*prefix);
|
||||||
|
}
|
||||||
|
|
||||||
SourceExprCommand::SourceExprCommand(bool supportReadOnlyMode)
|
SourceExprCommand::SourceExprCommand(bool supportReadOnlyMode)
|
||||||
{
|
{
|
||||||
addFlag({
|
addFlag({
|
||||||
|
|
@ -146,7 +150,8 @@ SourceExprCommand::SourceExprCommand(bool supportReadOnlyMode)
|
||||||
.shortName = 'f',
|
.shortName = 'f',
|
||||||
.description =
|
.description =
|
||||||
"Interpret installables as attribute paths relative to the Nix expression stored in *file*. "
|
"Interpret installables as attribute paths relative to the Nix expression stored in *file*. "
|
||||||
"If *file* is the character -, then a Nix expression will be read from standard input.",
|
"If *file* is the character -, then a Nix expression will be read from standard input. "
|
||||||
|
"Implies `--impure`.",
|
||||||
.category = installablesCategory,
|
.category = installablesCategory,
|
||||||
.labels = {"file"},
|
.labels = {"file"},
|
||||||
.handler = {&file},
|
.handler = {&file},
|
||||||
|
|
@ -623,11 +628,22 @@ std::tuple<std::string, FlakeRef, InstallableValue::DerivationInfo> InstallableF
|
||||||
auto drvPath = attr->forceDerivation();
|
auto drvPath = attr->forceDerivation();
|
||||||
|
|
||||||
std::set<std::string> outputsToInstall;
|
std::set<std::string> outputsToInstall;
|
||||||
|
std::optional<NixInt> priority;
|
||||||
|
|
||||||
if (auto aMeta = attr->maybeGetAttr(state->sMeta))
|
if (auto aOutputSpecified = attr->maybeGetAttr(state->sOutputSpecified)) {
|
||||||
|
if (aOutputSpecified->getBool()) {
|
||||||
|
if (auto aOutputName = attr->maybeGetAttr("outputName"))
|
||||||
|
outputsToInstall = { aOutputName->getString() };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (auto aMeta = attr->maybeGetAttr(state->sMeta)) {
|
||||||
if (auto aOutputsToInstall = aMeta->maybeGetAttr("outputsToInstall"))
|
if (auto aOutputsToInstall = aMeta->maybeGetAttr("outputsToInstall"))
|
||||||
for (auto & s : aOutputsToInstall->getListOfStrings())
|
for (auto & s : aOutputsToInstall->getListOfStrings())
|
||||||
outputsToInstall.insert(s);
|
outputsToInstall.insert(s);
|
||||||
|
if (auto aPriority = aMeta->maybeGetAttr("priority"))
|
||||||
|
priority = aPriority->getInt();
|
||||||
|
}
|
||||||
|
|
||||||
if (outputsToInstall.empty() || std::get_if<AllOutputs>(&outputsSpec)) {
|
if (outputsToInstall.empty() || std::get_if<AllOutputs>(&outputsSpec)) {
|
||||||
outputsToInstall.clear();
|
outputsToInstall.clear();
|
||||||
|
|
@ -645,6 +661,7 @@ std::tuple<std::string, FlakeRef, InstallableValue::DerivationInfo> InstallableF
|
||||||
auto drvInfo = DerivationInfo {
|
auto drvInfo = DerivationInfo {
|
||||||
.drvPath = std::move(drvPath),
|
.drvPath = std::move(drvPath),
|
||||||
.outputsToInstall = std::move(outputsToInstall),
|
.outputsToInstall = std::move(outputsToInstall),
|
||||||
|
.priority = priority,
|
||||||
};
|
};
|
||||||
|
|
||||||
return {attrPath, getLockedFlake()->flake.lockedRef, std::move(drvInfo)};
|
return {attrPath, getLockedFlake()->flake.lockedRef, std::move(drvInfo)};
|
||||||
|
|
@ -909,6 +926,9 @@ std::vector<std::pair<std::shared_ptr<Installable>, BuiltPath>> Installable::bui
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Realise::Outputs: {
|
case Realise::Outputs: {
|
||||||
|
if (settings.printMissing)
|
||||||
|
printMissing(store, pathsToBuild, lvlInfo);
|
||||||
|
|
||||||
for (auto & buildResult : store->buildPathsWithResults(pathsToBuild, bMode, evalStore)) {
|
for (auto & buildResult : store->buildPathsWithResults(pathsToBuild, bMode, evalStore)) {
|
||||||
if (!buildResult.success())
|
if (!buildResult.success())
|
||||||
buildResult.rethrow();
|
buildResult.rethrow();
|
||||||
|
|
@ -1022,21 +1042,26 @@ InstallablesCommand::InstallablesCommand()
|
||||||
|
|
||||||
void InstallablesCommand::prepare()
|
void InstallablesCommand::prepare()
|
||||||
{
|
{
|
||||||
|
installables = load();
|
||||||
|
}
|
||||||
|
|
||||||
|
Installables InstallablesCommand::load() {
|
||||||
|
Installables installables;
|
||||||
if (_installables.empty() && useDefaultInstallables())
|
if (_installables.empty() && useDefaultInstallables())
|
||||||
// FIXME: commands like "nix profile install" should not have a
|
// FIXME: commands like "nix profile install" should not have a
|
||||||
// default, probably.
|
// default, probably.
|
||||||
_installables.push_back(".");
|
_installables.push_back(".");
|
||||||
installables = parseInstallables(getStore(), _installables);
|
return parseInstallables(getStore(), _installables);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<FlakeRef> InstallablesCommand::getFlakeRefForCompletion()
|
std::vector<std::string> InstallablesCommand::getFlakesForCompletion()
|
||||||
{
|
{
|
||||||
if (_installables.empty()) {
|
if (_installables.empty()) {
|
||||||
if (useDefaultInstallables())
|
if (useDefaultInstallables())
|
||||||
return parseFlakeRefWithFragment(".", absPath(".")).first;
|
return {"."};
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
return parseFlakeRefWithFragment(_installables.front(), absPath(".")).first;
|
return _installables;
|
||||||
}
|
}
|
||||||
|
|
||||||
InstallableCommand::InstallableCommand(bool supportReadOnlyMode)
|
InstallableCommand::InstallableCommand(bool supportReadOnlyMode)
|
||||||
|
|
|
||||||
|
|
@ -132,6 +132,8 @@ struct Installable
|
||||||
const std::vector<std::shared_ptr<Installable>> & installables);
|
const std::vector<std::shared_ptr<Installable>> & installables);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef std::vector<std::shared_ptr<Installable>> Installables;
|
||||||
|
|
||||||
struct InstallableValue : Installable
|
struct InstallableValue : Installable
|
||||||
{
|
{
|
||||||
ref<EvalState> state;
|
ref<EvalState> state;
|
||||||
|
|
@ -142,6 +144,7 @@ struct InstallableValue : Installable
|
||||||
{
|
{
|
||||||
StorePath drvPath;
|
StorePath drvPath;
|
||||||
std::set<std::string> outputsToInstall;
|
std::set<std::string> outputsToInstall;
|
||||||
|
std::optional<NixInt> priority;
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual std::vector<DerivationInfo> toDerivations() = 0;
|
virtual std::vector<DerivationInfo> toDerivations() = 0;
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ libcmd_DIR := $(d)
|
||||||
|
|
||||||
libcmd_SOURCES := $(wildcard $(d)/*.cc)
|
libcmd_SOURCES := $(wildcard $(d)/*.cc)
|
||||||
|
|
||||||
libcmd_CXXFLAGS += -I src/libutil -I src/libstore -I src/libexpr -I src/libmain -I src/libfetchers
|
libcmd_CXXFLAGS += -I src/libutil -I src/libstore -I src/libexpr -I src/libmain -I src/libfetchers -I src/nix
|
||||||
|
|
||||||
libcmd_LDFLAGS += $(LOWDOWN_LIBS) -pthread
|
libcmd_LDFLAGS = $(EDITLINE_LIBS) -llowdown -pthread
|
||||||
|
|
||||||
libcmd_LIBS = libstore libutil libexpr libmain libfetchers
|
libcmd_LIBS = libstore libutil libexpr libmain libfetchers
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,12 @@ namespace nix {
|
||||||
|
|
||||||
std::string renderMarkdownToTerminal(std::string_view markdown)
|
std::string renderMarkdownToTerminal(std::string_view markdown)
|
||||||
{
|
{
|
||||||
|
int windowWidth = getWindowSize().second;
|
||||||
|
|
||||||
struct lowdown_opts opts {
|
struct lowdown_opts opts {
|
||||||
.type = LOWDOWN_TERM,
|
.type = LOWDOWN_TERM,
|
||||||
.maxdepth = 20,
|
.maxdepth = 20,
|
||||||
.cols = std::max(getWindowSize().second, (unsigned short) 80),
|
.cols = (size_t) std::max(windowWidth - 5, 60),
|
||||||
.hmargin = 0,
|
.hmargin = 0,
|
||||||
.vmargin = 0,
|
.vmargin = 0,
|
||||||
.feat = LOWDOWN_COMMONMARK | LOWDOWN_FENCED | LOWDOWN_DEFLIST | LOWDOWN_TABLES,
|
.feat = LOWDOWN_COMMONMARK | LOWDOWN_FENCED | LOWDOWN_DEFLIST | LOWDOWN_TABLES,
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ extern "C" {
|
||||||
#include "ansicolor.hh"
|
#include "ansicolor.hh"
|
||||||
#include "shared.hh"
|
#include "shared.hh"
|
||||||
#include "eval.hh"
|
#include "eval.hh"
|
||||||
|
#include "eval-cache.hh"
|
||||||
#include "eval-inline.hh"
|
#include "eval-inline.hh"
|
||||||
#include "attr-path.hh"
|
#include "attr-path.hh"
|
||||||
#include "store-api.hh"
|
#include "store-api.hh"
|
||||||
|
|
@ -48,34 +49,42 @@ struct NixRepl
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
std::string curDir;
|
std::string curDir;
|
||||||
std::unique_ptr<EvalState> state;
|
ref<EvalState> state;
|
||||||
Bindings * autoArgs;
|
Bindings * autoArgs;
|
||||||
|
|
||||||
|
size_t debugTraceIndex;
|
||||||
|
|
||||||
Strings loadedFiles;
|
Strings loadedFiles;
|
||||||
|
typedef std::vector<std::pair<Value*,std::string>> AnnotatedValues;
|
||||||
|
std::function<AnnotatedValues()> getValues;
|
||||||
|
|
||||||
const static int envSize = 32768;
|
const static int envSize = 32768;
|
||||||
StaticEnv staticEnv;
|
std::shared_ptr<StaticEnv> staticEnv;
|
||||||
Env * env;
|
Env * env;
|
||||||
int displ;
|
int displ;
|
||||||
StringSet varNames;
|
StringSet varNames;
|
||||||
|
|
||||||
const Path historyFile;
|
const Path historyFile;
|
||||||
|
|
||||||
NixRepl(const Strings & searchPath, nix::ref<Store> store);
|
NixRepl(const Strings & searchPath, nix::ref<Store> store,ref<EvalState> state,
|
||||||
|
std::function<AnnotatedValues()> getValues);
|
||||||
~NixRepl();
|
~NixRepl();
|
||||||
void mainLoop(const std::vector<std::string> & files);
|
void mainLoop();
|
||||||
StringSet completePrefix(const std::string & prefix);
|
StringSet completePrefix(const std::string & prefix);
|
||||||
bool getLine(std::string & input, const std::string &prompt);
|
bool getLine(std::string & input, const std::string & prompt);
|
||||||
StorePath getDerivationPath(Value & v);
|
StorePath getDerivationPath(Value & v);
|
||||||
bool processLine(std::string line);
|
bool processLine(std::string line);
|
||||||
|
|
||||||
void loadFile(const Path & path);
|
void loadFile(const Path & path);
|
||||||
void loadFlake(const std::string & flakeRef);
|
void loadFlake(const std::string & flakeRef);
|
||||||
void initEnv();
|
void initEnv();
|
||||||
|
void loadFiles();
|
||||||
void reloadFiles();
|
void reloadFiles();
|
||||||
void addAttrsToScope(Value & attrs);
|
void addAttrsToScope(Value & attrs);
|
||||||
void addVarToScope(const Symbol name, Value & v);
|
void addVarToScope(const Symbol name, Value & v);
|
||||||
Expr * parseString(std::string s);
|
Expr * parseString(std::string s);
|
||||||
void evalString(std::string s, Value & v);
|
void evalString(std::string s, Value & v);
|
||||||
|
void loadDebugTraceEnv(DebugTrace & dt);
|
||||||
|
|
||||||
typedef std::set<Value *> ValuesSeen;
|
typedef std::set<Value *> ValuesSeen;
|
||||||
std::ostream & printValue(std::ostream & str, Value & v, unsigned int maxDepth);
|
std::ostream & printValue(std::ostream & str, Value & v, unsigned int maxDepth);
|
||||||
|
|
@ -92,9 +101,12 @@ std::string removeWhitespace(std::string s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NixRepl::NixRepl(const Strings & searchPath, nix::ref<Store> store)
|
NixRepl::NixRepl(const Strings & searchPath, nix::ref<Store> store, ref<EvalState> state,
|
||||||
: state(std::make_unique<EvalState>(searchPath, store))
|
std::function<NixRepl::AnnotatedValues()> getValues)
|
||||||
, staticEnv(false, &state->staticBaseEnv)
|
: state(state)
|
||||||
|
, debugTraceIndex(0)
|
||||||
|
, getValues(getValues)
|
||||||
|
, staticEnv(new StaticEnv(false, state->staticBaseEnv.get()))
|
||||||
, historyFile(getDataDir() + "/nix/repl-history")
|
, historyFile(getDataDir() + "/nix/repl-history")
|
||||||
{
|
{
|
||||||
curDir = absPath(".");
|
curDir = absPath(".");
|
||||||
|
|
@ -106,23 +118,20 @@ NixRepl::~NixRepl()
|
||||||
write_history(historyFile.c_str());
|
write_history(historyFile.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string runNix(Path program, const Strings & args,
|
void runNix(Path program, const Strings & args,
|
||||||
const std::optional<std::string> & input = {})
|
const std::optional<std::string> & input = {})
|
||||||
{
|
{
|
||||||
auto subprocessEnv = getEnv();
|
auto subprocessEnv = getEnv();
|
||||||
subprocessEnv["NIX_CONFIG"] = globalConfig.toKeyValue();
|
subprocessEnv["NIX_CONFIG"] = globalConfig.toKeyValue();
|
||||||
|
|
||||||
auto res = runProgram(RunOptions {
|
runProgram2(RunOptions {
|
||||||
.program = settings.nixBinDir+ "/" + program,
|
.program = settings.nixBinDir+ "/" + program,
|
||||||
.args = args,
|
.args = args,
|
||||||
.environment = subprocessEnv,
|
.environment = subprocessEnv,
|
||||||
.input = input,
|
.input = input,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!statusOk(res.first))
|
return;
|
||||||
throw ExecError(res.first, "program '%1%' %2%", program, statusToString(res.first));
|
|
||||||
|
|
||||||
return res.second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NixRepl * curRepl; // ugly
|
static NixRepl * curRepl; // ugly
|
||||||
|
|
@ -198,16 +207,37 @@ namespace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NixRepl::mainLoop(const std::vector<std::string> & files)
|
static std::ostream & showDebugTrace(std::ostream & out, const PosTable & positions, const DebugTrace & dt)
|
||||||
|
{
|
||||||
|
if (dt.isError)
|
||||||
|
out << ANSI_RED "error: " << ANSI_NORMAL;
|
||||||
|
out << dt.hint.str() << "\n";
|
||||||
|
|
||||||
|
// prefer direct pos, but if noPos then try the expr.
|
||||||
|
auto pos = *dt.pos
|
||||||
|
? *dt.pos
|
||||||
|
: positions[dt.expr.getPos() ? dt.expr.getPos() : noPos];
|
||||||
|
|
||||||
|
if (pos) {
|
||||||
|
printAtPos(pos, out);
|
||||||
|
|
||||||
|
auto loc = getCodeLines(pos);
|
||||||
|
if (loc.has_value()) {
|
||||||
|
out << "\n";
|
||||||
|
printCodeLines(out, "", pos, *loc);
|
||||||
|
out << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NixRepl::mainLoop()
|
||||||
{
|
{
|
||||||
std::string error = ANSI_RED "error:" ANSI_NORMAL " ";
|
std::string error = ANSI_RED "error:" ANSI_NORMAL " ";
|
||||||
notice("Welcome to Nix " + nixVersion + ". Type :? for help.\n");
|
notice("Welcome to Nix " + nixVersion + ". Type :? for help.\n");
|
||||||
|
|
||||||
for (auto & i : files)
|
loadFiles();
|
||||||
loadedFiles.push_back(i);
|
|
||||||
|
|
||||||
reloadFiles();
|
|
||||||
if (!loadedFiles.empty()) notice("");
|
|
||||||
|
|
||||||
// Allow nix-repl specific settings in .inputrc
|
// Allow nix-repl specific settings in .inputrc
|
||||||
rl_readline_name = "nix-repl";
|
rl_readline_name = "nix-repl";
|
||||||
|
|
@ -227,9 +257,12 @@ void NixRepl::mainLoop(const std::vector<std::string> & files)
|
||||||
while (true) {
|
while (true) {
|
||||||
// When continuing input from previous lines, don't print a prompt, just align to the same
|
// When continuing input from previous lines, don't print a prompt, just align to the same
|
||||||
// number of chars as the prompt.
|
// number of chars as the prompt.
|
||||||
if (!getLine(input, input.empty() ? "nix-repl> " : " "))
|
if (!getLine(input, input.empty() ? "nix-repl> " : " ")) {
|
||||||
|
// ctrl-D should exit the debugger.
|
||||||
|
state->debugStop = false;
|
||||||
|
state->debugQuit = true;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
if (!removeWhitespace(input).empty() && !processLine(input)) return;
|
if (!removeWhitespace(input).empty() && !processLine(input)) return;
|
||||||
} catch (ParseError & e) {
|
} catch (ParseError & e) {
|
||||||
|
|
@ -240,6 +273,14 @@ void NixRepl::mainLoop(const std::vector<std::string> & files)
|
||||||
} else {
|
} else {
|
||||||
printMsg(lvlError, e.msg());
|
printMsg(lvlError, e.msg());
|
||||||
}
|
}
|
||||||
|
} catch (EvalError & e) {
|
||||||
|
// in debugger mode, an EvalError should trigger another repl session.
|
||||||
|
// when that session returns the exception will land here. No need to show it again;
|
||||||
|
// show the error for this repl session instead.
|
||||||
|
if (state->debugRepl && !state->debugTraces.empty())
|
||||||
|
showDebugTrace(std::cout, state->positions, state->debugTraces.front());
|
||||||
|
else
|
||||||
|
printMsg(lvlError, e.msg());
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
printMsg(lvlError, e.msg());
|
printMsg(lvlError, e.msg());
|
||||||
} catch (Interrupted & e) {
|
} catch (Interrupted & e) {
|
||||||
|
|
@ -394,6 +435,19 @@ StorePath NixRepl::getDerivationPath(Value & v) {
|
||||||
return *drvPath;
|
return *drvPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NixRepl::loadDebugTraceEnv(DebugTrace & dt)
|
||||||
|
{
|
||||||
|
initEnv();
|
||||||
|
|
||||||
|
auto se = state->getStaticEnv(dt.expr);
|
||||||
|
if (se) {
|
||||||
|
auto vm = mapStaticEnvBindings(state->symbols, *se.get(), dt.env);
|
||||||
|
|
||||||
|
// add staticenv vars.
|
||||||
|
for (auto & [name, value] : *(vm.get()))
|
||||||
|
addVarToScope(state->symbols.create(name), *value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool NixRepl::processLine(std::string line)
|
bool NixRepl::processLine(std::string line)
|
||||||
{
|
{
|
||||||
|
|
@ -429,12 +483,72 @@ bool NixRepl::processLine(std::string line)
|
||||||
<< " :p <expr> Evaluate and print expression recursively\n"
|
<< " :p <expr> Evaluate and print expression recursively\n"
|
||||||
<< " :q Exit nix-repl\n"
|
<< " :q Exit nix-repl\n"
|
||||||
<< " :r Reload all files\n"
|
<< " :r Reload all files\n"
|
||||||
<< " :s <expr> Build dependencies of derivation, then start nix-shell\n"
|
<< " :sh <expr> Build dependencies of derivation, then start nix-shell\n"
|
||||||
<< " :t <expr> Describe result of evaluation\n"
|
<< " :t <expr> Describe result of evaluation\n"
|
||||||
<< " :u <expr> Build derivation, then start nix-shell\n"
|
<< " :u <expr> Build derivation, then start nix-shell\n"
|
||||||
<< " :doc <expr> Show documentation of a builtin function\n"
|
<< " :doc <expr> Show documentation of a builtin function\n"
|
||||||
<< " :log <expr> Show logs for a derivation\n"
|
<< " :log <expr> Show logs for a derivation\n"
|
||||||
<< " :st [bool] Enable, disable or toggle showing traces for errors\n";
|
<< " :te [bool] Enable, disable or toggle showing traces for errors\n"
|
||||||
|
;
|
||||||
|
if (state->debugRepl) {
|
||||||
|
std::cout
|
||||||
|
<< "\n"
|
||||||
|
<< " Debug mode commands\n"
|
||||||
|
<< " :env Show env stack\n"
|
||||||
|
<< " :bt Show trace stack\n"
|
||||||
|
<< " :st Show current trace\n"
|
||||||
|
<< " :st <idx> Change to another trace in the stack\n"
|
||||||
|
<< " :c Go until end of program, exception, or builtins.break\n"
|
||||||
|
<< " :s Go one step\n"
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (state->debugRepl && (command == ":bt" || command == ":backtrace")) {
|
||||||
|
for (const auto & [idx, i] : enumerate(state->debugTraces)) {
|
||||||
|
std::cout << "\n" << ANSI_BLUE << idx << ANSI_NORMAL << ": ";
|
||||||
|
showDebugTrace(std::cout, state->positions, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (state->debugRepl && (command == ":env")) {
|
||||||
|
for (const auto & [idx, i] : enumerate(state->debugTraces)) {
|
||||||
|
if (idx == debugTraceIndex) {
|
||||||
|
printEnvBindings(*state, i.expr, i.env);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (state->debugRepl && (command == ":st")) {
|
||||||
|
try {
|
||||||
|
// change the DebugTrace index.
|
||||||
|
debugTraceIndex = stoi(arg);
|
||||||
|
} catch (...) { }
|
||||||
|
|
||||||
|
for (const auto & [idx, i] : enumerate(state->debugTraces)) {
|
||||||
|
if (idx == debugTraceIndex) {
|
||||||
|
std::cout << "\n" << ANSI_BLUE << idx << ANSI_NORMAL << ": ";
|
||||||
|
showDebugTrace(std::cout, state->positions, i);
|
||||||
|
std::cout << std::endl;
|
||||||
|
printEnvBindings(*state, i.expr, i.env);
|
||||||
|
loadDebugTraceEnv(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (state->debugRepl && (command == ":s" || command == ":step")) {
|
||||||
|
// set flag to stop at next DebugTrace; exit repl.
|
||||||
|
state->debugStop = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (state->debugRepl && (command == ":c" || command == ":continue")) {
|
||||||
|
// set flag to run to next breakpoint or end of program; exit repl.
|
||||||
|
state->debugStop = false;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (command == ":a" || command == ":add") {
|
else if (command == ":a" || command == ":add") {
|
||||||
|
|
@ -506,7 +620,7 @@ bool NixRepl::processLine(std::string line)
|
||||||
runNix("nix-shell", {state->store->printStorePath(drvPath)});
|
runNix("nix-shell", {state->store->printStorePath(drvPath)});
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (command == ":b" || command == ":bl" || command == ":i" || command == ":s" || command == ":log") {
|
else if (command == ":b" || command == ":bl" || command == ":i" || command == ":sh" || command == ":log") {
|
||||||
Value v;
|
Value v;
|
||||||
evalString(arg, v);
|
evalString(arg, v);
|
||||||
StorePath drvPath = getDerivationPath(v);
|
StorePath drvPath = getDerivationPath(v);
|
||||||
|
|
@ -567,8 +681,11 @@ bool NixRepl::processLine(std::string line)
|
||||||
printValue(std::cout, v, 1000000000) << std::endl;
|
printValue(std::cout, v, 1000000000) << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (command == ":q" || command == ":quit")
|
else if (command == ":q" || command == ":quit") {
|
||||||
|
state->debugStop = false;
|
||||||
|
state->debugQuit = true;
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
else if (command == ":doc") {
|
else if (command == ":doc") {
|
||||||
Value v;
|
Value v;
|
||||||
|
|
@ -593,7 +710,7 @@ bool NixRepl::processLine(std::string line)
|
||||||
throw Error("value does not have documentation");
|
throw Error("value does not have documentation");
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (command == ":st" || command == ":show-trace") {
|
else if (command == ":te" || command == ":trace-enable") {
|
||||||
if (arg == "false" || (arg == "" && loggerSettings.showTrace)) {
|
if (arg == "false" || (arg == "" && loggerSettings.showTrace)) {
|
||||||
std::cout << "not showing error traces\n";
|
std::cout << "not showing error traces\n";
|
||||||
loggerSettings.showTrace = false;
|
loggerSettings.showTrace = false;
|
||||||
|
|
@ -630,7 +747,6 @@ bool NixRepl::processLine(std::string line)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void NixRepl::loadFile(const Path & path)
|
void NixRepl::loadFile(const Path & path)
|
||||||
{
|
{
|
||||||
loadedFiles.remove(path);
|
loadedFiles.remove(path);
|
||||||
|
|
@ -669,10 +785,10 @@ void NixRepl::initEnv()
|
||||||
env = &state->allocEnv(envSize);
|
env = &state->allocEnv(envSize);
|
||||||
env->up = &state->baseEnv;
|
env->up = &state->baseEnv;
|
||||||
displ = 0;
|
displ = 0;
|
||||||
staticEnv.vars.clear();
|
staticEnv->vars.clear();
|
||||||
|
|
||||||
varNames.clear();
|
varNames.clear();
|
||||||
for (auto & i : state->staticBaseEnv.vars)
|
for (auto & i : state->staticBaseEnv->vars)
|
||||||
varNames.emplace(state->symbols[i.first]);
|
varNames.emplace(state->symbols[i.first]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -681,16 +797,24 @@ void NixRepl::reloadFiles()
|
||||||
{
|
{
|
||||||
initEnv();
|
initEnv();
|
||||||
|
|
||||||
|
loadFiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void NixRepl::loadFiles()
|
||||||
|
{
|
||||||
Strings old = loadedFiles;
|
Strings old = loadedFiles;
|
||||||
loadedFiles.clear();
|
loadedFiles.clear();
|
||||||
|
|
||||||
bool first = true;
|
|
||||||
for (auto & i : old) {
|
for (auto & i : old) {
|
||||||
if (!first) notice("");
|
|
||||||
first = false;
|
|
||||||
notice("Loading '%1%'...", i);
|
notice("Loading '%1%'...", i);
|
||||||
loadFile(i);
|
loadFile(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto & [i, what] : getValues()) {
|
||||||
|
notice("Loading installable '%1%'...", what);
|
||||||
|
addAttrsToScope(*i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -701,12 +825,12 @@ void NixRepl::addAttrsToScope(Value & attrs)
|
||||||
throw Error("environment full; cannot add more variables");
|
throw Error("environment full; cannot add more variables");
|
||||||
|
|
||||||
for (auto & i : *attrs.attrs) {
|
for (auto & i : *attrs.attrs) {
|
||||||
staticEnv.vars.emplace_back(i.name, displ);
|
staticEnv->vars.emplace_back(i.name, displ);
|
||||||
env->values[displ++] = i.value;
|
env->values[displ++] = i.value;
|
||||||
varNames.emplace(state->symbols[i.name]);
|
varNames.emplace(state->symbols[i.name]);
|
||||||
}
|
}
|
||||||
staticEnv.sort();
|
staticEnv->sort();
|
||||||
staticEnv.deduplicate();
|
staticEnv->deduplicate();
|
||||||
notice("Added %1% variables.", attrs.attrs->size());
|
notice("Added %1% variables.", attrs.attrs->size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -715,10 +839,10 @@ void NixRepl::addVarToScope(const Symbol name, Value & v)
|
||||||
{
|
{
|
||||||
if (displ >= envSize)
|
if (displ >= envSize)
|
||||||
throw Error("environment full; cannot add more variables");
|
throw Error("environment full; cannot add more variables");
|
||||||
if (auto oldVar = staticEnv.find(name); oldVar != staticEnv.vars.end())
|
if (auto oldVar = staticEnv->find(name); oldVar != staticEnv->vars.end())
|
||||||
staticEnv.vars.erase(oldVar);
|
staticEnv->vars.erase(oldVar);
|
||||||
staticEnv.vars.emplace_back(name, displ);
|
staticEnv->vars.emplace_back(name, displ);
|
||||||
staticEnv.sort();
|
staticEnv->sort();
|
||||||
env->values[displ++] = &v;
|
env->values[displ++] = &v;
|
||||||
varNames.emplace(state->symbols[name]);
|
varNames.emplace(state->symbols[name]);
|
||||||
}
|
}
|
||||||
|
|
@ -886,17 +1010,62 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CmdRepl : StoreCommand, MixEvalArgs
|
void runRepl(
|
||||||
|
ref<EvalState>evalState,
|
||||||
|
const ValMap & extraEnv)
|
||||||
{
|
{
|
||||||
std::vector<std::string> files;
|
auto getValues = [&]()->NixRepl::AnnotatedValues{
|
||||||
|
NixRepl::AnnotatedValues values;
|
||||||
|
return values;
|
||||||
|
};
|
||||||
|
const Strings & searchPath = {};
|
||||||
|
auto repl = std::make_unique<NixRepl>(
|
||||||
|
searchPath,
|
||||||
|
openStore(),
|
||||||
|
evalState,
|
||||||
|
getValues
|
||||||
|
);
|
||||||
|
|
||||||
CmdRepl()
|
repl->initEnv();
|
||||||
|
|
||||||
|
// add 'extra' vars.
|
||||||
|
for (auto & [name, value] : extraEnv)
|
||||||
|
repl->addVarToScope(repl->state->symbols.create(name), *value);
|
||||||
|
|
||||||
|
repl->mainLoop();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct CmdRepl : InstallablesCommand
|
||||||
|
{
|
||||||
|
CmdRepl(){
|
||||||
|
evalSettings.pureEval = false;
|
||||||
|
}
|
||||||
|
void prepare()
|
||||||
{
|
{
|
||||||
expectArgs({
|
if (!settings.isExperimentalFeatureEnabled(Xp::ReplFlake) && !(file) && this->_installables.size() >= 1) {
|
||||||
.label = "files",
|
warn("future versions of Nix will require using `--file` to load a file");
|
||||||
.handler = {&files},
|
if (this->_installables.size() > 1)
|
||||||
.completer = completePath
|
warn("more than one input file is not currently supported");
|
||||||
});
|
auto filePath = this->_installables[0].data();
|
||||||
|
file = std::optional(filePath);
|
||||||
|
_installables.front() = _installables.back();
|
||||||
|
_installables.pop_back();
|
||||||
|
}
|
||||||
|
installables = InstallablesCommand::load();
|
||||||
|
}
|
||||||
|
std::vector<std::string> files;
|
||||||
|
Strings getDefaultFlakeAttrPaths() override
|
||||||
|
{
|
||||||
|
return {""};
|
||||||
|
}
|
||||||
|
virtual bool useDefaultInstallables() override
|
||||||
|
{
|
||||||
|
return file.has_value() or expr.has_value();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool forceImpureByDefault() override
|
||||||
|
{
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string description() override
|
std::string description() override
|
||||||
|
|
@ -913,10 +1082,37 @@ struct CmdRepl : StoreCommand, MixEvalArgs
|
||||||
|
|
||||||
void run(ref<Store> store) override
|
void run(ref<Store> store) override
|
||||||
{
|
{
|
||||||
evalSettings.pureEval = false;
|
auto state = getEvalState();
|
||||||
auto repl = std::make_unique<NixRepl>(searchPath, openStore());
|
auto getValues = [&]()->NixRepl::AnnotatedValues{
|
||||||
|
auto installables = load();
|
||||||
|
NixRepl::AnnotatedValues values;
|
||||||
|
for (auto & installable: installables){
|
||||||
|
auto what = installable->what();
|
||||||
|
if (file){
|
||||||
|
auto [val, pos] = installable->toValue(*state);
|
||||||
|
auto what = installable->what();
|
||||||
|
state->forceValue(*val, pos);
|
||||||
|
auto autoArgs = getAutoArgs(*state);
|
||||||
|
auto valPost = state->allocValue();
|
||||||
|
state->autoCallFunction(*autoArgs, *val, *valPost);
|
||||||
|
state->forceValue(*valPost, pos);
|
||||||
|
values.push_back( {valPost, what });
|
||||||
|
} else {
|
||||||
|
auto [val, pos] = installable->toValue(*state);
|
||||||
|
values.push_back( {val, what} );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return values;
|
||||||
|
};
|
||||||
|
auto repl = std::make_unique<NixRepl>(
|
||||||
|
searchPath,
|
||||||
|
openStore(),
|
||||||
|
state,
|
||||||
|
getValues
|
||||||
|
);
|
||||||
repl->autoArgs = getAutoArgs(*repl->state);
|
repl->autoArgs = getAutoArgs(*repl->state);
|
||||||
repl->mainLoop(files);
|
repl->initEnv();
|
||||||
|
repl->mainLoop();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -47,7 +47,7 @@ struct AttrDb
|
||||||
{
|
{
|
||||||
auto state(_state->lock());
|
auto state(_state->lock());
|
||||||
|
|
||||||
Path cacheDir = getCacheDir() + "/nix/eval-cache-v3";
|
Path cacheDir = getCacheDir() + "/nix/eval-cache-v4";
|
||||||
createDirs(cacheDir);
|
createDirs(cacheDir);
|
||||||
|
|
||||||
Path dbPath = cacheDir + "/" + fingerprint.to_string(Base16, false) + ".sqlite";
|
Path dbPath = cacheDir + "/" + fingerprint.to_string(Base16, false) + ".sqlite";
|
||||||
|
|
@ -175,6 +175,24 @@ struct AttrDb
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AttrId setInt(
|
||||||
|
AttrKey key,
|
||||||
|
int n)
|
||||||
|
{
|
||||||
|
return doSQLite([&]()
|
||||||
|
{
|
||||||
|
auto state(_state->lock());
|
||||||
|
|
||||||
|
state->insertAttribute.use()
|
||||||
|
(key.first)
|
||||||
|
(symbols[key.second])
|
||||||
|
(AttrType::Int)
|
||||||
|
(n).exec();
|
||||||
|
|
||||||
|
return state->db.getLastInsertedRowId();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
AttrId setListOfStrings(
|
AttrId setListOfStrings(
|
||||||
AttrKey key,
|
AttrKey key,
|
||||||
const std::vector<std::string> & l)
|
const std::vector<std::string> & l)
|
||||||
|
|
@ -264,7 +282,7 @@ struct AttrDb
|
||||||
auto queryAttribute(state->queryAttribute.use()(key.first)(symbols[key.second]));
|
auto queryAttribute(state->queryAttribute.use()(key.first)(symbols[key.second]));
|
||||||
if (!queryAttribute.next()) return {};
|
if (!queryAttribute.next()) return {};
|
||||||
|
|
||||||
auto rowId = (AttrType) queryAttribute.getInt(0);
|
auto rowId = (AttrId) queryAttribute.getInt(0);
|
||||||
auto type = (AttrType) queryAttribute.getInt(1);
|
auto type = (AttrType) queryAttribute.getInt(1);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
|
@ -287,6 +305,8 @@ struct AttrDb
|
||||||
}
|
}
|
||||||
case AttrType::Bool:
|
case AttrType::Bool:
|
||||||
return {{rowId, queryAttribute.getInt(2) != 0}};
|
return {{rowId, queryAttribute.getInt(2) != 0}};
|
||||||
|
case AttrType::Int:
|
||||||
|
return {{rowId, int_t{queryAttribute.getInt(2)}}};
|
||||||
case AttrType::ListOfStrings:
|
case AttrType::ListOfStrings:
|
||||||
return {{rowId, tokenizeString<std::vector<std::string>>(queryAttribute.getStr(2), "\t")}};
|
return {{rowId, tokenizeString<std::vector<std::string>>(queryAttribute.getStr(2), "\t")}};
|
||||||
case AttrType::Missing:
|
case AttrType::Missing:
|
||||||
|
|
@ -426,6 +446,8 @@ Value & AttrCursor::forceValue()
|
||||||
cachedValue = {root->db->setString(getKey(), v.path), string_t{v.path, {}}};
|
cachedValue = {root->db->setString(getKey(), v.path), string_t{v.path, {}}};
|
||||||
else if (v.type() == nBool)
|
else if (v.type() == nBool)
|
||||||
cachedValue = {root->db->setBool(getKey(), v.boolean), v.boolean};
|
cachedValue = {root->db->setBool(getKey(), v.boolean), v.boolean};
|
||||||
|
else if (v.type() == nInt)
|
||||||
|
cachedValue = {root->db->setInt(getKey(), v.integer), int_t{v.integer}};
|
||||||
else if (v.type() == nAttrs)
|
else if (v.type() == nAttrs)
|
||||||
; // FIXME: do something?
|
; // FIXME: do something?
|
||||||
else
|
else
|
||||||
|
|
@ -464,7 +486,7 @@ std::shared_ptr<AttrCursor> AttrCursor::maybeGetAttr(Symbol name, bool forceErro
|
||||||
return nullptr;
|
return nullptr;
|
||||||
else if (std::get_if<failed_t>(&attr->second)) {
|
else if (std::get_if<failed_t>(&attr->second)) {
|
||||||
if (forceErrors)
|
if (forceErrors)
|
||||||
debug("reevaluating failed cached attribute '%s'");
|
debug("reevaluating failed cached attribute '%s'", getAttrPathStr(name));
|
||||||
else
|
else
|
||||||
throw CachedEvalError("cached failure of attribute '%s'", getAttrPathStr(name));
|
throw CachedEvalError("cached failure of attribute '%s'", getAttrPathStr(name));
|
||||||
} else
|
} else
|
||||||
|
|
@ -554,14 +576,14 @@ std::string AttrCursor::getString()
|
||||||
debug("using cached string attribute '%s'", getAttrPathStr());
|
debug("using cached string attribute '%s'", getAttrPathStr());
|
||||||
return s->first;
|
return s->first;
|
||||||
} else
|
} else
|
||||||
throw TypeError("'%s' is not a string", getAttrPathStr());
|
root->state.debugThrowLastTrace(TypeError("'%s' is not a string", getAttrPathStr()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto & v = forceValue();
|
auto & v = forceValue();
|
||||||
|
|
||||||
if (v.type() != nString && v.type() != nPath)
|
if (v.type() != nString && v.type() != nPath)
|
||||||
throw TypeError("'%s' is not a string but %s", getAttrPathStr(), showType(v.type()));
|
root->state.debugThrowLastTrace(TypeError("'%s' is not a string but %s", getAttrPathStr(), showType(v.type())));
|
||||||
|
|
||||||
return v.type() == nString ? v.string.s : v.path;
|
return v.type() == nString ? v.string.s : v.path;
|
||||||
}
|
}
|
||||||
|
|
@ -585,7 +607,7 @@ string_t AttrCursor::getStringWithContext()
|
||||||
return *s;
|
return *s;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
throw TypeError("'%s' is not a string", getAttrPathStr());
|
root->state.debugThrowLastTrace(TypeError("'%s' is not a string", getAttrPathStr()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -596,7 +618,7 @@ string_t AttrCursor::getStringWithContext()
|
||||||
else if (v.type() == nPath)
|
else if (v.type() == nPath)
|
||||||
return {v.path, {}};
|
return {v.path, {}};
|
||||||
else
|
else
|
||||||
throw TypeError("'%s' is not a string but %s", getAttrPathStr(), showType(v.type()));
|
root->state.debugThrowLastTrace(TypeError("'%s' is not a string but %s", getAttrPathStr(), showType(v.type())));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AttrCursor::getBool()
|
bool AttrCursor::getBool()
|
||||||
|
|
@ -609,18 +631,40 @@ bool AttrCursor::getBool()
|
||||||
debug("using cached Boolean attribute '%s'", getAttrPathStr());
|
debug("using cached Boolean attribute '%s'", getAttrPathStr());
|
||||||
return *b;
|
return *b;
|
||||||
} else
|
} else
|
||||||
throw TypeError("'%s' is not a Boolean", getAttrPathStr());
|
root->state.debugThrowLastTrace(TypeError("'%s' is not a Boolean", getAttrPathStr()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto & v = forceValue();
|
auto & v = forceValue();
|
||||||
|
|
||||||
if (v.type() != nBool)
|
if (v.type() != nBool)
|
||||||
throw TypeError("'%s' is not a Boolean", getAttrPathStr());
|
root->state.debugThrowLastTrace(TypeError("'%s' is not a Boolean", getAttrPathStr()));
|
||||||
|
|
||||||
return v.boolean;
|
return v.boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NixInt AttrCursor::getInt()
|
||||||
|
{
|
||||||
|
if (root->db) {
|
||||||
|
if (!cachedValue)
|
||||||
|
cachedValue = root->db->getAttr(getKey());
|
||||||
|
if (cachedValue && !std::get_if<placeholder_t>(&cachedValue->second)) {
|
||||||
|
if (auto i = std::get_if<int_t>(&cachedValue->second)) {
|
||||||
|
debug("using cached Integer attribute '%s'", getAttrPathStr());
|
||||||
|
return i->x;
|
||||||
|
} else
|
||||||
|
throw TypeError("'%s' is not an Integer", getAttrPathStr());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto & v = forceValue();
|
||||||
|
|
||||||
|
if (v.type() != nInt)
|
||||||
|
throw TypeError("'%s' is not an Integer", getAttrPathStr());
|
||||||
|
|
||||||
|
return v.integer;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::string> AttrCursor::getListOfStrings()
|
std::vector<std::string> AttrCursor::getListOfStrings()
|
||||||
{
|
{
|
||||||
if (root->db) {
|
if (root->db) {
|
||||||
|
|
@ -648,6 +692,7 @@ std::vector<std::string> AttrCursor::getListOfStrings()
|
||||||
for (auto & elem : v.listItems())
|
for (auto & elem : v.listItems())
|
||||||
res.push_back(std::string(root->state.forceStringNoCtx(*elem)));
|
res.push_back(std::string(root->state.forceStringNoCtx(*elem)));
|
||||||
|
|
||||||
|
if (root->db)
|
||||||
cachedValue = {root->db->setListOfStrings(getKey(), res), res};
|
cachedValue = {root->db->setListOfStrings(getKey(), res), res};
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
@ -663,14 +708,14 @@ std::vector<Symbol> AttrCursor::getAttrs()
|
||||||
debug("using cached attrset attribute '%s'", getAttrPathStr());
|
debug("using cached attrset attribute '%s'", getAttrPathStr());
|
||||||
return *attrs;
|
return *attrs;
|
||||||
} else
|
} else
|
||||||
throw TypeError("'%s' is not an attribute set", getAttrPathStr());
|
root->state.debugThrowLastTrace(TypeError("'%s' is not an attribute set", getAttrPathStr()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto & v = forceValue();
|
auto & v = forceValue();
|
||||||
|
|
||||||
if (v.type() != nAttrs)
|
if (v.type() != nAttrs)
|
||||||
throw TypeError("'%s' is not an attribute set", getAttrPathStr());
|
root->state.debugThrowLastTrace(TypeError("'%s' is not an attribute set", getAttrPathStr()));
|
||||||
|
|
||||||
std::vector<Symbol> attrs;
|
std::vector<Symbol> attrs;
|
||||||
for (auto & attr : *getValue().attrs)
|
for (auto & attr : *getValue().attrs)
|
||||||
|
|
|
||||||
|
|
@ -45,12 +45,14 @@ enum AttrType {
|
||||||
Failed = 5,
|
Failed = 5,
|
||||||
Bool = 6,
|
Bool = 6,
|
||||||
ListOfStrings = 7,
|
ListOfStrings = 7,
|
||||||
|
Int = 8,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct placeholder_t {};
|
struct placeholder_t {};
|
||||||
struct missing_t {};
|
struct missing_t {};
|
||||||
struct misc_t {};
|
struct misc_t {};
|
||||||
struct failed_t {};
|
struct failed_t {};
|
||||||
|
struct int_t { NixInt x; };
|
||||||
typedef uint64_t AttrId;
|
typedef uint64_t AttrId;
|
||||||
typedef std::pair<AttrId, Symbol> AttrKey;
|
typedef std::pair<AttrId, Symbol> AttrKey;
|
||||||
typedef std::pair<std::string, NixStringContext> string_t;
|
typedef std::pair<std::string, NixStringContext> string_t;
|
||||||
|
|
@ -63,6 +65,7 @@ typedef std::variant<
|
||||||
misc_t,
|
misc_t,
|
||||||
failed_t,
|
failed_t,
|
||||||
bool,
|
bool,
|
||||||
|
int_t,
|
||||||
std::vector<std::string>
|
std::vector<std::string>
|
||||||
> AttrValue;
|
> AttrValue;
|
||||||
|
|
||||||
|
|
@ -116,6 +119,8 @@ public:
|
||||||
|
|
||||||
bool getBool();
|
bool getBool();
|
||||||
|
|
||||||
|
NixInt getInt();
|
||||||
|
|
||||||
std::vector<std::string> getListOfStrings();
|
std::vector<std::string> getListOfStrings();
|
||||||
|
|
||||||
std::vector<Symbol> getAttrs();
|
std::vector<Symbol> getAttrs();
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
|
||||||
/* Note: Various places expect the allocated memory to be zeroed. */
|
/* Note: Various places expect the allocated memory to be zeroed. */
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
inline void * allocBytes(size_t n)
|
inline void * allocBytes(size_t n)
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
|
|
||||||
|
|
@ -36,7 +37,6 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
|
||||||
static char * allocString(size_t size)
|
static char * allocString(size_t size)
|
||||||
{
|
{
|
||||||
char * t;
|
char * t;
|
||||||
|
|
@ -147,7 +147,10 @@ void Value::print(const SymbolTable & symbols, std::ostream & str,
|
||||||
else {
|
else {
|
||||||
str << "[ ";
|
str << "[ ";
|
||||||
for (auto v2 : listItems()) {
|
for (auto v2 : listItems()) {
|
||||||
|
if (v2)
|
||||||
v2->print(symbols, str, seen);
|
v2->print(symbols, str, seen);
|
||||||
|
else
|
||||||
|
str << "(nullptr)";
|
||||||
str << " ";
|
str << " ";
|
||||||
}
|
}
|
||||||
str << "]";
|
str << "]";
|
||||||
|
|
@ -184,6 +187,11 @@ void Value::print(const SymbolTable & symbols, std::ostream & str, bool showRepe
|
||||||
print(symbols, str, showRepeated ? nullptr : &seen);
|
print(symbols, str, showRepeated ? nullptr : &seen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pretty print types for assertion errors
|
||||||
|
std::ostream & operator << (std::ostream & os, const ValueType t) {
|
||||||
|
os << showType(t);
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
std::string printValue(const EvalState & state, const Value & v)
|
std::string printValue(const EvalState & state, const Value & v)
|
||||||
{
|
{
|
||||||
|
|
@ -451,10 +459,15 @@ EvalState::EvalState(
|
||||||
, sKey(symbols.create("key"))
|
, sKey(symbols.create("key"))
|
||||||
, sPath(symbols.create("path"))
|
, sPath(symbols.create("path"))
|
||||||
, sPrefix(symbols.create("prefix"))
|
, sPrefix(symbols.create("prefix"))
|
||||||
|
, sOutputSpecified(symbols.create("outputSpecified"))
|
||||||
, repair(NoRepair)
|
, repair(NoRepair)
|
||||||
, emptyBindings(0)
|
, emptyBindings(0)
|
||||||
, store(store)
|
, store(store)
|
||||||
, buildStore(buildStore ? buildStore : store)
|
, buildStore(buildStore ? buildStore : store)
|
||||||
|
, debugRepl(nullptr)
|
||||||
|
, debugStop(false)
|
||||||
|
, debugQuit(false)
|
||||||
|
, trylevel(0)
|
||||||
, regexCache(makeRegexCache())
|
, regexCache(makeRegexCache())
|
||||||
#if HAVE_BOEHMGC
|
#if HAVE_BOEHMGC
|
||||||
, valueAllocCache(std::allocate_shared<void *>(traceable_allocator<void *>(), nullptr))
|
, valueAllocCache(std::allocate_shared<void *>(traceable_allocator<void *>(), nullptr))
|
||||||
|
|
@ -464,7 +477,7 @@ EvalState::EvalState(
|
||||||
, env1AllocCache(std::make_shared<void *>(nullptr))
|
, env1AllocCache(std::make_shared<void *>(nullptr))
|
||||||
#endif
|
#endif
|
||||||
, baseEnv(allocEnv(128))
|
, baseEnv(allocEnv(128))
|
||||||
, staticBaseEnv(false, 0)
|
, staticBaseEnv{std::make_shared<StaticEnv>(false, nullptr)}
|
||||||
{
|
{
|
||||||
countCalls = getEnv("NIX_COUNT_CALLS").value_or("0") != "0";
|
countCalls = getEnv("NIX_COUNT_CALLS").value_or("0") != "0";
|
||||||
|
|
||||||
|
|
@ -522,7 +535,7 @@ void EvalState::allowPath(const StorePath & storePath)
|
||||||
allowedPaths->insert(store->toRealPath(storePath));
|
allowedPaths->insert(store->toRealPath(storePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::allowAndSetStorePathString(const StorePath &storePath, Value & v)
|
void EvalState::allowAndSetStorePathString(const StorePath & storePath, Value & v)
|
||||||
{
|
{
|
||||||
allowPath(storePath);
|
allowPath(storePath);
|
||||||
|
|
||||||
|
|
@ -630,7 +643,7 @@ Value * EvalState::addConstant(const std::string & name, Value & v)
|
||||||
|
|
||||||
void EvalState::addConstant(const std::string & name, Value * v)
|
void EvalState::addConstant(const std::string & name, Value * v)
|
||||||
{
|
{
|
||||||
staticBaseEnv.vars.emplace_back(symbols.create(name), baseEnvDispl);
|
staticBaseEnv->vars.emplace_back(symbols.create(name), baseEnvDispl);
|
||||||
baseEnv.values[baseEnvDispl++] = v;
|
baseEnv.values[baseEnvDispl++] = v;
|
||||||
auto name2 = name.substr(0, 2) == "__" ? name.substr(2) : name;
|
auto name2 = name.substr(0, 2) == "__" ? name.substr(2) : name;
|
||||||
baseEnv.values[0]->attrs->push_back(Attr(symbols.create(name2), v));
|
baseEnv.values[0]->attrs->push_back(Attr(symbols.create(name2), v));
|
||||||
|
|
@ -655,7 +668,7 @@ Value * EvalState::addPrimOp(const std::string & name,
|
||||||
|
|
||||||
Value * v = allocValue();
|
Value * v = allocValue();
|
||||||
v->mkPrimOp(new PrimOp { .fun = primOp, .arity = arity, .name = name2 });
|
v->mkPrimOp(new PrimOp { .fun = primOp, .arity = arity, .name = name2 });
|
||||||
staticBaseEnv.vars.emplace_back(symbols.create(name), baseEnvDispl);
|
staticBaseEnv->vars.emplace_back(symbols.create(name), baseEnvDispl);
|
||||||
baseEnv.values[baseEnvDispl++] = v;
|
baseEnv.values[baseEnvDispl++] = v;
|
||||||
baseEnv.values[0]->attrs->push_back(Attr(sym, v));
|
baseEnv.values[0]->attrs->push_back(Attr(sym, v));
|
||||||
return v;
|
return v;
|
||||||
|
|
@ -681,7 +694,7 @@ Value * EvalState::addPrimOp(PrimOp && primOp)
|
||||||
|
|
||||||
Value * v = allocValue();
|
Value * v = allocValue();
|
||||||
v->mkPrimOp(new PrimOp(primOp));
|
v->mkPrimOp(new PrimOp(primOp));
|
||||||
staticBaseEnv.vars.emplace_back(envName, baseEnvDispl);
|
staticBaseEnv->vars.emplace_back(envName, baseEnvDispl);
|
||||||
baseEnv.values[baseEnvDispl++] = v;
|
baseEnv.values[baseEnvDispl++] = v;
|
||||||
baseEnv.values[0]->attrs->push_back(Attr(symbols.create(primOp.name), v));
|
baseEnv.values[0]->attrs->push_back(Attr(symbols.create(primOp.name), v));
|
||||||
return v;
|
return v;
|
||||||
|
|
@ -711,128 +724,291 @@ std::optional<EvalState::Doc> EvalState::getDoc(Value & v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// just for the current level of StaticEnv, not the whole chain.
|
||||||
|
void printStaticEnvBindings(const SymbolTable & st, const StaticEnv & se)
|
||||||
|
{
|
||||||
|
std::cout << ANSI_MAGENTA;
|
||||||
|
for (auto & i : se.vars)
|
||||||
|
std::cout << st[i.first] << " ";
|
||||||
|
std::cout << ANSI_NORMAL;
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// just for the current level of Env, not the whole chain.
|
||||||
|
void printWithBindings(const SymbolTable & st, const Env & env)
|
||||||
|
{
|
||||||
|
if (env.type == Env::HasWithAttrs) {
|
||||||
|
std::cout << "with: ";
|
||||||
|
std::cout << ANSI_MAGENTA;
|
||||||
|
Bindings::iterator j = env.values[0]->attrs->begin();
|
||||||
|
while (j != env.values[0]->attrs->end()) {
|
||||||
|
std::cout << st[j->name] << " ";
|
||||||
|
++j;
|
||||||
|
}
|
||||||
|
std::cout << ANSI_NORMAL;
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void printEnvBindings(const SymbolTable & st, const StaticEnv & se, const Env & env, int lvl)
|
||||||
|
{
|
||||||
|
std::cout << "Env level " << lvl << std::endl;
|
||||||
|
|
||||||
|
if (se.up && env.up) {
|
||||||
|
std::cout << "static: ";
|
||||||
|
printStaticEnvBindings(st, se);
|
||||||
|
printWithBindings(st, env);
|
||||||
|
std::cout << std::endl;
|
||||||
|
printEnvBindings(st, *se.up, *env.up, ++lvl);
|
||||||
|
} else {
|
||||||
|
std::cout << ANSI_MAGENTA;
|
||||||
|
// for the top level, don't print the double underscore ones;
|
||||||
|
// they are in builtins.
|
||||||
|
for (auto & i : se.vars)
|
||||||
|
if (!hasPrefix(st[i.first], "__"))
|
||||||
|
std::cout << st[i.first] << " ";
|
||||||
|
std::cout << ANSI_NORMAL;
|
||||||
|
std::cout << std::endl;
|
||||||
|
printWithBindings(st, env); // probably nothing there for the top level.
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void printEnvBindings(const EvalState &es, const Expr & expr, const Env & env)
|
||||||
|
{
|
||||||
|
// just print the names for now
|
||||||
|
auto se = es.getStaticEnv(expr);
|
||||||
|
if (se)
|
||||||
|
printEnvBindings(es.symbols, *se, env, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mapStaticEnvBindings(const SymbolTable & st, const StaticEnv & se, const Env & env, ValMap & vm)
|
||||||
|
{
|
||||||
|
// add bindings for the next level up first, so that the bindings for this level
|
||||||
|
// override the higher levels.
|
||||||
|
// The top level bindings (builtins) are skipped since they are added for us by initEnv()
|
||||||
|
if (env.up && se.up) {
|
||||||
|
mapStaticEnvBindings(st, *se.up, *env.up, vm);
|
||||||
|
|
||||||
|
if (env.type == Env::HasWithAttrs) {
|
||||||
|
// add 'with' bindings.
|
||||||
|
Bindings::iterator j = env.values[0]->attrs->begin();
|
||||||
|
while (j != env.values[0]->attrs->end()) {
|
||||||
|
vm[st[j->name]] = j->value;
|
||||||
|
++j;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// iterate through staticenv bindings and add them.
|
||||||
|
for (auto & i : se.vars)
|
||||||
|
vm[st[i.first]] = env.values[i.second];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<ValMap> mapStaticEnvBindings(const SymbolTable & st, const StaticEnv & se, const Env & env)
|
||||||
|
{
|
||||||
|
auto vm = std::make_unique<ValMap>();
|
||||||
|
mapStaticEnvBindings(st, se, env, *vm);
|
||||||
|
return vm;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EvalState::runDebugRepl(const Error * error, const Env & env, const Expr & expr)
|
||||||
|
{
|
||||||
|
// double check we've got the debugRepl function pointer.
|
||||||
|
if (!debugRepl)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto dts =
|
||||||
|
error && expr.getPos()
|
||||||
|
? std::make_unique<DebugTraceStacker>(
|
||||||
|
*this,
|
||||||
|
DebugTrace {
|
||||||
|
.pos = error->info().errPos ? *error->info().errPos : positions[expr.getPos()],
|
||||||
|
.expr = expr,
|
||||||
|
.env = env,
|
||||||
|
.hint = error->info().msg,
|
||||||
|
.isError = true
|
||||||
|
})
|
||||||
|
: nullptr;
|
||||||
|
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
printError("%s\n\n", error->what());
|
||||||
|
|
||||||
|
if (trylevel > 0 && error->info().level != lvlInfo)
|
||||||
|
printError("This exception occurred in a 'tryEval' call. Use " ANSI_GREEN "--ignore-try" ANSI_NORMAL " to skip these.\n");
|
||||||
|
|
||||||
|
printError(ANSI_BOLD "Starting REPL to allow you to inspect the current state of the evaluator.\n" ANSI_NORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto se = getStaticEnv(expr);
|
||||||
|
if (se) {
|
||||||
|
auto vm = mapStaticEnvBindings(symbols, *se.get(), env);
|
||||||
|
(debugRepl)(ref<EvalState>(shared_from_this()), *vm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Every "format" object (even temporary) takes up a few hundred bytes
|
/* Every "format" object (even temporary) takes up a few hundred bytes
|
||||||
of stack space, which is a real killer in the recursive
|
of stack space, which is a real killer in the recursive
|
||||||
evaluator. So here are some helper functions for throwing
|
evaluator. So here are some helper functions for throwing
|
||||||
exceptions. */
|
exceptions. */
|
||||||
|
void EvalState::throwEvalError(const PosIdx pos, const char * s, Env & env, Expr & expr)
|
||||||
void EvalState::throwEvalError(const PosIdx pos, const char * s) const
|
|
||||||
{
|
{
|
||||||
throw EvalError({
|
debugThrow(EvalError({
|
||||||
.msg = hintfmt(s),
|
.msg = hintfmt(s),
|
||||||
.errPos = positions[pos]
|
.errPos = positions[pos]
|
||||||
});
|
}), env, expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwTypeError(const PosIdx pos, const char * s, const Value & v) const
|
void EvalState::throwEvalError(const PosIdx pos, const char * s)
|
||||||
{
|
{
|
||||||
throw TypeError({
|
debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt(s, showType(v)),
|
.msg = hintfmt(s),
|
||||||
.errPos = positions[pos]
|
.errPos = positions[pos]
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwEvalError(const char * s, const std::string & s2) const
|
void EvalState::throwEvalError(const char * s, const std::string & s2)
|
||||||
{
|
{
|
||||||
throw EvalError(s, s2);
|
debugThrowLastTrace(EvalError(s, s2));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwEvalError(const PosIdx pos, const Suggestions & suggestions, const char * s,
|
void EvalState::throwEvalError(const PosIdx pos, const Suggestions & suggestions, const char * s,
|
||||||
const std::string & s2) const
|
const std::string & s2, Env & env, Expr & expr)
|
||||||
{
|
{
|
||||||
throw EvalError(ErrorInfo {
|
debugThrow(EvalError(ErrorInfo{
|
||||||
.msg = hintfmt(s, s2),
|
.msg = hintfmt(s, s2),
|
||||||
.errPos = positions[pos],
|
.errPos = positions[pos],
|
||||||
.suggestions = suggestions,
|
.suggestions = suggestions,
|
||||||
});
|
}), env, expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::string & s2) const
|
void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::string & s2)
|
||||||
{
|
{
|
||||||
throw EvalError(ErrorInfo {
|
debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt(s, s2),
|
.msg = hintfmt(s, s2),
|
||||||
.errPos = positions[pos]
|
.errPos = positions[pos]
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwEvalError(const char * s, const std::string & s2, const std::string & s3) const
|
void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::string & s2, Env & env, Expr & expr)
|
||||||
{
|
{
|
||||||
throw EvalError(s, s2, s3);
|
debugThrow(EvalError({
|
||||||
|
.msg = hintfmt(s, s2),
|
||||||
|
.errPos = positions[pos]
|
||||||
|
}), env, expr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EvalState::throwEvalError(const char * s, const std::string & s2,
|
||||||
|
const std::string & s3)
|
||||||
|
{
|
||||||
|
debugThrowLastTrace(EvalError({
|
||||||
|
.msg = hintfmt(s, s2),
|
||||||
|
.errPos = positions[noPos]
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::string & s2,
|
void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::string & s2,
|
||||||
const std::string & s3) const
|
const std::string & s3)
|
||||||
{
|
{
|
||||||
throw EvalError({
|
debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt(s, s2, s3),
|
.msg = hintfmt(s, s2),
|
||||||
.errPos = positions[pos]
|
.errPos = positions[pos]
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwEvalError(const PosIdx p1, const char * s, const Symbol sym, const PosIdx p2) const
|
void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::string & s2,
|
||||||
|
const std::string & s3, Env & env, Expr & expr)
|
||||||
|
{
|
||||||
|
debugThrow(EvalError({
|
||||||
|
.msg = hintfmt(s, s2),
|
||||||
|
.errPos = positions[pos]
|
||||||
|
}), env, expr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EvalState::throwEvalError(const PosIdx p1, const char * s, const Symbol sym, const PosIdx p2, Env & env, Expr & expr)
|
||||||
{
|
{
|
||||||
// p1 is where the error occurred; p2 is a position mentioned in the message.
|
// p1 is where the error occurred; p2 is a position mentioned in the message.
|
||||||
throw EvalError({
|
debugThrow(EvalError({
|
||||||
.msg = hintfmt(s, symbols[sym], positions[p2]),
|
.msg = hintfmt(s, symbols[sym], positions[p2]),
|
||||||
.errPos = positions[p1]
|
.errPos = positions[p1]
|
||||||
});
|
}), env, expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwTypeError(const PosIdx pos, const char * s) const
|
void EvalState::throwTypeError(const PosIdx pos, const char * s, const Value & v)
|
||||||
{
|
{
|
||||||
throw TypeError({
|
debugThrowLastTrace(TypeError({
|
||||||
|
.msg = hintfmt(s, showType(v)),
|
||||||
|
.errPos = positions[pos]
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
void EvalState::throwTypeError(const PosIdx pos, const char * s, const Value & v, Env & env, Expr & expr)
|
||||||
|
{
|
||||||
|
debugThrow(TypeError({
|
||||||
|
.msg = hintfmt(s, showType(v)),
|
||||||
|
.errPos = positions[pos]
|
||||||
|
}), env, expr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EvalState::throwTypeError(const PosIdx pos, const char * s)
|
||||||
|
{
|
||||||
|
debugThrowLastTrace(TypeError({
|
||||||
.msg = hintfmt(s),
|
.msg = hintfmt(s),
|
||||||
.errPos = positions[pos]
|
.errPos = positions[pos]
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwTypeError(const PosIdx pos, const char * s, const ExprLambda & fun,
|
void EvalState::throwTypeError(const PosIdx pos, const char * s, const ExprLambda & fun,
|
||||||
const Symbol s2) const
|
const Symbol s2, Env & env, Expr &expr)
|
||||||
{
|
{
|
||||||
throw TypeError({
|
debugThrow(TypeError({
|
||||||
.msg = hintfmt(s, fun.showNamePos(*this), symbols[s2]),
|
.msg = hintfmt(s, fun.showNamePos(*this), symbols[s2]),
|
||||||
.errPos = positions[pos]
|
.errPos = positions[pos]
|
||||||
});
|
}), env, expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwTypeError(const PosIdx pos, const Suggestions & suggestions, const char * s,
|
void EvalState::throwTypeError(const PosIdx pos, const Suggestions & suggestions, const char * s,
|
||||||
const ExprLambda & fun, const Symbol s2) const
|
const ExprLambda & fun, const Symbol s2, Env & env, Expr &expr)
|
||||||
{
|
{
|
||||||
throw TypeError(ErrorInfo {
|
debugThrow(TypeError(ErrorInfo {
|
||||||
.msg = hintfmt(s, fun.showNamePos(*this), symbols[s2]),
|
.msg = hintfmt(s, fun.showNamePos(*this), symbols[s2]),
|
||||||
.errPos = positions[pos],
|
.errPos = positions[pos],
|
||||||
.suggestions = suggestions,
|
.suggestions = suggestions,
|
||||||
});
|
}), env, expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EvalState::throwTypeError(const char * s, const Value & v, Env & env, Expr &expr)
|
||||||
void EvalState::throwTypeError(const char * s, const Value & v) const
|
|
||||||
{
|
{
|
||||||
throw TypeError(s, showType(v));
|
debugThrow(TypeError({
|
||||||
|
.msg = hintfmt(s, showType(v)),
|
||||||
|
.errPos = positions[expr.getPos()],
|
||||||
|
}), env, expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwAssertionError(const PosIdx pos, const char * s, const std::string & s1) const
|
void EvalState::throwAssertionError(const PosIdx pos, const char * s, const std::string & s1, Env & env, Expr &expr)
|
||||||
{
|
{
|
||||||
throw AssertionError({
|
debugThrow(AssertionError({
|
||||||
.msg = hintfmt(s, s1),
|
.msg = hintfmt(s, s1),
|
||||||
.errPos = positions[pos]
|
.errPos = positions[pos]
|
||||||
});
|
}), env, expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwUndefinedVarError(const PosIdx pos, const char * s, const std::string & s1) const
|
void EvalState::throwUndefinedVarError(const PosIdx pos, const char * s, const std::string & s1, Env & env, Expr &expr)
|
||||||
{
|
{
|
||||||
throw UndefinedVarError({
|
debugThrow(UndefinedVarError({
|
||||||
.msg = hintfmt(s, s1),
|
.msg = hintfmt(s, s1),
|
||||||
.errPos = positions[pos]
|
.errPos = positions[pos]
|
||||||
});
|
}), env, expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::throwMissingArgumentError(const PosIdx pos, const char * s, const std::string & s1) const
|
void EvalState::throwMissingArgumentError(const PosIdx pos, const char * s, const std::string & s1, Env & env, Expr &expr)
|
||||||
{
|
{
|
||||||
throw MissingArgumentError({
|
debugThrow(MissingArgumentError({
|
||||||
.msg = hintfmt(s, s1),
|
.msg = hintfmt(s, s1),
|
||||||
.errPos = positions[pos]
|
.errPos = positions[pos]
|
||||||
});
|
}), env, expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvalState::addErrorTrace(Error & e, const char * s, const std::string & s2) const
|
void EvalState::addErrorTrace(Error & e, const char * s, const std::string & s2) const
|
||||||
|
|
@ -845,6 +1021,32 @@ void EvalState::addErrorTrace(Error & e, const PosIdx pos, const char * s, const
|
||||||
e.addTrace(positions[pos], s, s2);
|
e.addTrace(positions[pos], s, s2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::unique_ptr<DebugTraceStacker> makeDebugTraceStacker(
|
||||||
|
EvalState & state,
|
||||||
|
Expr & expr,
|
||||||
|
Env & env,
|
||||||
|
std::optional<ErrPos> pos,
|
||||||
|
const char * s,
|
||||||
|
const std::string & s2)
|
||||||
|
{
|
||||||
|
return std::make_unique<DebugTraceStacker>(state,
|
||||||
|
DebugTrace {
|
||||||
|
.pos = pos,
|
||||||
|
.expr = expr,
|
||||||
|
.env = env,
|
||||||
|
.hint = hintfmt(s, s2),
|
||||||
|
.isError = false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
DebugTraceStacker::DebugTraceStacker(EvalState & evalState, DebugTrace t)
|
||||||
|
: evalState(evalState)
|
||||||
|
, trace(std::move(t))
|
||||||
|
{
|
||||||
|
evalState.debugTraces.push_front(trace);
|
||||||
|
if (evalState.debugStop && evalState.debugRepl)
|
||||||
|
evalState.runDebugRepl(nullptr, trace.env, trace.expr);
|
||||||
|
}
|
||||||
|
|
||||||
void Value::mkString(std::string_view s)
|
void Value::mkString(std::string_view s)
|
||||||
{
|
{
|
||||||
|
|
@ -903,12 +1105,11 @@ inline Value * EvalState::lookupVar(Env * env, const ExprVar & var, bool noEval)
|
||||||
return j->value;
|
return j->value;
|
||||||
}
|
}
|
||||||
if (!env->prevWith)
|
if (!env->prevWith)
|
||||||
throwUndefinedVarError(var.pos, "undefined variable '%1%'", symbols[var.name]);
|
throwUndefinedVarError(var.pos, "undefined variable '%1%'", symbols[var.name], *env, const_cast<ExprVar&>(var));
|
||||||
for (size_t l = env->prevWith; l; --l, env = env->up) ;
|
for (size_t l = env->prevWith; l; --l, env = env->up) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void EvalState::mkList(Value & v, size_t size)
|
void EvalState::mkList(Value & v, size_t size)
|
||||||
{
|
{
|
||||||
v.mkList(size);
|
v.mkList(size);
|
||||||
|
|
@ -1041,6 +1242,15 @@ void EvalState::cacheFile(
|
||||||
fileParseCache[resolvedPath] = e;
|
fileParseCache[resolvedPath] = e;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
auto dts = debugRepl
|
||||||
|
? makeDebugTraceStacker(
|
||||||
|
*this,
|
||||||
|
*e,
|
||||||
|
this->baseEnv,
|
||||||
|
e->getPos() ? std::optional(ErrPos(positions[e->getPos()])) : std::nullopt,
|
||||||
|
"while evaluating the file '%1%':", resolvedPath)
|
||||||
|
: nullptr;
|
||||||
|
|
||||||
// Enforce that 'flake.nix' is a direct attrset, not a
|
// Enforce that 'flake.nix' is a direct attrset, not a
|
||||||
// computation.
|
// computation.
|
||||||
if (mustBeTrivial &&
|
if (mustBeTrivial &&
|
||||||
|
|
@ -1068,7 +1278,7 @@ inline bool EvalState::evalBool(Env & env, Expr * e)
|
||||||
Value v;
|
Value v;
|
||||||
e->eval(*this, env, v);
|
e->eval(*this, env, v);
|
||||||
if (v.type() != nBool)
|
if (v.type() != nBool)
|
||||||
throwTypeError("value is %1% while a Boolean was expected", v);
|
throwTypeError(noPos, "value is %1% while a Boolean was expected", v, env, *e);
|
||||||
return v.boolean;
|
return v.boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1078,7 +1288,7 @@ inline bool EvalState::evalBool(Env & env, Expr * e, const PosIdx pos)
|
||||||
Value v;
|
Value v;
|
||||||
e->eval(*this, env, v);
|
e->eval(*this, env, v);
|
||||||
if (v.type() != nBool)
|
if (v.type() != nBool)
|
||||||
throwTypeError(pos, "value is %1% while a Boolean was expected", v);
|
throwTypeError(pos, "value is %1% while a Boolean was expected", v, env, *e);
|
||||||
return v.boolean;
|
return v.boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1087,7 +1297,7 @@ inline void EvalState::evalAttrs(Env & env, Expr * e, Value & v)
|
||||||
{
|
{
|
||||||
e->eval(*this, env, v);
|
e->eval(*this, env, v);
|
||||||
if (v.type() != nAttrs)
|
if (v.type() != nAttrs)
|
||||||
throwTypeError("value is %1% while a set was expected", v);
|
throwTypeError(noPos, "value is %1% while a set was expected", v, env, *e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1192,7 +1402,7 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v)
|
||||||
auto nameSym = state.symbols.create(nameVal.string.s);
|
auto nameSym = state.symbols.create(nameVal.string.s);
|
||||||
Bindings::iterator j = v.attrs->find(nameSym);
|
Bindings::iterator j = v.attrs->find(nameSym);
|
||||||
if (j != v.attrs->end())
|
if (j != v.attrs->end())
|
||||||
state.throwEvalError(i.pos, "dynamic attribute '%1%' already defined at %2%", nameSym, j->pos);
|
state.throwEvalError(i.pos, "dynamic attribute '%1%' already defined at %2%", nameSym, j->pos, env, *this);
|
||||||
|
|
||||||
i.valueExpr->setName(nameSym);
|
i.valueExpr->setName(nameSym);
|
||||||
/* Keep sorted order so find can catch duplicates */
|
/* Keep sorted order so find can catch duplicates */
|
||||||
|
|
@ -1266,6 +1476,15 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v)
|
||||||
e->eval(state, env, vTmp);
|
e->eval(state, env, vTmp);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
auto dts = state.debugRepl
|
||||||
|
? makeDebugTraceStacker(
|
||||||
|
state,
|
||||||
|
*this,
|
||||||
|
env,
|
||||||
|
state.positions[pos2],
|
||||||
|
"while evaluating the attribute '%1%'",
|
||||||
|
showAttrPath(state, env, attrPath))
|
||||||
|
: nullptr;
|
||||||
|
|
||||||
for (auto & i : attrPath) {
|
for (auto & i : attrPath) {
|
||||||
state.nrLookups++;
|
state.nrLookups++;
|
||||||
|
|
@ -1288,7 +1507,7 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v)
|
||||||
state.throwEvalError(
|
state.throwEvalError(
|
||||||
pos,
|
pos,
|
||||||
Suggestions::bestMatches(allAttrNames, state.symbols[name]),
|
Suggestions::bestMatches(allAttrNames, state.symbols[name]),
|
||||||
"attribute '%1%' missing", state.symbols[name]);
|
"attribute '%1%' missing", state.symbols[name], env, *this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vAttrs = j->value;
|
vAttrs = j->value;
|
||||||
|
|
@ -1379,7 +1598,6 @@ void EvalState::callFunction(Value & fun, size_t nrArgs, Value * * args, Value &
|
||||||
|
|
||||||
if (!lambda.hasFormals())
|
if (!lambda.hasFormals())
|
||||||
env2.values[displ++] = args[0];
|
env2.values[displ++] = args[0];
|
||||||
|
|
||||||
else {
|
else {
|
||||||
forceAttrs(*args[0], pos);
|
forceAttrs(*args[0], pos);
|
||||||
|
|
||||||
|
|
@ -1394,7 +1612,7 @@ void EvalState::callFunction(Value & fun, size_t nrArgs, Value * * args, Value &
|
||||||
auto j = args[0]->attrs->get(i.name);
|
auto j = args[0]->attrs->get(i.name);
|
||||||
if (!j) {
|
if (!j) {
|
||||||
if (!i.def) throwTypeError(pos, "%1% called without required argument '%2%'",
|
if (!i.def) throwTypeError(pos, "%1% called without required argument '%2%'",
|
||||||
lambda, i.name);
|
lambda, i.name, *fun.lambda.env, lambda);
|
||||||
env2.values[displ++] = i.def->maybeThunk(*this, env2);
|
env2.values[displ++] = i.def->maybeThunk(*this, env2);
|
||||||
} else {
|
} else {
|
||||||
attrsUsed++;
|
attrsUsed++;
|
||||||
|
|
@ -1416,8 +1634,7 @@ void EvalState::callFunction(Value & fun, size_t nrArgs, Value * * args, Value &
|
||||||
pos,
|
pos,
|
||||||
Suggestions::bestMatches(formalNames, symbols[i.name]),
|
Suggestions::bestMatches(formalNames, symbols[i.name]),
|
||||||
"%1% called with unexpected argument '%2%'",
|
"%1% called with unexpected argument '%2%'",
|
||||||
lambda,
|
lambda, i.name, *fun.lambda.env, lambda);
|
||||||
i.name);
|
|
||||||
}
|
}
|
||||||
abort(); // can't happen
|
abort(); // can't happen
|
||||||
}
|
}
|
||||||
|
|
@ -1428,6 +1645,15 @@ void EvalState::callFunction(Value & fun, size_t nrArgs, Value * * args, Value &
|
||||||
|
|
||||||
/* Evaluate the body. */
|
/* Evaluate the body. */
|
||||||
try {
|
try {
|
||||||
|
auto dts = debugRepl
|
||||||
|
? makeDebugTraceStacker(
|
||||||
|
*this, *lambda.body, env2, positions[lambda.pos],
|
||||||
|
"while evaluating %s",
|
||||||
|
lambda.name
|
||||||
|
? concatStrings("'", symbols[lambda.name], "'")
|
||||||
|
: "anonymous lambda")
|
||||||
|
: nullptr;
|
||||||
|
|
||||||
lambda.body->eval(*this, env2, vCur);
|
lambda.body->eval(*this, env2, vCur);
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
if (loggerSettings.showTrace.get()) {
|
if (loggerSettings.showTrace.get()) {
|
||||||
|
|
@ -1582,8 +1808,8 @@ void EvalState::autoCallFunction(Bindings & args, Value & fun, Value & res)
|
||||||
Nix attempted to evaluate a function as a top level expression; in
|
Nix attempted to evaluate a function as a top level expression; in
|
||||||
this case it must have its arguments supplied either by default
|
this case it must have its arguments supplied either by default
|
||||||
values, or passed explicitly with '--arg' or '--argstr'. See
|
values, or passed explicitly with '--arg' or '--argstr'. See
|
||||||
https://nixos.org/manual/nix/stable/#ss-functions.)", symbols[i.name]);
|
https://nixos.org/manual/nix/stable/expressions/language-constructs.html#functions.)", symbols[i.name],
|
||||||
|
*fun.lambda.env, *fun.lambda.fun);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1615,7 +1841,7 @@ void ExprAssert::eval(EvalState & state, Env & env, Value & v)
|
||||||
if (!state.evalBool(env, cond, pos)) {
|
if (!state.evalBool(env, cond, pos)) {
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
cond->show(state.symbols, out);
|
cond->show(state.symbols, out);
|
||||||
state.throwAssertionError(pos, "assertion '%1%' failed", out.str());
|
state.throwAssertionError(pos, "assertion '%1%' failed", out.str(), env, *this);
|
||||||
}
|
}
|
||||||
body->eval(state, env, v);
|
body->eval(state, env, v);
|
||||||
}
|
}
|
||||||
|
|
@ -1792,14 +2018,14 @@ void ExprConcatStrings::eval(EvalState & state, Env & env, Value & v)
|
||||||
nf = n;
|
nf = n;
|
||||||
nf += vTmp.fpoint;
|
nf += vTmp.fpoint;
|
||||||
} else
|
} else
|
||||||
state.throwEvalError(i_pos, "cannot add %1% to an integer", showType(vTmp));
|
state.throwEvalError(i_pos, "cannot add %1% to an integer", showType(vTmp), env, *this);
|
||||||
} else if (firstType == nFloat) {
|
} else if (firstType == nFloat) {
|
||||||
if (vTmp.type() == nInt) {
|
if (vTmp.type() == nInt) {
|
||||||
nf += vTmp.integer;
|
nf += vTmp.integer;
|
||||||
} else if (vTmp.type() == nFloat) {
|
} else if (vTmp.type() == nFloat) {
|
||||||
nf += vTmp.fpoint;
|
nf += vTmp.fpoint;
|
||||||
} else
|
} else
|
||||||
state.throwEvalError(i_pos, "cannot add %1% to a float", showType(vTmp));
|
state.throwEvalError(i_pos, "cannot add %1% to a float", showType(vTmp), env, *this);
|
||||||
} else {
|
} else {
|
||||||
if (s.empty()) s.reserve(es->size());
|
if (s.empty()) s.reserve(es->size());
|
||||||
/* skip canonization of first path, which would only be not
|
/* skip canonization of first path, which would only be not
|
||||||
|
|
@ -1819,7 +2045,7 @@ void ExprConcatStrings::eval(EvalState & state, Env & env, Value & v)
|
||||||
v.mkFloat(nf);
|
v.mkFloat(nf);
|
||||||
else if (firstType == nPath) {
|
else if (firstType == nPath) {
|
||||||
if (!context.empty())
|
if (!context.empty())
|
||||||
state.throwEvalError(pos, "a string that refers to a store path cannot be appended to a path");
|
state.throwEvalError(pos, "a string that refers to a store path cannot be appended to a path", env, *this);
|
||||||
v.mkPath(canonPath(str()));
|
v.mkPath(canonPath(str()));
|
||||||
} else
|
} else
|
||||||
v.mkStringMove(c_str(), context);
|
v.mkStringMove(c_str(), context);
|
||||||
|
|
@ -1846,6 +2072,12 @@ void EvalState::forceValueDeep(Value & v)
|
||||||
if (v.type() == nAttrs) {
|
if (v.type() == nAttrs) {
|
||||||
for (auto & i : *v.attrs)
|
for (auto & i : *v.attrs)
|
||||||
try {
|
try {
|
||||||
|
// If the value is a thunk, we're evaling. Otherwise no trace necessary.
|
||||||
|
auto dts = debugRepl && i.value->isThunk()
|
||||||
|
? makeDebugTraceStacker(*this, *i.value->thunk.expr, *i.value->thunk.env, positions[i.pos],
|
||||||
|
"while evaluating the attribute '%1%'", symbols[i.name])
|
||||||
|
: nullptr;
|
||||||
|
|
||||||
recurse(*i.value);
|
recurse(*i.value);
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
addErrorTrace(e, i.pos, "while evaluating the attribute '%1%'", symbols[i.name]);
|
addErrorTrace(e, i.pos, "while evaluating the attribute '%1%'", symbols[i.name]);
|
||||||
|
|
@ -1868,6 +2100,7 @@ NixInt EvalState::forceInt(Value & v, const PosIdx pos)
|
||||||
forceValue(v, pos);
|
forceValue(v, pos);
|
||||||
if (v.type() != nInt)
|
if (v.type() != nInt)
|
||||||
throwTypeError(pos, "value is %1% while an integer was expected", v);
|
throwTypeError(pos, "value is %1% while an integer was expected", v);
|
||||||
|
|
||||||
return v.integer;
|
return v.integer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1910,10 +2143,7 @@ std::string_view EvalState::forceString(Value & v, const PosIdx pos)
|
||||||
{
|
{
|
||||||
forceValue(v, pos);
|
forceValue(v, pos);
|
||||||
if (v.type() != nString) {
|
if (v.type() != nString) {
|
||||||
if (pos)
|
|
||||||
throwTypeError(pos, "value is %1% while a string was expected", v);
|
throwTypeError(pos, "value is %1% while a string was expected", v);
|
||||||
else
|
|
||||||
throwTypeError("value is %1% while a string was expected", v);
|
|
||||||
}
|
}
|
||||||
return v.string.s;
|
return v.string.s;
|
||||||
}
|
}
|
||||||
|
|
@ -2030,7 +2260,8 @@ BackedStringView EvalState::coerceToString(const PosIdx pos, Value & v, PathSet
|
||||||
if (maybeString)
|
if (maybeString)
|
||||||
return std::move(*maybeString);
|
return std::move(*maybeString);
|
||||||
auto i = v.attrs->find(sOutPath);
|
auto i = v.attrs->find(sOutPath);
|
||||||
if (i == v.attrs->end()) throwTypeError(pos, "cannot coerce a set to a string");
|
if (i == v.attrs->end())
|
||||||
|
throwTypeError(pos, "cannot coerce a set to a string");
|
||||||
return coerceToString(pos, *i->value, context, coerceMore, copyToStore);
|
return coerceToString(pos, *i->value, context, coerceMore, copyToStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2038,7 +2269,6 @@ BackedStringView EvalState::coerceToString(const PosIdx pos, Value & v, PathSet
|
||||||
return v.external->coerceToString(positions[pos], context, coerceMore, copyToStore);
|
return v.external->coerceToString(positions[pos], context, coerceMore, copyToStore);
|
||||||
|
|
||||||
if (coerceMore) {
|
if (coerceMore) {
|
||||||
|
|
||||||
/* Note that `false' is represented as an empty string for
|
/* Note that `false' is represented as an empty string for
|
||||||
shell scripting convenience, just like `null'. */
|
shell scripting convenience, just like `null'. */
|
||||||
if (v.type() == nBool && v.boolean) return "1";
|
if (v.type() == nBool && v.boolean) return "1";
|
||||||
|
|
@ -2183,7 +2413,9 @@ bool EvalState::eqValues(Value & v1, Value & v2)
|
||||||
return v1.fpoint == v2.fpoint;
|
return v1.fpoint == v2.fpoint;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throwEvalError("cannot compare %1% with %2%", showType(v1), showType(v2));
|
throwEvalError("cannot compare %1% with %2%",
|
||||||
|
showType(v1),
|
||||||
|
showType(v2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -25,7 +24,6 @@ enum RepairFlag : bool;
|
||||||
|
|
||||||
typedef void (* PrimOpFun) (EvalState & state, const PosIdx pos, Value * * args, Value & v);
|
typedef void (* PrimOpFun) (EvalState & state, const PosIdx pos, Value * * args, Value & v);
|
||||||
|
|
||||||
|
|
||||||
struct PrimOp
|
struct PrimOp
|
||||||
{
|
{
|
||||||
PrimOpFun fun;
|
PrimOpFun fun;
|
||||||
|
|
@ -35,6 +33,11 @@ struct PrimOp
|
||||||
const char * doc = nullptr;
|
const char * doc = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if HAVE_BOEHMGC
|
||||||
|
typedef std::map<std::string, Value *, std::less<std::string>, traceable_allocator<std::pair<const std::string, Value *> > > ValMap;
|
||||||
|
#else
|
||||||
|
typedef std::map<std::string, Value *> ValMap;
|
||||||
|
#endif
|
||||||
|
|
||||||
struct Env
|
struct Env
|
||||||
{
|
{
|
||||||
|
|
@ -44,6 +47,10 @@ struct Env
|
||||||
Value * values[0];
|
Value * values[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void printEnvBindings(const EvalState &es, const Expr & expr, const Env & env);
|
||||||
|
void printEnvBindings(const SymbolTable & st, const StaticEnv & se, const Env & env, int lvl = 0);
|
||||||
|
|
||||||
|
std::unique_ptr<ValMap> mapStaticEnvBindings(const SymbolTable & st, const StaticEnv & se, const Env & env);
|
||||||
|
|
||||||
void copyContext(const Value & v, PathSet & context);
|
void copyContext(const Value & v, PathSet & context);
|
||||||
|
|
||||||
|
|
@ -55,6 +62,7 @@ typedef std::map<Path, StorePath> SrcToStore;
|
||||||
|
|
||||||
std::ostream & printValue(const EvalState & state, std::ostream & str, const Value & v);
|
std::ostream & printValue(const EvalState & state, std::ostream & str, const Value & v);
|
||||||
std::string printValue(const EvalState & state, const Value & v);
|
std::string printValue(const EvalState & state, const Value & v);
|
||||||
|
std::ostream & operator << (std::ostream & os, const ValueType t);
|
||||||
|
|
||||||
|
|
||||||
typedef std::pair<std::string, std::string> SearchPathElem;
|
typedef std::pair<std::string, std::string> SearchPathElem;
|
||||||
|
|
@ -69,8 +77,17 @@ struct RegexCache;
|
||||||
|
|
||||||
std::shared_ptr<RegexCache> makeRegexCache();
|
std::shared_ptr<RegexCache> makeRegexCache();
|
||||||
|
|
||||||
|
struct DebugTrace {
|
||||||
|
std::optional<ErrPos> pos;
|
||||||
|
const Expr & expr;
|
||||||
|
const Env & env;
|
||||||
|
hintformat hint;
|
||||||
|
bool isError;
|
||||||
|
};
|
||||||
|
|
||||||
class EvalState
|
void debugError(Error * e, Env & env, Expr & expr);
|
||||||
|
|
||||||
|
class EvalState : public std::enable_shared_from_this<EvalState>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SymbolTable symbols;
|
SymbolTable symbols;
|
||||||
|
|
@ -86,7 +103,8 @@ public:
|
||||||
sOutputHash, sOutputHashAlgo, sOutputHashMode,
|
sOutputHash, sOutputHashAlgo, sOutputHashMode,
|
||||||
sRecurseForDerivations,
|
sRecurseForDerivations,
|
||||||
sDescription, sSelf, sEpsilon, sStartSet, sOperator, sKey, sPath,
|
sDescription, sSelf, sEpsilon, sStartSet, sOperator, sKey, sPath,
|
||||||
sPrefix;
|
sPrefix,
|
||||||
|
sOutputSpecified;
|
||||||
Symbol sDerivationNix;
|
Symbol sDerivationNix;
|
||||||
|
|
||||||
/* If set, force copying files to the Nix store even if they
|
/* If set, force copying files to the Nix store even if they
|
||||||
|
|
@ -108,12 +126,56 @@ public:
|
||||||
RootValue vCallFlake = nullptr;
|
RootValue vCallFlake = nullptr;
|
||||||
RootValue vImportedDrvToDerivation = nullptr;
|
RootValue vImportedDrvToDerivation = nullptr;
|
||||||
|
|
||||||
|
/* Debugger */
|
||||||
|
void (* debugRepl)(ref<EvalState> es, const ValMap & extraEnv);
|
||||||
|
bool debugStop;
|
||||||
|
bool debugQuit;
|
||||||
|
int trylevel;
|
||||||
|
std::list<DebugTrace> debugTraces;
|
||||||
|
std::map<const Expr*, const std::shared_ptr<const StaticEnv>> exprEnvs;
|
||||||
|
const std::shared_ptr<const StaticEnv> getStaticEnv(const Expr & expr) const
|
||||||
|
{
|
||||||
|
auto i = exprEnvs.find(&expr);
|
||||||
|
if (i != exprEnvs.end())
|
||||||
|
return i->second;
|
||||||
|
else
|
||||||
|
return std::shared_ptr<const StaticEnv>();;
|
||||||
|
}
|
||||||
|
|
||||||
|
void runDebugRepl(const Error * error, const Env & env, const Expr & expr);
|
||||||
|
|
||||||
|
template<class E>
|
||||||
|
[[gnu::noinline, gnu::noreturn]]
|
||||||
|
void debugThrow(E && error, const Env & env, const Expr & expr)
|
||||||
|
{
|
||||||
|
if (debugRepl)
|
||||||
|
runDebugRepl(&error, env, expr);
|
||||||
|
|
||||||
|
throw std::move(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class E>
|
||||||
|
[[gnu::noinline, gnu::noreturn]]
|
||||||
|
void debugThrowLastTrace(E && e)
|
||||||
|
{
|
||||||
|
// Call this in the situation where Expr and Env are inaccessible.
|
||||||
|
// The debugger will start in the last context that's in the
|
||||||
|
// DebugTrace stack.
|
||||||
|
if (debugRepl && !debugTraces.empty()) {
|
||||||
|
const DebugTrace & last = debugTraces.front();
|
||||||
|
runDebugRepl(&e, last.env, last.expr);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw std::move(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SrcToStore srcToStore;
|
SrcToStore srcToStore;
|
||||||
|
|
||||||
/* A cache from path names to parse trees. */
|
/* A cache from path names to parse trees. */
|
||||||
#if HAVE_BOEHMGC
|
#if HAVE_BOEHMGC
|
||||||
typedef std::map<Path, Expr *, std::less<Path>, traceable_allocator<std::pair<const Path, Expr *> > > FileParseCache;
|
typedef std::map<Path, Expr *, std::less<Path>, traceable_allocator<std::pair<const Path, Expr *>>> FileParseCache;
|
||||||
#else
|
#else
|
||||||
typedef std::map<Path, Expr *> FileParseCache;
|
typedef std::map<Path, Expr *> FileParseCache;
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -121,7 +183,7 @@ private:
|
||||||
|
|
||||||
/* A cache from path names to values. */
|
/* A cache from path names to values. */
|
||||||
#if HAVE_BOEHMGC
|
#if HAVE_BOEHMGC
|
||||||
typedef std::map<Path, Value, std::less<Path>, traceable_allocator<std::pair<const Path, Value> > > FileEvalCache;
|
typedef std::map<Path, Value, std::less<Path>, traceable_allocator<std::pair<const Path, Value>>> FileEvalCache;
|
||||||
#else
|
#else
|
||||||
typedef std::map<Path, Value> FileEvalCache;
|
typedef std::map<Path, Value> FileEvalCache;
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -184,10 +246,10 @@ public:
|
||||||
|
|
||||||
/* Parse a Nix expression from the specified file. */
|
/* Parse a Nix expression from the specified file. */
|
||||||
Expr * parseExprFromFile(const Path & path);
|
Expr * parseExprFromFile(const Path & path);
|
||||||
Expr * parseExprFromFile(const Path & path, StaticEnv & staticEnv);
|
Expr * parseExprFromFile(const Path & path, std::shared_ptr<StaticEnv> & staticEnv);
|
||||||
|
|
||||||
/* Parse a Nix expression from the specified string. */
|
/* Parse a Nix expression from the specified string. */
|
||||||
Expr * parseExprFromString(std::string s, const Path & basePath, StaticEnv & staticEnv);
|
Expr * parseExprFromString(std::string s, const Path & basePath, std::shared_ptr<StaticEnv> & staticEnv);
|
||||||
Expr * parseExprFromString(std::string s, const Path & basePath);
|
Expr * parseExprFromString(std::string s, const Path & basePath);
|
||||||
|
|
||||||
Expr * parseStdin();
|
Expr * parseStdin();
|
||||||
|
|
@ -197,7 +259,7 @@ public:
|
||||||
trivial (i.e. doesn't require arbitrary computation). */
|
trivial (i.e. doesn't require arbitrary computation). */
|
||||||
void evalFile(const Path & path, Value & v, bool mustBeTrivial = false);
|
void evalFile(const Path & path, Value & v, bool mustBeTrivial = false);
|
||||||
|
|
||||||
/* Like `cacheFile`, but with an already parsed expression. */
|
/* Like `evalFile`, but with an already parsed expression. */
|
||||||
void cacheFile(
|
void cacheFile(
|
||||||
const Path & path,
|
const Path & path,
|
||||||
const Path & resolvedPath,
|
const Path & resolvedPath,
|
||||||
|
|
@ -254,37 +316,68 @@ public:
|
||||||
std::string_view forceStringNoCtx(Value & v, const PosIdx pos = noPos);
|
std::string_view forceStringNoCtx(Value & v, const PosIdx pos = noPos);
|
||||||
|
|
||||||
[[gnu::noinline, gnu::noreturn]]
|
[[gnu::noinline, gnu::noreturn]]
|
||||||
void throwEvalError(const PosIdx pos, const char * s) const;
|
void throwEvalError(const PosIdx pos, const char * s);
|
||||||
[[gnu::noinline, gnu::noreturn]]
|
[[gnu::noinline, gnu::noreturn]]
|
||||||
void throwTypeError(const PosIdx pos, const char * s, const Value & v) const;
|
void throwEvalError(const PosIdx pos, const char * s,
|
||||||
|
Env & env, Expr & expr);
|
||||||
[[gnu::noinline, gnu::noreturn]]
|
[[gnu::noinline, gnu::noreturn]]
|
||||||
void throwEvalError(const char * s, const std::string & s2) const;
|
void throwEvalError(const char * s, const std::string & s2);
|
||||||
[[gnu::noinline, gnu::noreturn]]
|
[[gnu::noinline, gnu::noreturn]]
|
||||||
void throwEvalError(const PosIdx pos, const Suggestions & suggestions, const char * s,
|
void throwEvalError(const PosIdx pos, const char * s, const std::string & s2);
|
||||||
const std::string & s2) const;
|
|
||||||
[[gnu::noinline, gnu::noreturn]]
|
[[gnu::noinline, gnu::noreturn]]
|
||||||
void throwEvalError(const PosIdx pos, const char * s, const std::string & s2) const;
|
void throwEvalError(const char * s, const std::string & s2,
|
||||||
|
Env & env, Expr & expr);
|
||||||
[[gnu::noinline, gnu::noreturn]]
|
[[gnu::noinline, gnu::noreturn]]
|
||||||
void throwEvalError(const char * s, const std::string & s2, const std::string & s3) const;
|
void throwEvalError(const PosIdx pos, const char * s, const std::string & s2,
|
||||||
|
Env & env, Expr & expr);
|
||||||
[[gnu::noinline, gnu::noreturn]]
|
[[gnu::noinline, gnu::noreturn]]
|
||||||
void throwEvalError(const PosIdx pos, const char * s, const std::string & s2, const std::string & s3) const;
|
void throwEvalError(const char * s, const std::string & s2, const std::string & s3,
|
||||||
|
Env & env, Expr & expr);
|
||||||
[[gnu::noinline, gnu::noreturn]]
|
[[gnu::noinline, gnu::noreturn]]
|
||||||
void throwEvalError(const PosIdx p1, const char * s, const Symbol sym, const PosIdx p2) const;
|
void throwEvalError(const PosIdx pos, const char * s, const std::string & s2, const std::string & s3,
|
||||||
|
Env & env, Expr & expr);
|
||||||
[[gnu::noinline, gnu::noreturn]]
|
[[gnu::noinline, gnu::noreturn]]
|
||||||
void throwTypeError(const PosIdx pos, const char * s) const;
|
void throwEvalError(const PosIdx pos, const char * s, const std::string & s2, const std::string & s3);
|
||||||
[[gnu::noinline, gnu::noreturn]]
|
[[gnu::noinline, gnu::noreturn]]
|
||||||
void throwTypeError(const PosIdx pos, const char * s, const ExprLambda & fun, const Symbol s2) const;
|
void throwEvalError(const char * s, const std::string & s2, const std::string & s3);
|
||||||
[[gnu::noinline, gnu::noreturn]]
|
[[gnu::noinline, gnu::noreturn]]
|
||||||
void throwTypeError(const PosIdx pos, const Suggestions & suggestions, const char * s,
|
void throwEvalError(const PosIdx pos, const Suggestions & suggestions, const char * s, const std::string & s2,
|
||||||
const ExprLambda & fun, const Symbol s2) const;
|
Env & env, Expr & expr);
|
||||||
[[gnu::noinline, gnu::noreturn]]
|
[[gnu::noinline, gnu::noreturn]]
|
||||||
void throwTypeError(const char * s, const Value & v) const;
|
void throwEvalError(const PosIdx p1, const char * s, const Symbol sym, const PosIdx p2,
|
||||||
|
Env & env, Expr & expr);
|
||||||
|
|
||||||
[[gnu::noinline, gnu::noreturn]]
|
[[gnu::noinline, gnu::noreturn]]
|
||||||
void throwAssertionError(const PosIdx pos, const char * s, const std::string & s1) const;
|
void throwTypeError(const PosIdx pos, const char * s, const Value & v);
|
||||||
[[gnu::noinline, gnu::noreturn]]
|
[[gnu::noinline, gnu::noreturn]]
|
||||||
void throwUndefinedVarError(const PosIdx pos, const char * s, const std::string & s1) const;
|
void throwTypeError(const PosIdx pos, const char * s, const Value & v,
|
||||||
|
Env & env, Expr & expr);
|
||||||
[[gnu::noinline, gnu::noreturn]]
|
[[gnu::noinline, gnu::noreturn]]
|
||||||
void throwMissingArgumentError(const PosIdx pos, const char * s, const std::string & s1) const;
|
void throwTypeError(const PosIdx pos, const char * s);
|
||||||
|
[[gnu::noinline, gnu::noreturn]]
|
||||||
|
void throwTypeError(const PosIdx pos, const char * s,
|
||||||
|
Env & env, Expr & expr);
|
||||||
|
[[gnu::noinline, gnu::noreturn]]
|
||||||
|
void throwTypeError(const PosIdx pos, const char * s, const ExprLambda & fun, const Symbol s2,
|
||||||
|
Env & env, Expr & expr);
|
||||||
|
[[gnu::noinline, gnu::noreturn]]
|
||||||
|
void throwTypeError(const PosIdx pos, const Suggestions & suggestions, const char * s, const ExprLambda & fun, const Symbol s2,
|
||||||
|
Env & env, Expr & expr);
|
||||||
|
[[gnu::noinline, gnu::noreturn]]
|
||||||
|
void throwTypeError(const char * s, const Value & v,
|
||||||
|
Env & env, Expr & expr);
|
||||||
|
|
||||||
|
[[gnu::noinline, gnu::noreturn]]
|
||||||
|
void throwAssertionError(const PosIdx pos, const char * s, const std::string & s1,
|
||||||
|
Env & env, Expr & expr);
|
||||||
|
|
||||||
|
[[gnu::noinline, gnu::noreturn]]
|
||||||
|
void throwUndefinedVarError(const PosIdx pos, const char * s, const std::string & s1,
|
||||||
|
Env & env, Expr & expr);
|
||||||
|
|
||||||
|
[[gnu::noinline, gnu::noreturn]]
|
||||||
|
void throwMissingArgumentError(const PosIdx pos, const char * s, const std::string & s1,
|
||||||
|
Env & env, Expr & expr);
|
||||||
|
|
||||||
[[gnu::noinline]]
|
[[gnu::noinline]]
|
||||||
void addErrorTrace(Error & e, const char * s, const std::string & s2) const;
|
void addErrorTrace(Error & e, const char * s, const std::string & s2) const;
|
||||||
|
|
@ -324,7 +417,7 @@ public:
|
||||||
Env & baseEnv;
|
Env & baseEnv;
|
||||||
|
|
||||||
/* The same, but used during parsing to resolve variables. */
|
/* The same, but used during parsing to resolve variables. */
|
||||||
StaticEnv staticBaseEnv; // !!! should be private
|
std::shared_ptr<StaticEnv> staticBaseEnv; // !!! should be private
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
@ -365,7 +458,7 @@ private:
|
||||||
friend struct ExprLet;
|
friend struct ExprLet;
|
||||||
|
|
||||||
Expr * parse(char * text, size_t length, FileOrigin origin, const PathView path,
|
Expr * parse(char * text, size_t length, FileOrigin origin, const PathView path,
|
||||||
const PathView basePath, StaticEnv & staticEnv);
|
const PathView basePath, std::shared_ptr<StaticEnv> & staticEnv);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
@ -460,6 +553,16 @@ private:
|
||||||
friend struct Value;
|
friend struct Value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct DebugTraceStacker {
|
||||||
|
DebugTraceStacker(EvalState & evalState, DebugTrace t);
|
||||||
|
~DebugTraceStacker()
|
||||||
|
{
|
||||||
|
// assert(evalState.debugTraces.front() == trace);
|
||||||
|
evalState.debugTraces.pop_front();
|
||||||
|
}
|
||||||
|
EvalState & evalState;
|
||||||
|
DebugTrace trace;
|
||||||
|
};
|
||||||
|
|
||||||
/* Return a string representing the type of the value `v'. */
|
/* Return a string representing the type of the value `v'. */
|
||||||
std::string_view showType(ValueType type);
|
std::string_view showType(ValueType type);
|
||||||
|
|
@ -544,6 +647,15 @@ struct EvalSettings : Config
|
||||||
|
|
||||||
Setting<bool> useEvalCache{this, true, "eval-cache",
|
Setting<bool> useEvalCache{this, true, "eval-cache",
|
||||||
"Whether to use the flake evaluation cache."};
|
"Whether to use the flake evaluation cache."};
|
||||||
|
|
||||||
|
Setting<bool> ignoreExceptionsDuringTry{this, false, "ignore-try",
|
||||||
|
R"(
|
||||||
|
If set to true, ignore exceptions inside 'tryEval' calls when evaluating nix expressions in
|
||||||
|
debug mode (using the --debugger flag). By default the debugger will pause on all exceptions.
|
||||||
|
)"};
|
||||||
|
|
||||||
|
Setting<bool> traceVerbose{this, false, "trace-verbose",
|
||||||
|
"Whether `builtins.traceVerbose` should trace its first argument when evaluated."};
|
||||||
};
|
};
|
||||||
|
|
||||||
extern EvalSettings evalSettings;
|
extern EvalSettings evalSettings;
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ static void writeTrustedList(const TrustedList & trustedList)
|
||||||
|
|
||||||
void ConfigFile::apply()
|
void ConfigFile::apply()
|
||||||
{
|
{
|
||||||
std::set<std::string> whitelist{"bash-prompt", "bash-prompt-suffix", "flake-registry"};
|
std::set<std::string> whitelist{"bash-prompt", "bash-prompt-prefix", "bash-prompt-suffix", "flake-registry"};
|
||||||
|
|
||||||
for (auto & [name, value] : settings) {
|
for (auto & [name, value] : settings) {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -386,6 +386,18 @@ LockedFlake lockFlake(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check whether this input has overrides for a
|
||||||
|
non-existent input. */
|
||||||
|
for (auto [inputPath, inputOverride] : overrides) {
|
||||||
|
auto inputPath2(inputPath);
|
||||||
|
auto follow = inputPath2.back();
|
||||||
|
inputPath2.pop_back();
|
||||||
|
if (inputPath2 == inputPathPrefix && !flakeInputs.count(follow))
|
||||||
|
warn(
|
||||||
|
"input '%s' has an override for a non-existent input '%s'",
|
||||||
|
printInputPath(inputPathPrefix), follow);
|
||||||
|
}
|
||||||
|
|
||||||
/* Go over the flake inputs, resolve/fetch them if
|
/* Go over the flake inputs, resolve/fetch them if
|
||||||
necessary (i.e. if they're new or the flakeref changed
|
necessary (i.e. if they're new or the flakeref changed
|
||||||
from what's in the lock file). */
|
from what's in the lock file). */
|
||||||
|
|
@ -515,6 +527,15 @@ LockedFlake lockFlake(
|
||||||
if (!lockFlags.allowMutable && !input.ref->input.isLocked())
|
if (!lockFlags.allowMutable && !input.ref->input.isLocked())
|
||||||
throw Error("cannot update flake input '%s' in pure mode", inputPathS);
|
throw Error("cannot update flake input '%s' in pure mode", inputPathS);
|
||||||
|
|
||||||
|
/* Note: in case of an --override-input, we use
|
||||||
|
the *original* ref (input2.ref) for the
|
||||||
|
"original" field, rather than the
|
||||||
|
override. This ensures that the override isn't
|
||||||
|
nuked the next time we update the lock
|
||||||
|
file. That is, overrides are sticky unless you
|
||||||
|
use --no-write-lock-file. */
|
||||||
|
auto ref = input2.ref ? *input2.ref : *input.ref;
|
||||||
|
|
||||||
if (input.isFlake) {
|
if (input.isFlake) {
|
||||||
Path localPath = parentPath;
|
Path localPath = parentPath;
|
||||||
FlakeRef localRef = *input.ref;
|
FlakeRef localRef = *input.ref;
|
||||||
|
|
@ -526,15 +547,7 @@ LockedFlake lockFlake(
|
||||||
|
|
||||||
auto inputFlake = getFlake(state, localRef, useRegistries, flakeCache, inputPath);
|
auto inputFlake = getFlake(state, localRef, useRegistries, flakeCache, inputPath);
|
||||||
|
|
||||||
/* Note: in case of an --override-input, we use
|
auto childNode = std::make_shared<LockedNode>(inputFlake.lockedRef, ref);
|
||||||
the *original* ref (input2.ref) for the
|
|
||||||
"original" field, rather than the
|
|
||||||
override. This ensures that the override isn't
|
|
||||||
nuked the next time we update the lock
|
|
||||||
file. That is, overrides are sticky unless you
|
|
||||||
use --no-write-lock-file. */
|
|
||||||
auto childNode = std::make_shared<LockedNode>(
|
|
||||||
inputFlake.lockedRef, input2.ref ? *input2.ref : *input.ref);
|
|
||||||
|
|
||||||
node->inputs.insert_or_assign(id, childNode);
|
node->inputs.insert_or_assign(id, childNode);
|
||||||
|
|
||||||
|
|
@ -562,7 +575,7 @@ LockedFlake lockFlake(
|
||||||
auto [sourceInfo, resolvedRef, lockedRef] = fetchOrSubstituteTree(
|
auto [sourceInfo, resolvedRef, lockedRef] = fetchOrSubstituteTree(
|
||||||
state, *input.ref, useRegistries, flakeCache);
|
state, *input.ref, useRegistries, flakeCache);
|
||||||
node->inputs.insert_or_assign(id,
|
node->inputs.insert_or_assign(id,
|
||||||
std::make_shared<LockedNode>(lockedRef, *input.ref, false));
|
std::make_shared<LockedNode>(lockedRef, ref, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -725,6 +738,7 @@ static void prim_getFlake(EvalState & state, const PosIdx pos, Value * * args, V
|
||||||
lockFlake(state, flakeRef,
|
lockFlake(state, flakeRef,
|
||||||
LockFlags {
|
LockFlags {
|
||||||
.updateLockFile = false,
|
.updateLockFile = false,
|
||||||
|
.writeLockFile = false,
|
||||||
.useRegistries = !evalSettings.pureEval && fetchSettings.useRegistries,
|
.useRegistries = !evalSettings.pureEval && fetchSettings.useRegistries,
|
||||||
.allowMutable = !evalSettings.pureEval,
|
.allowMutable = !evalSettings.pureEval,
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
|
|
@ -132,9 +132,21 @@ DrvInfo::Outputs DrvInfo::queryOutputs(bool withPaths, bool onlyOutputsToInstall
|
||||||
} else
|
} else
|
||||||
outputs.emplace("out", withPaths ? std::optional{queryOutPath()} : std::nullopt);
|
outputs.emplace("out", withPaths ? std::optional{queryOutPath()} : std::nullopt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!onlyOutputsToInstall || !attrs)
|
if (!onlyOutputsToInstall || !attrs)
|
||||||
return outputs;
|
return outputs;
|
||||||
|
|
||||||
|
Bindings::iterator i;
|
||||||
|
if (attrs && (i = attrs->find(state->sOutputSpecified)) != attrs->end() && state->forceBool(*i->value, i->pos)) {
|
||||||
|
Outputs result;
|
||||||
|
auto out = outputs.find(queryOutputName());
|
||||||
|
if (out == outputs.end())
|
||||||
|
throw Error("derivation does not have output '%s'", queryOutputName());
|
||||||
|
result.insert(*out);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
/* Check for `meta.outputsToInstall` and return `outputs` reduced to that. */
|
/* Check for `meta.outputsToInstall` and return `outputs` reduced to that. */
|
||||||
const Value * outTI = queryMeta("outputsToInstall");
|
const Value * outTI = queryMeta("outputsToInstall");
|
||||||
if (!outTI) return outputs;
|
if (!outTI) return outputs;
|
||||||
|
|
@ -149,6 +161,7 @@ DrvInfo::Outputs DrvInfo::queryOutputs(bool withPaths, bool onlyOutputsToInstall
|
||||||
result.insert(*out);
|
result.insert(*out);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ public:
|
||||||
|
|
||||||
|
|
||||||
#if HAVE_BOEHMGC
|
#if HAVE_BOEHMGC
|
||||||
typedef std::list<DrvInfo, traceable_allocator<DrvInfo> > DrvInfos;
|
typedef std::list<DrvInfo, traceable_allocator<DrvInfo>> DrvInfos;
|
||||||
#else
|
#else
|
||||||
typedef std::list<DrvInfo> DrvInfos;
|
typedef std::list<DrvInfo> DrvInfos;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -198,7 +198,7 @@ or { return OR_KW; }
|
||||||
(...|\$[^\{\"\\]|\\.|\$\\.)+ would have triggered.
|
(...|\$[^\{\"\\]|\\.|\$\\.)+ would have triggered.
|
||||||
This is technically invalid, but we leave the problem to the
|
This is technically invalid, but we leave the problem to the
|
||||||
parser who fails with exact location. */
|
parser who fails with exact location. */
|
||||||
return STR;
|
return EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
\'\'(\ *\n)? { PUSH_STATE(IND_STRING); return IND_STRING_OPEN; }
|
\'\'(\ *\n)? { PUSH_STATE(IND_STRING); return IND_STRING_OPEN; }
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,8 @@
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
|
||||||
/* Displaying abstract syntax trees. */
|
/* Displaying abstract syntax trees. */
|
||||||
|
|
||||||
static void showString(std::ostream & str, std::string_view s)
|
static void showString(std::ostream & str, std::string_view s)
|
||||||
|
|
@ -294,35 +292,46 @@ std::string showAttrPath(const SymbolTable & symbols, const AttrPath & attrPath)
|
||||||
|
|
||||||
/* Computing levels/displacements for variables. */
|
/* Computing levels/displacements for variables. */
|
||||||
|
|
||||||
void Expr::bindVars(const EvalState & es, const StaticEnv & env)
|
void Expr::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
||||||
{
|
{
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExprInt::bindVars(const EvalState & es, const StaticEnv & env)
|
void ExprInt::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
||||||
{
|
{
|
||||||
|
if (es.debugRepl)
|
||||||
|
es.exprEnvs.insert(std::make_pair(this, env));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExprFloat::bindVars(const EvalState & es, const StaticEnv & env)
|
void ExprFloat::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
||||||
{
|
{
|
||||||
|
if (es.debugRepl)
|
||||||
|
es.exprEnvs.insert(std::make_pair(this, env));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExprString::bindVars(const EvalState & es, const StaticEnv & env)
|
void ExprString::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
||||||
{
|
{
|
||||||
|
if (es.debugRepl)
|
||||||
|
es.exprEnvs.insert(std::make_pair(this, env));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExprPath::bindVars(const EvalState & es, const StaticEnv & env)
|
void ExprPath::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
||||||
{
|
{
|
||||||
|
if (es.debugRepl)
|
||||||
|
es.exprEnvs.insert(std::make_pair(this, env));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExprVar::bindVars(const EvalState & es, const StaticEnv & env)
|
void ExprVar::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
||||||
{
|
{
|
||||||
|
if (es.debugRepl)
|
||||||
|
es.exprEnvs.insert(std::make_pair(this, env));
|
||||||
|
|
||||||
/* Check whether the variable appears in the environment. If so,
|
/* Check whether the variable appears in the environment. If so,
|
||||||
set its level and displacement. */
|
set its level and displacement. */
|
||||||
const StaticEnv * curEnv;
|
const StaticEnv * curEnv;
|
||||||
Level level;
|
Level level;
|
||||||
int withLevel = -1;
|
int withLevel = -1;
|
||||||
for (curEnv = &env, level = 0; curEnv; curEnv = curEnv->up, level++) {
|
for (curEnv = env.get(), level = 0; curEnv; curEnv = curEnv->up, level++) {
|
||||||
if (curEnv->isWith) {
|
if (curEnv->isWith) {
|
||||||
if (withLevel == -1) withLevel = level;
|
if (withLevel == -1) withLevel = level;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -348,8 +357,11 @@ void ExprVar::bindVars(const EvalState & es, const StaticEnv & env)
|
||||||
this->level = withLevel;
|
this->level = withLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExprSelect::bindVars(const EvalState & es, const StaticEnv & env)
|
void ExprSelect::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
||||||
{
|
{
|
||||||
|
if (es.debugRepl)
|
||||||
|
es.exprEnvs.insert(std::make_pair(this, env));
|
||||||
|
|
||||||
e->bindVars(es, env);
|
e->bindVars(es, env);
|
||||||
if (def) def->bindVars(es, env);
|
if (def) def->bindVars(es, env);
|
||||||
for (auto & i : attrPath)
|
for (auto & i : attrPath)
|
||||||
|
|
@ -357,64 +369,78 @@ void ExprSelect::bindVars(const EvalState & es, const StaticEnv & env)
|
||||||
i.expr->bindVars(es, env);
|
i.expr->bindVars(es, env);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExprOpHasAttr::bindVars(const EvalState & es, const StaticEnv & env)
|
void ExprOpHasAttr::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
||||||
{
|
{
|
||||||
|
if (es.debugRepl)
|
||||||
|
es.exprEnvs.insert(std::make_pair(this, env));
|
||||||
|
|
||||||
e->bindVars(es, env);
|
e->bindVars(es, env);
|
||||||
for (auto & i : attrPath)
|
for (auto & i : attrPath)
|
||||||
if (!i.symbol)
|
if (!i.symbol)
|
||||||
i.expr->bindVars(es, env);
|
i.expr->bindVars(es, env);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExprAttrs::bindVars(const EvalState & es, const StaticEnv & env)
|
void ExprAttrs::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
||||||
{
|
{
|
||||||
const StaticEnv * dynamicEnv = &env;
|
if (es.debugRepl)
|
||||||
StaticEnv newEnv(false, &env, recursive ? attrs.size() : 0);
|
es.exprEnvs.insert(std::make_pair(this, env));
|
||||||
|
|
||||||
if (recursive) {
|
if (recursive) {
|
||||||
dynamicEnv = &newEnv;
|
auto newEnv = std::make_shared<StaticEnv>(false, env.get(), recursive ? attrs.size() : 0);
|
||||||
|
|
||||||
Displacement displ = 0;
|
Displacement displ = 0;
|
||||||
for (auto & i : attrs)
|
for (auto & i : attrs)
|
||||||
newEnv.vars.emplace_back(i.first, i.second.displ = displ++);
|
newEnv->vars.emplace_back(i.first, i.second.displ = displ++);
|
||||||
|
|
||||||
// No need to sort newEnv since attrs is in sorted order.
|
// No need to sort newEnv since attrs is in sorted order.
|
||||||
|
|
||||||
for (auto & i : attrs)
|
for (auto & i : attrs)
|
||||||
i.second.e->bindVars(es, i.second.inherited ? env : newEnv);
|
i.second.e->bindVars(es, i.second.inherited ? env : newEnv);
|
||||||
}
|
|
||||||
|
|
||||||
else
|
for (auto & i : dynamicAttrs) {
|
||||||
|
i.nameExpr->bindVars(es, newEnv);
|
||||||
|
i.valueExpr->bindVars(es, newEnv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
for (auto & i : attrs)
|
for (auto & i : attrs)
|
||||||
i.second.e->bindVars(es, env);
|
i.second.e->bindVars(es, env);
|
||||||
|
|
||||||
for (auto & i : dynamicAttrs) {
|
for (auto & i : dynamicAttrs) {
|
||||||
i.nameExpr->bindVars(es, *dynamicEnv);
|
i.nameExpr->bindVars(es, env);
|
||||||
i.valueExpr->bindVars(es, *dynamicEnv);
|
i.valueExpr->bindVars(es, env);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExprList::bindVars(const EvalState & es, const StaticEnv & env)
|
void ExprList::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
||||||
{
|
{
|
||||||
|
if (es.debugRepl)
|
||||||
|
es.exprEnvs.insert(std::make_pair(this, env));
|
||||||
|
|
||||||
for (auto & i : elems)
|
for (auto & i : elems)
|
||||||
i->bindVars(es, env);
|
i->bindVars(es, env);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExprLambda::bindVars(const EvalState & es, const StaticEnv & env)
|
void ExprLambda::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
||||||
{
|
{
|
||||||
StaticEnv newEnv(
|
if (es.debugRepl)
|
||||||
false, &env,
|
es.exprEnvs.insert(std::make_pair(this, env));
|
||||||
|
|
||||||
|
auto newEnv = std::make_shared<StaticEnv>(
|
||||||
|
false, env.get(),
|
||||||
(hasFormals() ? formals->formals.size() : 0) +
|
(hasFormals() ? formals->formals.size() : 0) +
|
||||||
(!arg ? 0 : 1));
|
(!arg ? 0 : 1));
|
||||||
|
|
||||||
Displacement displ = 0;
|
Displacement displ = 0;
|
||||||
|
|
||||||
if (arg) newEnv.vars.emplace_back(arg, displ++);
|
if (arg) newEnv->vars.emplace_back(arg, displ++);
|
||||||
|
|
||||||
if (hasFormals()) {
|
if (hasFormals()) {
|
||||||
for (auto & i : formals->formals)
|
for (auto & i : formals->formals)
|
||||||
newEnv.vars.emplace_back(i.name, displ++);
|
newEnv->vars.emplace_back(i.name, displ++);
|
||||||
|
|
||||||
newEnv.sort();
|
newEnv->sort();
|
||||||
|
|
||||||
for (auto & i : formals->formals)
|
for (auto & i : formals->formals)
|
||||||
if (i.def) i.def->bindVars(es, newEnv);
|
if (i.def) i.def->bindVars(es, newEnv);
|
||||||
|
|
@ -423,20 +449,26 @@ void ExprLambda::bindVars(const EvalState & es, const StaticEnv & env)
|
||||||
body->bindVars(es, newEnv);
|
body->bindVars(es, newEnv);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExprCall::bindVars(const EvalState & es, const StaticEnv & env)
|
void ExprCall::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
||||||
{
|
{
|
||||||
|
if (es.debugRepl)
|
||||||
|
es.exprEnvs.insert(std::make_pair(this, env));
|
||||||
|
|
||||||
fun->bindVars(es, env);
|
fun->bindVars(es, env);
|
||||||
for (auto e : args)
|
for (auto e : args)
|
||||||
e->bindVars(es, env);
|
e->bindVars(es, env);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExprLet::bindVars(const EvalState & es, const StaticEnv & env)
|
void ExprLet::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
||||||
{
|
{
|
||||||
StaticEnv newEnv(false, &env, attrs->attrs.size());
|
if (es.debugRepl)
|
||||||
|
es.exprEnvs.insert(std::make_pair(this, env));
|
||||||
|
|
||||||
|
auto newEnv = std::make_shared<StaticEnv>(false, env.get(), attrs->attrs.size());
|
||||||
|
|
||||||
Displacement displ = 0;
|
Displacement displ = 0;
|
||||||
for (auto & i : attrs->attrs)
|
for (auto & i : attrs->attrs)
|
||||||
newEnv.vars.emplace_back(i.first, i.second.displ = displ++);
|
newEnv->vars.emplace_back(i.first, i.second.displ = displ++);
|
||||||
|
|
||||||
// No need to sort newEnv since attrs->attrs is in sorted order.
|
// No need to sort newEnv since attrs->attrs is in sorted order.
|
||||||
|
|
||||||
|
|
@ -446,51 +478,71 @@ void ExprLet::bindVars(const EvalState & es, const StaticEnv & env)
|
||||||
body->bindVars(es, newEnv);
|
body->bindVars(es, newEnv);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExprWith::bindVars(const EvalState & es, const StaticEnv & env)
|
void ExprWith::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
||||||
{
|
{
|
||||||
|
if (es.debugRepl)
|
||||||
|
es.exprEnvs.insert(std::make_pair(this, env));
|
||||||
|
|
||||||
/* Does this `with' have an enclosing `with'? If so, record its
|
/* Does this `with' have an enclosing `with'? If so, record its
|
||||||
level so that `lookupVar' can look up variables in the previous
|
level so that `lookupVar' can look up variables in the previous
|
||||||
`with' if this one doesn't contain the desired attribute. */
|
`with' if this one doesn't contain the desired attribute. */
|
||||||
const StaticEnv * curEnv;
|
const StaticEnv * curEnv;
|
||||||
Level level;
|
Level level;
|
||||||
prevWith = 0;
|
prevWith = 0;
|
||||||
for (curEnv = &env, level = 1; curEnv; curEnv = curEnv->up, level++)
|
for (curEnv = env.get(), level = 1; curEnv; curEnv = curEnv->up, level++)
|
||||||
if (curEnv->isWith) {
|
if (curEnv->isWith) {
|
||||||
prevWith = level;
|
prevWith = level;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (es.debugRepl)
|
||||||
|
es.exprEnvs.insert(std::make_pair(this, env));
|
||||||
|
|
||||||
attrs->bindVars(es, env);
|
attrs->bindVars(es, env);
|
||||||
StaticEnv newEnv(true, &env);
|
auto newEnv = std::make_shared<StaticEnv>(true, env.get());
|
||||||
body->bindVars(es, newEnv);
|
body->bindVars(es, newEnv);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExprIf::bindVars(const EvalState & es, const StaticEnv & env)
|
void ExprIf::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
||||||
{
|
{
|
||||||
|
if (es.debugRepl)
|
||||||
|
es.exprEnvs.insert(std::make_pair(this, env));
|
||||||
|
|
||||||
cond->bindVars(es, env);
|
cond->bindVars(es, env);
|
||||||
then->bindVars(es, env);
|
then->bindVars(es, env);
|
||||||
else_->bindVars(es, env);
|
else_->bindVars(es, env);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExprAssert::bindVars(const EvalState & es, const StaticEnv & env)
|
void ExprAssert::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
||||||
{
|
{
|
||||||
|
if (es.debugRepl)
|
||||||
|
es.exprEnvs.insert(std::make_pair(this, env));
|
||||||
|
|
||||||
cond->bindVars(es, env);
|
cond->bindVars(es, env);
|
||||||
body->bindVars(es, env);
|
body->bindVars(es, env);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExprOpNot::bindVars(const EvalState & es, const StaticEnv & env)
|
void ExprOpNot::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
||||||
{
|
{
|
||||||
|
if (es.debugRepl)
|
||||||
|
es.exprEnvs.insert(std::make_pair(this, env));
|
||||||
|
|
||||||
e->bindVars(es, env);
|
e->bindVars(es, env);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExprConcatStrings::bindVars(const EvalState & es, const StaticEnv & env)
|
void ExprConcatStrings::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
||||||
{
|
{
|
||||||
|
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);
|
i.second->bindVars(es, env);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExprPos::bindVars(const EvalState & es, const StaticEnv & env)
|
void ExprPos::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
||||||
{
|
{
|
||||||
|
if (es.debugRepl)
|
||||||
|
es.exprEnvs.insert(std::make_pair(this, env));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ MakeError(UndefinedVarError, Error);
|
||||||
MakeError(MissingArgumentError, EvalError);
|
MakeError(MissingArgumentError, EvalError);
|
||||||
MakeError(RestrictedPathError, Error);
|
MakeError(RestrictedPathError, Error);
|
||||||
|
|
||||||
|
|
||||||
/* Position objects. */
|
/* Position objects. */
|
||||||
|
|
||||||
struct Pos
|
struct Pos
|
||||||
|
|
@ -143,24 +142,25 @@ struct Expr
|
||||||
{
|
{
|
||||||
virtual ~Expr() { };
|
virtual ~Expr() { };
|
||||||
virtual void show(const SymbolTable & symbols, std::ostream & str) const;
|
virtual void show(const SymbolTable & symbols, std::ostream & str) const;
|
||||||
virtual void bindVars(const EvalState & es, const StaticEnv & env);
|
virtual void bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env);
|
||||||
virtual void eval(EvalState & state, Env & env, Value & v);
|
virtual void eval(EvalState & state, Env & env, Value & v);
|
||||||
virtual Value * maybeThunk(EvalState & state, Env & env);
|
virtual Value * maybeThunk(EvalState & state, Env & env);
|
||||||
virtual void setName(Symbol name);
|
virtual void setName(Symbol name);
|
||||||
|
virtual PosIdx getPos() const { return noPos; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#define COMMON_METHODS \
|
#define COMMON_METHODS \
|
||||||
void show(const SymbolTable & symbols, std::ostream & str) const; \
|
void show(const SymbolTable & symbols, std::ostream & str) const override; \
|
||||||
void eval(EvalState & state, Env & env, Value & v); \
|
void eval(EvalState & state, Env & env, Value & v) override; \
|
||||||
void bindVars(const EvalState & es, const StaticEnv & env);
|
void bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env) override;
|
||||||
|
|
||||||
struct ExprInt : Expr
|
struct ExprInt : Expr
|
||||||
{
|
{
|
||||||
NixInt n;
|
NixInt n;
|
||||||
Value v;
|
Value v;
|
||||||
ExprInt(NixInt n) : n(n) { v.mkInt(n); };
|
ExprInt(NixInt n) : n(n) { v.mkInt(n); };
|
||||||
|
Value * maybeThunk(EvalState & state, Env & env) override;
|
||||||
COMMON_METHODS
|
COMMON_METHODS
|
||||||
Value * maybeThunk(EvalState & state, Env & env);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ExprFloat : Expr
|
struct ExprFloat : Expr
|
||||||
|
|
@ -168,8 +168,8 @@ struct ExprFloat : Expr
|
||||||
NixFloat nf;
|
NixFloat nf;
|
||||||
Value v;
|
Value v;
|
||||||
ExprFloat(NixFloat nf) : nf(nf) { v.mkFloat(nf); };
|
ExprFloat(NixFloat nf) : nf(nf) { v.mkFloat(nf); };
|
||||||
|
Value * maybeThunk(EvalState & state, Env & env) override;
|
||||||
COMMON_METHODS
|
COMMON_METHODS
|
||||||
Value * maybeThunk(EvalState & state, Env & env);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ExprString : Expr
|
struct ExprString : Expr
|
||||||
|
|
@ -177,8 +177,8 @@ struct ExprString : Expr
|
||||||
std::string s;
|
std::string s;
|
||||||
Value v;
|
Value v;
|
||||||
ExprString(std::string s) : s(std::move(s)) { v.mkString(this->s.data()); };
|
ExprString(std::string s) : s(std::move(s)) { v.mkString(this->s.data()); };
|
||||||
|
Value * maybeThunk(EvalState & state, Env & env) override;
|
||||||
COMMON_METHODS
|
COMMON_METHODS
|
||||||
Value * maybeThunk(EvalState & state, Env & env);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ExprPath : Expr
|
struct ExprPath : Expr
|
||||||
|
|
@ -186,8 +186,8 @@ struct ExprPath : Expr
|
||||||
std::string s;
|
std::string s;
|
||||||
Value v;
|
Value v;
|
||||||
ExprPath(std::string s) : s(std::move(s)) { v.mkPath(this->s.c_str()); };
|
ExprPath(std::string s) : s(std::move(s)) { v.mkPath(this->s.c_str()); };
|
||||||
|
Value * maybeThunk(EvalState & state, Env & env) override;
|
||||||
COMMON_METHODS
|
COMMON_METHODS
|
||||||
Value * maybeThunk(EvalState & state, Env & env);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef uint32_t Level;
|
typedef uint32_t Level;
|
||||||
|
|
@ -213,8 +213,9 @@ struct ExprVar : Expr
|
||||||
|
|
||||||
ExprVar(Symbol name) : name(name) { };
|
ExprVar(Symbol name) : name(name) { };
|
||||||
ExprVar(const PosIdx & pos, Symbol name) : pos(pos), name(name) { };
|
ExprVar(const PosIdx & pos, Symbol name) : pos(pos), name(name) { };
|
||||||
|
Value * maybeThunk(EvalState & state, Env & env) override;
|
||||||
|
PosIdx getPos() const override { return pos; }
|
||||||
COMMON_METHODS
|
COMMON_METHODS
|
||||||
Value * maybeThunk(EvalState & state, Env & env);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ExprSelect : Expr
|
struct ExprSelect : Expr
|
||||||
|
|
@ -224,6 +225,7 @@ struct ExprSelect : Expr
|
||||||
AttrPath attrPath;
|
AttrPath attrPath;
|
||||||
ExprSelect(const PosIdx & pos, Expr * e, const AttrPath & attrPath, Expr * def) : pos(pos), e(e), def(def), attrPath(attrPath) { };
|
ExprSelect(const PosIdx & pos, Expr * e, const AttrPath & attrPath, Expr * def) : pos(pos), e(e), def(def), attrPath(attrPath) { };
|
||||||
ExprSelect(const PosIdx & pos, Expr * e, Symbol name) : pos(pos), e(e), def(0) { attrPath.push_back(AttrName(name)); };
|
ExprSelect(const PosIdx & pos, Expr * e, Symbol name) : pos(pos), e(e), def(0) { attrPath.push_back(AttrName(name)); };
|
||||||
|
PosIdx getPos() const override { return pos; }
|
||||||
COMMON_METHODS
|
COMMON_METHODS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -232,6 +234,7 @@ struct ExprOpHasAttr : Expr
|
||||||
Expr * e;
|
Expr * e;
|
||||||
AttrPath attrPath;
|
AttrPath attrPath;
|
||||||
ExprOpHasAttr(Expr * e, const AttrPath & attrPath) : e(e), attrPath(attrPath) { };
|
ExprOpHasAttr(Expr * e, const AttrPath & attrPath) : e(e), attrPath(attrPath) { };
|
||||||
|
PosIdx getPos() const override { return e->getPos(); }
|
||||||
COMMON_METHODS
|
COMMON_METHODS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -260,6 +263,7 @@ struct ExprAttrs : Expr
|
||||||
DynamicAttrDefs dynamicAttrs;
|
DynamicAttrDefs dynamicAttrs;
|
||||||
ExprAttrs(const PosIdx &pos) : recursive(false), pos(pos) { };
|
ExprAttrs(const PosIdx &pos) : recursive(false), pos(pos) { };
|
||||||
ExprAttrs() : recursive(false) { };
|
ExprAttrs() : recursive(false) { };
|
||||||
|
PosIdx getPos() const override { return pos; }
|
||||||
COMMON_METHODS
|
COMMON_METHODS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -268,6 +272,11 @@ struct ExprList : Expr
|
||||||
std::vector<Expr *> elems;
|
std::vector<Expr *> elems;
|
||||||
ExprList() { };
|
ExprList() { };
|
||||||
COMMON_METHODS
|
COMMON_METHODS
|
||||||
|
|
||||||
|
PosIdx getPos() const override
|
||||||
|
{
|
||||||
|
return elems.empty() ? noPos : elems.front()->getPos();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Formal
|
struct Formal
|
||||||
|
|
@ -317,9 +326,10 @@ struct ExprLambda : Expr
|
||||||
: pos(pos), formals(formals), body(body)
|
: pos(pos), formals(formals), body(body)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void setName(Symbol name);
|
void setName(Symbol name) override;
|
||||||
std::string showNamePos(const EvalState & state) const;
|
std::string showNamePos(const EvalState & state) const;
|
||||||
inline bool hasFormals() const { return formals != nullptr; }
|
inline bool hasFormals() const { return formals != nullptr; }
|
||||||
|
PosIdx getPos() const override { return pos; }
|
||||||
COMMON_METHODS
|
COMMON_METHODS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -331,6 +341,7 @@ struct ExprCall : Expr
|
||||||
ExprCall(const PosIdx & pos, Expr * fun, std::vector<Expr *> && args)
|
ExprCall(const PosIdx & pos, Expr * fun, std::vector<Expr *> && args)
|
||||||
: fun(fun), args(args), pos(pos)
|
: fun(fun), args(args), pos(pos)
|
||||||
{ }
|
{ }
|
||||||
|
PosIdx getPos() const override { return pos; }
|
||||||
COMMON_METHODS
|
COMMON_METHODS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -348,6 +359,7 @@ struct ExprWith : Expr
|
||||||
Expr * attrs, * body;
|
Expr * attrs, * body;
|
||||||
size_t prevWith;
|
size_t prevWith;
|
||||||
ExprWith(const PosIdx & pos, Expr * attrs, Expr * body) : pos(pos), attrs(attrs), body(body) { };
|
ExprWith(const PosIdx & pos, Expr * attrs, Expr * body) : pos(pos), attrs(attrs), body(body) { };
|
||||||
|
PosIdx getPos() const override { return pos; }
|
||||||
COMMON_METHODS
|
COMMON_METHODS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -356,6 +368,7 @@ struct ExprIf : Expr
|
||||||
PosIdx pos;
|
PosIdx pos;
|
||||||
Expr * cond, * then, * else_;
|
Expr * cond, * then, * else_;
|
||||||
ExprIf(const PosIdx & pos, Expr * cond, Expr * then, Expr * else_) : pos(pos), cond(cond), then(then), else_(else_) { };
|
ExprIf(const PosIdx & pos, Expr * cond, Expr * then, Expr * else_) : pos(pos), cond(cond), then(then), else_(else_) { };
|
||||||
|
PosIdx getPos() const override { return pos; }
|
||||||
COMMON_METHODS
|
COMMON_METHODS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -364,6 +377,7 @@ struct ExprAssert : Expr
|
||||||
PosIdx pos;
|
PosIdx pos;
|
||||||
Expr * cond, * body;
|
Expr * cond, * body;
|
||||||
ExprAssert(const PosIdx & pos, Expr * cond, Expr * body) : pos(pos), cond(cond), body(body) { };
|
ExprAssert(const PosIdx & pos, Expr * cond, Expr * body) : pos(pos), cond(cond), body(body) { };
|
||||||
|
PosIdx getPos() const override { return pos; }
|
||||||
COMMON_METHODS
|
COMMON_METHODS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -381,15 +395,16 @@ struct ExprOpNot : Expr
|
||||||
Expr * e1, * e2; \
|
Expr * e1, * e2; \
|
||||||
name(Expr * e1, Expr * e2) : e1(e1), e2(e2) { }; \
|
name(Expr * e1, Expr * e2) : e1(e1), e2(e2) { }; \
|
||||||
name(const PosIdx & pos, Expr * e1, Expr * e2) : pos(pos), e1(e1), e2(e2) { }; \
|
name(const PosIdx & pos, Expr * e1, Expr * e2) : pos(pos), e1(e1), e2(e2) { }; \
|
||||||
void show(const SymbolTable & symbols, std::ostream & str) const \
|
void show(const SymbolTable & symbols, std::ostream & str) const override \
|
||||||
{ \
|
{ \
|
||||||
str << "("; e1->show(symbols, str); str << " " s " "; e2->show(symbols, str); str << ")"; \
|
str << "("; e1->show(symbols, str); str << " " s " "; e2->show(symbols, str); str << ")"; \
|
||||||
} \
|
} \
|
||||||
void bindVars(const EvalState & es, const StaticEnv & env) \
|
void bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env) override \
|
||||||
{ \
|
{ \
|
||||||
e1->bindVars(es, env); e2->bindVars(es, env); \
|
e1->bindVars(es, env); e2->bindVars(es, env); \
|
||||||
} \
|
} \
|
||||||
void eval(EvalState & state, Env & env, Value & v); \
|
void eval(EvalState & state, Env & env, Value & v) override; \
|
||||||
|
PosIdx getPos() const override { return pos; } \
|
||||||
};
|
};
|
||||||
|
|
||||||
MakeBinOp(ExprOpEq, "==")
|
MakeBinOp(ExprOpEq, "==")
|
||||||
|
|
@ -404,9 +419,10 @@ struct ExprConcatStrings : Expr
|
||||||
{
|
{
|
||||||
PosIdx pos;
|
PosIdx pos;
|
||||||
bool forceString;
|
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)
|
ExprConcatStrings(const PosIdx & pos, bool forceString, std::vector<std::pair<PosIdx, Expr *>> * es)
|
||||||
: pos(pos), forceString(forceString), es(es) { };
|
: pos(pos), forceString(forceString), es(es) { };
|
||||||
|
PosIdx getPos() const override { return pos; }
|
||||||
COMMON_METHODS
|
COMMON_METHODS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -414,6 +430,7 @@ struct ExprPos : Expr
|
||||||
{
|
{
|
||||||
PosIdx pos;
|
PosIdx pos;
|
||||||
ExprPos(const PosIdx & pos) : pos(pos) { };
|
ExprPos(const PosIdx & pos) : pos(pos) { };
|
||||||
|
PosIdx getPos() const override { return pos; }
|
||||||
COMMON_METHODS
|
COMMON_METHODS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -193,7 +193,7 @@ static Formals * toFormals(ParseData & data, ParserFormals * formals,
|
||||||
|
|
||||||
|
|
||||||
static Expr * stripIndentation(const PosIdx pos, SymbolTable & symbols,
|
static Expr * stripIndentation(const PosIdx pos, SymbolTable & symbols,
|
||||||
std::vector<std::pair<PosIdx, std::variant<Expr *, StringToken> > > & es)
|
std::vector<std::pair<PosIdx, std::variant<Expr *, StringToken>>> & es)
|
||||||
{
|
{
|
||||||
if (es.empty()) return new ExprString("");
|
if (es.empty()) return new ExprString("");
|
||||||
|
|
||||||
|
|
@ -233,7 +233,7 @@ static Expr * stripIndentation(const PosIdx pos, SymbolTable & symbols,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Strip spaces from each line. */
|
/* Strip spaces from each line. */
|
||||||
auto * es2 = new std::vector<std::pair<PosIdx, Expr *> >;
|
auto * es2 = new std::vector<std::pair<PosIdx, Expr *>>;
|
||||||
atStartOfLine = true;
|
atStartOfLine = true;
|
||||||
size_t curDropped = 0;
|
size_t curDropped = 0;
|
||||||
size_t n = es.size();
|
size_t n = es.size();
|
||||||
|
|
@ -320,8 +320,8 @@ void yyerror(YYLTYPE * loc, yyscan_t scanner, ParseData * data, const char * err
|
||||||
StringToken uri;
|
StringToken uri;
|
||||||
StringToken str;
|
StringToken str;
|
||||||
std::vector<nix::AttrName> * attrNames;
|
std::vector<nix::AttrName> * attrNames;
|
||||||
std::vector<std::pair<nix::PosIdx, nix::Expr *> > * string_parts;
|
std::vector<std::pair<nix::PosIdx, nix::Expr *>> * string_parts;
|
||||||
std::vector<std::pair<nix::PosIdx, std::variant<nix::Expr *, StringToken> > > * ind_string_parts;
|
std::vector<std::pair<nix::PosIdx, std::variant<nix::Expr *, StringToken>>> * ind_string_parts;
|
||||||
}
|
}
|
||||||
|
|
||||||
%type <e> start expr expr_function expr_if expr_op
|
%type <e> start expr expr_function expr_if expr_op
|
||||||
|
|
@ -415,7 +415,7 @@ expr_op
|
||||||
| expr_op UPDATE expr_op { $$ = new ExprOpUpdate(CUR_POS, $1, $3); }
|
| expr_op UPDATE expr_op { $$ = new ExprOpUpdate(CUR_POS, $1, $3); }
|
||||||
| expr_op '?' attrpath { $$ = new ExprOpHasAttr($1, *$3); }
|
| expr_op '?' attrpath { $$ = new ExprOpHasAttr($1, *$3); }
|
||||||
| expr_op '+' expr_op
|
| expr_op '+' expr_op
|
||||||
{ $$ = new ExprConcatStrings(CUR_POS, false, new std::vector<std::pair<PosIdx, Expr *> >({{makeCurPos(@1, data), $1}, {makeCurPos(@3, data), $3}})); }
|
{ $$ = new ExprConcatStrings(CUR_POS, false, new std::vector<std::pair<PosIdx, Expr *>>({{makeCurPos(@1, data), $1}, {makeCurPos(@3, data), $3}})); }
|
||||||
| expr_op '-' expr_op { $$ = new ExprCall(CUR_POS, new ExprVar(data->symbols.create("__sub")), {$1, $3}); }
|
| expr_op '-' expr_op { $$ = new ExprCall(CUR_POS, new ExprVar(data->symbols.create("__sub")), {$1, $3}); }
|
||||||
| expr_op '*' expr_op { $$ = new ExprCall(CUR_POS, new ExprVar(data->symbols.create("__mul")), {$1, $3}); }
|
| expr_op '*' expr_op { $$ = new ExprCall(CUR_POS, new ExprVar(data->symbols.create("__mul")), {$1, $3}); }
|
||||||
| expr_op '/' expr_op { $$ = new ExprCall(CUR_POS, new ExprVar(data->symbols.create("__div")), {$1, $3}); }
|
| expr_op '/' expr_op { $$ = new ExprCall(CUR_POS, new ExprVar(data->symbols.create("__div")), {$1, $3}); }
|
||||||
|
|
@ -503,9 +503,9 @@ string_parts_interpolated
|
||||||
: string_parts_interpolated STR
|
: string_parts_interpolated STR
|
||||||
{ $$ = $1; $1->emplace_back(makeCurPos(@2, data), new ExprString(std::string($2))); }
|
{ $$ = $1; $1->emplace_back(makeCurPos(@2, data), new ExprString(std::string($2))); }
|
||||||
| string_parts_interpolated DOLLAR_CURLY expr '}' { $$ = $1; $1->emplace_back(makeCurPos(@2, data), $3); }
|
| string_parts_interpolated DOLLAR_CURLY expr '}' { $$ = $1; $1->emplace_back(makeCurPos(@2, data), $3); }
|
||||||
| DOLLAR_CURLY expr '}' { $$ = new std::vector<std::pair<PosIdx, Expr *> >; $$->emplace_back(makeCurPos(@1, data), $2); }
|
| DOLLAR_CURLY expr '}' { $$ = new std::vector<std::pair<PosIdx, Expr *>>; $$->emplace_back(makeCurPos(@1, data), $2); }
|
||||||
| STR DOLLAR_CURLY expr '}' {
|
| STR DOLLAR_CURLY expr '}' {
|
||||||
$$ = new std::vector<std::pair<PosIdx, Expr *> >;
|
$$ = new std::vector<std::pair<PosIdx, Expr *>>;
|
||||||
$$->emplace_back(makeCurPos(@1, data), new ExprString(std::string($1)));
|
$$->emplace_back(makeCurPos(@1, data), new ExprString(std::string($1)));
|
||||||
$$->emplace_back(makeCurPos(@2, data), $3);
|
$$->emplace_back(makeCurPos(@2, data), $3);
|
||||||
}
|
}
|
||||||
|
|
@ -520,6 +520,12 @@ path_start
|
||||||
$$ = new ExprPath(path);
|
$$ = new ExprPath(path);
|
||||||
}
|
}
|
||||||
| HPATH {
|
| HPATH {
|
||||||
|
if (evalSettings.pureEval) {
|
||||||
|
throw Error(
|
||||||
|
"the path '%s' can not be resolved in pure mode",
|
||||||
|
std::string_view($1.p, $1.l)
|
||||||
|
);
|
||||||
|
}
|
||||||
Path path(getHome() + std::string($1.p + 1, $1.l - 1));
|
Path path(getHome() + std::string($1.p + 1, $1.l - 1));
|
||||||
$$ = new ExprPath(path);
|
$$ = new ExprPath(path);
|
||||||
}
|
}
|
||||||
|
|
@ -528,7 +534,7 @@ path_start
|
||||||
ind_string_parts
|
ind_string_parts
|
||||||
: ind_string_parts IND_STR { $$ = $1; $1->emplace_back(makeCurPos(@2, data), $2); }
|
: ind_string_parts IND_STR { $$ = $1; $1->emplace_back(makeCurPos(@2, data), $2); }
|
||||||
| ind_string_parts DOLLAR_CURLY expr '}' { $$ = $1; $1->emplace_back(makeCurPos(@2, data), $3); }
|
| ind_string_parts DOLLAR_CURLY expr '}' { $$ = $1; $1->emplace_back(makeCurPos(@2, data), $3); }
|
||||||
| { $$ = new std::vector<std::pair<PosIdx, std::variant<Expr *, StringToken> > >; }
|
| { $$ = new std::vector<std::pair<PosIdx, std::variant<Expr *, StringToken>>>; }
|
||||||
;
|
;
|
||||||
|
|
||||||
binds
|
binds
|
||||||
|
|
@ -643,7 +649,7 @@ namespace nix {
|
||||||
|
|
||||||
|
|
||||||
Expr * EvalState::parse(char * text, size_t length, FileOrigin origin,
|
Expr * EvalState::parse(char * text, size_t length, FileOrigin origin,
|
||||||
const PathView path, const PathView basePath, StaticEnv & staticEnv)
|
const PathView path, const PathView basePath, std::shared_ptr<StaticEnv> & staticEnv)
|
||||||
{
|
{
|
||||||
yyscan_t scanner;
|
yyscan_t scanner;
|
||||||
std::string file;
|
std::string file;
|
||||||
|
|
@ -706,7 +712,7 @@ Expr * EvalState::parseExprFromFile(const Path & path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Expr * EvalState::parseExprFromFile(const Path & path, StaticEnv & staticEnv)
|
Expr * EvalState::parseExprFromFile(const Path & path, std::shared_ptr<StaticEnv> & staticEnv)
|
||||||
{
|
{
|
||||||
auto buffer = readFile(path);
|
auto buffer = readFile(path);
|
||||||
// readFile should have left some extra space for terminators
|
// readFile should have left some extra space for terminators
|
||||||
|
|
@ -715,7 +721,7 @@ Expr * EvalState::parseExprFromFile(const Path & path, StaticEnv & staticEnv)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Expr * EvalState::parseExprFromString(std::string s, const Path & basePath, StaticEnv & staticEnv)
|
Expr * EvalState::parseExprFromString(std::string s, const Path & basePath, std::shared_ptr<StaticEnv> & staticEnv)
|
||||||
{
|
{
|
||||||
s.append("\0\0", 2);
|
s.append("\0\0", 2);
|
||||||
return parse(s.data(), s.size(), foString, "", basePath, staticEnv);
|
return parse(s.data(), s.size(), foString, "", basePath, staticEnv);
|
||||||
|
|
@ -782,13 +788,13 @@ Path EvalState::findFile(SearchPath & searchPath, const std::string_view path, c
|
||||||
if (hasPrefix(path, "nix/"))
|
if (hasPrefix(path, "nix/"))
|
||||||
return concatStrings(corepkgsPrefix, path.substr(4));
|
return concatStrings(corepkgsPrefix, path.substr(4));
|
||||||
|
|
||||||
throw ThrownError({
|
debugThrowLastTrace(ThrownError({
|
||||||
.msg = hintfmt(evalSettings.pureEval
|
.msg = hintfmt(evalSettings.pureEval
|
||||||
? "cannot look up '<%s>' in pure evaluation mode (use '--impure' to override)"
|
? "cannot look up '<%s>' in pure evaluation mode (use '--impure' to override)"
|
||||||
: "file '%s' was not found in the Nix search path (add it using $NIX_PATH or -I)",
|
: "file '%s' was not found in the Nix search path (add it using $NIX_PATH or -I)",
|
||||||
path),
|
path),
|
||||||
.errPos = positions[pos]
|
.errPos = positions[pos]
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ StringMap EvalState::realiseContext(const PathSet & context)
|
||||||
auto [ctx, outputName] = decodeContext(*store, i);
|
auto [ctx, outputName] = decodeContext(*store, i);
|
||||||
auto ctxS = store->printStorePath(ctx);
|
auto ctxS = store->printStorePath(ctx);
|
||||||
if (!store->isValidPath(ctx))
|
if (!store->isValidPath(ctx))
|
||||||
throw InvalidPathError(store->printStorePath(ctx));
|
debugThrowLastTrace(InvalidPathError(store->printStorePath(ctx)));
|
||||||
if (!outputName.empty() && ctx.isDerivation()) {
|
if (!outputName.empty() && ctx.isDerivation()) {
|
||||||
drvs.push_back({ctx, {outputName}});
|
drvs.push_back({ctx, {outputName}});
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -57,9 +57,9 @@ StringMap EvalState::realiseContext(const PathSet & context)
|
||||||
if (drvs.empty()) return {};
|
if (drvs.empty()) return {};
|
||||||
|
|
||||||
if (!evalSettings.enableImportFromDerivation)
|
if (!evalSettings.enableImportFromDerivation)
|
||||||
throw Error(
|
debugThrowLastTrace(Error(
|
||||||
"cannot build '%1%' during evaluation because the option 'allow-import-from-derivation' is disabled",
|
"cannot build '%1%' during evaluation because the option 'allow-import-from-derivation' is disabled",
|
||||||
store->printStorePath(drvs.begin()->drvPath));
|
store->printStorePath(drvs.begin()->drvPath)));
|
||||||
|
|
||||||
/* Build/substitute the context. */
|
/* Build/substitute the context. */
|
||||||
std::vector<DerivedPath> buildReqs;
|
std::vector<DerivedPath> buildReqs;
|
||||||
|
|
@ -72,8 +72,8 @@ StringMap EvalState::realiseContext(const PathSet & context)
|
||||||
for (auto & outputName : outputs) {
|
for (auto & outputName : outputs) {
|
||||||
auto outputPath = get(outputPaths, outputName);
|
auto outputPath = get(outputPaths, outputName);
|
||||||
if (!outputPath)
|
if (!outputPath)
|
||||||
throw Error("derivation '%s' does not have an output named '%s'",
|
debugThrowLastTrace(Error("derivation '%s' does not have an output named '%s'",
|
||||||
store->printStorePath(drvPath), outputName);
|
store->printStorePath(drvPath), outputName));
|
||||||
res.insert_or_assign(
|
res.insert_or_assign(
|
||||||
downstreamPlaceholder(*store, drvPath, outputName),
|
downstreamPlaceholder(*store, drvPath, outputName),
|
||||||
store->printStorePath(*outputPath)
|
store->printStorePath(*outputPath)
|
||||||
|
|
@ -216,11 +216,11 @@ static void import(EvalState & state, const PosIdx pos, Value & vPath, Value * v
|
||||||
Env * env = &state.allocEnv(vScope->attrs->size());
|
Env * env = &state.allocEnv(vScope->attrs->size());
|
||||||
env->up = &state.baseEnv;
|
env->up = &state.baseEnv;
|
||||||
|
|
||||||
StaticEnv staticEnv(false, &state.staticBaseEnv, vScope->attrs->size());
|
auto staticEnv = std::make_shared<StaticEnv>(false, state.staticBaseEnv.get(), vScope->attrs->size());
|
||||||
|
|
||||||
unsigned int displ = 0;
|
unsigned int displ = 0;
|
||||||
for (auto & attr : *vScope->attrs) {
|
for (auto & attr : *vScope->attrs) {
|
||||||
staticEnv.vars.emplace_back(attr.name, displ);
|
staticEnv->vars.emplace_back(attr.name, displ);
|
||||||
env->values[displ++] = attr.value;
|
env->values[displ++] = attr.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -319,17 +319,16 @@ void prim_importNative(EvalState & state, const PosIdx pos, Value * * args, Valu
|
||||||
|
|
||||||
void *handle = dlopen(path.c_str(), RTLD_LAZY | RTLD_LOCAL);
|
void *handle = dlopen(path.c_str(), RTLD_LAZY | RTLD_LOCAL);
|
||||||
if (!handle)
|
if (!handle)
|
||||||
throw EvalError("could not open '%1%': %2%", path, dlerror());
|
state.debugThrowLastTrace(EvalError("could not open '%1%': %2%", path, dlerror()));
|
||||||
|
|
||||||
dlerror();
|
dlerror();
|
||||||
ValueInitializer func = (ValueInitializer) dlsym(handle, sym.c_str());
|
ValueInitializer func = (ValueInitializer) dlsym(handle, sym.c_str());
|
||||||
if(!func) {
|
if(!func) {
|
||||||
char *message = dlerror();
|
char *message = dlerror();
|
||||||
if (message)
|
if (message)
|
||||||
throw EvalError("could not load symbol '%1%' from '%2%': %3%", sym, path, message);
|
state.debugThrowLastTrace(EvalError("could not load symbol '%1%' from '%2%': %3%", sym, path, message));
|
||||||
else
|
else
|
||||||
throw EvalError("symbol '%1%' from '%2%' resolved to NULL when a function pointer was expected",
|
state.debugThrowLastTrace(EvalError("symbol '%1%' from '%2%' resolved to NULL when a function pointer was expected", sym, path));
|
||||||
sym, path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(func)(state, v);
|
(func)(state, v);
|
||||||
|
|
@ -344,12 +343,11 @@ void prim_exec(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
||||||
state.forceList(*args[0], pos);
|
state.forceList(*args[0], pos);
|
||||||
auto elems = args[0]->listElems();
|
auto elems = args[0]->listElems();
|
||||||
auto count = args[0]->listSize();
|
auto count = args[0]->listSize();
|
||||||
if (count == 0) {
|
if (count == 0)
|
||||||
throw EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("at least one argument to 'exec' required"),
|
.msg = hintfmt("at least one argument to 'exec' required"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
}
|
|
||||||
PathSet context;
|
PathSet context;
|
||||||
auto program = state.coerceToString(pos, *elems[0], context, false, false).toOwned();
|
auto program = state.coerceToString(pos, *elems[0], context, false, false).toOwned();
|
||||||
Strings commandArgs;
|
Strings commandArgs;
|
||||||
|
|
@ -359,11 +357,11 @@ void prim_exec(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
||||||
try {
|
try {
|
||||||
auto _ = state.realiseContext(context); // FIXME: Handle CA derivations
|
auto _ = state.realiseContext(context); // FIXME: Handle CA derivations
|
||||||
} catch (InvalidPathError & e) {
|
} catch (InvalidPathError & e) {
|
||||||
throw EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("cannot execute '%1%', since path '%2%' is not valid",
|
.msg = hintfmt("cannot execute '%1%', since path '%2%' is not valid",
|
||||||
program, e.path),
|
program, e.path),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto output = runProgram(program, true, commandArgs);
|
auto output = runProgram(program, true, commandArgs);
|
||||||
|
|
@ -547,7 +545,7 @@ struct CompareValues
|
||||||
if (v1->type() == nInt && v2->type() == nFloat)
|
if (v1->type() == nInt && v2->type() == nFloat)
|
||||||
return v1->integer < v2->fpoint;
|
return v1->integer < v2->fpoint;
|
||||||
if (v1->type() != v2->type())
|
if (v1->type() != v2->type())
|
||||||
throw EvalError("cannot compare %1% with %2%", showType(*v1), showType(*v2));
|
state.debugThrowLastTrace(EvalError("cannot compare %1% with %2%", showType(*v1), showType(*v2)));
|
||||||
switch (v1->type()) {
|
switch (v1->type()) {
|
||||||
case nInt:
|
case nInt:
|
||||||
return v1->integer < v2->integer;
|
return v1->integer < v2->integer;
|
||||||
|
|
@ -569,14 +567,14 @@ struct CompareValues
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
throw EvalError("cannot compare %1% with %2%", showType(*v1), showType(*v2));
|
state.debugThrowLastTrace(EvalError("cannot compare %1% with %2%", showType(*v1), showType(*v2)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#if HAVE_BOEHMGC
|
#if HAVE_BOEHMGC
|
||||||
typedef std::list<Value *, gc_allocator<Value *> > ValueList;
|
typedef std::list<Value *, gc_allocator<Value *>> ValueList;
|
||||||
#else
|
#else
|
||||||
typedef std::list<Value *> ValueList;
|
typedef std::list<Value *> ValueList;
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -599,10 +597,10 @@ static Bindings::iterator getAttr(
|
||||||
|
|
||||||
auto aPos = attrSet->pos;
|
auto aPos = attrSet->pos;
|
||||||
if (!aPos) {
|
if (!aPos) {
|
||||||
throw TypeError({
|
state.debugThrowLastTrace(TypeError({
|
||||||
.msg = errorMsg,
|
.msg = errorMsg,
|
||||||
.errPos = state.positions[pos],
|
.errPos = state.positions[pos],
|
||||||
});
|
}));
|
||||||
} else {
|
} else {
|
||||||
auto e = TypeError({
|
auto e = TypeError({
|
||||||
.msg = errorMsg,
|
.msg = errorMsg,
|
||||||
|
|
@ -612,7 +610,7 @@ static Bindings::iterator getAttr(
|
||||||
// Adding another trace for the function name to make it clear
|
// Adding another trace for the function name to make it clear
|
||||||
// which call received wrong arguments.
|
// which call received wrong arguments.
|
||||||
e.addTrace(state.positions[pos], hintfmt("while invoking '%s'", funcName));
|
e.addTrace(state.positions[pos], hintfmt("while invoking '%s'", funcName));
|
||||||
throw e;
|
state.debugThrowLastTrace(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -666,10 +664,10 @@ static void prim_genericClosure(EvalState & state, const PosIdx pos, Value * * a
|
||||||
Bindings::iterator key =
|
Bindings::iterator key =
|
||||||
e->attrs->find(state.sKey);
|
e->attrs->find(state.sKey);
|
||||||
if (key == e->attrs->end())
|
if (key == e->attrs->end())
|
||||||
throw EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("attribute 'key' required"),
|
.msg = hintfmt("attribute 'key' required"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.forceValue(*key->value, pos);
|
state.forceValue(*key->value, pos);
|
||||||
|
|
||||||
if (!doneKeys.insert(key->value).second) continue;
|
if (!doneKeys.insert(key->value).second) continue;
|
||||||
|
|
@ -725,6 +723,41 @@ static RegisterPrimOp primop_genericClosure(RegisterPrimOp::Info {
|
||||||
.fun = prim_genericClosure,
|
.fun = prim_genericClosure,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
static RegisterPrimOp primop_break({
|
||||||
|
.name = "break",
|
||||||
|
.args = {"v"},
|
||||||
|
.doc = R"(
|
||||||
|
In debug mode (enabled using `--debugger`), pause Nix expression evaluation and enter the REPL.
|
||||||
|
Otherwise, return the argument `v`.
|
||||||
|
)",
|
||||||
|
.fun = [](EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
||||||
|
{
|
||||||
|
if (state.debugRepl && !state.debugTraces.empty()) {
|
||||||
|
auto error = Error(ErrorInfo {
|
||||||
|
.level = lvlInfo,
|
||||||
|
.msg = hintfmt("breakpoint reached"),
|
||||||
|
.errPos = state.positions[pos],
|
||||||
|
});
|
||||||
|
|
||||||
|
auto & dt = state.debugTraces.front();
|
||||||
|
state.runDebugRepl(&error, dt.env, dt.expr);
|
||||||
|
|
||||||
|
if (state.debugQuit) {
|
||||||
|
// If the user elects to quit the repl, throw an exception.
|
||||||
|
throw Error(ErrorInfo{
|
||||||
|
.level = lvlInfo,
|
||||||
|
.msg = hintfmt("quit the debugger"),
|
||||||
|
.errPos = state.positions[noPos],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the value we were passed.
|
||||||
|
v = *args[0];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
static RegisterPrimOp primop_abort({
|
static RegisterPrimOp primop_abort({
|
||||||
.name = "abort",
|
.name = "abort",
|
||||||
.args = {"s"},
|
.args = {"s"},
|
||||||
|
|
@ -735,7 +768,7 @@ static RegisterPrimOp primop_abort({
|
||||||
{
|
{
|
||||||
PathSet context;
|
PathSet context;
|
||||||
auto s = state.coerceToString(pos, *args[0], context).toOwned();
|
auto s = state.coerceToString(pos, *args[0], context).toOwned();
|
||||||
throw Abort("evaluation aborted with the following error message: '%1%'", s);
|
state.debugThrowLastTrace(Abort("evaluation aborted with the following error message: '%1%'", s));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -753,7 +786,7 @@ static RegisterPrimOp primop_throw({
|
||||||
{
|
{
|
||||||
PathSet context;
|
PathSet context;
|
||||||
auto s = state.coerceToString(pos, *args[0], context).toOwned();
|
auto s = state.coerceToString(pos, *args[0], context).toOwned();
|
||||||
throw ThrownError(s);
|
state.debugThrowLastTrace(ThrownError(s));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -818,6 +851,18 @@ static RegisterPrimOp primop_floor({
|
||||||
static void prim_tryEval(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
static void prim_tryEval(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
||||||
{
|
{
|
||||||
auto attrs = state.buildBindings(2);
|
auto attrs = state.buildBindings(2);
|
||||||
|
|
||||||
|
/* increment state.trylevel, and decrement it when this function returns. */
|
||||||
|
MaintainCount trylevel(state.trylevel);
|
||||||
|
|
||||||
|
void (* savedDebugRepl)(ref<EvalState> es, const ValMap & extraEnv) = nullptr;
|
||||||
|
if (state.debugRepl && evalSettings.ignoreExceptionsDuringTry)
|
||||||
|
{
|
||||||
|
/* to prevent starting the repl from exceptions withing a tryEval, null it. */
|
||||||
|
savedDebugRepl = state.debugRepl;
|
||||||
|
state.debugRepl = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
state.forceValue(*args[0], pos);
|
state.forceValue(*args[0], pos);
|
||||||
attrs.insert(state.sValue, args[0]);
|
attrs.insert(state.sValue, args[0]);
|
||||||
|
|
@ -826,6 +871,11 @@ static void prim_tryEval(EvalState & state, const PosIdx pos, Value * * args, Va
|
||||||
attrs.alloc(state.sValue).mkBool(false);
|
attrs.alloc(state.sValue).mkBool(false);
|
||||||
attrs.alloc("success").mkBool(false);
|
attrs.alloc("success").mkBool(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// restore the debugRepl pointer if we saved it earlier.
|
||||||
|
if (savedDebugRepl)
|
||||||
|
state.debugRepl = savedDebugRepl;
|
||||||
|
|
||||||
v.mkAttrs(attrs);
|
v.mkAttrs(attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -937,6 +987,15 @@ static RegisterPrimOp primop_trace({
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/* Takes two arguments and evaluates to the second one. Used as the
|
||||||
|
* builtins.traceVerbose implementation when --trace-verbose is not enabled
|
||||||
|
*/
|
||||||
|
static void prim_second(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
||||||
|
{
|
||||||
|
state.forceValue(*args[1], pos);
|
||||||
|
v = *args[1];
|
||||||
|
}
|
||||||
|
|
||||||
/*************************************************************
|
/*************************************************************
|
||||||
* Derivations
|
* Derivations
|
||||||
*************************************************************/
|
*************************************************************/
|
||||||
|
|
@ -1008,37 +1067,37 @@ static void prim_derivationStrict(EvalState & state, const PosIdx pos, Value * *
|
||||||
if (s == "recursive") ingestionMethod = FileIngestionMethod::Recursive;
|
if (s == "recursive") ingestionMethod = FileIngestionMethod::Recursive;
|
||||||
else if (s == "flat") ingestionMethod = FileIngestionMethod::Flat;
|
else if (s == "flat") ingestionMethod = FileIngestionMethod::Flat;
|
||||||
else
|
else
|
||||||
throw EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("invalid value '%s' for 'outputHashMode' attribute", s),
|
.msg = hintfmt("invalid value '%s' for 'outputHashMode' attribute", s),
|
||||||
.errPos = state.positions[posDrvName]
|
.errPos = state.positions[posDrvName]
|
||||||
});
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
auto handleOutputs = [&](const Strings & ss) {
|
auto handleOutputs = [&](const Strings & ss) {
|
||||||
outputs.clear();
|
outputs.clear();
|
||||||
for (auto & j : ss) {
|
for (auto & j : ss) {
|
||||||
if (outputs.find(j) != outputs.end())
|
if (outputs.find(j) != outputs.end())
|
||||||
throw EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("duplicate derivation output '%1%'", j),
|
.msg = hintfmt("duplicate derivation output '%1%'", j),
|
||||||
.errPos = state.positions[posDrvName]
|
.errPos = state.positions[posDrvName]
|
||||||
});
|
}));
|
||||||
/* !!! Check whether j is a valid attribute
|
/* !!! Check whether j is a valid attribute
|
||||||
name. */
|
name. */
|
||||||
/* Derivations cannot be named ‘drv’, because
|
/* Derivations cannot be named ‘drv’, because
|
||||||
then we'd have an attribute ‘drvPath’ in
|
then we'd have an attribute ‘drvPath’ in
|
||||||
the resulting set. */
|
the resulting set. */
|
||||||
if (j == "drv")
|
if (j == "drv")
|
||||||
throw EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("invalid derivation output name 'drv'" ),
|
.msg = hintfmt("invalid derivation output name 'drv'" ),
|
||||||
.errPos = state.positions[posDrvName]
|
.errPos = state.positions[posDrvName]
|
||||||
});
|
}));
|
||||||
outputs.insert(j);
|
outputs.insert(j);
|
||||||
}
|
}
|
||||||
if (outputs.empty())
|
if (outputs.empty())
|
||||||
throw EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("derivation cannot have an empty set of outputs"),
|
.msg = hintfmt("derivation cannot have an empty set of outputs"),
|
||||||
.errPos = state.positions[posDrvName]
|
.errPos = state.positions[posDrvName]
|
||||||
});
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -1163,23 +1222,23 @@ static void prim_derivationStrict(EvalState & state, const PosIdx pos, Value * *
|
||||||
|
|
||||||
/* Do we have all required attributes? */
|
/* Do we have all required attributes? */
|
||||||
if (drv.builder == "")
|
if (drv.builder == "")
|
||||||
throw EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("required attribute 'builder' missing"),
|
.msg = hintfmt("required attribute 'builder' missing"),
|
||||||
.errPos = state.positions[posDrvName]
|
.errPos = state.positions[posDrvName]
|
||||||
});
|
}));
|
||||||
|
|
||||||
if (drv.platform == "")
|
if (drv.platform == "")
|
||||||
throw EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("required attribute 'system' missing"),
|
.msg = hintfmt("required attribute 'system' missing"),
|
||||||
.errPos = state.positions[posDrvName]
|
.errPos = state.positions[posDrvName]
|
||||||
});
|
}));
|
||||||
|
|
||||||
/* Check whether the derivation name is valid. */
|
/* Check whether the derivation name is valid. */
|
||||||
if (isDerivation(drvName))
|
if (isDerivation(drvName))
|
||||||
throw EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("derivation names are not allowed to end in '%s'", drvExtension),
|
.msg = hintfmt("derivation names are not allowed to end in '%s'", drvExtension),
|
||||||
.errPos = state.positions[posDrvName]
|
.errPos = state.positions[posDrvName]
|
||||||
});
|
}));
|
||||||
|
|
||||||
if (outputHash) {
|
if (outputHash) {
|
||||||
/* Handle fixed-output derivations.
|
/* Handle fixed-output derivations.
|
||||||
|
|
@ -1187,10 +1246,10 @@ static void prim_derivationStrict(EvalState & state, const PosIdx pos, Value * *
|
||||||
Ignore `__contentAddressed` because fixed output derivations are
|
Ignore `__contentAddressed` because fixed output derivations are
|
||||||
already content addressed. */
|
already content addressed. */
|
||||||
if (outputs.size() != 1 || *(outputs.begin()) != "out")
|
if (outputs.size() != 1 || *(outputs.begin()) != "out")
|
||||||
throw Error({
|
state.debugThrowLastTrace(Error({
|
||||||
.msg = hintfmt("multiple outputs are not supported in fixed-output derivations"),
|
.msg = hintfmt("multiple outputs are not supported in fixed-output derivations"),
|
||||||
.errPos = state.positions[posDrvName]
|
.errPos = state.positions[posDrvName]
|
||||||
});
|
}));
|
||||||
|
|
||||||
auto h = newHashAllowEmpty(*outputHash, parseHashTypeOpt(outputHashAlgo));
|
auto h = newHashAllowEmpty(*outputHash, parseHashTypeOpt(outputHashAlgo));
|
||||||
|
|
||||||
|
|
@ -1358,10 +1417,10 @@ static RegisterPrimOp primop_toPath({
|
||||||
static void prim_storePath(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
static void prim_storePath(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
||||||
{
|
{
|
||||||
if (evalSettings.pureEval)
|
if (evalSettings.pureEval)
|
||||||
throw EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("'%s' is not allowed in pure evaluation mode", "builtins.storePath"),
|
.msg = hintfmt("'%s' is not allowed in pure evaluation mode", "builtins.storePath"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
|
|
||||||
PathSet context;
|
PathSet context;
|
||||||
Path path = state.checkSourcePath(state.coerceToPath(pos, *args[0], context));
|
Path path = state.checkSourcePath(state.coerceToPath(pos, *args[0], context));
|
||||||
|
|
@ -1370,10 +1429,10 @@ static void prim_storePath(EvalState & state, const PosIdx pos, Value * * args,
|
||||||
e.g. nix-push does the right thing. */
|
e.g. nix-push does the right thing. */
|
||||||
if (!state.store->isStorePath(path)) path = canonPath(path, true);
|
if (!state.store->isStorePath(path)) path = canonPath(path, true);
|
||||||
if (!state.store->isInStore(path))
|
if (!state.store->isInStore(path))
|
||||||
throw EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("path '%1%' is not in the Nix store", path),
|
.msg = hintfmt("path '%1%' is not in the Nix store", path),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
auto path2 = state.store->toStorePath(path).first;
|
auto path2 = state.store->toStorePath(path).first;
|
||||||
if (!settings.readOnlyMode)
|
if (!settings.readOnlyMode)
|
||||||
state.store->ensurePath(path2);
|
state.store->ensurePath(path2);
|
||||||
|
|
@ -1476,7 +1535,7 @@ static void prim_readFile(EvalState & state, const PosIdx pos, Value * * args, V
|
||||||
auto path = realisePath(state, pos, *args[0]);
|
auto path = realisePath(state, pos, *args[0]);
|
||||||
auto s = readFile(path);
|
auto s = readFile(path);
|
||||||
if (s.find((char) 0) != std::string::npos)
|
if (s.find((char) 0) != std::string::npos)
|
||||||
throw Error("the contents of the file '%1%' cannot be represented as a Nix string", path);
|
state.debugThrowLastTrace(Error("the contents of the file '%1%' cannot be represented as a Nix string", path));
|
||||||
StorePathSet refs;
|
StorePathSet refs;
|
||||||
if (state.store->isInStore(path)) {
|
if (state.store->isInStore(path)) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -1528,13 +1587,12 @@ static void prim_findFile(EvalState & state, const PosIdx pos, Value * * args, V
|
||||||
auto rewrites = state.realiseContext(context);
|
auto rewrites = state.realiseContext(context);
|
||||||
path = rewriteStrings(path, rewrites);
|
path = rewriteStrings(path, rewrites);
|
||||||
} catch (InvalidPathError & e) {
|
} catch (InvalidPathError & e) {
|
||||||
throw EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("cannot find '%1%', since path '%2%' is not valid", path, e.path),
|
.msg = hintfmt("cannot find '%1%', since path '%2%' is not valid", path, e.path),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
searchPath.emplace_back(prefix, path);
|
searchPath.emplace_back(prefix, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1555,10 +1613,10 @@ static void prim_hashFile(EvalState & state, const PosIdx pos, Value * * args, V
|
||||||
auto type = state.forceStringNoCtx(*args[0], pos);
|
auto type = state.forceStringNoCtx(*args[0], pos);
|
||||||
std::optional<HashType> ht = parseHashType(type);
|
std::optional<HashType> ht = parseHashType(type);
|
||||||
if (!ht)
|
if (!ht)
|
||||||
throw Error({
|
state.debugThrowLastTrace(Error({
|
||||||
.msg = hintfmt("unknown hash type '%1%'", type),
|
.msg = hintfmt("unknown hash type '%1%'", type),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
|
|
||||||
auto path = realisePath(state, pos, *args[1]);
|
auto path = realisePath(state, pos, *args[1]);
|
||||||
|
|
||||||
|
|
@ -1795,13 +1853,13 @@ static void prim_toFile(EvalState & state, const PosIdx pos, Value * * args, Val
|
||||||
|
|
||||||
for (auto path : context) {
|
for (auto path : context) {
|
||||||
if (path.at(0) != '/')
|
if (path.at(0) != '/')
|
||||||
throw EvalError( {
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt(
|
.msg = hintfmt(
|
||||||
"in 'toFile': the file named '%1%' must not contain a reference "
|
"in 'toFile': the file named '%1%' must not contain a reference "
|
||||||
"to a derivation but contains (%2%)",
|
"to a derivation but contains (%2%)",
|
||||||
name, path),
|
name, path),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
refs.insert(state.store->parseStorePath(path));
|
refs.insert(state.store->parseStorePath(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1959,7 +2017,7 @@ static void addPath(
|
||||||
? state.store->computeStorePathForPath(name, path, method, htSHA256, filter).first
|
? state.store->computeStorePathForPath(name, path, method, htSHA256, filter).first
|
||||||
: state.store->addToStore(name, path, method, htSHA256, filter, state.repair, refs);
|
: state.store->addToStore(name, path, method, htSHA256, filter, state.repair, refs);
|
||||||
if (expectedHash && expectedStorePath != dstPath)
|
if (expectedHash && expectedStorePath != dstPath)
|
||||||
throw Error("store path mismatch in (possibly filtered) path added from '%s'", path);
|
state.debugThrowLastTrace(Error("store path mismatch in (possibly filtered) path added from '%s'", path));
|
||||||
state.allowAndSetStorePathString(dstPath, v);
|
state.allowAndSetStorePathString(dstPath, v);
|
||||||
} else
|
} else
|
||||||
state.allowAndSetStorePathString(*expectedStorePath, v);
|
state.allowAndSetStorePathString(*expectedStorePath, v);
|
||||||
|
|
@ -1977,12 +2035,12 @@ static void prim_filterSource(EvalState & state, const PosIdx pos, Value * * arg
|
||||||
|
|
||||||
state.forceValue(*args[0], pos);
|
state.forceValue(*args[0], pos);
|
||||||
if (args[0]->type() != nFunction)
|
if (args[0]->type() != nFunction)
|
||||||
throw TypeError({
|
state.debugThrowLastTrace(TypeError({
|
||||||
.msg = hintfmt(
|
.msg = hintfmt(
|
||||||
"first argument in call to 'filterSource' is not a function but %1%",
|
"first argument in call to 'filterSource' is not a function but %1%",
|
||||||
showType(*args[0])),
|
showType(*args[0])),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
|
|
||||||
addPath(state, pos, std::string(baseNameOf(path)), path, args[0], FileIngestionMethod::Recursive, std::nullopt, v, context);
|
addPath(state, pos, std::string(baseNameOf(path)), path, args[0], FileIngestionMethod::Recursive, std::nullopt, v, context);
|
||||||
}
|
}
|
||||||
|
|
@ -2066,16 +2124,16 @@ static void prim_path(EvalState & state, const PosIdx pos, Value * * args, Value
|
||||||
else if (n == "sha256")
|
else if (n == "sha256")
|
||||||
expectedHash = newHashAllowEmpty(state.forceStringNoCtx(*attr.value, attr.pos), htSHA256);
|
expectedHash = newHashAllowEmpty(state.forceStringNoCtx(*attr.value, attr.pos), htSHA256);
|
||||||
else
|
else
|
||||||
throw EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("unsupported argument '%1%' to 'addPath'", state.symbols[attr.name]),
|
.msg = hintfmt("unsupported argument '%1%' to 'addPath'", state.symbols[attr.name]),
|
||||||
.errPos = state.positions[attr.pos]
|
.errPos = state.positions[attr.pos]
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
if (path.empty())
|
if (path.empty())
|
||||||
throw EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("'path' required"),
|
.msg = hintfmt("'path' required"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
if (name.empty())
|
if (name.empty())
|
||||||
name = baseNameOf(path);
|
name = baseNameOf(path);
|
||||||
|
|
||||||
|
|
@ -2447,10 +2505,10 @@ static void prim_functionArgs(EvalState & state, const PosIdx pos, Value * * arg
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!args[0]->isLambda())
|
if (!args[0]->isLambda())
|
||||||
throw TypeError({
|
state.debugThrowLastTrace(TypeError({
|
||||||
.msg = hintfmt("'functionArgs' requires a function"),
|
.msg = hintfmt("'functionArgs' requires a function"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
|
|
||||||
if (!args[0]->lambda.fun->hasFormals()) {
|
if (!args[0]->lambda.fun->hasFormals()) {
|
||||||
v.mkAttrs(&state.emptyBindings);
|
v.mkAttrs(&state.emptyBindings);
|
||||||
|
|
@ -2538,7 +2596,7 @@ static void prim_zipAttrsWith(EvalState & state, const PosIdx pos, Value * * arg
|
||||||
attrsSeen[attr.name].first++;
|
attrsSeen[attr.name].first++;
|
||||||
} catch (TypeError & e) {
|
} catch (TypeError & e) {
|
||||||
e.addTrace(state.positions[pos], hintfmt("while invoking '%s'", "zipAttrsWith"));
|
e.addTrace(state.positions[pos], hintfmt("while invoking '%s'", "zipAttrsWith"));
|
||||||
throw;
|
state.debugThrowLastTrace(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2625,10 +2683,10 @@ static void elemAt(EvalState & state, const PosIdx pos, Value & list, int n, Val
|
||||||
{
|
{
|
||||||
state.forceList(list, pos);
|
state.forceList(list, pos);
|
||||||
if (n < 0 || (unsigned int) n >= list.listSize())
|
if (n < 0 || (unsigned int) n >= list.listSize())
|
||||||
throw Error({
|
state.debugThrowLastTrace(Error({
|
||||||
.msg = hintfmt("list index %1% is out of bounds", n),
|
.msg = hintfmt("list index %1% is out of bounds", n),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
state.forceValue(*list.listElems()[n], pos);
|
state.forceValue(*list.listElems()[n], pos);
|
||||||
v = *list.listElems()[n];
|
v = *list.listElems()[n];
|
||||||
}
|
}
|
||||||
|
|
@ -2673,10 +2731,10 @@ static void prim_tail(EvalState & state, const PosIdx pos, Value * * args, Value
|
||||||
{
|
{
|
||||||
state.forceList(*args[0], pos);
|
state.forceList(*args[0], pos);
|
||||||
if (args[0]->listSize() == 0)
|
if (args[0]->listSize() == 0)
|
||||||
throw Error({
|
state.debugThrowLastTrace(Error({
|
||||||
.msg = hintfmt("'tail' called on an empty list"),
|
.msg = hintfmt("'tail' called on an empty list"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
|
|
||||||
state.mkList(v, args[0]->listSize() - 1);
|
state.mkList(v, args[0]->listSize() - 1);
|
||||||
for (unsigned int n = 0; n < v.listSize(); ++n)
|
for (unsigned int n = 0; n < v.listSize(); ++n)
|
||||||
|
|
@ -2911,10 +2969,10 @@ static void prim_genList(EvalState & state, const PosIdx pos, Value * * args, Va
|
||||||
auto len = state.forceInt(*args[1], pos);
|
auto len = state.forceInt(*args[1], pos);
|
||||||
|
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
throw EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("cannot create list of size %1%", len),
|
.msg = hintfmt("cannot create list of size %1%", len),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
|
|
||||||
state.mkList(v, len);
|
state.mkList(v, len);
|
||||||
|
|
||||||
|
|
@ -3123,7 +3181,7 @@ static void prim_concatMap(EvalState & state, const PosIdx pos, Value * * args,
|
||||||
state.forceList(lists[n], lists[n].determinePos(args[0]->determinePos(pos)));
|
state.forceList(lists[n], lists[n].determinePos(args[0]->determinePos(pos)));
|
||||||
} catch (TypeError &e) {
|
} catch (TypeError &e) {
|
||||||
e.addTrace(state.positions[pos], hintfmt("while invoking '%s'", "concatMap"));
|
e.addTrace(state.positions[pos], hintfmt("while invoking '%s'", "concatMap"));
|
||||||
throw;
|
state.debugThrowLastTrace(e);
|
||||||
}
|
}
|
||||||
len += lists[n].listSize();
|
len += lists[n].listSize();
|
||||||
}
|
}
|
||||||
|
|
@ -3218,10 +3276,10 @@ static void prim_div(EvalState & state, const PosIdx pos, Value * * args, Value
|
||||||
|
|
||||||
NixFloat f2 = state.forceFloat(*args[1], pos);
|
NixFloat f2 = state.forceFloat(*args[1], pos);
|
||||||
if (f2 == 0)
|
if (f2 == 0)
|
||||||
throw EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("division by zero"),
|
.msg = hintfmt("division by zero"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
|
|
||||||
if (args[0]->type() == nFloat || args[1]->type() == nFloat) {
|
if (args[0]->type() == nFloat || args[1]->type() == nFloat) {
|
||||||
v.mkFloat(state.forceFloat(*args[0], pos) / state.forceFloat(*args[1], pos));
|
v.mkFloat(state.forceFloat(*args[0], pos) / state.forceFloat(*args[1], pos));
|
||||||
|
|
@ -3230,10 +3288,10 @@ static void prim_div(EvalState & state, const PosIdx pos, Value * * args, Value
|
||||||
NixInt i2 = state.forceInt(*args[1], pos);
|
NixInt i2 = state.forceInt(*args[1], pos);
|
||||||
/* Avoid division overflow as it might raise SIGFPE. */
|
/* Avoid division overflow as it might raise SIGFPE. */
|
||||||
if (i1 == std::numeric_limits<NixInt>::min() && i2 == -1)
|
if (i1 == std::numeric_limits<NixInt>::min() && i2 == -1)
|
||||||
throw EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("overflow in integer division"),
|
.msg = hintfmt("overflow in integer division"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
|
|
||||||
v.mkInt(i1 / i2);
|
v.mkInt(i1 / i2);
|
||||||
}
|
}
|
||||||
|
|
@ -3361,10 +3419,10 @@ static void prim_substring(EvalState & state, const PosIdx pos, Value * * args,
|
||||||
auto s = state.coerceToString(pos, *args[2], context);
|
auto s = state.coerceToString(pos, *args[2], context);
|
||||||
|
|
||||||
if (start < 0)
|
if (start < 0)
|
||||||
throw EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("negative start position in 'substring'"),
|
.msg = hintfmt("negative start position in 'substring'"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
|
|
||||||
v.mkString((unsigned int) start >= s->size() ? "" : s->substr(start, len), context);
|
v.mkString((unsigned int) start >= s->size() ? "" : s->substr(start, len), context);
|
||||||
}
|
}
|
||||||
|
|
@ -3412,10 +3470,10 @@ static void prim_hashString(EvalState & state, const PosIdx pos, Value * * args,
|
||||||
auto type = state.forceStringNoCtx(*args[0], pos);
|
auto type = state.forceStringNoCtx(*args[0], pos);
|
||||||
std::optional<HashType> ht = parseHashType(type);
|
std::optional<HashType> ht = parseHashType(type);
|
||||||
if (!ht)
|
if (!ht)
|
||||||
throw Error({
|
state.debugThrowLastTrace(Error({
|
||||||
.msg = hintfmt("unknown hash type '%1%'", type),
|
.msg = hintfmt("unknown hash type '%1%'", type),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
|
|
||||||
PathSet context; // discarded
|
PathSet context; // discarded
|
||||||
auto s = state.forceString(*args[1], context, pos);
|
auto s = state.forceString(*args[1], context, pos);
|
||||||
|
|
@ -3482,19 +3540,18 @@ void prim_match(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
||||||
(v.listElems()[i] = state.allocValue())->mkString(match[i + 1].str());
|
(v.listElems()[i] = state.allocValue())->mkString(match[i + 1].str());
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (std::regex_error &e) {
|
} catch (std::regex_error & e) {
|
||||||
if (e.code() == std::regex_constants::error_space) {
|
if (e.code() == std::regex_constants::error_space) {
|
||||||
// limit is _GLIBCXX_REGEX_STATE_LIMIT for libstdc++
|
// limit is _GLIBCXX_REGEX_STATE_LIMIT for libstdc++
|
||||||
throw EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("memory limit exceeded by regular expression '%s'", re),
|
.msg = hintfmt("memory limit exceeded by regular expression '%s'", re),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
} else {
|
} else
|
||||||
throw EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("invalid regular expression '%s'", re),
|
.msg = hintfmt("invalid regular expression '%s'", re),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3529,7 +3586,7 @@ static RegisterPrimOp primop_match({
|
||||||
builtins.match "[[:space:]]+([[:upper:]]+)[[:space:]]+" " FOO "
|
builtins.match "[[:space:]]+([[:upper:]]+)[[:space:]]+" " FOO "
|
||||||
```
|
```
|
||||||
|
|
||||||
Evaluates to `[ "foo" ]`.
|
Evaluates to `[ "FOO" ]`.
|
||||||
)s",
|
)s",
|
||||||
.fun = prim_match,
|
.fun = prim_match,
|
||||||
});
|
});
|
||||||
|
|
@ -3587,19 +3644,18 @@ void prim_split(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
||||||
|
|
||||||
assert(idx == 2 * len + 1);
|
assert(idx == 2 * len + 1);
|
||||||
|
|
||||||
} catch (std::regex_error &e) {
|
} catch (std::regex_error & e) {
|
||||||
if (e.code() == std::regex_constants::error_space) {
|
if (e.code() == std::regex_constants::error_space) {
|
||||||
// limit is _GLIBCXX_REGEX_STATE_LIMIT for libstdc++
|
// limit is _GLIBCXX_REGEX_STATE_LIMIT for libstdc++
|
||||||
throw EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("memory limit exceeded by regular expression '%s'", re),
|
.msg = hintfmt("memory limit exceeded by regular expression '%s'", re),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
} else {
|
} else
|
||||||
throw EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("invalid regular expression '%s'", re),
|
.msg = hintfmt("invalid regular expression '%s'", re),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3675,10 +3731,10 @@ static void prim_replaceStrings(EvalState & state, const PosIdx pos, Value * * a
|
||||||
state.forceList(*args[0], pos);
|
state.forceList(*args[0], pos);
|
||||||
state.forceList(*args[1], pos);
|
state.forceList(*args[1], pos);
|
||||||
if (args[0]->listSize() != args[1]->listSize())
|
if (args[0]->listSize() != args[1]->listSize())
|
||||||
throw EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("'from' and 'to' arguments to 'replaceStrings' have different lengths"),
|
.msg = hintfmt("'from' and 'to' arguments to 'replaceStrings' have different lengths"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
|
|
||||||
std::vector<std::string> from;
|
std::vector<std::string> from;
|
||||||
from.reserve(args[0]->listSize());
|
from.reserve(args[0]->listSize());
|
||||||
|
|
@ -3896,6 +3952,18 @@ void EvalState::createBaseEnv()
|
||||||
addPrimOp("__exec", 1, prim_exec);
|
addPrimOp("__exec", 1, prim_exec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addPrimOp({
|
||||||
|
.fun = evalSettings.traceVerbose ? prim_trace : prim_second,
|
||||||
|
.arity = 2,
|
||||||
|
.name = "__traceVerbose",
|
||||||
|
.args = { "e1", "e2" },
|
||||||
|
.doc = R"(
|
||||||
|
Evaluate *e1* and print its abstract syntax representation on standard
|
||||||
|
error if `--trace-verbose` is enabled. Then return *e2*. This function
|
||||||
|
is useful for debugging.
|
||||||
|
)",
|
||||||
|
});
|
||||||
|
|
||||||
/* Add a value containing the current Nix expression search path. */
|
/* Add a value containing the current Nix expression search path. */
|
||||||
mkList(v, searchPath.size());
|
mkList(v, searchPath.size());
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
@ -3931,7 +3999,7 @@ void EvalState::createBaseEnv()
|
||||||
because attribute lookups expect it to be sorted. */
|
because attribute lookups expect it to be sorted. */
|
||||||
baseEnv.values[0]->attrs->sort();
|
baseEnv.values[0]->attrs->sort();
|
||||||
|
|
||||||
staticBaseEnv.sort();
|
staticBaseEnv->sort();
|
||||||
|
|
||||||
/* Note: we have to initialize the 'derivation' constant *after*
|
/* Note: we have to initialize the 'derivation' constant *after*
|
||||||
building baseEnv/staticBaseEnv because it uses 'builtins'. */
|
building baseEnv/staticBaseEnv because it uses 'builtins'. */
|
||||||
|
|
|
||||||
|
|
@ -108,16 +108,16 @@ static void fetchTree(
|
||||||
|
|
||||||
if (auto aType = args[0]->attrs->get(state.sType)) {
|
if (auto aType = args[0]->attrs->get(state.sType)) {
|
||||||
if (type)
|
if (type)
|
||||||
throw Error({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("unexpected attribute 'type'"),
|
.msg = hintfmt("unexpected attribute 'type'"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
type = state.forceStringNoCtx(*aType->value, aType->pos);
|
type = state.forceStringNoCtx(*aType->value, aType->pos);
|
||||||
} else if (!type)
|
} else if (!type)
|
||||||
throw Error({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("attribute 'type' is missing in call to 'fetchTree'"),
|
.msg = hintfmt("attribute 'type' is missing in call to 'fetchTree'"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
|
|
||||||
attrs.emplace("type", type.value());
|
attrs.emplace("type", type.value());
|
||||||
|
|
||||||
|
|
@ -138,16 +138,16 @@ static void fetchTree(
|
||||||
else if (attr.value->type() == nInt)
|
else if (attr.value->type() == nInt)
|
||||||
attrs.emplace(state.symbols[attr.name], uint64_t(attr.value->integer));
|
attrs.emplace(state.symbols[attr.name], uint64_t(attr.value->integer));
|
||||||
else
|
else
|
||||||
throw TypeError("fetchTree argument '%s' is %s while a string, Boolean or integer is expected",
|
state.debugThrowLastTrace(TypeError("fetchTree argument '%s' is %s while a string, Boolean or integer is expected",
|
||||||
state.symbols[attr.name], showType(*attr.value));
|
state.symbols[attr.name], showType(*attr.value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!params.allowNameArgument)
|
if (!params.allowNameArgument)
|
||||||
if (auto nameIter = attrs.find("name"); nameIter != attrs.end())
|
if (auto nameIter = attrs.find("name"); nameIter != attrs.end())
|
||||||
throw Error({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("attribute 'name' isn't supported in call to 'fetchTree'"),
|
.msg = hintfmt("attribute 'name' isn’t supported in call to 'fetchTree'"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
|
|
||||||
input = fetchers::Input::fromAttrs(std::move(attrs));
|
input = fetchers::Input::fromAttrs(std::move(attrs));
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -167,7 +167,7 @@ static void fetchTree(
|
||||||
input = lookupInRegistries(state.store, input).first;
|
input = lookupInRegistries(state.store, input).first;
|
||||||
|
|
||||||
if (evalSettings.pureEval && !input.isLocked())
|
if (evalSettings.pureEval && !input.isLocked())
|
||||||
throw Error("in pure evaluation mode, 'fetchTree' requires a locked input, at %s", state.positions[pos]);
|
state.debugThrowLastTrace(EvalError("in pure evaluation mode, 'fetchTree' requires a locked input, at %s", state.positions[pos]));
|
||||||
|
|
||||||
auto [tree, input2] = input.fetch(state.store);
|
auto [tree, input2] = input.fetch(state.store);
|
||||||
|
|
||||||
|
|
@ -206,17 +206,17 @@ static void fetch(EvalState & state, const PosIdx pos, Value * * args, Value & v
|
||||||
else if (n == "name")
|
else if (n == "name")
|
||||||
name = state.forceStringNoCtx(*attr.value, attr.pos);
|
name = state.forceStringNoCtx(*attr.value, attr.pos);
|
||||||
else
|
else
|
||||||
throw EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("unsupported argument '%s' to '%s'", n, who),
|
.msg = hintfmt("unsupported argument '%s' to '%s'", n, who),
|
||||||
.errPos = state.positions[attr.pos]
|
.errPos = state.positions[attr.pos]
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!url)
|
if (!url)
|
||||||
throw EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("'url' argument required"),
|
.msg = hintfmt("'url' argument required"),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
});
|
}));
|
||||||
} else
|
} else
|
||||||
url = state.forceStringNoCtx(*args[0], pos);
|
url = state.forceStringNoCtx(*args[0], pos);
|
||||||
|
|
||||||
|
|
@ -228,7 +228,7 @@ static void fetch(EvalState & state, const PosIdx pos, Value * * args, Value & v
|
||||||
name = baseNameOf(*url);
|
name = baseNameOf(*url);
|
||||||
|
|
||||||
if (evalSettings.pureEval && !expectedHash)
|
if (evalSettings.pureEval && !expectedHash)
|
||||||
throw Error("in pure evaluation mode, '%s' requires a 'sha256' argument", who);
|
state.debugThrowLastTrace(EvalError("in pure evaluation mode, '%s' requires a 'sha256' argument", who));
|
||||||
|
|
||||||
// early exit if pinned and already in the store
|
// early exit if pinned and already in the store
|
||||||
if (expectedHash && expectedHash->type == htSHA256) {
|
if (expectedHash && expectedHash->type == htSHA256) {
|
||||||
|
|
@ -255,8 +255,8 @@ static void fetch(EvalState & state, const PosIdx pos, Value * * args, Value & v
|
||||||
? state.store->queryPathInfo(storePath)->narHash
|
? state.store->queryPathInfo(storePath)->narHash
|
||||||
: hashFile(htSHA256, state.store->toRealPath(storePath));
|
: hashFile(htSHA256, state.store->toRealPath(storePath));
|
||||||
if (hash != *expectedHash)
|
if (hash != *expectedHash)
|
||||||
throw Error((unsigned int) 102, "hash mismatch in file downloaded from '%s':\n specified: %s\n got: %s",
|
state.debugThrowLastTrace(EvalError((unsigned int) 102, "hash mismatch in file downloaded from '%s':\n specified: %s\n got: %s",
|
||||||
*url, expectedHash->to_string(Base32, true), hash.to_string(Base32, true));
|
*url, expectedHash->to_string(Base32, true), hash.to_string(Base32, true)));
|
||||||
}
|
}
|
||||||
|
|
||||||
state.allowAndSetStorePathString(storePath, v);
|
state.allowAndSetStorePathString(storePath, v);
|
||||||
|
|
@ -364,6 +364,10 @@ static RegisterPrimOp primop_fetchGit({
|
||||||
A Boolean parameter that specifies whether submodules should be
|
A Boolean parameter that specifies whether submodules should be
|
||||||
checked out. Defaults to `false`.
|
checked out. Defaults to `false`.
|
||||||
|
|
||||||
|
- shallow\
|
||||||
|
A Boolean parameter that specifies whether fetching a shallow clone
|
||||||
|
is allowed. Defaults to `false`.
|
||||||
|
|
||||||
- allRefs\
|
- allRefs\
|
||||||
Whether to fetch all refs of the repository. With this argument being
|
Whether to fetch all refs of the repository. With this argument being
|
||||||
true, it's possible to load a `rev` from *any* `ref` (by default only
|
true, it's possible to load a `rev` from *any* `ref` (by default only
|
||||||
|
|
|
||||||
68
src/libexpr/tests/json.cc
Normal file
68
src/libexpr/tests/json.cc
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
#include "libexprtests.hh"
|
||||||
|
#include "value-to-json.hh"
|
||||||
|
|
||||||
|
namespace nix {
|
||||||
|
// Testing the conversion to JSON
|
||||||
|
|
||||||
|
class JSONValueTest : public LibExprTest {
|
||||||
|
protected:
|
||||||
|
std::string getJSONValue(Value& value) {
|
||||||
|
std::stringstream ss;
|
||||||
|
PathSet ps;
|
||||||
|
printValueAsJSON(state, true, value, noPos, ss, ps);
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F(JSONValueTest, null) {
|
||||||
|
Value v;
|
||||||
|
v.mkNull();
|
||||||
|
ASSERT_EQ(getJSONValue(v), "null");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(JSONValueTest, BoolFalse) {
|
||||||
|
Value v;
|
||||||
|
v.mkBool(false);
|
||||||
|
ASSERT_EQ(getJSONValue(v),"false");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(JSONValueTest, BoolTrue) {
|
||||||
|
Value v;
|
||||||
|
v.mkBool(true);
|
||||||
|
ASSERT_EQ(getJSONValue(v), "true");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(JSONValueTest, IntPositive) {
|
||||||
|
Value v;
|
||||||
|
v.mkInt(100);
|
||||||
|
ASSERT_EQ(getJSONValue(v), "100");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(JSONValueTest, IntNegative) {
|
||||||
|
Value v;
|
||||||
|
v.mkInt(-100);
|
||||||
|
ASSERT_EQ(getJSONValue(v), "-100");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(JSONValueTest, String) {
|
||||||
|
Value v;
|
||||||
|
v.mkString("test");
|
||||||
|
ASSERT_EQ(getJSONValue(v), "\"test\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(JSONValueTest, StringQuotes) {
|
||||||
|
Value v;
|
||||||
|
|
||||||
|
v.mkString("test\"");
|
||||||
|
ASSERT_EQ(getJSONValue(v), "\"test\\\"\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
// The dummy store doesn't support writing files. Fails with this exception message:
|
||||||
|
// C++ exception with description "error: operation 'addToStoreFromDump' is
|
||||||
|
// not supported by store 'dummy'" thrown in the test body.
|
||||||
|
TEST_F(JSONValueTest, DISABLED_Path) {
|
||||||
|
Value v;
|
||||||
|
v.mkPath("test");
|
||||||
|
ASSERT_EQ(getJSONValue(v), "\"/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-x\"");
|
||||||
|
}
|
||||||
|
} /* namespace nix */
|
||||||
136
src/libexpr/tests/libexprtests.hh
Normal file
136
src/libexpr/tests/libexprtests.hh
Normal file
|
|
@ -0,0 +1,136 @@
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <gmock/gmock.h>
|
||||||
|
|
||||||
|
#include "value.hh"
|
||||||
|
#include "nixexpr.hh"
|
||||||
|
#include "eval.hh"
|
||||||
|
#include "eval-inline.hh"
|
||||||
|
#include "store-api.hh"
|
||||||
|
|
||||||
|
|
||||||
|
namespace nix {
|
||||||
|
class LibExprTest : public ::testing::Test {
|
||||||
|
public:
|
||||||
|
static void SetUpTestSuite() {
|
||||||
|
initGC();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
LibExprTest()
|
||||||
|
: store(openStore("dummy://"))
|
||||||
|
, state({}, store)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
Value eval(std::string input, bool forceValue = true) {
|
||||||
|
Value v;
|
||||||
|
Expr * e = state.parseExprFromString(input, "");
|
||||||
|
assert(e);
|
||||||
|
state.eval(e, v);
|
||||||
|
if (forceValue)
|
||||||
|
state.forceValue(v, noPos);
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
Symbol createSymbol(const char * value) {
|
||||||
|
return state.symbols.create(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
ref<Store> store;
|
||||||
|
EvalState state;
|
||||||
|
};
|
||||||
|
|
||||||
|
MATCHER(IsListType, "") {
|
||||||
|
return arg != nList;
|
||||||
|
}
|
||||||
|
|
||||||
|
MATCHER(IsList, "") {
|
||||||
|
return arg.type() == nList;
|
||||||
|
}
|
||||||
|
|
||||||
|
MATCHER(IsString, "") {
|
||||||
|
return arg.type() == nString;
|
||||||
|
}
|
||||||
|
|
||||||
|
MATCHER(IsNull, "") {
|
||||||
|
return arg.type() == nNull;
|
||||||
|
}
|
||||||
|
|
||||||
|
MATCHER(IsThunk, "") {
|
||||||
|
return arg.type() == nThunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
MATCHER(IsAttrs, "") {
|
||||||
|
return arg.type() == nAttrs;
|
||||||
|
}
|
||||||
|
|
||||||
|
MATCHER_P(IsStringEq, s, fmt("The string is equal to \"%1%\"", s)) {
|
||||||
|
if (arg.type() != nString) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return std::string_view(arg.string.s) == s;
|
||||||
|
}
|
||||||
|
|
||||||
|
MATCHER_P(IsIntEq, v, fmt("The string is equal to \"%1%\"", v)) {
|
||||||
|
if (arg.type() != nInt) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return arg.integer == v;
|
||||||
|
}
|
||||||
|
|
||||||
|
MATCHER_P(IsFloatEq, v, fmt("The float is equal to \"%1%\"", v)) {
|
||||||
|
if (arg.type() != nFloat) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return arg.fpoint == v;
|
||||||
|
}
|
||||||
|
|
||||||
|
MATCHER(IsTrue, "") {
|
||||||
|
if (arg.type() != nBool) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return arg.boolean == true;
|
||||||
|
}
|
||||||
|
|
||||||
|
MATCHER(IsFalse, "") {
|
||||||
|
if (arg.type() != nBool) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return arg.boolean == false;
|
||||||
|
}
|
||||||
|
|
||||||
|
MATCHER_P(IsPathEq, p, fmt("Is a path equal to \"%1%\"", p)) {
|
||||||
|
if (arg.type() != nPath) {
|
||||||
|
*result_listener << "Expected a path got " << arg.type();
|
||||||
|
return false;
|
||||||
|
} else if (std::string_view(arg.string.s) != p) {
|
||||||
|
*result_listener << "Expected a path that equals \"" << p << "\" but got: " << arg.string.s;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MATCHER_P(IsListOfSize, n, fmt("Is a list of size [%1%]", n)) {
|
||||||
|
if (arg.type() != nList) {
|
||||||
|
*result_listener << "Expected list got " << arg.type();
|
||||||
|
return false;
|
||||||
|
} else if (arg.listSize() != (size_t)n) {
|
||||||
|
*result_listener << "Expected as list of size " << n << " got " << arg.listSize();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
MATCHER_P(IsAttrsOfSize, n, fmt("Is a set of size [%1%]", n)) {
|
||||||
|
if (arg.type() != nAttrs) {
|
||||||
|
*result_listener << "Expexted set got " << arg.type();
|
||||||
|
return false;
|
||||||
|
} else if (arg.attrs->size() != (size_t)n) {
|
||||||
|
*result_listener << "Expected a set with " << n << " attributes but got " << arg.attrs->size();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} /* namespace nix */
|
||||||
15
src/libexpr/tests/local.mk
Normal file
15
src/libexpr/tests/local.mk
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
check: libexpr-tests_RUN
|
||||||
|
|
||||||
|
programs += libexpr-tests
|
||||||
|
|
||||||
|
libexpr-tests_DIR := $(d)
|
||||||
|
|
||||||
|
libexpr-tests_INSTALL_DIR :=
|
||||||
|
|
||||||
|
libexpr-tests_SOURCES := $(wildcard $(d)/*.cc)
|
||||||
|
|
||||||
|
libexpr-tests_CXXFLAGS += -I src/libexpr -I src/libutil -I src/libstore -I src/libexpr/tests
|
||||||
|
|
||||||
|
libexpr-tests_LIBS = libexpr libutil libstore libfetchers
|
||||||
|
|
||||||
|
libexpr-tests_LDFLAGS := $(GTEST_LIBS) -lgmock
|
||||||
839
src/libexpr/tests/primops.cc
Normal file
839
src/libexpr/tests/primops.cc
Normal file
|
|
@ -0,0 +1,839 @@
|
||||||
|
#include <gmock/gmock.h>
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "libexprtests.hh"
|
||||||
|
|
||||||
|
namespace nix {
|
||||||
|
class CaptureLogger : public Logger
|
||||||
|
{
|
||||||
|
std::ostringstream oss;
|
||||||
|
|
||||||
|
public:
|
||||||
|
CaptureLogger() {}
|
||||||
|
|
||||||
|
std::string get() const {
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
void log(Verbosity lvl, const FormatOrString & fs) override {
|
||||||
|
oss << fs.s << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void logEI(const ErrorInfo & ei) override {
|
||||||
|
showErrorInfo(oss, ei, loggerSettings.showTrace.get());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class CaptureLogging {
|
||||||
|
Logger * oldLogger;
|
||||||
|
std::unique_ptr<CaptureLogger> tempLogger;
|
||||||
|
public:
|
||||||
|
CaptureLogging() : tempLogger(std::make_unique<CaptureLogger>()) {
|
||||||
|
oldLogger = logger;
|
||||||
|
logger = tempLogger.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
~CaptureLogging() {
|
||||||
|
logger = oldLogger;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string get() const {
|
||||||
|
return tempLogger->get();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Testing eval of PrimOp's
|
||||||
|
class PrimOpTest : public LibExprTest {};
|
||||||
|
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, throw) {
|
||||||
|
ASSERT_THROW(eval("throw \"foo\""), ThrownError);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, abort) {
|
||||||
|
ASSERT_THROW(eval("abort \"abort\""), Abort);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, ceil) {
|
||||||
|
auto v = eval("builtins.ceil 1.9");
|
||||||
|
ASSERT_THAT(v, IsIntEq(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, floor) {
|
||||||
|
auto v = eval("builtins.floor 1.9");
|
||||||
|
ASSERT_THAT(v, IsIntEq(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, tryEvalFailure) {
|
||||||
|
auto v = eval("builtins.tryEval (throw \"\")");
|
||||||
|
ASSERT_THAT(v, IsAttrsOfSize(2));
|
||||||
|
auto s = createSymbol("success");
|
||||||
|
auto p = v.attrs->get(s);
|
||||||
|
ASSERT_NE(p, nullptr);
|
||||||
|
ASSERT_THAT(*p->value, IsFalse());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, tryEvalSuccess) {
|
||||||
|
auto v = eval("builtins.tryEval 123");
|
||||||
|
ASSERT_THAT(v, IsAttrs());
|
||||||
|
auto s = createSymbol("success");
|
||||||
|
auto p = v.attrs->get(s);
|
||||||
|
ASSERT_NE(p, nullptr);
|
||||||
|
ASSERT_THAT(*p->value, IsTrue());
|
||||||
|
s = createSymbol("value");
|
||||||
|
p = v.attrs->get(s);
|
||||||
|
ASSERT_NE(p, nullptr);
|
||||||
|
ASSERT_THAT(*p->value, IsIntEq(123));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, getEnv) {
|
||||||
|
setenv("_NIX_UNIT_TEST_ENV_VALUE", "test value", 1);
|
||||||
|
auto v = eval("builtins.getEnv \"_NIX_UNIT_TEST_ENV_VALUE\"");
|
||||||
|
ASSERT_THAT(v, IsStringEq("test value"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, seq) {
|
||||||
|
ASSERT_THROW(eval("let x = throw \"test\"; in builtins.seq x { }"), ThrownError);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, seqNotDeep) {
|
||||||
|
auto v = eval("let x = { z = throw \"test\"; }; in builtins.seq x { }");
|
||||||
|
ASSERT_THAT(v, IsAttrs());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, deepSeq) {
|
||||||
|
ASSERT_THROW(eval("let x = { z = throw \"test\"; }; in builtins.deepSeq x { }"), ThrownError);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, trace) {
|
||||||
|
CaptureLogging l;
|
||||||
|
auto v = eval("builtins.trace \"test string 123\" 123");
|
||||||
|
ASSERT_THAT(v, IsIntEq(123));
|
||||||
|
auto text = l.get();
|
||||||
|
ASSERT_NE(text.find("test string 123"), std::string::npos);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, placeholder) {
|
||||||
|
auto v = eval("builtins.placeholder \"out\"");
|
||||||
|
ASSERT_THAT(v, IsStringEq("/1rz4g4znpzjwh1xymhjpm42vipw92pr73vdgl6xs1hycac8kf2n9"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, baseNameOf) {
|
||||||
|
auto v = eval("builtins.baseNameOf /some/path");
|
||||||
|
ASSERT_THAT(v, IsStringEq("path"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, dirOf) {
|
||||||
|
auto v = eval("builtins.dirOf /some/path");
|
||||||
|
ASSERT_THAT(v, IsPathEq("/some"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, attrValues) {
|
||||||
|
auto v = eval("builtins.attrValues { x = \"foo\"; a = 1; }");
|
||||||
|
ASSERT_THAT(v, IsListOfSize(2));
|
||||||
|
ASSERT_THAT(*v.listElems()[0], IsIntEq(1));
|
||||||
|
ASSERT_THAT(*v.listElems()[1], IsStringEq("foo"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, getAttr) {
|
||||||
|
auto v = eval("builtins.getAttr \"x\" { x = \"foo\"; }");
|
||||||
|
ASSERT_THAT(v, IsStringEq("foo"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, getAttrNotFound) {
|
||||||
|
// FIXME: TypeError is really bad here, also the error wording is worse
|
||||||
|
// than on Nix <=2.3
|
||||||
|
ASSERT_THROW(eval("builtins.getAttr \"y\" { }"), TypeError);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, unsafeGetAttrPos) {
|
||||||
|
// The `y` attribute is at position
|
||||||
|
const char* expr = "builtins.unsafeGetAttrPos \"y\" { y = \"x\"; }";
|
||||||
|
auto v = eval(expr);
|
||||||
|
ASSERT_THAT(v, IsAttrsOfSize(3));
|
||||||
|
|
||||||
|
auto file = v.attrs->find(createSymbol("file"));
|
||||||
|
ASSERT_NE(file, nullptr);
|
||||||
|
// FIXME: The file when running these tests is the input string?!?
|
||||||
|
ASSERT_THAT(*file->value, IsStringEq(expr));
|
||||||
|
|
||||||
|
auto line = v.attrs->find(createSymbol("line"));
|
||||||
|
ASSERT_NE(line, nullptr);
|
||||||
|
ASSERT_THAT(*line->value, IsIntEq(1));
|
||||||
|
|
||||||
|
auto column = v.attrs->find(createSymbol("column"));
|
||||||
|
ASSERT_NE(column, nullptr);
|
||||||
|
ASSERT_THAT(*column->value, IsIntEq(33));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, hasAttr) {
|
||||||
|
auto v = eval("builtins.hasAttr \"x\" { x = 1; }");
|
||||||
|
ASSERT_THAT(v, IsTrue());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, hasAttrNotFound) {
|
||||||
|
auto v = eval("builtins.hasAttr \"x\" { }");
|
||||||
|
ASSERT_THAT(v, IsFalse());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, isAttrs) {
|
||||||
|
auto v = eval("builtins.isAttrs {}");
|
||||||
|
ASSERT_THAT(v, IsTrue());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, isAttrsFalse) {
|
||||||
|
auto v = eval("builtins.isAttrs null");
|
||||||
|
ASSERT_THAT(v, IsFalse());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, removeAttrs) {
|
||||||
|
auto v = eval("builtins.removeAttrs { x = 1; } [\"x\"]");
|
||||||
|
ASSERT_THAT(v, IsAttrsOfSize(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, removeAttrsRetains) {
|
||||||
|
auto v = eval("builtins.removeAttrs { x = 1; y = 2; } [\"x\"]");
|
||||||
|
ASSERT_THAT(v, IsAttrsOfSize(1));
|
||||||
|
ASSERT_NE(v.attrs->find(createSymbol("y")), nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, listToAttrsEmptyList) {
|
||||||
|
auto v = eval("builtins.listToAttrs []");
|
||||||
|
ASSERT_THAT(v, IsAttrsOfSize(0));
|
||||||
|
ASSERT_EQ(v.type(), nAttrs);
|
||||||
|
ASSERT_EQ(v.attrs->size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, listToAttrsNotFieldName) {
|
||||||
|
ASSERT_THROW(eval("builtins.listToAttrs [{}]"), Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, listToAttrs) {
|
||||||
|
auto v = eval("builtins.listToAttrs [ { name = \"key\"; value = 123; } ]");
|
||||||
|
ASSERT_THAT(v, IsAttrsOfSize(1));
|
||||||
|
auto key = v.attrs->find(createSymbol("key"));
|
||||||
|
ASSERT_NE(key, nullptr);
|
||||||
|
ASSERT_THAT(*key->value, IsIntEq(123));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, intersectAttrs) {
|
||||||
|
auto v = eval("builtins.intersectAttrs { a = 1; b = 2; } { b = 3; c = 4; }");
|
||||||
|
ASSERT_THAT(v, IsAttrsOfSize(1));
|
||||||
|
auto b = v.attrs->find(createSymbol("b"));
|
||||||
|
ASSERT_NE(b, nullptr);
|
||||||
|
ASSERT_THAT(*b->value, IsIntEq(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, catAttrs) {
|
||||||
|
auto v = eval("builtins.catAttrs \"a\" [{a = 1;} {b = 0;} {a = 2;}]");
|
||||||
|
ASSERT_THAT(v, IsListOfSize(2));
|
||||||
|
ASSERT_THAT(*v.listElems()[0], IsIntEq(1));
|
||||||
|
ASSERT_THAT(*v.listElems()[1], IsIntEq(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, functionArgs) {
|
||||||
|
auto v = eval("builtins.functionArgs ({ x, y ? 123}: 1)");
|
||||||
|
ASSERT_THAT(v, IsAttrsOfSize(2));
|
||||||
|
|
||||||
|
auto x = v.attrs->find(createSymbol("x"));
|
||||||
|
ASSERT_NE(x, nullptr);
|
||||||
|
ASSERT_THAT(*x->value, IsFalse());
|
||||||
|
|
||||||
|
auto y = v.attrs->find(createSymbol("y"));
|
||||||
|
ASSERT_NE(y, nullptr);
|
||||||
|
ASSERT_THAT(*y->value, IsTrue());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, mapAttrs) {
|
||||||
|
auto v = eval("builtins.mapAttrs (name: value: value * 10) { a = 1; b = 2; }");
|
||||||
|
ASSERT_THAT(v, IsAttrsOfSize(2));
|
||||||
|
|
||||||
|
auto a = v.attrs->find(createSymbol("a"));
|
||||||
|
ASSERT_NE(a, nullptr);
|
||||||
|
ASSERT_THAT(*a->value, IsThunk());
|
||||||
|
state.forceValue(*a->value, noPos);
|
||||||
|
ASSERT_THAT(*a->value, IsIntEq(10));
|
||||||
|
|
||||||
|
auto b = v.attrs->find(createSymbol("b"));
|
||||||
|
ASSERT_NE(b, nullptr);
|
||||||
|
ASSERT_THAT(*b->value, IsThunk());
|
||||||
|
state.forceValue(*b->value, noPos);
|
||||||
|
ASSERT_THAT(*b->value, IsIntEq(20));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, isList) {
|
||||||
|
auto v = eval("builtins.isList []");
|
||||||
|
ASSERT_THAT(v, IsTrue());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, isListFalse) {
|
||||||
|
auto v = eval("builtins.isList null");
|
||||||
|
ASSERT_THAT(v, IsFalse());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, elemtAt) {
|
||||||
|
auto v = eval("builtins.elemAt [0 1 2 3] 3");
|
||||||
|
ASSERT_THAT(v, IsIntEq(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, elemtAtOutOfBounds) {
|
||||||
|
ASSERT_THROW(eval("builtins.elemAt [0 1 2 3] 5"), Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, head) {
|
||||||
|
auto v = eval("builtins.head [ 3 2 1 0 ]");
|
||||||
|
ASSERT_THAT(v, IsIntEq(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, headEmpty) {
|
||||||
|
ASSERT_THROW(eval("builtins.head [ ]"), Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, headWrongType) {
|
||||||
|
ASSERT_THROW(eval("builtins.head { }"), Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, tail) {
|
||||||
|
auto v = eval("builtins.tail [ 3 2 1 0 ]");
|
||||||
|
ASSERT_THAT(v, IsListOfSize(3));
|
||||||
|
for (const auto [n, elem] : enumerate(v.listItems()))
|
||||||
|
ASSERT_THAT(*elem, IsIntEq(2 - static_cast<int>(n)));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, tailEmpty) {
|
||||||
|
ASSERT_THROW(eval("builtins.tail []"), Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, map) {
|
||||||
|
auto v = eval("map (x: \"foo\" + x) [ \"bar\" \"bla\" \"abc\" ]");
|
||||||
|
ASSERT_THAT(v, IsListOfSize(3));
|
||||||
|
auto elem = v.listElems()[0];
|
||||||
|
ASSERT_THAT(*elem, IsThunk());
|
||||||
|
state.forceValue(*elem, noPos);
|
||||||
|
ASSERT_THAT(*elem, IsStringEq("foobar"));
|
||||||
|
|
||||||
|
elem = v.listElems()[1];
|
||||||
|
ASSERT_THAT(*elem, IsThunk());
|
||||||
|
state.forceValue(*elem, noPos);
|
||||||
|
ASSERT_THAT(*elem, IsStringEq("foobla"));
|
||||||
|
|
||||||
|
elem = v.listElems()[2];
|
||||||
|
ASSERT_THAT(*elem, IsThunk());
|
||||||
|
state.forceValue(*elem, noPos);
|
||||||
|
ASSERT_THAT(*elem, IsStringEq("fooabc"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, filter) {
|
||||||
|
auto v = eval("builtins.filter (x: x == 2) [ 3 2 3 2 3 2 ]");
|
||||||
|
ASSERT_THAT(v, IsListOfSize(3));
|
||||||
|
for (const auto elem : v.listItems())
|
||||||
|
ASSERT_THAT(*elem, IsIntEq(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, elemTrue) {
|
||||||
|
auto v = eval("builtins.elem 3 [ 1 2 3 4 5 ]");
|
||||||
|
ASSERT_THAT(v, IsTrue());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, elemFalse) {
|
||||||
|
auto v = eval("builtins.elem 6 [ 1 2 3 4 5 ]");
|
||||||
|
ASSERT_THAT(v, IsFalse());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, concatLists) {
|
||||||
|
auto v = eval("builtins.concatLists [[1 2] [3 4]]");
|
||||||
|
ASSERT_THAT(v, IsListOfSize(4));
|
||||||
|
for (const auto [i, elem] : enumerate(v.listItems()))
|
||||||
|
ASSERT_THAT(*elem, IsIntEq(static_cast<int>(i)+1));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, length) {
|
||||||
|
auto v = eval("builtins.length [ 1 2 3 ]");
|
||||||
|
ASSERT_THAT(v, IsIntEq(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, foldStrict) {
|
||||||
|
auto v = eval("builtins.foldl' (a: b: a + b) 0 [1 2 3]");
|
||||||
|
ASSERT_THAT(v, IsIntEq(6));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, anyTrue) {
|
||||||
|
auto v = eval("builtins.any (x: x == 2) [ 1 2 3 ]");
|
||||||
|
ASSERT_THAT(v, IsTrue());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, anyFalse) {
|
||||||
|
auto v = eval("builtins.any (x: x == 5) [ 1 2 3 ]");
|
||||||
|
ASSERT_THAT(v, IsFalse());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, allTrue) {
|
||||||
|
auto v = eval("builtins.all (x: x > 0) [ 1 2 3 ]");
|
||||||
|
ASSERT_THAT(v, IsTrue());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, allFalse) {
|
||||||
|
auto v = eval("builtins.all (x: x <= 0) [ 1 2 3 ]");
|
||||||
|
ASSERT_THAT(v, IsFalse());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, genList) {
|
||||||
|
auto v = eval("builtins.genList (x: x + 1) 3");
|
||||||
|
ASSERT_EQ(v.type(), nList);
|
||||||
|
ASSERT_EQ(v.listSize(), 3);
|
||||||
|
for (const auto [i, elem] : enumerate(v.listItems())) {
|
||||||
|
ASSERT_THAT(*elem, IsThunk());
|
||||||
|
state.forceValue(*elem, noPos);
|
||||||
|
ASSERT_THAT(*elem, IsIntEq(static_cast<int>(i)+1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, sortLessThan) {
|
||||||
|
auto v = eval("builtins.sort builtins.lessThan [ 483 249 526 147 42 77 ]");
|
||||||
|
ASSERT_EQ(v.type(), nList);
|
||||||
|
ASSERT_EQ(v.listSize(), 6);
|
||||||
|
|
||||||
|
const std::vector<int> numbers = { 42, 77, 147, 249, 483, 526 };
|
||||||
|
for (const auto [n, elem] : enumerate(v.listItems()))
|
||||||
|
ASSERT_THAT(*elem, IsIntEq(numbers[n]));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, partition) {
|
||||||
|
auto v = eval("builtins.partition (x: x > 10) [1 23 9 3 42]");
|
||||||
|
ASSERT_THAT(v, IsAttrsOfSize(2));
|
||||||
|
|
||||||
|
auto right = v.attrs->get(createSymbol("right"));
|
||||||
|
ASSERT_NE(right, nullptr);
|
||||||
|
ASSERT_THAT(*right->value, IsListOfSize(2));
|
||||||
|
ASSERT_THAT(*right->value->listElems()[0], IsIntEq(23));
|
||||||
|
ASSERT_THAT(*right->value->listElems()[1], IsIntEq(42));
|
||||||
|
|
||||||
|
auto wrong = v.attrs->get(createSymbol("wrong"));
|
||||||
|
ASSERT_NE(wrong, nullptr);
|
||||||
|
ASSERT_EQ(wrong->value->type(), nList);
|
||||||
|
ASSERT_EQ(wrong->value->listSize(), 3);
|
||||||
|
ASSERT_THAT(*wrong->value, IsListOfSize(3));
|
||||||
|
ASSERT_THAT(*wrong->value->listElems()[0], IsIntEq(1));
|
||||||
|
ASSERT_THAT(*wrong->value->listElems()[1], IsIntEq(9));
|
||||||
|
ASSERT_THAT(*wrong->value->listElems()[2], IsIntEq(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, concatMap) {
|
||||||
|
auto v = eval("builtins.concatMap (x: x ++ [0]) [ [1 2] [3 4] ]");
|
||||||
|
ASSERT_EQ(v.type(), nList);
|
||||||
|
ASSERT_EQ(v.listSize(), 6);
|
||||||
|
|
||||||
|
const std::vector<int> numbers = { 1, 2, 0, 3, 4, 0 };
|
||||||
|
for (const auto [n, elem] : enumerate(v.listItems()))
|
||||||
|
ASSERT_THAT(*elem, IsIntEq(numbers[n]));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, addInt) {
|
||||||
|
auto v = eval("builtins.add 3 5");
|
||||||
|
ASSERT_THAT(v, IsIntEq(8));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, addFloat) {
|
||||||
|
auto v = eval("builtins.add 3.0 5.0");
|
||||||
|
ASSERT_THAT(v, IsFloatEq(8.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, addFloatToInt) {
|
||||||
|
auto v = eval("builtins.add 3.0 5");
|
||||||
|
ASSERT_THAT(v, IsFloatEq(8.0));
|
||||||
|
|
||||||
|
v = eval("builtins.add 3 5.0");
|
||||||
|
ASSERT_THAT(v, IsFloatEq(8.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, subInt) {
|
||||||
|
auto v = eval("builtins.sub 5 2");
|
||||||
|
ASSERT_THAT(v, IsIntEq(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, subFloat) {
|
||||||
|
auto v = eval("builtins.sub 5.0 2.0");
|
||||||
|
ASSERT_THAT(v, IsFloatEq(3.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, subFloatFromInt) {
|
||||||
|
auto v = eval("builtins.sub 5.0 2");
|
||||||
|
ASSERT_THAT(v, IsFloatEq(3.0));
|
||||||
|
|
||||||
|
v = eval("builtins.sub 4 2.0");
|
||||||
|
ASSERT_THAT(v, IsFloatEq(2.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, mulInt) {
|
||||||
|
auto v = eval("builtins.mul 3 5");
|
||||||
|
ASSERT_THAT(v, IsIntEq(15));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, mulFloat) {
|
||||||
|
auto v = eval("builtins.mul 3.0 5.0");
|
||||||
|
ASSERT_THAT(v, IsFloatEq(15.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, mulFloatMixed) {
|
||||||
|
auto v = eval("builtins.mul 3 5.0");
|
||||||
|
ASSERT_THAT(v, IsFloatEq(15.0));
|
||||||
|
|
||||||
|
v = eval("builtins.mul 2.0 5");
|
||||||
|
ASSERT_THAT(v, IsFloatEq(10.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, divInt) {
|
||||||
|
auto v = eval("builtins.div 5 (-1)");
|
||||||
|
ASSERT_THAT(v, IsIntEq(-5));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, divIntZero) {
|
||||||
|
ASSERT_THROW(eval("builtins.div 5 0"), EvalError);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, divFloat) {
|
||||||
|
auto v = eval("builtins.div 5.0 (-1)");
|
||||||
|
ASSERT_THAT(v, IsFloatEq(-5.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, divFloatZero) {
|
||||||
|
ASSERT_THROW(eval("builtins.div 5.0 0.0"), EvalError);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, bitOr) {
|
||||||
|
auto v = eval("builtins.bitOr 1 2");
|
||||||
|
ASSERT_THAT(v, IsIntEq(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, bitXor) {
|
||||||
|
auto v = eval("builtins.bitXor 3 2");
|
||||||
|
ASSERT_THAT(v, IsIntEq(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, lessThanFalse) {
|
||||||
|
auto v = eval("builtins.lessThan 3 1");
|
||||||
|
ASSERT_THAT(v, IsFalse());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, lessThanTrue) {
|
||||||
|
auto v = eval("builtins.lessThan 1 3");
|
||||||
|
ASSERT_THAT(v, IsTrue());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, toStringAttrsThrows) {
|
||||||
|
ASSERT_THROW(eval("builtins.toString {}"), EvalError);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, toStringLambdaThrows) {
|
||||||
|
ASSERT_THROW(eval("builtins.toString (x: x)"), EvalError);
|
||||||
|
}
|
||||||
|
|
||||||
|
class ToStringPrimOpTest :
|
||||||
|
public PrimOpTest,
|
||||||
|
public testing::WithParamInterface<std::tuple<std::string, std::string_view>>
|
||||||
|
{};
|
||||||
|
|
||||||
|
TEST_P(ToStringPrimOpTest, toString) {
|
||||||
|
const auto [input, output] = GetParam();
|
||||||
|
auto v = eval(input);
|
||||||
|
ASSERT_THAT(v, IsStringEq(output));
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CASE(input, output) (std::make_tuple(std::string_view("builtins.toString " input), std::string_view(output)))
|
||||||
|
INSTANTIATE_TEST_SUITE_P(
|
||||||
|
toString,
|
||||||
|
ToStringPrimOpTest,
|
||||||
|
testing::Values(
|
||||||
|
CASE(R"("foo")", "foo"),
|
||||||
|
CASE(R"(1)", "1"),
|
||||||
|
CASE(R"([1 2 3])", "1 2 3"),
|
||||||
|
CASE(R"(.123)", "0.123000"),
|
||||||
|
CASE(R"(true)", "1"),
|
||||||
|
CASE(R"(false)", ""),
|
||||||
|
CASE(R"(null)", ""),
|
||||||
|
CASE(R"({ v = "bar"; __toString = self: self.v; })", "bar"),
|
||||||
|
CASE(R"({ v = "bar"; __toString = self: self.v; outPath = "foo"; })", "bar"),
|
||||||
|
CASE(R"({ outPath = "foo"; })", "foo"),
|
||||||
|
CASE(R"(./test)", "/test")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
#undef CASE
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, substring){
|
||||||
|
auto v = eval("builtins.substring 0 3 \"nixos\"");
|
||||||
|
ASSERT_THAT(v, IsStringEq("nix"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, substringSmallerString){
|
||||||
|
auto v = eval("builtins.substring 0 3 \"n\"");
|
||||||
|
ASSERT_THAT(v, IsStringEq("n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, substringEmptyString){
|
||||||
|
auto v = eval("builtins.substring 1 3 \"\"");
|
||||||
|
ASSERT_THAT(v, IsStringEq(""));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, stringLength) {
|
||||||
|
auto v = eval("builtins.stringLength \"123\"");
|
||||||
|
ASSERT_THAT(v, IsIntEq(3));
|
||||||
|
}
|
||||||
|
TEST_F(PrimOpTest, hashStringMd5) {
|
||||||
|
auto v = eval("builtins.hashString \"md5\" \"asdf\"");
|
||||||
|
ASSERT_THAT(v, IsStringEq("912ec803b2ce49e4a541068d495ab570"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, hashStringSha1) {
|
||||||
|
auto v = eval("builtins.hashString \"sha1\" \"asdf\"");
|
||||||
|
ASSERT_THAT(v, IsStringEq("3da541559918a808c2402bba5012f6c60b27661c"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, hashStringSha256) {
|
||||||
|
auto v = eval("builtins.hashString \"sha256\" \"asdf\"");
|
||||||
|
ASSERT_THAT(v, IsStringEq("f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, hashStringSha512) {
|
||||||
|
auto v = eval("builtins.hashString \"sha512\" \"asdf\"");
|
||||||
|
ASSERT_THAT(v, IsStringEq("401b09eab3c013d4ca54922bb802bec8fd5318192b0a75f201d8b3727429080fb337591abd3e44453b954555b7a0812e1081c39b740293f765eae731f5a65ed1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, hashStringInvalidHashType) {
|
||||||
|
ASSERT_THROW(eval("builtins.hashString \"foobar\" \"asdf\""), Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, nixPath) {
|
||||||
|
auto v = eval("builtins.nixPath");
|
||||||
|
ASSERT_EQ(v.type(), nList);
|
||||||
|
// We can't test much more as currently the EvalSettings are a global
|
||||||
|
// that we can't easily swap / replace
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, langVersion) {
|
||||||
|
auto v = eval("builtins.langVersion");
|
||||||
|
ASSERT_EQ(v.type(), nInt);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, storeDir) {
|
||||||
|
auto v = eval("builtins.storeDir");
|
||||||
|
ASSERT_THAT(v, IsStringEq("/nix/store"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, nixVersion) {
|
||||||
|
auto v = eval("builtins.nixVersion");
|
||||||
|
ASSERT_THAT(v, IsStringEq(nixVersion));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, currentSystem) {
|
||||||
|
auto v = eval("builtins.currentSystem");
|
||||||
|
ASSERT_THAT(v, IsStringEq(settings.thisSystem.get()));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, derivation) {
|
||||||
|
auto v = eval("derivation");
|
||||||
|
ASSERT_EQ(v.type(), nFunction);
|
||||||
|
ASSERT_TRUE(v.isLambda());
|
||||||
|
ASSERT_NE(v.lambda.fun, nullptr);
|
||||||
|
ASSERT_TRUE(v.lambda.fun->hasFormals());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, currentTime) {
|
||||||
|
auto v = eval("builtins.currentTime");
|
||||||
|
ASSERT_EQ(v.type(), nInt);
|
||||||
|
ASSERT_TRUE(v.integer > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, splitVersion) {
|
||||||
|
auto v = eval("builtins.splitVersion \"1.2.3git\"");
|
||||||
|
ASSERT_THAT(v, IsListOfSize(4));
|
||||||
|
|
||||||
|
const std::vector<std::string_view> strings = { "1", "2", "3", "git" };
|
||||||
|
for (const auto [n, p] : enumerate(v.listItems()))
|
||||||
|
ASSERT_THAT(*p, IsStringEq(strings[n]));
|
||||||
|
}
|
||||||
|
|
||||||
|
class CompareVersionsPrimOpTest :
|
||||||
|
public PrimOpTest,
|
||||||
|
public testing::WithParamInterface<std::tuple<std::string, const int>>
|
||||||
|
{};
|
||||||
|
|
||||||
|
TEST_P(CompareVersionsPrimOpTest, compareVersions) {
|
||||||
|
auto [expression, expectation] = GetParam();
|
||||||
|
auto v = eval(expression);
|
||||||
|
ASSERT_THAT(v, IsIntEq(expectation));
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CASE(a, b, expected) (std::make_tuple("builtins.compareVersions \"" #a "\" \"" #b "\"", expected))
|
||||||
|
INSTANTIATE_TEST_SUITE_P(
|
||||||
|
compareVersions,
|
||||||
|
CompareVersionsPrimOpTest,
|
||||||
|
testing::Values(
|
||||||
|
// The first two are weird cases. Intuition tells they should
|
||||||
|
// be the same but they aren't.
|
||||||
|
CASE(1.0, 1.0.0, -1),
|
||||||
|
CASE(1.0.0, 1.0, 1),
|
||||||
|
// the following are from the nix-env manual:
|
||||||
|
CASE(1.0, 2.3, -1),
|
||||||
|
CASE(2.1, 2.3, -1),
|
||||||
|
CASE(2.3, 2.3, 0),
|
||||||
|
CASE(2.5, 2.3, 1),
|
||||||
|
CASE(3.1, 2.3, 1),
|
||||||
|
CASE(2.3.1, 2.3, 1),
|
||||||
|
CASE(2.3.1, 2.3a, 1),
|
||||||
|
CASE(2.3pre1, 2.3, -1),
|
||||||
|
CASE(2.3pre3, 2.3pre12, -1),
|
||||||
|
CASE(2.3a, 2.3c, -1),
|
||||||
|
CASE(2.3pre1, 2.3c, -1),
|
||||||
|
CASE(2.3pre1, 2.3q, -1)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
#undef CASE
|
||||||
|
|
||||||
|
|
||||||
|
class ParseDrvNamePrimOpTest :
|
||||||
|
public PrimOpTest,
|
||||||
|
public testing::WithParamInterface<std::tuple<std::string, std::string_view, std::string_view>>
|
||||||
|
{};
|
||||||
|
|
||||||
|
TEST_P(ParseDrvNamePrimOpTest, parseDrvName) {
|
||||||
|
auto [input, expectedName, expectedVersion] = GetParam();
|
||||||
|
const auto expr = fmt("builtins.parseDrvName \"%1%\"", input);
|
||||||
|
auto v = eval(expr);
|
||||||
|
ASSERT_THAT(v, IsAttrsOfSize(2));
|
||||||
|
|
||||||
|
auto name = v.attrs->find(createSymbol("name"));
|
||||||
|
ASSERT_TRUE(name);
|
||||||
|
ASSERT_THAT(*name->value, IsStringEq(expectedName));
|
||||||
|
|
||||||
|
auto version = v.attrs->find(createSymbol("version"));
|
||||||
|
ASSERT_TRUE(version);
|
||||||
|
ASSERT_THAT(*version->value, IsStringEq(expectedVersion));
|
||||||
|
}
|
||||||
|
|
||||||
|
INSTANTIATE_TEST_SUITE_P(
|
||||||
|
parseDrvName,
|
||||||
|
ParseDrvNamePrimOpTest,
|
||||||
|
testing::Values(
|
||||||
|
std::make_tuple("nix-0.12pre12876", "nix", "0.12pre12876"),
|
||||||
|
std::make_tuple("a-b-c-1234pre5+git", "a-b-c", "1234pre5+git")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, replaceStrings) {
|
||||||
|
// FIXME: add a test that verifies the string context is as expected
|
||||||
|
auto v = eval("builtins.replaceStrings [\"oo\" \"a\"] [\"a\" \"i\"] \"foobar\"");
|
||||||
|
ASSERT_EQ(v.type(), nString);
|
||||||
|
ASSERT_EQ(v.string.s, std::string_view("fabir"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, concatStringsSep) {
|
||||||
|
// FIXME: add a test that verifies the string context is as expected
|
||||||
|
auto v = eval("builtins.concatStringsSep \"%\" [\"foo\" \"bar\" \"baz\"]");
|
||||||
|
ASSERT_EQ(v.type(), nString);
|
||||||
|
ASSERT_EQ(std::string_view(v.string.s), "foo%bar%baz");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, split1) {
|
||||||
|
// v = [ "" [ "a" ] "c" ]
|
||||||
|
auto v = eval("builtins.split \"(a)b\" \"abc\"");
|
||||||
|
ASSERT_THAT(v, IsListOfSize(3));
|
||||||
|
|
||||||
|
ASSERT_THAT(*v.listElems()[0], IsStringEq(""));
|
||||||
|
|
||||||
|
ASSERT_THAT(*v.listElems()[1], IsListOfSize(1));
|
||||||
|
ASSERT_THAT(*v.listElems()[1]->listElems()[0], IsStringEq("a"));
|
||||||
|
|
||||||
|
ASSERT_THAT(*v.listElems()[2], IsStringEq("c"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, split2) {
|
||||||
|
// v is expected to be a list [ "" [ "a" ] "b" [ "c"] "" ]
|
||||||
|
auto v = eval("builtins.split \"([ac])\" \"abc\"");
|
||||||
|
ASSERT_THAT(v, IsListOfSize(5));
|
||||||
|
|
||||||
|
ASSERT_THAT(*v.listElems()[0], IsStringEq(""));
|
||||||
|
|
||||||
|
ASSERT_THAT(*v.listElems()[1], IsListOfSize(1));
|
||||||
|
ASSERT_THAT(*v.listElems()[1]->listElems()[0], IsStringEq("a"));
|
||||||
|
|
||||||
|
ASSERT_THAT(*v.listElems()[2], IsStringEq("b"));
|
||||||
|
|
||||||
|
ASSERT_THAT(*v.listElems()[3], IsListOfSize(1));
|
||||||
|
ASSERT_THAT(*v.listElems()[3]->listElems()[0], IsStringEq("c"));
|
||||||
|
|
||||||
|
ASSERT_THAT(*v.listElems()[4], IsStringEq(""));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, split3) {
|
||||||
|
auto v = eval("builtins.split \"(a)|(c)\" \"abc\"");
|
||||||
|
ASSERT_THAT(v, IsListOfSize(5));
|
||||||
|
|
||||||
|
// First list element
|
||||||
|
ASSERT_THAT(*v.listElems()[0], IsStringEq(""));
|
||||||
|
|
||||||
|
// 2nd list element is a list [ "" null ]
|
||||||
|
ASSERT_THAT(*v.listElems()[1], IsListOfSize(2));
|
||||||
|
ASSERT_THAT(*v.listElems()[1]->listElems()[0], IsStringEq("a"));
|
||||||
|
ASSERT_THAT(*v.listElems()[1]->listElems()[1], IsNull());
|
||||||
|
|
||||||
|
// 3rd element
|
||||||
|
ASSERT_THAT(*v.listElems()[2], IsStringEq("b"));
|
||||||
|
|
||||||
|
// 4th element is a list: [ null "c" ]
|
||||||
|
ASSERT_THAT(*v.listElems()[3], IsListOfSize(2));
|
||||||
|
ASSERT_THAT(*v.listElems()[3]->listElems()[0], IsNull());
|
||||||
|
ASSERT_THAT(*v.listElems()[3]->listElems()[1], IsStringEq("c"));
|
||||||
|
|
||||||
|
// 5th element is the empty string
|
||||||
|
ASSERT_THAT(*v.listElems()[4], IsStringEq(""));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, split4) {
|
||||||
|
auto v = eval("builtins.split \"([[:upper:]]+)\" \" FOO \"");
|
||||||
|
ASSERT_THAT(v, IsListOfSize(3));
|
||||||
|
auto first = v.listElems()[0];
|
||||||
|
auto second = v.listElems()[1];
|
||||||
|
auto third = v.listElems()[2];
|
||||||
|
|
||||||
|
ASSERT_THAT(*first, IsStringEq(" "));
|
||||||
|
|
||||||
|
ASSERT_THAT(*second, IsListOfSize(1));
|
||||||
|
ASSERT_THAT(*second->listElems()[0], IsStringEq("FOO"));
|
||||||
|
|
||||||
|
ASSERT_THAT(*third, IsStringEq(" "));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, match1) {
|
||||||
|
auto v = eval("builtins.match \"ab\" \"abc\"");
|
||||||
|
ASSERT_THAT(v, IsNull());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, match2) {
|
||||||
|
auto v = eval("builtins.match \"abc\" \"abc\"");
|
||||||
|
ASSERT_THAT(v, IsListOfSize(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, match3) {
|
||||||
|
auto v = eval("builtins.match \"a(b)(c)\" \"abc\"");
|
||||||
|
ASSERT_THAT(v, IsListOfSize(2));
|
||||||
|
ASSERT_THAT(*v.listElems()[0], IsStringEq("b"));
|
||||||
|
ASSERT_THAT(*v.listElems()[1], IsStringEq("c"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, match4) {
|
||||||
|
auto v = eval("builtins.match \"[[:space:]]+([[:upper:]]+)[[:space:]]+\" \" FOO \"");
|
||||||
|
ASSERT_THAT(v, IsListOfSize(1));
|
||||||
|
ASSERT_THAT(*v.listElems()[0], IsStringEq("FOO"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(PrimOpTest, attrNames) {
|
||||||
|
auto v = eval("builtins.attrNames { x = 1; y = 2; z = 3; a = 2; }");
|
||||||
|
ASSERT_THAT(v, IsListOfSize(4));
|
||||||
|
|
||||||
|
// ensure that the list is sorted
|
||||||
|
const std::vector<std::string_view> expected { "a", "x", "y", "z" };
|
||||||
|
for (const auto [n, elem] : enumerate(v.listItems()))
|
||||||
|
ASSERT_THAT(*elem, IsStringEq(expected[n]));
|
||||||
|
}
|
||||||
|
} /* namespace nix */
|
||||||
196
src/libexpr/tests/trivial.cc
Normal file
196
src/libexpr/tests/trivial.cc
Normal file
|
|
@ -0,0 +1,196 @@
|
||||||
|
#include "libexprtests.hh"
|
||||||
|
|
||||||
|
namespace nix {
|
||||||
|
// Testing of trivial expressions
|
||||||
|
class TrivialExpressionTest : public LibExprTest {};
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, true) {
|
||||||
|
auto v = eval("true");
|
||||||
|
ASSERT_THAT(v, IsTrue());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, false) {
|
||||||
|
auto v = eval("false");
|
||||||
|
ASSERT_THAT(v, IsFalse());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, null) {
|
||||||
|
auto v = eval("null");
|
||||||
|
ASSERT_THAT(v, IsNull());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, 1) {
|
||||||
|
auto v = eval("1");
|
||||||
|
ASSERT_THAT(v, IsIntEq(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, 1plus1) {
|
||||||
|
auto v = eval("1+1");
|
||||||
|
ASSERT_THAT(v, IsIntEq(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, minus1) {
|
||||||
|
auto v = eval("-1");
|
||||||
|
ASSERT_THAT(v, IsIntEq(-1));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, 1minus1) {
|
||||||
|
auto v = eval("1-1");
|
||||||
|
ASSERT_THAT(v, IsIntEq(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, lambdaAdd) {
|
||||||
|
auto v = eval("let add = a: b: a + b; in add 1 2");
|
||||||
|
ASSERT_THAT(v, IsIntEq(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, list) {
|
||||||
|
auto v = eval("[]");
|
||||||
|
ASSERT_THAT(v, IsListOfSize(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, attrs) {
|
||||||
|
auto v = eval("{}");
|
||||||
|
ASSERT_THAT(v, IsAttrsOfSize(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, float) {
|
||||||
|
auto v = eval("1.234");
|
||||||
|
ASSERT_THAT(v, IsFloatEq(1.234));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, updateAttrs) {
|
||||||
|
auto v = eval("{ a = 1; } // { b = 2; a = 3; }");
|
||||||
|
ASSERT_THAT(v, IsAttrsOfSize(2));
|
||||||
|
auto a = v.attrs->find(createSymbol("a"));
|
||||||
|
ASSERT_NE(a, nullptr);
|
||||||
|
ASSERT_THAT(*a->value, IsIntEq(3));
|
||||||
|
|
||||||
|
auto b = v.attrs->find(createSymbol("b"));
|
||||||
|
ASSERT_NE(b, nullptr);
|
||||||
|
ASSERT_THAT(*b->value, IsIntEq(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, hasAttrOpFalse) {
|
||||||
|
auto v = eval("{} ? a");
|
||||||
|
ASSERT_THAT(v, IsFalse());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, hasAttrOpTrue) {
|
||||||
|
auto v = eval("{ a = 123; } ? a");
|
||||||
|
ASSERT_THAT(v, IsTrue());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, withFound) {
|
||||||
|
auto v = eval("with { a = 23; }; a");
|
||||||
|
ASSERT_THAT(v, IsIntEq(23));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, withNotFound) {
|
||||||
|
ASSERT_THROW(eval("with {}; a"), Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, withOverride) {
|
||||||
|
auto v = eval("with { a = 23; }; with { a = 42; }; a");
|
||||||
|
ASSERT_THAT(v, IsIntEq(42));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, letOverWith) {
|
||||||
|
auto v = eval("let a = 23; in with { a = 1; }; a");
|
||||||
|
ASSERT_THAT(v, IsIntEq(23));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, multipleLet) {
|
||||||
|
auto v = eval("let a = 23; in let a = 42; in a");
|
||||||
|
ASSERT_THAT(v, IsIntEq(42));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, defaultFunctionArgs) {
|
||||||
|
auto v = eval("({ a ? 123 }: a) {}");
|
||||||
|
ASSERT_THAT(v, IsIntEq(123));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, defaultFunctionArgsOverride) {
|
||||||
|
auto v = eval("({ a ? 123 }: a) { a = 5; }");
|
||||||
|
ASSERT_THAT(v, IsIntEq(5));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, defaultFunctionArgsCaptureBack) {
|
||||||
|
auto v = eval("({ a ? 123 }@args: args) {}");
|
||||||
|
ASSERT_THAT(v, IsAttrsOfSize(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, defaultFunctionArgsCaptureFront) {
|
||||||
|
auto v = eval("(args@{ a ? 123 }: args) {}");
|
||||||
|
ASSERT_THAT(v, IsAttrsOfSize(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, assertThrows) {
|
||||||
|
ASSERT_THROW(eval("let x = arg: assert arg == 1; 123; in x 2"), Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, assertPassed) {
|
||||||
|
auto v = eval("let x = arg: assert arg == 1; 123; in x 1");
|
||||||
|
ASSERT_THAT(v, IsIntEq(123));
|
||||||
|
}
|
||||||
|
|
||||||
|
class AttrSetMergeTrvialExpressionTest :
|
||||||
|
public TrivialExpressionTest,
|
||||||
|
public testing::WithParamInterface<const char*>
|
||||||
|
{};
|
||||||
|
|
||||||
|
TEST_P(AttrSetMergeTrvialExpressionTest, attrsetMergeLazy) {
|
||||||
|
// Usually Nix rejects duplicate keys in an attrset but it does allow
|
||||||
|
// so if it is an attribute set that contains disjoint sets of keys.
|
||||||
|
// The below is equivalent to `{a.b = 1; a.c = 2; }`.
|
||||||
|
// The attribute set `a` will be a Thunk at first as the attribuets
|
||||||
|
// have to be merged (or otherwise computed) and that is done in a lazy
|
||||||
|
// manner.
|
||||||
|
|
||||||
|
auto expr = GetParam();
|
||||||
|
auto v = eval(expr);
|
||||||
|
ASSERT_THAT(v, IsAttrsOfSize(1));
|
||||||
|
|
||||||
|
auto a = v.attrs->find(createSymbol("a"));
|
||||||
|
ASSERT_NE(a, nullptr);
|
||||||
|
|
||||||
|
ASSERT_THAT(*a->value, IsThunk());
|
||||||
|
state.forceValue(*a->value, noPos);
|
||||||
|
|
||||||
|
ASSERT_THAT(*a->value, IsAttrsOfSize(2));
|
||||||
|
|
||||||
|
auto b = a->value->attrs->find(createSymbol("b"));
|
||||||
|
ASSERT_NE(b, nullptr);
|
||||||
|
ASSERT_THAT(*b->value, IsIntEq(1));
|
||||||
|
|
||||||
|
auto c = a->value->attrs->find(createSymbol("c"));
|
||||||
|
ASSERT_NE(c, nullptr);
|
||||||
|
ASSERT_THAT(*c->value, IsIntEq(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
INSTANTIATE_TEST_SUITE_P(
|
||||||
|
attrsetMergeLazy,
|
||||||
|
AttrSetMergeTrvialExpressionTest,
|
||||||
|
testing::Values(
|
||||||
|
"{ a.b = 1; a.c = 2; }",
|
||||||
|
"{ a = { b = 1; }; a = { c = 2; }; }"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, functor) {
|
||||||
|
auto v = eval("{ __functor = self: arg: self.v + arg; v = 10; } 5");
|
||||||
|
ASSERT_THAT(v, IsIntEq(15));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, bindOr) {
|
||||||
|
auto v = eval("{ or = 1; }");
|
||||||
|
ASSERT_THAT(v, IsAttrsOfSize(1));
|
||||||
|
auto b = v.attrs->find(createSymbol("or"));
|
||||||
|
ASSERT_NE(b, nullptr);
|
||||||
|
ASSERT_THAT(*b->value, IsIntEq(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(TrivialExpressionTest, orCantBeUsed) {
|
||||||
|
ASSERT_THROW(eval("let or = 1; in or"), Error);
|
||||||
|
}
|
||||||
|
} /* namespace nix */
|
||||||
|
|
@ -85,6 +85,7 @@ void printValueAsJSON(EvalState & state, bool strict,
|
||||||
.errPos = state.positions[v.determinePos(pos)]
|
.errPos = state.positions[v.determinePos(pos)]
|
||||||
});
|
});
|
||||||
e.addTrace(state.positions[pos], hintfmt("message for the trace"));
|
e.addTrace(state.positions[pos], hintfmt("message for the trace"));
|
||||||
|
state.debugThrowLastTrace(e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -99,7 +100,7 @@ void printValueAsJSON(EvalState & state, bool strict,
|
||||||
void ExternalValueBase::printValueAsJSON(EvalState & state, bool strict,
|
void ExternalValueBase::printValueAsJSON(EvalState & state, bool strict,
|
||||||
JSONPlaceholder & out, PathSet & context) const
|
JSONPlaceholder & out, PathSet & context) const
|
||||||
{
|
{
|
||||||
throw TypeError("cannot convert %1% to JSON", showType());
|
state.debugThrowLastTrace(TypeError("cannot convert %1% to JSON", showType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -404,9 +404,9 @@ public:
|
||||||
|
|
||||||
|
|
||||||
#if HAVE_BOEHMGC
|
#if HAVE_BOEHMGC
|
||||||
typedef std::vector<Value *, traceable_allocator<Value *> > ValueVector;
|
typedef std::vector<Value *, traceable_allocator<Value *>> ValueVector;
|
||||||
typedef std::map<Symbol, Value *, std::less<Symbol>, traceable_allocator<std::pair<const Symbol, Value *> > > ValueMap;
|
typedef std::map<Symbol, Value *, std::less<Symbol>, traceable_allocator<std::pair<const Symbol, Value *>>> ValueMap;
|
||||||
typedef std::map<Symbol, ValueVector, std::less<Symbol>, traceable_allocator<std::pair<const Symbol, ValueVector> > > ValueVectorMap;
|
typedef std::map<Symbol, ValueVector, std::less<Symbol>, traceable_allocator<std::pair<const Symbol, ValueVector>>> ValueVectorMap;
|
||||||
#else
|
#else
|
||||||
typedef std::vector<Value *> ValueVector;
|
typedef std::vector<Value *> ValueVector;
|
||||||
typedef std::map<Symbol, Value *> ValueMap;
|
typedef std::map<Symbol, Value *> ValueMap;
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ struct FetchSettings : public Config
|
||||||
Setting<bool> warnDirty{this, true, "warn-dirty",
|
Setting<bool> warnDirty{this, true, "warn-dirty",
|
||||||
"Whether to warn about dirty Git/Mercurial trees."};
|
"Whether to warn about dirty Git/Mercurial trees."};
|
||||||
|
|
||||||
Setting<std::string> flakeRegistry{this, "https://github.com/NixOS/flake-registry/raw/master/flake-registry.json", "flake-registry",
|
Setting<std::string> flakeRegistry{this, "https://channels.nixos.org/flake-registry.json", "flake-registry",
|
||||||
"Path or URI of the global flake registry."};
|
"Path or URI of the global flake registry."};
|
||||||
|
|
||||||
Setting<bool> useRegistries{this, true, "use-registries",
|
Setting<bool> useRegistries{this, true, "use-registries",
|
||||||
|
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
#include "git-utils.hh"
|
|
||||||
|
|
||||||
#include <regex>
|
|
||||||
|
|
||||||
std::optional<std::string> parseListReferenceHeadRef(std::string_view line)
|
|
||||||
{
|
|
||||||
const static std::regex head_ref_regex("^ref: ([^\\s]+)\\t+HEAD$");
|
|
||||||
std::match_results<std::string_view::const_iterator> match;
|
|
||||||
if (std::regex_match(line.cbegin(), line.cend(), match, head_ref_regex)) {
|
|
||||||
return match[1];
|
|
||||||
} else {
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::optional<std::string> parseListReferenceForRev(std::string_view rev, std::string_view line)
|
|
||||||
{
|
|
||||||
const static std::regex rev_regex("^([^\\t]+)\\t+(.*)$");
|
|
||||||
std::match_results<std::string_view::const_iterator> match;
|
|
||||||
if (!std::regex_match(line.cbegin(), line.cend(), match, rev_regex)) {
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
if (rev != match[2].str()) {
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
return match[1];
|
|
||||||
}
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <string_view>
|
|
||||||
#include <optional>
|
|
||||||
|
|
||||||
// Parses the HEAD ref as reported by `git ls-remote --symref`
|
|
||||||
//
|
|
||||||
// Returns the head branch name as reported by `git ls-remote --symref`, e.g., if
|
|
||||||
// ls-remote returns the output below, "main" is returned based on the ref line.
|
|
||||||
//
|
|
||||||
// ref: refs/heads/main HEAD
|
|
||||||
//
|
|
||||||
// If the repository is in 'detached head' state (HEAD is pointing to a rev
|
|
||||||
// instead of a branch), parseListReferenceForRev("HEAD") may be used instead.
|
|
||||||
std::optional<std::string> parseListReferenceHeadRef(std::string_view line);
|
|
||||||
|
|
||||||
// Parses a reference line from `git ls-remote --symref`, e.g.,
|
|
||||||
// parseListReferenceForRev("refs/heads/master", line) will return 6926...
|
|
||||||
// given the line below.
|
|
||||||
//
|
|
||||||
// 6926beab444c33fb57b21819b6642d032016bb1e refs/heads/master
|
|
||||||
std::optional<std::string> parseListReferenceForRev(std::string_view rev, std::string_view line);
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
#include "url-parts.hh"
|
#include "url-parts.hh"
|
||||||
#include "pathlocks.hh"
|
#include "pathlocks.hh"
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
#include "git-utils.hh"
|
#include "git.hh"
|
||||||
|
|
||||||
#include "fetch-settings.hh"
|
#include "fetch-settings.hh"
|
||||||
|
|
||||||
|
|
@ -26,11 +26,6 @@ namespace {
|
||||||
// old version of git, which will ignore unrecognized `-c` options.
|
// old version of git, which will ignore unrecognized `-c` options.
|
||||||
const std::string gitInitialBranch = "__nix_dummy_branch";
|
const std::string gitInitialBranch = "__nix_dummy_branch";
|
||||||
|
|
||||||
std::string getGitDir()
|
|
||||||
{
|
|
||||||
return getEnv("GIT_DIR").value_or(".git");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isCacheFileWithinTtl(const time_t now, const struct stat & st)
|
bool isCacheFileWithinTtl(const time_t now, const struct stat & st)
|
||||||
{
|
{
|
||||||
return st.st_mtime + settings.tarballTtl > now;
|
return st.st_mtime + settings.tarballTtl > now;
|
||||||
|
|
@ -72,13 +67,16 @@ std::optional<std::string> readHead(const Path & path)
|
||||||
|
|
||||||
std::string_view line = output;
|
std::string_view line = output;
|
||||||
line = line.substr(0, line.find("\n"));
|
line = line.substr(0, line.find("\n"));
|
||||||
if (const auto ref = parseListReferenceHeadRef(line); ref) {
|
if (const auto parseResult = git::parseLsRemoteLine(line)) {
|
||||||
debug("resolved HEAD ref '%s' for repo '%s'", *ref, path);
|
switch (parseResult->kind) {
|
||||||
return *ref;
|
case git::LsRemoteRefLine::Kind::Symbolic:
|
||||||
|
debug("resolved HEAD ref '%s' for repo '%s'", parseResult->target, path);
|
||||||
|
break;
|
||||||
|
case git::LsRemoteRefLine::Kind::Object:
|
||||||
|
debug("resolved HEAD rev '%s' for repo '%s'", parseResult->target, path);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (const auto rev = parseListReferenceForRev("HEAD", line); rev) {
|
return parseResult->target;
|
||||||
debug("resolved HEAD rev '%s' for repo '%s'", *rev, path);
|
|
||||||
return *rev;
|
|
||||||
}
|
}
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
@ -87,8 +85,9 @@ std::optional<std::string> readHead(const Path & path)
|
||||||
bool storeCachedHead(const std::string& actualUrl, const std::string& headRef)
|
bool storeCachedHead(const std::string& actualUrl, const std::string& headRef)
|
||||||
{
|
{
|
||||||
Path cacheDir = getCachePath(actualUrl);
|
Path cacheDir = getCachePath(actualUrl);
|
||||||
|
auto gitDir = ".";
|
||||||
try {
|
try {
|
||||||
runProgram("git", true, { "-C", cacheDir, "symbolic-ref", "--", "HEAD", headRef });
|
runProgram("git", true, { "-C", cacheDir, "--git-dir", gitDir, "symbolic-ref", "--", "HEAD", headRef });
|
||||||
} catch (ExecError &e) {
|
} catch (ExecError &e) {
|
||||||
if (!WIFEXITED(e.status)) throw;
|
if (!WIFEXITED(e.status)) throw;
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -149,7 +148,7 @@ struct WorkdirInfo
|
||||||
WorkdirInfo getWorkdirInfo(const Input & input, const Path & workdir)
|
WorkdirInfo getWorkdirInfo(const Input & input, const Path & workdir)
|
||||||
{
|
{
|
||||||
const bool submodules = maybeGetBoolAttr(input.attrs, "submodules").value_or(false);
|
const bool submodules = maybeGetBoolAttr(input.attrs, "submodules").value_or(false);
|
||||||
auto gitDir = getGitDir();
|
std::string gitDir(".git");
|
||||||
|
|
||||||
auto env = getEnv();
|
auto env = getEnv();
|
||||||
// Set LC_ALL to C: because we rely on the error messages from git rev-parse to determine what went wrong
|
// Set LC_ALL to C: because we rely on the error messages from git rev-parse to determine what went wrong
|
||||||
|
|
@ -184,7 +183,7 @@ WorkdirInfo getWorkdirInfo(const Input & input, const Path & workdir)
|
||||||
if (hasHead) {
|
if (hasHead) {
|
||||||
// Using git diff is preferrable over lower-level operations here,
|
// Using git diff is preferrable over lower-level operations here,
|
||||||
// because its conceptually simpler and we only need the exit code anyways.
|
// because its conceptually simpler and we only need the exit code anyways.
|
||||||
auto gitDiffOpts = Strings({ "-C", workdir, "diff", "HEAD", "--quiet"});
|
auto gitDiffOpts = Strings({ "-C", workdir, "--git-dir", gitDir, "diff", "HEAD", "--quiet"});
|
||||||
if (!submodules) {
|
if (!submodules) {
|
||||||
// Changes in submodules should only make the tree dirty
|
// Changes in submodules should only make the tree dirty
|
||||||
// when those submodules will be copied as well.
|
// when those submodules will be copied as well.
|
||||||
|
|
@ -205,6 +204,7 @@ WorkdirInfo getWorkdirInfo(const Input & input, const Path & workdir)
|
||||||
std::pair<StorePath, Input> fetchFromWorkdir(ref<Store> store, Input & input, const Path & workdir, const WorkdirInfo & workdirInfo)
|
std::pair<StorePath, Input> fetchFromWorkdir(ref<Store> store, Input & input, const Path & workdir, const WorkdirInfo & workdirInfo)
|
||||||
{
|
{
|
||||||
const bool submodules = maybeGetBoolAttr(input.attrs, "submodules").value_or(false);
|
const bool submodules = maybeGetBoolAttr(input.attrs, "submodules").value_or(false);
|
||||||
|
auto gitDir = ".git";
|
||||||
|
|
||||||
if (!fetchSettings.allowDirty)
|
if (!fetchSettings.allowDirty)
|
||||||
throw Error("Git tree '%s' is dirty", workdir);
|
throw Error("Git tree '%s' is dirty", workdir);
|
||||||
|
|
@ -212,7 +212,7 @@ std::pair<StorePath, Input> fetchFromWorkdir(ref<Store> store, Input & input, co
|
||||||
if (fetchSettings.warnDirty)
|
if (fetchSettings.warnDirty)
|
||||||
warn("Git tree '%s' is dirty", workdir);
|
warn("Git tree '%s' is dirty", workdir);
|
||||||
|
|
||||||
auto gitOpts = Strings({ "-C", workdir, "ls-files", "-z" });
|
auto gitOpts = Strings({ "-C", workdir, "--git-dir", gitDir, "ls-files", "-z" });
|
||||||
if (submodules)
|
if (submodules)
|
||||||
gitOpts.emplace_back("--recurse-submodules");
|
gitOpts.emplace_back("--recurse-submodules");
|
||||||
|
|
||||||
|
|
@ -242,7 +242,7 @@ std::pair<StorePath, Input> fetchFromWorkdir(ref<Store> store, Input & input, co
|
||||||
// modified dirty file?
|
// modified dirty file?
|
||||||
input.attrs.insert_or_assign(
|
input.attrs.insert_or_assign(
|
||||||
"lastModified",
|
"lastModified",
|
||||||
workdirInfo.hasHead ? std::stoull(runProgram("git", true, { "-C", actualPath, "log", "-1", "--format=%ct", "--no-show-signature", "HEAD" })) : 0);
|
workdirInfo.hasHead ? std::stoull(runProgram("git", true, { "-C", actualPath, "--git-dir", gitDir, "log", "-1", "--format=%ct", "--no-show-signature", "HEAD" })) : 0);
|
||||||
|
|
||||||
return {std::move(storePath), input};
|
return {std::move(storePath), input};
|
||||||
}
|
}
|
||||||
|
|
@ -367,7 +367,7 @@ struct GitInputScheme : InputScheme
|
||||||
{
|
{
|
||||||
auto sourcePath = getSourcePath(input);
|
auto sourcePath = getSourcePath(input);
|
||||||
assert(sourcePath);
|
assert(sourcePath);
|
||||||
auto gitDir = getGitDir();
|
auto gitDir = ".git";
|
||||||
|
|
||||||
runProgram("git", true,
|
runProgram("git", true,
|
||||||
{ "-C", *sourcePath, "--git-dir", gitDir, "add", "--force", "--intent-to-add", "--", std::string(file) });
|
{ "-C", *sourcePath, "--git-dir", gitDir, "add", "--force", "--intent-to-add", "--", std::string(file) });
|
||||||
|
|
@ -393,7 +393,7 @@ struct GitInputScheme : InputScheme
|
||||||
std::pair<StorePath, Input> fetch(ref<Store> store, const Input & _input) override
|
std::pair<StorePath, Input> fetch(ref<Store> store, const Input & _input) override
|
||||||
{
|
{
|
||||||
Input input(_input);
|
Input input(_input);
|
||||||
auto gitDir = getGitDir();
|
auto gitDir = ".git";
|
||||||
|
|
||||||
std::string name = input.getName();
|
std::string name = input.getName();
|
||||||
|
|
||||||
|
|
@ -451,11 +451,10 @@ struct GitInputScheme : InputScheme
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const Attrs unlockedAttrs({
|
Attrs unlockedAttrs({
|
||||||
{"type", cacheType},
|
{"type", cacheType},
|
||||||
{"name", name},
|
{"name", name},
|
||||||
{"url", actualUrl},
|
{"url", actualUrl},
|
||||||
{"ref", *input.getRef()},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Path repoDir;
|
Path repoDir;
|
||||||
|
|
@ -468,6 +467,7 @@ struct GitInputScheme : InputScheme
|
||||||
head = "master";
|
head = "master";
|
||||||
}
|
}
|
||||||
input.attrs.insert_or_assign("ref", *head);
|
input.attrs.insert_or_assign("ref", *head);
|
||||||
|
unlockedAttrs.insert_or_assign("ref", *head);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!input.getRev())
|
if (!input.getRev())
|
||||||
|
|
@ -484,6 +484,7 @@ struct GitInputScheme : InputScheme
|
||||||
head = "master";
|
head = "master";
|
||||||
}
|
}
|
||||||
input.attrs.insert_or_assign("ref", *head);
|
input.attrs.insert_or_assign("ref", *head);
|
||||||
|
unlockedAttrs.insert_or_assign("ref", *head);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto res = getCache()->lookup(store, unlockedAttrs)) {
|
if (auto res = getCache()->lookup(store, unlockedAttrs)) {
|
||||||
|
|
@ -573,7 +574,7 @@ struct GitInputScheme : InputScheme
|
||||||
bool isShallow = chomp(runProgram("git", true, { "-C", repoDir, "--git-dir", gitDir, "rev-parse", "--is-shallow-repository" })) == "true";
|
bool isShallow = chomp(runProgram("git", true, { "-C", repoDir, "--git-dir", gitDir, "rev-parse", "--is-shallow-repository" })) == "true";
|
||||||
|
|
||||||
if (isShallow && !shallow)
|
if (isShallow && !shallow)
|
||||||
throw Error("'%s' is a shallow Git repository, but a non-shallow repository is needed", actualUrl);
|
throw Error("'%s' is a shallow Git repository, but shallow repositories are only allowed when `shallow = true;` is specified.", actualUrl);
|
||||||
|
|
||||||
// FIXME: check whether rev is an ancestor of ref.
|
// FIXME: check whether rev is an ancestor of ref.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
#include "store-api.hh"
|
#include "store-api.hh"
|
||||||
#include "types.hh"
|
#include "types.hh"
|
||||||
#include "url-parts.hh"
|
#include "url-parts.hh"
|
||||||
#include "git-utils.hh"
|
#include "git.hh"
|
||||||
#include "fetchers.hh"
|
#include "fetchers.hh"
|
||||||
#include "fetch-settings.hh"
|
#include "fetch-settings.hh"
|
||||||
|
|
||||||
|
|
@ -243,7 +243,10 @@ struct GitHubInputScheme : GitArchiveInputScheme
|
||||||
Hash getRevFromRef(nix::ref<Store> store, const Input & input) const override
|
Hash getRevFromRef(nix::ref<Store> store, const Input & input) const override
|
||||||
{
|
{
|
||||||
auto host = maybeGetStrAttr(input.attrs, "host").value_or("github.com");
|
auto host = maybeGetStrAttr(input.attrs, "host").value_or("github.com");
|
||||||
auto url = fmt("https://api.%s/repos/%s/%s/commits/%s", // FIXME: check
|
auto url = fmt(
|
||||||
|
host == "github.com"
|
||||||
|
? "https://api.%s/repos/%s/%s/commits/%s"
|
||||||
|
: "https://%s/api/v3/repos/%s/%s/commits/%s",
|
||||||
host, getStrAttr(input.attrs, "owner"), getStrAttr(input.attrs, "repo"), *input.getRef());
|
host, getStrAttr(input.attrs, "owner"), getStrAttr(input.attrs, "repo"), *input.getRef());
|
||||||
|
|
||||||
Headers headers = makeHeadersWithAuthTokens(host);
|
Headers headers = makeHeadersWithAuthTokens(host);
|
||||||
|
|
@ -262,7 +265,10 @@ struct GitHubInputScheme : GitArchiveInputScheme
|
||||||
// FIXME: use regular /archive URLs instead? api.github.com
|
// FIXME: use regular /archive URLs instead? api.github.com
|
||||||
// might have stricter rate limits.
|
// might have stricter rate limits.
|
||||||
auto host = maybeGetStrAttr(input.attrs, "host").value_or("github.com");
|
auto host = maybeGetStrAttr(input.attrs, "host").value_or("github.com");
|
||||||
auto url = fmt("https://api.%s/repos/%s/%s/tarball/%s", // FIXME: check if this is correct for self hosted instances
|
auto url = fmt(
|
||||||
|
host == "github.com"
|
||||||
|
? "https://api.%s/repos/%s/%s/tarball/%s"
|
||||||
|
: "https://%s/api/v3/repos/%s/%s/tarball/%s",
|
||||||
host, getStrAttr(input.attrs, "owner"), getStrAttr(input.attrs, "repo"),
|
host, getStrAttr(input.attrs, "owner"), getStrAttr(input.attrs, "repo"),
|
||||||
input.getRev()->to_string(Base16, false));
|
input.getRev()->to_string(Base16, false));
|
||||||
|
|
||||||
|
|
@ -375,7 +381,7 @@ struct SourceHutInputScheme : GitArchiveInputScheme
|
||||||
|
|
||||||
Headers headers = makeHeadersWithAuthTokens(host);
|
Headers headers = makeHeadersWithAuthTokens(host);
|
||||||
|
|
||||||
std::string ref_uri;
|
std::string refUri;
|
||||||
if (ref == "HEAD") {
|
if (ref == "HEAD") {
|
||||||
auto file = store->toRealPath(
|
auto file = store->toRealPath(
|
||||||
downloadFile(store, fmt("%s/HEAD", base_url), "source", false, headers).storePath);
|
downloadFile(store, fmt("%s/HEAD", base_url), "source", false, headers).storePath);
|
||||||
|
|
@ -383,14 +389,15 @@ struct SourceHutInputScheme : GitArchiveInputScheme
|
||||||
std::string line;
|
std::string line;
|
||||||
getline(is, line);
|
getline(is, line);
|
||||||
|
|
||||||
auto r = parseListReferenceHeadRef(line);
|
auto remoteLine = git::parseLsRemoteLine(line);
|
||||||
if (!r) {
|
if (!remoteLine) {
|
||||||
throw BadURL("in '%d', couldn't resolve HEAD ref '%d'", input.to_string(), ref);
|
throw BadURL("in '%d', couldn't resolve HEAD ref '%d'", input.to_string(), ref);
|
||||||
}
|
}
|
||||||
ref_uri = *r;
|
refUri = remoteLine->target;
|
||||||
} else {
|
} else {
|
||||||
ref_uri = fmt("refs/(heads|tags)/%s", ref);
|
refUri = fmt("refs/(heads|tags)/%s", ref);
|
||||||
}
|
}
|
||||||
|
std::regex refRegex(refUri);
|
||||||
|
|
||||||
auto file = store->toRealPath(
|
auto file = store->toRealPath(
|
||||||
downloadFile(store, fmt("%s/info/refs", base_url), "source", false, headers).storePath);
|
downloadFile(store, fmt("%s/info/refs", base_url), "source", false, headers).storePath);
|
||||||
|
|
@ -399,7 +406,9 @@ struct SourceHutInputScheme : GitArchiveInputScheme
|
||||||
std::string line;
|
std::string line;
|
||||||
std::optional<std::string> id;
|
std::optional<std::string> id;
|
||||||
while(!id && getline(is, line)) {
|
while(!id && getline(is, line)) {
|
||||||
id = parseListReferenceForRev(ref_uri, line);
|
auto parsedLine = git::parseLsRemoteLine(line);
|
||||||
|
if (parsedLine && parsedLine->reference && std::regex_match(*parsedLine->reference, refRegex))
|
||||||
|
id = parsedLine->target;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!id)
|
if(!id)
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include "archive.hh"
|
#include "archive.hh"
|
||||||
#include "tarfile.hh"
|
#include "tarfile.hh"
|
||||||
#include "types.hh"
|
#include "types.hh"
|
||||||
|
#include "split.hh"
|
||||||
|
|
||||||
namespace nix::fetchers {
|
namespace nix::fetchers {
|
||||||
|
|
||||||
|
|
@ -168,24 +169,34 @@ std::pair<Tree, time_t> downloadTarball(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TarballInputScheme : InputScheme
|
// An input scheme corresponding to a curl-downloadable resource.
|
||||||
|
struct CurlInputScheme : InputScheme
|
||||||
{
|
{
|
||||||
|
virtual const std::string inputType() const = 0;
|
||||||
|
const std::set<std::string> transportUrlSchemes = {"file", "http", "https"};
|
||||||
|
|
||||||
|
const bool hasTarballExtension(std::string_view path) const
|
||||||
|
{
|
||||||
|
return hasSuffix(path, ".zip") || hasSuffix(path, ".tar")
|
||||||
|
|| hasSuffix(path, ".tgz") || hasSuffix(path, ".tar.gz")
|
||||||
|
|| hasSuffix(path, ".tar.xz") || hasSuffix(path, ".tar.bz2")
|
||||||
|
|| hasSuffix(path, ".tar.zst");
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool isValidURL(const ParsedURL & url) const = 0;
|
||||||
|
|
||||||
std::optional<Input> inputFromURL(const ParsedURL & url) override
|
std::optional<Input> inputFromURL(const ParsedURL & url) override
|
||||||
{
|
{
|
||||||
if (url.scheme != "file" && url.scheme != "http" && url.scheme != "https") return {};
|
if (!isValidURL(url))
|
||||||
|
return std::nullopt;
|
||||||
if (!hasSuffix(url.path, ".zip")
|
|
||||||
&& !hasSuffix(url.path, ".tar")
|
|
||||||
&& !hasSuffix(url.path, ".tgz")
|
|
||||||
&& !hasSuffix(url.path, ".tar.gz")
|
|
||||||
&& !hasSuffix(url.path, ".tar.xz")
|
|
||||||
&& !hasSuffix(url.path, ".tar.bz2")
|
|
||||||
&& !hasSuffix(url.path, ".tar.zst"))
|
|
||||||
return {};
|
|
||||||
|
|
||||||
Input input;
|
Input input;
|
||||||
input.attrs.insert_or_assign("type", "tarball");
|
|
||||||
input.attrs.insert_or_assign("url", url.to_string());
|
auto urlWithoutApplicationScheme = url;
|
||||||
|
urlWithoutApplicationScheme.scheme = parseUrlScheme(url.scheme).transport;
|
||||||
|
|
||||||
|
input.attrs.insert_or_assign("type", inputType());
|
||||||
|
input.attrs.insert_or_assign("url", urlWithoutApplicationScheme.to_string());
|
||||||
auto narHash = url.query.find("narHash");
|
auto narHash = url.query.find("narHash");
|
||||||
if (narHash != url.query.end())
|
if (narHash != url.query.end())
|
||||||
input.attrs.insert_or_assign("narHash", narHash->second);
|
input.attrs.insert_or_assign("narHash", narHash->second);
|
||||||
|
|
@ -194,14 +205,17 @@ struct TarballInputScheme : InputScheme
|
||||||
|
|
||||||
std::optional<Input> inputFromAttrs(const Attrs & attrs) override
|
std::optional<Input> inputFromAttrs(const Attrs & attrs) override
|
||||||
{
|
{
|
||||||
if (maybeGetStrAttr(attrs, "type") != "tarball") return {};
|
auto type = maybeGetStrAttr(attrs, "type");
|
||||||
|
if (type != inputType()) return {};
|
||||||
|
|
||||||
|
std::set<std::string> allowedNames = {"type", "url", "narHash", "name", "unpack"};
|
||||||
for (auto & [name, value] : attrs)
|
for (auto & [name, value] : attrs)
|
||||||
if (name != "type" && name != "url" && /* name != "hash" && */ name != "narHash" && name != "name")
|
if (!allowedNames.count(name))
|
||||||
throw Error("unsupported tarball input attribute '%s'", name);
|
throw Error("unsupported %s input attribute '%s'", *type, name);
|
||||||
|
|
||||||
Input input;
|
Input input;
|
||||||
input.attrs = attrs;
|
input.attrs = attrs;
|
||||||
|
|
||||||
//input.locked = (bool) maybeGetStrAttr(input.attrs, "hash");
|
//input.locked = (bool) maybeGetStrAttr(input.attrs, "hash");
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
@ -209,14 +223,9 @@ struct TarballInputScheme : InputScheme
|
||||||
ParsedURL toURL(const Input & input) override
|
ParsedURL toURL(const Input & input) override
|
||||||
{
|
{
|
||||||
auto url = parseURL(getStrAttr(input.attrs, "url"));
|
auto url = parseURL(getStrAttr(input.attrs, "url"));
|
||||||
// NAR hashes are preferred over file hashes since tar/zip files
|
// NAR hashes are preferred over file hashes since tar/zip files // don't have a canonical representation.
|
||||||
// don't have a canonical representation.
|
|
||||||
if (auto narHash = input.getNarHash())
|
if (auto narHash = input.getNarHash())
|
||||||
url.query.insert_or_assign("narHash", narHash->to_string(SRI, true));
|
url.query.insert_or_assign("narHash", narHash->to_string(SRI, true));
|
||||||
/*
|
|
||||||
else if (auto hash = maybeGetStrAttr(input.attrs, "hash"))
|
|
||||||
url.query.insert_or_assign("hash", Hash(*hash).to_string(SRI, true));
|
|
||||||
*/
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -225,6 +234,42 @@ struct TarballInputScheme : InputScheme
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FileInputScheme : CurlInputScheme
|
||||||
|
{
|
||||||
|
const std::string inputType() const override { return "file"; }
|
||||||
|
|
||||||
|
bool isValidURL(const ParsedURL & url) const override
|
||||||
|
{
|
||||||
|
auto parsedUrlScheme = parseUrlScheme(url.scheme);
|
||||||
|
return transportUrlSchemes.count(std::string(parsedUrlScheme.transport))
|
||||||
|
&& (parsedUrlScheme.application
|
||||||
|
? parsedUrlScheme.application.value() == inputType()
|
||||||
|
: !hasTarballExtension(url.path));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<StorePath, Input> fetch(ref<Store> store, const Input & input) override
|
||||||
|
{
|
||||||
|
auto file = downloadFile(store, getStrAttr(input.attrs, "url"), input.getName(), false);
|
||||||
|
return {std::move(file.storePath), input};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TarballInputScheme : CurlInputScheme
|
||||||
|
{
|
||||||
|
const std::string inputType() const override { return "tarball"; }
|
||||||
|
|
||||||
|
bool isValidURL(const ParsedURL & url) const override
|
||||||
|
{
|
||||||
|
auto parsedUrlScheme = parseUrlScheme(url.scheme);
|
||||||
|
|
||||||
|
return transportUrlSchemes.count(std::string(parsedUrlScheme.transport))
|
||||||
|
&& (parsedUrlScheme.application
|
||||||
|
? parsedUrlScheme.application.value() == inputType()
|
||||||
|
: hasTarballExtension(url.path));
|
||||||
|
}
|
||||||
|
|
||||||
std::pair<StorePath, Input> fetch(ref<Store> store, const Input & input) override
|
std::pair<StorePath, Input> fetch(ref<Store> store, const Input & input) override
|
||||||
{
|
{
|
||||||
auto tree = downloadTarball(store, getStrAttr(input.attrs, "url"), input.getName(), false).first;
|
auto tree = downloadTarball(store, getStrAttr(input.attrs, "url"), input.getName(), false).first;
|
||||||
|
|
@ -233,5 +278,6 @@ struct TarballInputScheme : InputScheme
|
||||||
};
|
};
|
||||||
|
|
||||||
static auto rTarballInputScheme = OnStartup([] { registerInputScheme(std::make_unique<TarballInputScheme>()); });
|
static auto rTarballInputScheme = OnStartup([] { registerInputScheme(std::make_unique<TarballInputScheme>()); });
|
||||||
|
static auto rFileInputScheme = OnStartup([] { registerInputScheme(std::make_unique<FileInputScheme>()); });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,22 @@ HookInstance::HookInstance()
|
||||||
{
|
{
|
||||||
debug("starting build hook '%s'", settings.buildHook);
|
debug("starting build hook '%s'", settings.buildHook);
|
||||||
|
|
||||||
|
auto buildHookArgs = tokenizeString<std::list<std::string>>(settings.buildHook.get());
|
||||||
|
|
||||||
|
if (buildHookArgs.empty())
|
||||||
|
throw Error("'build-hook' setting is empty");
|
||||||
|
|
||||||
|
auto buildHook = buildHookArgs.front();
|
||||||
|
buildHookArgs.pop_front();
|
||||||
|
|
||||||
|
Strings args;
|
||||||
|
|
||||||
|
for (auto & arg : buildHookArgs)
|
||||||
|
args.push_back(arg);
|
||||||
|
|
||||||
|
args.push_back(std::string(baseNameOf(settings.buildHook.get())));
|
||||||
|
args.push_back(std::to_string(verbosity));
|
||||||
|
|
||||||
/* Create a pipe to get the output of the child. */
|
/* Create a pipe to get the output of the child. */
|
||||||
fromHook.create();
|
fromHook.create();
|
||||||
|
|
||||||
|
|
@ -36,14 +52,9 @@ HookInstance::HookInstance()
|
||||||
if (dup2(builderOut.readSide.get(), 5) == -1)
|
if (dup2(builderOut.readSide.get(), 5) == -1)
|
||||||
throw SysError("dupping builder's stdout/stderr");
|
throw SysError("dupping builder's stdout/stderr");
|
||||||
|
|
||||||
Strings args = {
|
execv(buildHook.c_str(), stringsToCharPtrs(args).data());
|
||||||
std::string(baseNameOf(settings.buildHook.get())),
|
|
||||||
std::to_string(verbosity),
|
|
||||||
};
|
|
||||||
|
|
||||||
execv(settings.buildHook.get().c_str(), stringsToCharPtrs(args).data());
|
throw SysError("executing '%s'", buildHook);
|
||||||
|
|
||||||
throw SysError("executing '%s'", settings.buildHook);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
pid.setSeparatePG(true);
|
pid.setSeparatePG(true);
|
||||||
|
|
|
||||||
|
|
@ -846,18 +846,43 @@ void LocalDerivationGoal::startBuilder()
|
||||||
/* Some distros patch Linux to not allow unprivileged
|
/* Some distros patch Linux to not allow unprivileged
|
||||||
* user namespaces. If we get EPERM or EINVAL, try
|
* user namespaces. If we get EPERM or EINVAL, try
|
||||||
* without CLONE_NEWUSER and see if that works.
|
* without CLONE_NEWUSER and see if that works.
|
||||||
|
* Details: https://salsa.debian.org/kernel-team/linux/-/commit/d98e00eda6bea437e39b9e80444eee84a32438a6
|
||||||
*/
|
*/
|
||||||
usingUserNamespace = false;
|
usingUserNamespace = false;
|
||||||
flags &= ~CLONE_NEWUSER;
|
flags &= ~CLONE_NEWUSER;
|
||||||
child = clone(childEntry, stack + stackSize, flags, this);
|
child = clone(childEntry, stack + stackSize, flags, this);
|
||||||
}
|
}
|
||||||
|
if (child == -1) {
|
||||||
|
switch(errno) {
|
||||||
|
case EPERM:
|
||||||
|
case EINVAL: {
|
||||||
|
int errno_ = errno;
|
||||||
|
if (!userNamespacesEnabled && errno==EPERM)
|
||||||
|
notice("user namespaces appear to be disabled; they are required for sandboxing; check /proc/sys/user/max_user_namespaces");
|
||||||
|
if (userNamespacesEnabled) {
|
||||||
|
Path procSysKernelUnprivilegedUsernsClone = "/proc/sys/kernel/unprivileged_userns_clone";
|
||||||
|
if (pathExists(procSysKernelUnprivilegedUsernsClone)
|
||||||
|
&& trim(readFile(procSysKernelUnprivilegedUsernsClone)) == "0") {
|
||||||
|
notice("user namespaces appear to be disabled; they are required for sandboxing; check /proc/sys/kernel/unprivileged_userns_clone");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Path procSelfNsUser = "/proc/self/ns/user";
|
||||||
|
if (!pathExists(procSelfNsUser))
|
||||||
|
notice("/proc/self/ns/user does not exist; your kernel was likely built without CONFIG_USER_NS=y, which is required for sandboxing");
|
||||||
/* Otherwise exit with EPERM so we can handle this in the
|
/* Otherwise exit with EPERM so we can handle this in the
|
||||||
parent. This is only done when sandbox-fallback is set
|
parent. This is only done when sandbox-fallback is set
|
||||||
to true (the default). */
|
to true (the default). */
|
||||||
if (child == -1 && (errno == EPERM || errno == EINVAL) && settings.sandboxFallback)
|
if (settings.sandboxFallback)
|
||||||
_exit(1);
|
_exit(1);
|
||||||
if (child == -1) throw SysError("cloning builder process");
|
/* Mention sandbox-fallback in the error message so the user
|
||||||
|
knows that having it disabled contributed to the
|
||||||
|
unrecoverability of this failure */
|
||||||
|
throw SysError(errno_, "creating sandboxed builder process using clone(), without sandbox-fallback");
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
throw SysError("creating sandboxed builder process using clone()");
|
||||||
|
}
|
||||||
|
}
|
||||||
writeFull(builderOut.writeSide.get(),
|
writeFull(builderOut.writeSide.get(),
|
||||||
fmt("%d %d\n", usingUserNamespace, child));
|
fmt("%d %d\n", usingUserNamespace, child));
|
||||||
_exit(0);
|
_exit(0);
|
||||||
|
|
@ -1718,6 +1743,18 @@ void LocalDerivationGoal::runChild()
|
||||||
|
|
||||||
for (auto & i : dirsInChroot) {
|
for (auto & i : dirsInChroot) {
|
||||||
if (i.second.source == "/proc") continue; // backwards compatibility
|
if (i.second.source == "/proc") continue; // backwards compatibility
|
||||||
|
|
||||||
|
#if HAVE_EMBEDDED_SANDBOX_SHELL
|
||||||
|
if (i.second.source == "__embedded_sandbox_shell__") {
|
||||||
|
static unsigned char sh[] = {
|
||||||
|
#include "embedded-sandbox-shell.gen.hh"
|
||||||
|
};
|
||||||
|
auto dst = chrootRootDir + i.first;
|
||||||
|
createDirs(dirOf(dst));
|
||||||
|
writeFile(dst, std::string_view((const char *) sh, sizeof(sh)));
|
||||||
|
chmod_(dst, 0555);
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
doBind(i.second.source, chrootRootDir + i.first, i.second.optional);
|
doBind(i.second.source, chrootRootDir + i.first, i.second.optional);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,7 @@ void PathSubstitutionGoal::tryNext()
|
||||||
only after we've downloaded the path. */
|
only after we've downloaded the path. */
|
||||||
if (!sub->isTrusted && worker.store.pathInfoIsUntrusted(*info))
|
if (!sub->isTrusted && worker.store.pathInfoIsUntrusted(*info))
|
||||||
{
|
{
|
||||||
warn("the substitute for '%s' from '%s' is not signed by any of the keys in 'trusted-public-keys'",
|
warn("ignoring substitute for '%s' from '%s', as it's not signed by any of the keys in 'trusted-public-keys'",
|
||||||
worker.store.printStorePath(storePath), sub->getUri());
|
worker.store.printStorePath(storePath), sub->getUri());
|
||||||
tryNext();
|
tryNext();
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -93,8 +93,9 @@ static void createLinks(State & state, const Path & srcDir, const Path & dstDir,
|
||||||
auto prevPriority = state.priorities[dstFile];
|
auto prevPriority = state.priorities[dstFile];
|
||||||
if (prevPriority == priority)
|
if (prevPriority == priority)
|
||||||
throw Error(
|
throw Error(
|
||||||
"packages '%1%' and '%2%' have the same priority %3%; "
|
"files '%1%' and '%2%' have the same priority %3%; "
|
||||||
"use 'nix-env --set-flag priority NUMBER INSTALLED_PKGNAME' "
|
"use 'nix-env --set-flag priority NUMBER INSTALLED_PKGNAME' "
|
||||||
|
"or type 'nix profile install --help' if using 'nix profile' to find out how"
|
||||||
"to change the priority of one of the conflicting packages"
|
"to change the priority of one of the conflicting packages"
|
||||||
" (0 being the highest priority)",
|
" (0 being the highest priority)",
|
||||||
srcFile, readLink(dstFile), priority);
|
srcFile, readLink(dstFile), priority);
|
||||||
|
|
|
||||||
|
|
@ -135,6 +135,7 @@ void LocalStore::addTempRoot(const StorePath & path)
|
||||||
state->fdRootsSocket.close();
|
state->fdRootsSocket.close();
|
||||||
goto restart;
|
goto restart;
|
||||||
}
|
}
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -153,6 +154,7 @@ void LocalStore::addTempRoot(const StorePath & path)
|
||||||
state->fdRootsSocket.close();
|
state->fdRootsSocket.close();
|
||||||
goto restart;
|
goto restart;
|
||||||
}
|
}
|
||||||
|
throw;
|
||||||
} catch (EndOfFile & e) {
|
} catch (EndOfFile & e) {
|
||||||
debug("GC socket disconnected");
|
debug("GC socket disconnected");
|
||||||
state->fdRootsSocket.close();
|
state->fdRootsSocket.close();
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,6 @@ Settings::Settings()
|
||||||
, nixStateDir(canonPath(getEnv("NIX_STATE_DIR").value_or(NIX_STATE_DIR)))
|
, nixStateDir(canonPath(getEnv("NIX_STATE_DIR").value_or(NIX_STATE_DIR)))
|
||||||
, nixConfDir(canonPath(getEnv("NIX_CONF_DIR").value_or(NIX_CONF_DIR)))
|
, nixConfDir(canonPath(getEnv("NIX_CONF_DIR").value_or(NIX_CONF_DIR)))
|
||||||
, nixUserConfFiles(getUserConfigFiles())
|
, nixUserConfFiles(getUserConfigFiles())
|
||||||
, nixLibexecDir(canonPath(getEnv("NIX_LIBEXEC_DIR").value_or(NIX_LIBEXEC_DIR)))
|
|
||||||
, nixBinDir(canonPath(getEnv("NIX_BIN_DIR").value_or(NIX_BIN_DIR)))
|
, nixBinDir(canonPath(getEnv("NIX_BIN_DIR").value_or(NIX_BIN_DIR)))
|
||||||
, nixManDir(canonPath(NIX_MAN_DIR))
|
, nixManDir(canonPath(NIX_MAN_DIR))
|
||||||
, nixDaemonSocketFile(canonPath(getEnv("NIX_DAEMON_SOCKET_PATH").value_or(nixStateDir + DEFAULT_SOCKET_PATH)))
|
, nixDaemonSocketFile(canonPath(getEnv("NIX_DAEMON_SOCKET_PATH").value_or(nixStateDir + DEFAULT_SOCKET_PATH)))
|
||||||
|
|
@ -67,12 +66,13 @@ Settings::Settings()
|
||||||
sandboxPaths = tokenizeString<StringSet>("/bin/sh=" SANDBOX_SHELL);
|
sandboxPaths = tokenizeString<StringSet>("/bin/sh=" SANDBOX_SHELL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* chroot-like behavior from Apple's sandbox */
|
||||||
/* chroot-like behavior from Apple's sandbox */
|
|
||||||
#if __APPLE__
|
#if __APPLE__
|
||||||
sandboxPaths = tokenizeString<StringSet>("/System/Library/Frameworks /System/Library/PrivateFrameworks /bin/sh /bin/bash /private/tmp /private/var/tmp /usr/lib");
|
sandboxPaths = tokenizeString<StringSet>("/System/Library/Frameworks /System/Library/PrivateFrameworks /bin/sh /bin/bash /private/tmp /private/var/tmp /usr/lib");
|
||||||
allowedImpureHostPrefixes = tokenizeString<StringSet>("/System/Library /usr/lib /dev /bin/sh");
|
allowedImpureHostPrefixes = tokenizeString<StringSet>("/System/Library /usr/lib /dev /bin/sh");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
buildHook = getSelfExe().value_or("nix") + " __build-remote";
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadConfFile()
|
void loadConfFile()
|
||||||
|
|
@ -114,7 +114,13 @@ std::vector<Path> getUserConfigFiles()
|
||||||
|
|
||||||
unsigned int Settings::getDefaultCores()
|
unsigned int Settings::getDefaultCores()
|
||||||
{
|
{
|
||||||
return std::max(1U, std::thread::hardware_concurrency());
|
const unsigned int concurrency = std::max(1U, std::thread::hardware_concurrency());
|
||||||
|
const unsigned int maxCPU = getMaxCPU();
|
||||||
|
|
||||||
|
if (maxCPU > 0)
|
||||||
|
return maxCPU;
|
||||||
|
else
|
||||||
|
return concurrency;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringSet Settings::getDefaultSystemFeatures()
|
StringSet Settings::getDefaultSystemFeatures()
|
||||||
|
|
|
||||||
|
|
@ -79,9 +79,6 @@ public:
|
||||||
/* A list of user configuration files to load. */
|
/* A list of user configuration files to load. */
|
||||||
std::vector<Path> nixUserConfFiles;
|
std::vector<Path> nixUserConfFiles;
|
||||||
|
|
||||||
/* The directory where internal helper programs are stored. */
|
|
||||||
Path nixLibexecDir;
|
|
||||||
|
|
||||||
/* The directory where the main programs are stored. */
|
/* The directory where the main programs are stored. */
|
||||||
Path nixBinDir;
|
Path nixBinDir;
|
||||||
|
|
||||||
|
|
@ -195,7 +192,7 @@ public:
|
||||||
)",
|
)",
|
||||||
{"build-timeout"}};
|
{"build-timeout"}};
|
||||||
|
|
||||||
PathSetting buildHook{this, true, nixLibexecDir + "/nix/build-remote", "build-hook",
|
PathSetting buildHook{this, true, "", "build-hook",
|
||||||
"The path of the helper program that executes builds to remote machines."};
|
"The path of the helper program that executes builds to remote machines."};
|
||||||
|
|
||||||
Setting<std::string> builders{
|
Setting<std::string> builders{
|
||||||
|
|
@ -802,7 +799,7 @@ public:
|
||||||
)"};
|
)"};
|
||||||
|
|
||||||
Setting<StringSet> ignoredAcls{
|
Setting<StringSet> ignoredAcls{
|
||||||
this, {"security.selinux", "system.nfs4_acl"}, "ignored-acls",
|
this, {"security.selinux", "system.nfs4_acl", "security.csm"}, "ignored-acls",
|
||||||
R"(
|
R"(
|
||||||
A list of ACLs that should be ignored, normally Nix attempts to
|
A list of ACLs that should be ignored, normally Nix attempts to
|
||||||
remove all ACLs from files and directories in the Nix store, but
|
remove all ACLs from files and directories in the Nix store, but
|
||||||
|
|
|
||||||
|
|
@ -161,7 +161,12 @@ protected:
|
||||||
void getFile(const std::string & path,
|
void getFile(const std::string & path,
|
||||||
Callback<std::optional<std::string>> callback) noexcept override
|
Callback<std::optional<std::string>> callback) noexcept override
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
checkEnabled();
|
checkEnabled();
|
||||||
|
} catch (...) {
|
||||||
|
callback.rethrow();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto request(makeRequest(path));
|
auto request(makeRequest(path));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,7 @@ protected:
|
||||||
} catch (SysError & e) {
|
} catch (SysError & e) {
|
||||||
if (e.errNo == ENOENT)
|
if (e.errNo == ENOENT)
|
||||||
throw NoSuchBinaryCacheFile("file '%s' does not exist in binary cache", path);
|
throw NoSuchBinaryCacheFile("file '%s' does not exist in binary cache", path);
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -107,7 +108,7 @@ bool LocalBinaryCacheStore::fileExists(const std::string & path)
|
||||||
|
|
||||||
std::set<std::string> LocalBinaryCacheStore::uriSchemes()
|
std::set<std::string> LocalBinaryCacheStore::uriSchemes()
|
||||||
{
|
{
|
||||||
if (getEnv("_NIX_FORCE_HTTP_BINARY_CACHE_STORE") == "1")
|
if (getEnv("_NIX_FORCE_HTTP") == "1")
|
||||||
return {};
|
return {};
|
||||||
else
|
else
|
||||||
return {"file"};
|
return {"file"};
|
||||||
|
|
|
||||||
|
|
@ -39,14 +39,23 @@ libstore_CXXFLAGS += \
|
||||||
-DNIX_STATE_DIR=\"$(localstatedir)/nix\" \
|
-DNIX_STATE_DIR=\"$(localstatedir)/nix\" \
|
||||||
-DNIX_LOG_DIR=\"$(localstatedir)/log/nix\" \
|
-DNIX_LOG_DIR=\"$(localstatedir)/log/nix\" \
|
||||||
-DNIX_CONF_DIR=\"$(sysconfdir)/nix\" \
|
-DNIX_CONF_DIR=\"$(sysconfdir)/nix\" \
|
||||||
-DNIX_LIBEXEC_DIR=\"$(libexecdir)\" \
|
|
||||||
-DNIX_BIN_DIR=\"$(bindir)\" \
|
-DNIX_BIN_DIR=\"$(bindir)\" \
|
||||||
-DNIX_MAN_DIR=\"$(mandir)\" \
|
-DNIX_MAN_DIR=\"$(mandir)\" \
|
||||||
-DLSOF=\"$(lsof)\"
|
-DLSOF=\"$(lsof)\"
|
||||||
|
|
||||||
|
ifeq ($(embedded_sandbox_shell),yes)
|
||||||
|
libstore_CXXFLAGS += -DSANDBOX_SHELL=\"__embedded_sandbox_shell__\"
|
||||||
|
|
||||||
|
$(d)/build/local-derivation-goal.cc: $(d)/embedded-sandbox-shell.gen.hh
|
||||||
|
|
||||||
|
$(d)/embedded-sandbox-shell.gen.hh: $(sandbox_shell)
|
||||||
|
$(trace-gen) hexdump -v -e '1/1 "0x%x," "\n"' < $< > $@.tmp
|
||||||
|
@mv $@.tmp $@
|
||||||
|
else
|
||||||
ifneq ($(sandbox_shell),)
|
ifneq ($(sandbox_shell),)
|
||||||
libstore_CXXFLAGS += -DSANDBOX_SHELL="\"$(sandbox_shell)\""
|
libstore_CXXFLAGS += -DSANDBOX_SHELL="\"$(sandbox_shell)\""
|
||||||
endif
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
$(d)/local-store.cc: $(d)/schema.sql.gen.hh $(d)/ca-specific-schema.sql.gen.hh
|
$(d)/local-store.cc: $(d)/schema.sql.gen.hh $(d)/ca-specific-schema.sql.gen.hh
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,13 +67,26 @@ bool UserLock::findFreeUser() {
|
||||||
#if __linux__
|
#if __linux__
|
||||||
/* Get the list of supplementary groups of this build user. This
|
/* Get the list of supplementary groups of this build user. This
|
||||||
is usually either empty or contains a group such as "kvm". */
|
is usually either empty or contains a group such as "kvm". */
|
||||||
supplementaryGIDs.resize(10);
|
int ngroups = 32; // arbitrary initial guess
|
||||||
int ngroups = supplementaryGIDs.size();
|
supplementaryGIDs.resize(ngroups);
|
||||||
int err = getgrouplist(pw->pw_name, pw->pw_gid,
|
|
||||||
supplementaryGIDs.data(), &ngroups);
|
|
||||||
if (err == -1)
|
|
||||||
throw Error("failed to get list of supplementary groups for '%1%'", pw->pw_name);
|
|
||||||
|
|
||||||
|
int err = getgrouplist(pw->pw_name, pw->pw_gid, supplementaryGIDs.data(),
|
||||||
|
&ngroups);
|
||||||
|
|
||||||
|
// Our initial size of 32 wasn't sufficient, the correct size has
|
||||||
|
// been stored in ngroups, so we try again.
|
||||||
|
if (err == -1) {
|
||||||
|
supplementaryGIDs.resize(ngroups);
|
||||||
|
err = getgrouplist(pw->pw_name, pw->pw_gid, supplementaryGIDs.data(),
|
||||||
|
&ngroups);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If it failed once more, then something must be broken.
|
||||||
|
if (err == -1)
|
||||||
|
throw Error("failed to get list of supplementary groups for '%1%'",
|
||||||
|
pw->pw_name);
|
||||||
|
|
||||||
|
// Finally, trim back the GID list to its real size
|
||||||
supplementaryGIDs.resize(ngroups);
|
supplementaryGIDs.resize(ngroups);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,9 @@ public:
|
||||||
/* How often to purge expired entries from the cache. */
|
/* How often to purge expired entries from the cache. */
|
||||||
const int purgeInterval = 24 * 3600;
|
const int purgeInterval = 24 * 3600;
|
||||||
|
|
||||||
|
/* How long to cache binary cache info (i.e. /nix-cache-info) */
|
||||||
|
const int cacheInfoTtl = 7 * 24 * 3600;
|
||||||
|
|
||||||
struct Cache
|
struct Cache
|
||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
|
|
@ -98,7 +101,7 @@ public:
|
||||||
"insert or replace into BinaryCaches(url, timestamp, storeDir, wantMassQuery, priority) values (?, ?, ?, ?, ?)");
|
"insert or replace into BinaryCaches(url, timestamp, storeDir, wantMassQuery, priority) values (?, ?, ?, ?, ?)");
|
||||||
|
|
||||||
state->queryCache.create(state->db,
|
state->queryCache.create(state->db,
|
||||||
"select id, storeDir, wantMassQuery, priority from BinaryCaches where url = ?");
|
"select id, storeDir, wantMassQuery, priority from BinaryCaches where url = ? and timestamp > ?");
|
||||||
|
|
||||||
state->insertNAR.create(state->db,
|
state->insertNAR.create(state->db,
|
||||||
"insert or replace into NARs(cache, hashPart, namePart, url, compression, fileHash, fileSize, narHash, "
|
"insert or replace into NARs(cache, hashPart, namePart, url, compression, fileHash, fileSize, narHash, "
|
||||||
|
|
@ -183,7 +186,7 @@ public:
|
||||||
|
|
||||||
auto i = state->caches.find(uri);
|
auto i = state->caches.find(uri);
|
||||||
if (i == state->caches.end()) {
|
if (i == state->caches.end()) {
|
||||||
auto queryCache(state->queryCache.use()(uri));
|
auto queryCache(state->queryCache.use()(uri)(time(0) - cacheInfoTtl));
|
||||||
if (!queryCache.next())
|
if (!queryCache.next())
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
state->caches.emplace(uri,
|
state->caches.emplace(uri,
|
||||||
|
|
|
||||||
|
|
@ -69,8 +69,6 @@ NarInfo::NarInfo(const Store & store, const std::string & s, const std::string &
|
||||||
if (value != "unknown-deriver")
|
if (value != "unknown-deriver")
|
||||||
deriver = StorePath(value);
|
deriver = StorePath(value);
|
||||||
}
|
}
|
||||||
else if (name == "System")
|
|
||||||
system = value;
|
|
||||||
else if (name == "Sig")
|
else if (name == "Sig")
|
||||||
sigs.insert(value);
|
sigs.insert(value);
|
||||||
else if (name == "CA") {
|
else if (name == "CA") {
|
||||||
|
|
@ -106,9 +104,6 @@ std::string NarInfo::to_string(const Store & store) const
|
||||||
if (deriver)
|
if (deriver)
|
||||||
res += "Deriver: " + std::string(deriver->to_string()) + "\n";
|
res += "Deriver: " + std::string(deriver->to_string()) + "\n";
|
||||||
|
|
||||||
if (!system.empty())
|
|
||||||
res += "System: " + system + "\n";
|
|
||||||
|
|
||||||
for (auto sig : sigs)
|
for (auto sig : sigs)
|
||||||
res += "Sig: " + sig + "\n";
|
res += "Sig: " + sig + "\n";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ struct NarInfo : ValidPathInfo
|
||||||
std::string compression;
|
std::string compression;
|
||||||
std::optional<Hash> fileHash;
|
std::optional<Hash> fileHash;
|
||||||
uint64_t fileSize = 0;
|
uint64_t fileSize = 0;
|
||||||
std::string system;
|
|
||||||
|
|
||||||
NarInfo() = delete;
|
NarInfo() = delete;
|
||||||
NarInfo(StorePath && path, Hash narHash) : ValidPathInfo(std::move(path), narHash) { }
|
NarInfo(StorePath && path, Hash narHash) : ValidPathInfo(std::move(path), narHash) { }
|
||||||
|
|
|
||||||
|
|
@ -718,13 +718,12 @@ void RemoteStore::registerDrvOutput(const Realisation & info)
|
||||||
void RemoteStore::queryRealisationUncached(const DrvOutput & id,
|
void RemoteStore::queryRealisationUncached(const DrvOutput & id,
|
||||||
Callback<std::shared_ptr<const Realisation>> callback) noexcept
|
Callback<std::shared_ptr<const Realisation>> callback) noexcept
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
auto conn(getConnection());
|
auto conn(getConnection());
|
||||||
|
|
||||||
if (GET_PROTOCOL_MINOR(conn->daemonVersion) < 27) {
|
if (GET_PROTOCOL_MINOR(conn->daemonVersion) < 27) {
|
||||||
warn("the daemon is too old to support content-addressed derivations, please upgrade it to 2.4");
|
warn("the daemon is too old to support content-addressed derivations, please upgrade it to 2.4");
|
||||||
try {
|
return callback(nullptr);
|
||||||
callback(nullptr);
|
|
||||||
} catch (...) { return callback.rethrow(); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
conn->to << wopQueryRealisation;
|
conn->to << wopQueryRealisation;
|
||||||
|
|
@ -747,7 +746,6 @@ void RemoteStore::queryRealisationUncached(const DrvOutput & id,
|
||||||
}
|
}
|
||||||
}();
|
}();
|
||||||
|
|
||||||
try {
|
|
||||||
callback(std::shared_ptr<const Realisation>(real));
|
callback(std::shared_ptr<const Realisation>(real));
|
||||||
} catch (...) { return callback.rethrow(); }
|
} catch (...) { return callback.rethrow(); }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,9 @@
|
||||||
(allow file*
|
(allow file*
|
||||||
(literal "/private/var/select/sh"))
|
(literal "/private/var/select/sh"))
|
||||||
|
|
||||||
; Allow Rosetta 2 to run x86_64 binaries on aarch64-darwin.
|
; Allow Rosetta 2 to run x86_64 binaries on aarch64-darwin (and vice versa).
|
||||||
(allow file-read*
|
(allow file-read*
|
||||||
(subpath "/Library/Apple/usr/libexec/oah")
|
(subpath "/Library/Apple/usr/libexec/oah")
|
||||||
(subpath "/System/Library/Apple/usr/libexec/oah"))
|
(subpath "/System/Library/Apple/usr/libexec/oah")
|
||||||
|
(subpath "/System/Library/LaunchDaemons/com.apple.oahd.plist")
|
||||||
|
(subpath "/Library/Apple/System/Library/LaunchDaemons/com.apple.oahd.plist"))
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
create table if not exists ValidPaths (
|
create table if not exists ValidPaths (
|
||||||
id integer primary key autoincrement not null,
|
id integer primary key autoincrement not null,
|
||||||
path text unique not null,
|
path text unique not null,
|
||||||
hash text not null,
|
hash text not null, -- base16 representation
|
||||||
registrationTime integer not null,
|
registrationTime integer not null,
|
||||||
deriver text,
|
deriver text,
|
||||||
narSize integer,
|
narSize integer,
|
||||||
|
|
|
||||||
|
|
@ -1302,7 +1302,8 @@ std::pair<std::string, Store::Params> splitUriAndParams(const std::string & uri_
|
||||||
return {uri, params};
|
return {uri, params};
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isNonUriPath(const std::string & spec) {
|
static bool isNonUriPath(const std::string & spec)
|
||||||
|
{
|
||||||
return
|
return
|
||||||
// is not a URL
|
// is not a URL
|
||||||
spec.find("://") == std::string::npos
|
spec.find("://") == std::string::npos
|
||||||
|
|
@ -1319,6 +1320,31 @@ std::shared_ptr<Store> openFromNonUri(const std::string & uri, const Store::Para
|
||||||
return std::make_shared<LocalStore>(params);
|
return std::make_shared<LocalStore>(params);
|
||||||
else if (pathExists(settings.nixDaemonSocketFile))
|
else if (pathExists(settings.nixDaemonSocketFile))
|
||||||
return std::make_shared<UDSRemoteStore>(params);
|
return std::make_shared<UDSRemoteStore>(params);
|
||||||
|
#if __linux__
|
||||||
|
else if (!pathExists(stateDir)
|
||||||
|
&& params.empty()
|
||||||
|
&& getuid() != 0
|
||||||
|
&& !getEnv("NIX_STORE_DIR").has_value()
|
||||||
|
&& !getEnv("NIX_STATE_DIR").has_value())
|
||||||
|
{
|
||||||
|
/* If /nix doesn't exist, there is no daemon socket, and
|
||||||
|
we're not root, then automatically set up a chroot
|
||||||
|
store in ~/.local/share/nix/root. */
|
||||||
|
auto chrootStore = getDataDir() + "/nix/root";
|
||||||
|
if (!pathExists(chrootStore)) {
|
||||||
|
try {
|
||||||
|
createDirs(chrootStore);
|
||||||
|
} catch (Error & e) {
|
||||||
|
return std::make_shared<LocalStore>(params);
|
||||||
|
}
|
||||||
|
warn("'/nix' does not exist, so Nix will use '%s' as a chroot store", chrootStore);
|
||||||
|
} else
|
||||||
|
debug("'/nix' does not exist, so Nix will use '%s' as a chroot store", chrootStore);
|
||||||
|
Store::Params params2;
|
||||||
|
params2["root"] = chrootStore;
|
||||||
|
return std::make_shared<LocalStore>(params2);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
else
|
else
|
||||||
return std::make_shared<LocalStore>(params);
|
return std::make_shared<LocalStore>(params);
|
||||||
} else if (uri == "daemon") {
|
} else if (uri == "daemon") {
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ bool Args::processFlag(Strings::iterator & pos, Strings::iterator end)
|
||||||
bool anyCompleted = false;
|
bool anyCompleted = false;
|
||||||
for (size_t n = 0 ; n < flag.handler.arity; ++n) {
|
for (size_t n = 0 ; n < flag.handler.arity; ++n) {
|
||||||
if (pos == end) {
|
if (pos == end) {
|
||||||
if (flag.handler.arity == ArityAny) break;
|
if (flag.handler.arity == ArityAny || anyCompleted) break;
|
||||||
throw UsageError("flag '%s' requires %d argument(s)", name, flag.handler.arity);
|
throw UsageError("flag '%s' requires %d argument(s)", name, flag.handler.arity);
|
||||||
}
|
}
|
||||||
if (auto prefix = needsCompletion(*pos)) {
|
if (auto prefix = needsCompletion(*pos)) {
|
||||||
|
|
@ -362,6 +362,14 @@ bool MultiCommand::processArgs(const Strings & args, bool finish)
|
||||||
return Args::processArgs(args, finish);
|
return Args::processArgs(args, finish);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MultiCommand::completionHook()
|
||||||
|
{
|
||||||
|
if (command)
|
||||||
|
return command->second->completionHook();
|
||||||
|
else
|
||||||
|
return Args::completionHook();
|
||||||
|
}
|
||||||
|
|
||||||
nlohmann::json MultiCommand::toJSON()
|
nlohmann::json MultiCommand::toJSON()
|
||||||
{
|
{
|
||||||
auto cmds = nlohmann::json::object();
|
auto cmds = nlohmann::json::object();
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@ public:
|
||||||
/* Return a short one-line description of the command. */
|
/* Return a short one-line description of the command. */
|
||||||
virtual std::string description() { return ""; }
|
virtual std::string description() { return ""; }
|
||||||
|
|
||||||
|
virtual bool forceImpureByDefault() { return false; }
|
||||||
|
|
||||||
/* Return documentation about this command, in Markdown format. */
|
/* Return documentation about this command, in Markdown format. */
|
||||||
virtual std::string doc() { return ""; }
|
virtual std::string doc() { return ""; }
|
||||||
|
|
||||||
|
|
@ -146,6 +148,11 @@ protected:
|
||||||
argument (if any) have been processed. */
|
argument (if any) have been processed. */
|
||||||
virtual void initialFlagsProcessed() {}
|
virtual void initialFlagsProcessed() {}
|
||||||
|
|
||||||
|
/* Called after the command line has been processed if we need to generate
|
||||||
|
completions. Useful for commands that need to know the whole command line
|
||||||
|
in order to know what completions to generate. */
|
||||||
|
virtual void completionHook() { }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void addFlag(Flag && flag);
|
void addFlag(Flag && flag);
|
||||||
|
|
@ -221,6 +228,8 @@ public:
|
||||||
|
|
||||||
bool processArgs(const Strings & args, bool finish) override;
|
bool processArgs(const Strings & args, bool finish) override;
|
||||||
|
|
||||||
|
void completionHook() override;
|
||||||
|
|
||||||
nlohmann::json toJSON() override;
|
nlohmann::json toJSON() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,15 @@ struct ErrPos {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::optional<LinesOfCode> getCodeLines(const ErrPos & errPos);
|
||||||
|
|
||||||
|
void printCodeLines(std::ostream & out,
|
||||||
|
const std::string & prefix,
|
||||||
|
const ErrPos & errPos,
|
||||||
|
const LinesOfCode & loc);
|
||||||
|
|
||||||
|
void printAtPos(const ErrPos & pos, std::ostream & out);
|
||||||
|
|
||||||
struct Trace {
|
struct Trace {
|
||||||
std::optional<ErrPos> pos;
|
std::optional<ErrPos> pos;
|
||||||
hintformat hint;
|
hintformat hint;
|
||||||
|
|
@ -195,13 +204,19 @@ public:
|
||||||
int errNo;
|
int errNo;
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
SysError(const Args & ... args)
|
SysError(int errNo_, const Args & ... args)
|
||||||
: Error("")
|
: Error("")
|
||||||
{
|
{
|
||||||
errNo = errno;
|
errNo = errNo_;
|
||||||
auto hf = hintfmt(args...);
|
auto hf = hintfmt(args...);
|
||||||
err.msg = hintfmt("%1%: %2%", normaltxt(hf.str()), strerror(errNo));
|
err.msg = hintfmt("%1%: %2%", normaltxt(hf.str()), strerror(errNo));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename... Args>
|
||||||
|
SysError(const Args & ... args)
|
||||||
|
: SysError(errno, args ...)
|
||||||
|
{
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ std::map<ExperimentalFeature, std::string> stringifiedXpFeatures = {
|
||||||
{ Xp::RecursiveNix, "recursive-nix" },
|
{ Xp::RecursiveNix, "recursive-nix" },
|
||||||
{ Xp::NoUrlLiterals, "no-url-literals" },
|
{ Xp::NoUrlLiterals, "no-url-literals" },
|
||||||
{ Xp::FetchClosure, "fetch-closure" },
|
{ Xp::FetchClosure, "fetch-closure" },
|
||||||
|
{ Xp::ReplFlake, "repl-flake" },
|
||||||
};
|
};
|
||||||
|
|
||||||
const std::optional<ExperimentalFeature> parseExperimentalFeature(const std::string_view & name)
|
const std::optional<ExperimentalFeature> parseExperimentalFeature(const std::string_view & name)
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ enum struct ExperimentalFeature
|
||||||
RecursiveNix,
|
RecursiveNix,
|
||||||
NoUrlLiterals,
|
NoUrlLiterals,
|
||||||
FetchClosure,
|
FetchClosure,
|
||||||
|
ReplFlake,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
25
src/libutil/git.cc
Normal file
25
src/libutil/git.cc
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
#include "git.hh"
|
||||||
|
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
|
namespace nix {
|
||||||
|
namespace git {
|
||||||
|
|
||||||
|
std::optional<LsRemoteRefLine> parseLsRemoteLine(std::string_view line)
|
||||||
|
{
|
||||||
|
const static std::regex line_regex("^(ref: *)?([^\\s]+)(?:\\t+(.*))?$");
|
||||||
|
std::match_results<std::string_view::const_iterator> match;
|
||||||
|
if (!std::regex_match(line.cbegin(), line.cend(), match, line_regex))
|
||||||
|
return std::nullopt;
|
||||||
|
|
||||||
|
return LsRemoteRefLine {
|
||||||
|
.kind = match[1].length() == 0
|
||||||
|
? LsRemoteRefLine::Kind::Object
|
||||||
|
: LsRemoteRefLine::Kind::Symbolic,
|
||||||
|
.target = match[2],
|
||||||
|
.reference = match[3].length() == 0 ? std::nullopt : std::optional<std::string>{ match[3] }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
40
src/libutil/git.hh
Normal file
40
src/libutil/git.hh
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
|
namespace nix {
|
||||||
|
|
||||||
|
namespace git {
|
||||||
|
|
||||||
|
// A line from the output of `git ls-remote --symref`.
|
||||||
|
//
|
||||||
|
// These can be of two kinds:
|
||||||
|
//
|
||||||
|
// - Symbolic references of the form
|
||||||
|
//
|
||||||
|
// ref: {target} {reference}
|
||||||
|
//
|
||||||
|
// where {target} is itself a reference and {reference} is optional
|
||||||
|
//
|
||||||
|
// - Object references of the form
|
||||||
|
//
|
||||||
|
// {target} {reference}
|
||||||
|
//
|
||||||
|
// where {target} is a commit id and {reference} is mandatory
|
||||||
|
struct LsRemoteRefLine {
|
||||||
|
enum struct Kind {
|
||||||
|
Symbolic,
|
||||||
|
Object
|
||||||
|
};
|
||||||
|
Kind kind;
|
||||||
|
std::string target;
|
||||||
|
std::optional<std::string> reference;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::optional<LsRemoteRefLine> parseLsRemoteLine(std::string_view line);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -8,9 +8,9 @@ std::string hiliteMatches(
|
||||||
std::string_view prefix,
|
std::string_view prefix,
|
||||||
std::string_view postfix)
|
std::string_view postfix)
|
||||||
{
|
{
|
||||||
// Avoid copy on zero matches
|
// Avoid extra work on zero matches
|
||||||
if (matches.size() == 0)
|
if (matches.size() == 0)
|
||||||
return (std::string) s;
|
return std::string(s);
|
||||||
|
|
||||||
std::sort(matches.begin(), matches.end(), [](const auto & a, const auto & b) {
|
std::sort(matches.begin(), matches.end(), [](const auto & a, const auto & b) {
|
||||||
return a.position() < b.position();
|
return a.position() < b.position();
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue