Merge remote-tracking branch 'origin/master' into cli-guideline

This commit is contained in:
Rok Garbas 2020-12-07 15:13:36 +01:00
commit 24db5b125f
No known key found for this signature in database
GPG key ID: A0E01EF44C27BF00
78 changed files with 2092 additions and 1536 deletions

3
.gitignore vendored
View file

@ -18,7 +18,8 @@ perl/Makefile.config
/doc/manual/nix.json /doc/manual/nix.json
/doc/manual/conf-file.json /doc/manual/conf-file.json
/doc/manual/builtins.json /doc/manual/builtins.json
/doc/manual/src/command-ref/nix.md /doc/manual/src/SUMMARY.md
/doc/manual/src/command-ref/new-cli
/doc/manual/src/command-ref/conf-file.md /doc/manual/src/command-ref/conf-file.md
/doc/manual/src/expressions/builtins.md /doc/manual/src/expressions/builtins.md

500
config/config.guess vendored
View file

@ -1,8 +1,8 @@
#! /bin/sh #! /bin/sh
# Attempt to guess a canonical system name. # Attempt to guess a canonical system name.
# Copyright 1992-2018 Free Software Foundation, Inc. # Copyright 1992-2020 Free Software Foundation, Inc.
timestamp='2018-08-02' timestamp='2020-11-19'
# This file is free software; you can redistribute it and/or modify it # This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by # under the terms of the GNU General Public License as published by
@ -27,12 +27,12 @@ timestamp='2018-08-02'
# Originally written by Per Bothner; maintained since 2000 by Ben Elliston. # Originally written by Per Bothner; maintained since 2000 by Ben Elliston.
# #
# You can get the latest version of this script from: # You can get the latest version of this script from:
# https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess # https://git.savannah.gnu.org/cgit/config.git/plain/config.guess
# #
# Please send patches to <config-patches@gnu.org>. # Please send patches to <config-patches@gnu.org>.
me=`echo "$0" | sed -e 's,.*/,,'` me=$(echo "$0" | sed -e 's,.*/,,')
usage="\ usage="\
Usage: $0 [OPTION] Usage: $0 [OPTION]
@ -50,7 +50,7 @@ version="\
GNU config.guess ($timestamp) GNU config.guess ($timestamp)
Originally written by Per Bothner. Originally written by Per Bothner.
Copyright 1992-2018 Free Software Foundation, Inc. Copyright 1992-2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@ -96,13 +96,14 @@ fi
tmp= tmp=
# shellcheck disable=SC2172 # shellcheck disable=SC2172
trap 'test -z "$tmp" || rm -fr "$tmp"' 1 2 13 15 trap 'test -z "$tmp" || rm -fr "$tmp"' 0 1 2 13 15
trap 'exitcode=$?; test -z "$tmp" || rm -fr "$tmp"; exit $exitcode' 0
set_cc_for_build() { set_cc_for_build() {
# prevent multiple calls if $tmp is already set
test "$tmp" && return 0
: "${TMPDIR=/tmp}" : "${TMPDIR=/tmp}"
# shellcheck disable=SC2039 # shellcheck disable=SC2039
{ tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || { tmp=$( (umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null) && test -n "$tmp" && test -d "$tmp" ; } ||
{ test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir "$tmp" 2>/dev/null) ; } || { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir "$tmp" 2>/dev/null) ; } ||
{ tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir "$tmp" 2>/dev/null) && echo "Warning: creating insecure temp directory" >&2 ; } || { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir "$tmp" 2>/dev/null) && echo "Warning: creating insecure temp directory" >&2 ; } ||
{ echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; }
@ -130,16 +131,14 @@ if test -f /.attbin/uname ; then
PATH=$PATH:/.attbin ; export PATH PATH=$PATH:/.attbin ; export PATH
fi fi
UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown UNAME_MACHINE=$( (uname -m) 2>/dev/null) || UNAME_MACHINE=unknown
UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown UNAME_RELEASE=$( (uname -r) 2>/dev/null) || UNAME_RELEASE=unknown
UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown UNAME_SYSTEM=$( (uname -s) 2>/dev/null) || UNAME_SYSTEM=unknown
UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown UNAME_VERSION=$( (uname -v) 2>/dev/null) || UNAME_VERSION=unknown
case "$UNAME_SYSTEM" in case "$UNAME_SYSTEM" in
Linux|GNU|GNU/*) Linux|GNU|GNU/*)
# If the system lacks a compiler, then just pick glibc. LIBC=unknown
# We could probably try harder.
LIBC=gnu
set_cc_for_build set_cc_for_build
cat <<-EOF > "$dummy.c" cat <<-EOF > "$dummy.c"
@ -148,18 +147,30 @@ Linux|GNU|GNU/*)
LIBC=uclibc LIBC=uclibc
#elif defined(__dietlibc__) #elif defined(__dietlibc__)
LIBC=dietlibc LIBC=dietlibc
#else #elif defined(__GLIBC__)
LIBC=gnu LIBC=gnu
#else
#include <stdarg.h>
/* First heuristic to detect musl libc. */
#ifdef __DEFINED_va_list
LIBC=musl
#endif
#endif #endif
EOF EOF
eval "`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g'`" eval "$($CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g')"
# If ldd exists, use it to detect musl libc. # Second heuristic to detect musl libc.
if command -v ldd >/dev/null && \ if [ "$LIBC" = unknown ] &&
ldd --version 2>&1 | grep -q ^musl command -v ldd >/dev/null &&
then ldd --version 2>&1 | grep -q ^musl; then
LIBC=musl LIBC=musl
fi fi
# If the system lacks a compiler, then just pick glibc.
# We could probably try harder.
if [ "$LIBC" = unknown ]; then
LIBC=gnu
fi
;; ;;
esac esac
@ -178,19 +189,20 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in
# Note: NetBSD doesn't particularly care about the vendor # Note: NetBSD doesn't particularly care about the vendor
# portion of the name. We always set it to "unknown". # portion of the name. We always set it to "unknown".
sysctl="sysctl -n hw.machine_arch" sysctl="sysctl -n hw.machine_arch"
UNAME_MACHINE_ARCH=`(uname -p 2>/dev/null || \ UNAME_MACHINE_ARCH=$( (uname -p 2>/dev/null || \
"/sbin/$sysctl" 2>/dev/null || \ "/sbin/$sysctl" 2>/dev/null || \
"/usr/sbin/$sysctl" 2>/dev/null || \ "/usr/sbin/$sysctl" 2>/dev/null || \
echo unknown)` echo unknown))
case "$UNAME_MACHINE_ARCH" in case "$UNAME_MACHINE_ARCH" in
aarch64eb) machine=aarch64_be-unknown ;;
armeb) machine=armeb-unknown ;; armeb) machine=armeb-unknown ;;
arm*) machine=arm-unknown ;; arm*) machine=arm-unknown ;;
sh3el) machine=shl-unknown ;; sh3el) machine=shl-unknown ;;
sh3eb) machine=sh-unknown ;; sh3eb) machine=sh-unknown ;;
sh5el) machine=sh5le-unknown ;; sh5el) machine=sh5le-unknown ;;
earmv*) earmv*)
arch=`echo "$UNAME_MACHINE_ARCH" | sed -e 's,^e\(armv[0-9]\).*$,\1,'` arch=$(echo "$UNAME_MACHINE_ARCH" | sed -e 's,^e\(armv[0-9]\).*$,\1,')
endian=`echo "$UNAME_MACHINE_ARCH" | sed -ne 's,^.*\(eb\)$,\1,p'` endian=$(echo "$UNAME_MACHINE_ARCH" | sed -ne 's,^.*\(eb\)$,\1,p')
machine="${arch}${endian}"-unknown machine="${arch}${endian}"-unknown
;; ;;
*) machine="$UNAME_MACHINE_ARCH"-unknown ;; *) machine="$UNAME_MACHINE_ARCH"-unknown ;;
@ -221,7 +233,7 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in
case "$UNAME_MACHINE_ARCH" in case "$UNAME_MACHINE_ARCH" in
earm*) earm*)
expr='s/^earmv[0-9]/-eabi/;s/eb$//' expr='s/^earmv[0-9]/-eabi/;s/eb$//'
abi=`echo "$UNAME_MACHINE_ARCH" | sed -e "$expr"` abi=$(echo "$UNAME_MACHINE_ARCH" | sed -e "$expr")
;; ;;
esac esac
# The OS release # The OS release
@ -234,7 +246,7 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in
release='-gnu' release='-gnu'
;; ;;
*) *)
release=`echo "$UNAME_RELEASE" | sed -e 's/[-_].*//' | cut -d. -f1,2` release=$(echo "$UNAME_RELEASE" | sed -e 's/[-_].*//' | cut -d. -f1,2)
;; ;;
esac esac
# Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
@ -243,15 +255,15 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in
echo "$machine-${os}${release}${abi-}" echo "$machine-${os}${release}${abi-}"
exit ;; exit ;;
*:Bitrig:*:*) *:Bitrig:*:*)
UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'` UNAME_MACHINE_ARCH=$(arch | sed 's/Bitrig.//')
echo "$UNAME_MACHINE_ARCH"-unknown-bitrig"$UNAME_RELEASE" echo "$UNAME_MACHINE_ARCH"-unknown-bitrig"$UNAME_RELEASE"
exit ;; exit ;;
*:OpenBSD:*:*) *:OpenBSD:*:*)
UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` UNAME_MACHINE_ARCH=$(arch | sed 's/OpenBSD.//')
echo "$UNAME_MACHINE_ARCH"-unknown-openbsd"$UNAME_RELEASE" echo "$UNAME_MACHINE_ARCH"-unknown-openbsd"$UNAME_RELEASE"
exit ;; exit ;;
*:LibertyBSD:*:*) *:LibertyBSD:*:*)
UNAME_MACHINE_ARCH=`arch | sed 's/^.*BSD\.//'` UNAME_MACHINE_ARCH=$(arch | sed 's/^.*BSD\.//')
echo "$UNAME_MACHINE_ARCH"-unknown-libertybsd"$UNAME_RELEASE" echo "$UNAME_MACHINE_ARCH"-unknown-libertybsd"$UNAME_RELEASE"
exit ;; exit ;;
*:MidnightBSD:*:*) *:MidnightBSD:*:*)
@ -263,6 +275,9 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in
*:SolidBSD:*:*) *:SolidBSD:*:*)
echo "$UNAME_MACHINE"-unknown-solidbsd"$UNAME_RELEASE" echo "$UNAME_MACHINE"-unknown-solidbsd"$UNAME_RELEASE"
exit ;; exit ;;
*:OS108:*:*)
echo "$UNAME_MACHINE"-unknown-os108_"$UNAME_RELEASE"
exit ;;
macppc:MirBSD:*:*) macppc:MirBSD:*:*)
echo powerpc-unknown-mirbsd"$UNAME_RELEASE" echo powerpc-unknown-mirbsd"$UNAME_RELEASE"
exit ;; exit ;;
@ -272,6 +287,9 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in
*:Sortix:*:*) *:Sortix:*:*)
echo "$UNAME_MACHINE"-unknown-sortix echo "$UNAME_MACHINE"-unknown-sortix
exit ;; exit ;;
*:Twizzler:*:*)
echo "$UNAME_MACHINE"-unknown-twizzler
exit ;;
*:Redox:*:*) *:Redox:*:*)
echo "$UNAME_MACHINE"-unknown-redox echo "$UNAME_MACHINE"-unknown-redox
exit ;; exit ;;
@ -281,17 +299,17 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in
alpha:OSF1:*:*) alpha:OSF1:*:*)
case $UNAME_RELEASE in case $UNAME_RELEASE in
*4.0) *4.0)
UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` UNAME_RELEASE=$(/usr/sbin/sizer -v | awk '{print $3}')
;; ;;
*5.*) *5.*)
UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` UNAME_RELEASE=$(/usr/sbin/sizer -v | awk '{print $4}')
;; ;;
esac esac
# According to Compaq, /usr/sbin/psrinfo has been available on # According to Compaq, /usr/sbin/psrinfo has been available on
# OSF/1 and Tru64 systems produced since 1995. I hope that # OSF/1 and Tru64 systems produced since 1995. I hope that
# covers most systems running today. This code pipes the CPU # covers most systems running today. This code pipes the CPU
# types through head -n 1, so we only detect the type of CPU 0. # types through head -n 1, so we only detect the type of CPU 0.
ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` ALPHA_CPU_TYPE=$(/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1)
case "$ALPHA_CPU_TYPE" in case "$ALPHA_CPU_TYPE" in
"EV4 (21064)") "EV4 (21064)")
UNAME_MACHINE=alpha ;; UNAME_MACHINE=alpha ;;
@ -329,7 +347,7 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in
# A Tn.n version is a released field test version. # A Tn.n version is a released field test version.
# A Xn.n version is an unreleased experimental baselevel. # A Xn.n version is an unreleased experimental baselevel.
# 1.2 uses "1.2" for uname -r. # 1.2 uses "1.2" for uname -r.
echo "$UNAME_MACHINE"-dec-osf"`echo "$UNAME_RELEASE" | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`" echo "$UNAME_MACHINE"-dec-osf"$(echo "$UNAME_RELEASE" | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz)"
# Reset EXIT trap before exiting to avoid spurious non-zero exit code. # Reset EXIT trap before exiting to avoid spurious non-zero exit code.
exitcode=$? exitcode=$?
trap '' 0 trap '' 0
@ -363,7 +381,7 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in
exit ;; exit ;;
Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*)
# akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE.
if test "`(/bin/universe) 2>/dev/null`" = att ; then if test "$( (/bin/universe) 2>/dev/null)" = att ; then
echo pyramid-pyramid-sysv3 echo pyramid-pyramid-sysv3
else else
echo pyramid-pyramid-bsd echo pyramid-pyramid-bsd
@ -376,54 +394,59 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in
echo sparc-icl-nx6 echo sparc-icl-nx6
exit ;; exit ;;
DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*)
case `/usr/bin/uname -p` in case $(/usr/bin/uname -p) in
sparc) echo sparc-icl-nx7; exit ;; sparc) echo sparc-icl-nx7; exit ;;
esac ;; esac ;;
s390x:SunOS:*:*) s390x:SunOS:*:*)
echo "$UNAME_MACHINE"-ibm-solaris2"`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`" echo "$UNAME_MACHINE"-ibm-solaris2"$(echo "$UNAME_RELEASE" | sed -e 's/[^.]*//')"
exit ;; exit ;;
sun4H:SunOS:5.*:*) sun4H:SunOS:5.*:*)
echo sparc-hal-solaris2"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`" echo sparc-hal-solaris2"$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*//')"
exit ;; exit ;;
sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
echo sparc-sun-solaris2"`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`" echo sparc-sun-solaris2"$(echo "$UNAME_RELEASE" | sed -e 's/[^.]*//')"
exit ;; exit ;;
i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*) i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*)
echo i386-pc-auroraux"$UNAME_RELEASE" echo i386-pc-auroraux"$UNAME_RELEASE"
exit ;; exit ;;
i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*)
UNAME_REL="`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`" set_cc_for_build
case `isainfo -b` in SUN_ARCH=i386
32) # If there is a compiler, see if it is configured for 64-bit objects.
echo i386-pc-solaris2"$UNAME_REL" # Note that the Sun cc does not turn __LP64__ into 1 like gcc does.
;; # This test works for both compilers.
64) if test "$CC_FOR_BUILD" != no_compiler_found; then
echo x86_64-pc-solaris2"$UNAME_REL" if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \
;; (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
esac grep IS_64BIT_ARCH >/dev/null
then
SUN_ARCH=x86_64
fi
fi
echo "$SUN_ARCH"-pc-solaris2"$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*//')"
exit ;; exit ;;
sun4*:SunOS:6*:*) sun4*:SunOS:6*:*)
# According to config.sub, this is the proper way to canonicalize # According to config.sub, this is the proper way to canonicalize
# SunOS6. Hard to guess exactly what SunOS6 will be like, but # SunOS6. Hard to guess exactly what SunOS6 will be like, but
# it's likely to be more like Solaris than SunOS4. # it's likely to be more like Solaris than SunOS4.
echo sparc-sun-solaris3"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`" echo sparc-sun-solaris3"$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*//')"
exit ;; exit ;;
sun4*:SunOS:*:*) sun4*:SunOS:*:*)
case "`/usr/bin/arch -k`" in case "$(/usr/bin/arch -k)" in
Series*|S4*) Series*|S4*)
UNAME_RELEASE=`uname -v` UNAME_RELEASE=$(uname -v)
;; ;;
esac esac
# Japanese Language versions have a version number like `4.1.3-JL'. # Japanese Language versions have a version number like `4.1.3-JL'.
echo sparc-sun-sunos"`echo "$UNAME_RELEASE"|sed -e 's/-/_/'`" echo sparc-sun-sunos"$(echo "$UNAME_RELEASE"|sed -e 's/-/_/')"
exit ;; exit ;;
sun3*:SunOS:*:*) sun3*:SunOS:*:*)
echo m68k-sun-sunos"$UNAME_RELEASE" echo m68k-sun-sunos"$UNAME_RELEASE"
exit ;; exit ;;
sun*:*:4.2BSD:*) sun*:*:4.2BSD:*)
UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` UNAME_RELEASE=$( (sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null)
test "x$UNAME_RELEASE" = x && UNAME_RELEASE=3 test "x$UNAME_RELEASE" = x && UNAME_RELEASE=3
case "`/bin/arch`" in case "$(/bin/arch)" in
sun3) sun3)
echo m68k-sun-sunos"$UNAME_RELEASE" echo m68k-sun-sunos"$UNAME_RELEASE"
;; ;;
@ -503,8 +526,8 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in
} }
EOF EOF
$CC_FOR_BUILD -o "$dummy" "$dummy.c" && $CC_FOR_BUILD -o "$dummy" "$dummy.c" &&
dummyarg=`echo "$UNAME_RELEASE" | sed -n 's/\([0-9]*\).*/\1/p'` && dummyarg=$(echo "$UNAME_RELEASE" | sed -n 's/\([0-9]*\).*/\1/p') &&
SYSTEM_NAME=`"$dummy" "$dummyarg"` && SYSTEM_NAME=$("$dummy" "$dummyarg") &&
{ echo "$SYSTEM_NAME"; exit; } { echo "$SYSTEM_NAME"; exit; }
echo mips-mips-riscos"$UNAME_RELEASE" echo mips-mips-riscos"$UNAME_RELEASE"
exit ;; exit ;;
@ -531,11 +554,11 @@ EOF
exit ;; exit ;;
AViiON:dgux:*:*) AViiON:dgux:*:*)
# DG/UX returns AViiON for all architectures # DG/UX returns AViiON for all architectures
UNAME_PROCESSOR=`/usr/bin/uname -p` UNAME_PROCESSOR=$(/usr/bin/uname -p)
if [ "$UNAME_PROCESSOR" = mc88100 ] || [ "$UNAME_PROCESSOR" = mc88110 ] if test "$UNAME_PROCESSOR" = mc88100 || test "$UNAME_PROCESSOR" = mc88110
then then
if [ "$TARGET_BINARY_INTERFACE"x = m88kdguxelfx ] || \ if test "$TARGET_BINARY_INTERFACE"x = m88kdguxelfx || \
[ "$TARGET_BINARY_INTERFACE"x = x ] test "$TARGET_BINARY_INTERFACE"x = x
then then
echo m88k-dg-dgux"$UNAME_RELEASE" echo m88k-dg-dgux"$UNAME_RELEASE"
else else
@ -559,17 +582,17 @@ EOF
echo m68k-tektronix-bsd echo m68k-tektronix-bsd
exit ;; exit ;;
*:IRIX*:*:*) *:IRIX*:*:*)
echo mips-sgi-irix"`echo "$UNAME_RELEASE"|sed -e 's/-/_/g'`" echo mips-sgi-irix"$(echo "$UNAME_RELEASE"|sed -e 's/-/_/g')"
exit ;; exit ;;
????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id
exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' exit ;; # Note that: echo "'$(uname -s)'" gives 'AIX '
i*86:AIX:*:*) i*86:AIX:*:*)
echo i386-ibm-aix echo i386-ibm-aix
exit ;; exit ;;
ia64:AIX:*:*) ia64:AIX:*:*)
if [ -x /usr/bin/oslevel ] ; then if test -x /usr/bin/oslevel ; then
IBM_REV=`/usr/bin/oslevel` IBM_REV=$(/usr/bin/oslevel)
else else
IBM_REV="$UNAME_VERSION.$UNAME_RELEASE" IBM_REV="$UNAME_VERSION.$UNAME_RELEASE"
fi fi
@ -589,7 +612,7 @@ EOF
exit(0); exit(0);
} }
EOF EOF
if $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` if $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=$("$dummy")
then then
echo "$SYSTEM_NAME" echo "$SYSTEM_NAME"
else else
@ -602,15 +625,15 @@ EOF
fi fi
exit ;; exit ;;
*:AIX:*:[4567]) *:AIX:*:[4567])
IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` IBM_CPU_ID=$(/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }')
if /usr/sbin/lsattr -El "$IBM_CPU_ID" | grep ' POWER' >/dev/null 2>&1; then if /usr/sbin/lsattr -El "$IBM_CPU_ID" | grep ' POWER' >/dev/null 2>&1; then
IBM_ARCH=rs6000 IBM_ARCH=rs6000
else else
IBM_ARCH=powerpc IBM_ARCH=powerpc
fi fi
if [ -x /usr/bin/lslpp ] ; then if test -x /usr/bin/lslpp ; then
IBM_REV=`/usr/bin/lslpp -Lqc bos.rte.libc | IBM_REV=$(/usr/bin/lslpp -Lqc bos.rte.libc |
awk -F: '{ print $3 }' | sed s/[0-9]*$/0/` awk -F: '{ print $3 }' | sed s/[0-9]*$/0/)
else else
IBM_REV="$UNAME_VERSION.$UNAME_RELEASE" IBM_REV="$UNAME_VERSION.$UNAME_RELEASE"
fi fi
@ -638,14 +661,14 @@ EOF
echo m68k-hp-bsd4.4 echo m68k-hp-bsd4.4
exit ;; exit ;;
9000/[34678]??:HP-UX:*:*) 9000/[34678]??:HP-UX:*:*)
HPUX_REV=`echo "$UNAME_RELEASE"|sed -e 's/[^.]*.[0B]*//'` HPUX_REV=$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*.[0B]*//')
case "$UNAME_MACHINE" in case "$UNAME_MACHINE" in
9000/31?) HP_ARCH=m68000 ;; 9000/31?) HP_ARCH=m68000 ;;
9000/[34]??) HP_ARCH=m68k ;; 9000/[34]??) HP_ARCH=m68k ;;
9000/[678][0-9][0-9]) 9000/[678][0-9][0-9])
if [ -x /usr/bin/getconf ]; then if test -x /usr/bin/getconf; then
sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` sc_cpu_version=$(/usr/bin/getconf SC_CPU_VERSION 2>/dev/null)
sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` sc_kernel_bits=$(/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null)
case "$sc_cpu_version" in case "$sc_cpu_version" in
523) HP_ARCH=hppa1.0 ;; # CPU_PA_RISC1_0 523) HP_ARCH=hppa1.0 ;; # CPU_PA_RISC1_0
528) HP_ARCH=hppa1.1 ;; # CPU_PA_RISC1_1 528) HP_ARCH=hppa1.1 ;; # CPU_PA_RISC1_1
@ -657,7 +680,7 @@ EOF
esac ;; esac ;;
esac esac
fi fi
if [ "$HP_ARCH" = "" ]; then if test "$HP_ARCH" = ""; then
set_cc_for_build set_cc_for_build
sed 's/^ //' << EOF > "$dummy.c" sed 's/^ //' << EOF > "$dummy.c"
@ -692,11 +715,11 @@ EOF
exit (0); exit (0);
} }
EOF EOF
(CCOPTS="" $CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null) && HP_ARCH=`"$dummy"` (CCOPTS="" $CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null) && HP_ARCH=$("$dummy")
test -z "$HP_ARCH" && HP_ARCH=hppa test -z "$HP_ARCH" && HP_ARCH=hppa
fi ;; fi ;;
esac esac
if [ "$HP_ARCH" = hppa2.0w ] if test "$HP_ARCH" = hppa2.0w
then then
set_cc_for_build set_cc_for_build
@ -720,7 +743,7 @@ EOF
echo "$HP_ARCH"-hp-hpux"$HPUX_REV" echo "$HP_ARCH"-hp-hpux"$HPUX_REV"
exit ;; exit ;;
ia64:HP-UX:*:*) ia64:HP-UX:*:*)
HPUX_REV=`echo "$UNAME_RELEASE"|sed -e 's/[^.]*.[0B]*//'` HPUX_REV=$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*.[0B]*//')
echo ia64-hp-hpux"$HPUX_REV" echo ia64-hp-hpux"$HPUX_REV"
exit ;; exit ;;
3050*:HI-UX:*:*) 3050*:HI-UX:*:*)
@ -750,7 +773,7 @@ EOF
exit (0); exit (0);
} }
EOF EOF
$CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` && $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=$("$dummy") &&
{ echo "$SYSTEM_NAME"; exit; } { echo "$SYSTEM_NAME"; exit; }
echo unknown-hitachi-hiuxwe2 echo unknown-hitachi-hiuxwe2
exit ;; exit ;;
@ -770,7 +793,7 @@ EOF
echo hppa1.0-hp-osf echo hppa1.0-hp-osf
exit ;; exit ;;
i*86:OSF1:*:*) i*86:OSF1:*:*)
if [ -x /usr/sbin/sysversion ] ; then if test -x /usr/sbin/sysversion ; then
echo "$UNAME_MACHINE"-unknown-osf1mk echo "$UNAME_MACHINE"-unknown-osf1mk
else else
echo "$UNAME_MACHINE"-unknown-osf1 echo "$UNAME_MACHINE"-unknown-osf1
@ -819,14 +842,14 @@ EOF
echo craynv-cray-unicosmp"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' echo craynv-cray-unicosmp"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'
exit ;; exit ;;
F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
FUJITSU_PROC=`uname -m | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` FUJITSU_PROC=$(uname -m | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz)
FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` FUJITSU_SYS=$(uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///')
FUJITSU_REL=`echo "$UNAME_RELEASE" | sed -e 's/ /_/'` FUJITSU_REL=$(echo "$UNAME_RELEASE" | sed -e 's/ /_/')
echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
exit ;; exit ;;
5000:UNIX_System_V:4.*:*) 5000:UNIX_System_V:4.*:*)
FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` FUJITSU_SYS=$(uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///')
FUJITSU_REL=`echo "$UNAME_RELEASE" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/ /_/'` FUJITSU_REL=$(echo "$UNAME_RELEASE" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/ /_/')
echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
exit ;; exit ;;
i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
@ -838,26 +861,26 @@ EOF
*:BSD/OS:*:*) *:BSD/OS:*:*)
echo "$UNAME_MACHINE"-unknown-bsdi"$UNAME_RELEASE" echo "$UNAME_MACHINE"-unknown-bsdi"$UNAME_RELEASE"
exit ;; exit ;;
arm*:FreeBSD:*:*) arm:FreeBSD:*:*)
UNAME_PROCESSOR=`uname -p` UNAME_PROCESSOR=$(uname -p)
set_cc_for_build set_cc_for_build
if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \
| grep -q __ARM_PCS_VFP | grep -q __ARM_PCS_VFP
then then
echo "${UNAME_PROCESSOR}"-unknown-freebsd"`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`"-gnueabi echo "${UNAME_PROCESSOR}"-unknown-freebsd"$(echo ${UNAME_RELEASE}|sed -e 's/[-(].*//')"-gnueabi
else else
echo "${UNAME_PROCESSOR}"-unknown-freebsd"`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`"-gnueabihf echo "${UNAME_PROCESSOR}"-unknown-freebsd"$(echo ${UNAME_RELEASE}|sed -e 's/[-(].*//')"-gnueabihf
fi fi
exit ;; exit ;;
*:FreeBSD:*:*) *:FreeBSD:*:*)
UNAME_PROCESSOR=`/usr/bin/uname -p` UNAME_PROCESSOR=$(/usr/bin/uname -p)
case "$UNAME_PROCESSOR" in case "$UNAME_PROCESSOR" in
amd64) amd64)
UNAME_PROCESSOR=x86_64 ;; UNAME_PROCESSOR=x86_64 ;;
i386) i386)
UNAME_PROCESSOR=i586 ;; UNAME_PROCESSOR=i586 ;;
esac esac
echo "$UNAME_PROCESSOR"-unknown-freebsd"`echo "$UNAME_RELEASE"|sed -e 's/[-(].*//'`" echo "$UNAME_PROCESSOR"-unknown-freebsd"$(echo "$UNAME_RELEASE"|sed -e 's/[-(].*//')"
exit ;; exit ;;
i*:CYGWIN*:*) i*:CYGWIN*:*)
echo "$UNAME_MACHINE"-pc-cygwin echo "$UNAME_MACHINE"-pc-cygwin
@ -890,18 +913,18 @@ EOF
echo "$UNAME_MACHINE"-pc-uwin echo "$UNAME_MACHINE"-pc-uwin
exit ;; exit ;;
amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
echo x86_64-unknown-cygwin echo x86_64-pc-cygwin
exit ;; exit ;;
prep*:SunOS:5.*:*) prep*:SunOS:5.*:*)
echo powerpcle-unknown-solaris2"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`" echo powerpcle-unknown-solaris2"$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*//')"
exit ;; exit ;;
*:GNU:*:*) *:GNU:*:*)
# the GNU system # the GNU system
echo "`echo "$UNAME_MACHINE"|sed -e 's,[-/].*$,,'`-unknown-$LIBC`echo "$UNAME_RELEASE"|sed -e 's,/.*$,,'`" echo "$(echo "$UNAME_MACHINE"|sed -e 's,[-/].*$,,')-unknown-$LIBC$(echo "$UNAME_RELEASE"|sed -e 's,/.*$,,')"
exit ;; exit ;;
*:GNU/*:*:*) *:GNU/*:*:*)
# other systems with GNU libc and userland # other systems with GNU libc and userland
echo "$UNAME_MACHINE-unknown-`echo "$UNAME_SYSTEM" | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"``echo "$UNAME_RELEASE"|sed -e 's/[-(].*//'`-$LIBC" echo "$UNAME_MACHINE-unknown-$(echo "$UNAME_SYSTEM" | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]")$(echo "$UNAME_RELEASE"|sed -e 's/[-(].*//')-$LIBC"
exit ;; exit ;;
*:Minix:*:*) *:Minix:*:*)
echo "$UNAME_MACHINE"-unknown-minix echo "$UNAME_MACHINE"-unknown-minix
@ -914,7 +937,7 @@ EOF
echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
exit ;; exit ;;
alpha:Linux:*:*) alpha:Linux:*:*)
case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in case $(sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' /proc/cpuinfo 2>/dev/null) in
EV5) UNAME_MACHINE=alphaev5 ;; EV5) UNAME_MACHINE=alphaev5 ;;
EV56) UNAME_MACHINE=alphaev56 ;; EV56) UNAME_MACHINE=alphaev56 ;;
PCA56) UNAME_MACHINE=alphapca56 ;; PCA56) UNAME_MACHINE=alphapca56 ;;
@ -981,22 +1004,50 @@ EOF
exit ;; exit ;;
mips:Linux:*:* | mips64:Linux:*:*) mips:Linux:*:* | mips64:Linux:*:*)
set_cc_for_build set_cc_for_build
IS_GLIBC=0
test x"${LIBC}" = xgnu && IS_GLIBC=1
sed 's/^ //' << EOF > "$dummy.c" sed 's/^ //' << EOF > "$dummy.c"
#undef CPU #undef CPU
#undef ${UNAME_MACHINE} #undef mips
#undef ${UNAME_MACHINE}el #undef mipsel
#undef mips64
#undef mips64el
#if ${IS_GLIBC} && defined(_ABI64)
LIBCABI=gnuabi64
#else
#if ${IS_GLIBC} && defined(_ABIN32)
LIBCABI=gnuabin32
#else
LIBCABI=${LIBC}
#endif
#endif
#if ${IS_GLIBC} && defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6
CPU=mipsisa64r6
#else
#if ${IS_GLIBC} && !defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6
CPU=mipsisa32r6
#else
#if defined(__mips64)
CPU=mips64
#else
CPU=mips
#endif
#endif
#endif
#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
CPU=${UNAME_MACHINE}el MIPS_ENDIAN=el
#else #else
#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
CPU=${UNAME_MACHINE} MIPS_ENDIAN=
#else #else
CPU= MIPS_ENDIAN=
#endif #endif
#endif #endif
EOF EOF
eval "`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU'`" eval "$($CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU\|^MIPS_ENDIAN\|^LIBCABI')"
test "x$CPU" != x && { echo "$CPU-unknown-linux-$LIBC"; exit; } test "x$CPU" != x && { echo "$CPU${MIPS_ENDIAN}-unknown-linux-$LIBCABI"; exit; }
;; ;;
mips64el:Linux:*:*) mips64el:Linux:*:*)
echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
@ -1015,7 +1066,7 @@ EOF
exit ;; exit ;;
parisc:Linux:*:* | hppa:Linux:*:*) parisc:Linux:*:* | hppa:Linux:*:*)
# Look for CPU level # Look for CPU level
case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in case $(grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2) in
PA7*) echo hppa1.1-unknown-linux-"$LIBC" ;; PA7*) echo hppa1.1-unknown-linux-"$LIBC" ;;
PA8*) echo hppa2.0-unknown-linux-"$LIBC" ;; PA8*) echo hppa2.0-unknown-linux-"$LIBC" ;;
*) echo hppa-unknown-linux-"$LIBC" ;; *) echo hppa-unknown-linux-"$LIBC" ;;
@ -1055,7 +1106,17 @@ EOF
echo "$UNAME_MACHINE"-dec-linux-"$LIBC" echo "$UNAME_MACHINE"-dec-linux-"$LIBC"
exit ;; exit ;;
x86_64:Linux:*:*) x86_64:Linux:*:*)
echo "$UNAME_MACHINE"-pc-linux-"$LIBC" set_cc_for_build
LIBCABI=$LIBC
if test "$CC_FOR_BUILD" != no_compiler_found; then
if (echo '#ifdef __ILP32__'; echo IS_X32; echo '#endif') | \
(CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
grep IS_X32 >/dev/null
then
LIBCABI="$LIBC"x32
fi
fi
echo "$UNAME_MACHINE"-pc-linux-"$LIBCABI"
exit ;; exit ;;
xtensa*:Linux:*:*) xtensa*:Linux:*:*)
echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
@ -1095,7 +1156,7 @@ EOF
echo "$UNAME_MACHINE"-pc-msdosdjgpp echo "$UNAME_MACHINE"-pc-msdosdjgpp
exit ;; exit ;;
i*86:*:4.*:*) i*86:*:4.*:*)
UNAME_REL=`echo "$UNAME_RELEASE" | sed 's/\/MP$//'` UNAME_REL=$(echo "$UNAME_RELEASE" | sed 's/\/MP$//')
if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
echo "$UNAME_MACHINE"-univel-sysv"$UNAME_REL" echo "$UNAME_MACHINE"-univel-sysv"$UNAME_REL"
else else
@ -1104,19 +1165,19 @@ EOF
exit ;; exit ;;
i*86:*:5:[678]*) i*86:*:5:[678]*)
# UnixWare 7.x, OpenUNIX and OpenServer 6. # UnixWare 7.x, OpenUNIX and OpenServer 6.
case `/bin/uname -X | grep "^Machine"` in case $(/bin/uname -X | grep "^Machine") in
*486*) UNAME_MACHINE=i486 ;; *486*) UNAME_MACHINE=i486 ;;
*Pentium) UNAME_MACHINE=i586 ;; *Pentium) UNAME_MACHINE=i586 ;;
*Pent*|*Celeron) UNAME_MACHINE=i686 ;; *Pent*|*Celeron) UNAME_MACHINE=i686 ;;
esac esac
echo "$UNAME_MACHINE-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}{$UNAME_VERSION}" echo "$UNAME_MACHINE-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}"
exit ;; exit ;;
i*86:*:3.2:*) i*86:*:3.2:*)
if test -f /usr/options/cb.name; then if test -f /usr/options/cb.name; then
UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name` UNAME_REL=$(sed -n 's/.*Version //p' </usr/options/cb.name)
echo "$UNAME_MACHINE"-pc-isc"$UNAME_REL" echo "$UNAME_MACHINE"-pc-isc"$UNAME_REL"
elif /bin/uname -X 2>/dev/null >/dev/null ; then elif /bin/uname -X 2>/dev/null >/dev/null ; then
UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` UNAME_REL=$( (/bin/uname -X|grep Release|sed -e 's/.*= //'))
(/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486
(/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \
&& UNAME_MACHINE=i586 && UNAME_MACHINE=i586
@ -1166,7 +1227,7 @@ EOF
3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0)
OS_REL='' OS_REL=''
test -r /etc/.relid \ test -r /etc/.relid \
&& OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` && OS_REL=.$(sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid)
/bin/uname -p 2>/dev/null | grep 86 >/dev/null \ /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
&& { echo i486-ncr-sysv4.3"$OS_REL"; exit; } && { echo i486-ncr-sysv4.3"$OS_REL"; exit; }
/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
@ -1177,7 +1238,7 @@ EOF
NCR*:*:4.2:* | MPRAS*:*:4.2:*) NCR*:*:4.2:* | MPRAS*:*:4.2:*)
OS_REL='.3' OS_REL='.3'
test -r /etc/.relid \ test -r /etc/.relid \
&& OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` && OS_REL=.$(sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid)
/bin/uname -p 2>/dev/null | grep 86 >/dev/null \ /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
&& { echo i486-ncr-sysv4.3"$OS_REL"; exit; } && { echo i486-ncr-sysv4.3"$OS_REL"; exit; }
/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
@ -1210,7 +1271,7 @@ EOF
exit ;; exit ;;
*:SINIX-*:*:*) *:SINIX-*:*:*)
if uname -p 2>/dev/null >/dev/null ; then if uname -p 2>/dev/null >/dev/null ; then
UNAME_MACHINE=`(uname -p) 2>/dev/null` UNAME_MACHINE=$( (uname -p) 2>/dev/null)
echo "$UNAME_MACHINE"-sni-sysv4 echo "$UNAME_MACHINE"-sni-sysv4
else else
echo ns32k-sni-sysv echo ns32k-sni-sysv
@ -1244,7 +1305,7 @@ EOF
echo mips-sony-newsos6 echo mips-sony-newsos6
exit ;; exit ;;
R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
if [ -d /usr/nec ]; then if test -d /usr/nec; then
echo mips-nec-sysv"$UNAME_RELEASE" echo mips-nec-sysv"$UNAME_RELEASE"
else else
echo mips-unknown-sysv"$UNAME_RELEASE" echo mips-unknown-sysv"$UNAME_RELEASE"
@ -1292,14 +1353,24 @@ EOF
*:Rhapsody:*:*) *:Rhapsody:*:*)
echo "$UNAME_MACHINE"-apple-rhapsody"$UNAME_RELEASE" echo "$UNAME_MACHINE"-apple-rhapsody"$UNAME_RELEASE"
exit ;; exit ;;
arm64:Darwin:*:*)
echo aarch64-apple-darwin"$UNAME_RELEASE"
exit ;;
*:Darwin:*:*) *:Darwin:*:*)
UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown UNAME_PROCESSOR=$(uname -p)
case $UNAME_PROCESSOR in
unknown) UNAME_PROCESSOR=powerpc ;;
esac
if command -v xcode-select > /dev/null 2> /dev/null && \
! xcode-select --print-path > /dev/null 2> /dev/null ; then
# Avoid executing cc if there is no toolchain installed as
# cc will be a stub that puts up a graphical alert
# prompting the user to install developer tools.
CC_FOR_BUILD=no_compiler_found
else
set_cc_for_build set_cc_for_build
if test "$UNAME_PROCESSOR" = unknown ; then
UNAME_PROCESSOR=powerpc
fi fi
if test "`echo "$UNAME_RELEASE" | sed -e 's/\..*//'`" -le 10 ; then if test "$CC_FOR_BUILD" != no_compiler_found; then
if [ "$CC_FOR_BUILD" != no_compiler_found ]; then
if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \
(CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
grep IS_64BIT_ARCH >/dev/null grep IS_64BIT_ARCH >/dev/null
@ -1316,20 +1387,14 @@ EOF
then then
UNAME_PROCESSOR=powerpc UNAME_PROCESSOR=powerpc
fi fi
fi
elif test "$UNAME_PROCESSOR" = i386 ; then elif test "$UNAME_PROCESSOR" = i386 ; then
# Avoid executing cc on OS X 10.9, as it ships with a stub # uname -m returns i386 or x86_64
# that puts up a graphical alert prompting to install UNAME_PROCESSOR=$UNAME_MACHINE
# developer tools. Any system running Mac OS X 10.7 or
# later (Darwin 11 and later) is required to have a 64-bit
# processor. This is not true of the ARM version of Darwin
# that Apple uses in portable devices.
UNAME_PROCESSOR=x86_64
fi fi
echo "$UNAME_PROCESSOR"-apple-darwin"$UNAME_RELEASE" echo "$UNAME_PROCESSOR"-apple-darwin"$UNAME_RELEASE"
exit ;; exit ;;
*:procnto*:*:* | *:QNX:[0123456789]*:*) *:procnto*:*:* | *:QNX:[0123456789]*:*)
UNAME_PROCESSOR=`uname -p` UNAME_PROCESSOR=$(uname -p)
if test "$UNAME_PROCESSOR" = x86; then if test "$UNAME_PROCESSOR" = x86; then
UNAME_PROCESSOR=i386 UNAME_PROCESSOR=i386
UNAME_MACHINE=pc UNAME_MACHINE=pc
@ -1397,10 +1462,10 @@ EOF
echo mips-sei-seiux"$UNAME_RELEASE" echo mips-sei-seiux"$UNAME_RELEASE"
exit ;; exit ;;
*:DragonFly:*:*) *:DragonFly:*:*)
echo "$UNAME_MACHINE"-unknown-dragonfly"`echo "$UNAME_RELEASE"|sed -e 's/[-(].*//'`" echo "$UNAME_MACHINE"-unknown-dragonfly"$(echo "$UNAME_RELEASE"|sed -e 's/[-(].*//')"
exit ;; exit ;;
*:*VMS:*:*) *:*VMS:*:*)
UNAME_MACHINE=`(uname -p) 2>/dev/null` UNAME_MACHINE=$( (uname -p) 2>/dev/null)
case "$UNAME_MACHINE" in case "$UNAME_MACHINE" in
A*) echo alpha-dec-vms ; exit ;; A*) echo alpha-dec-vms ; exit ;;
I*) echo ia64-dec-vms ; exit ;; I*) echo ia64-dec-vms ; exit ;;
@ -1410,7 +1475,7 @@ EOF
echo i386-pc-xenix echo i386-pc-xenix
exit ;; exit ;;
i*86:skyos:*:*) i*86:skyos:*:*)
echo "$UNAME_MACHINE"-pc-skyos"`echo "$UNAME_RELEASE" | sed -e 's/ .*$//'`" echo "$UNAME_MACHINE"-pc-skyos"$(echo "$UNAME_RELEASE" | sed -e 's/ .*$//')"
exit ;; exit ;;
i*86:rdos:*:*) i*86:rdos:*:*)
echo "$UNAME_MACHINE"-pc-rdos echo "$UNAME_MACHINE"-pc-rdos
@ -1424,8 +1489,148 @@ EOF
amd64:Isilon\ OneFS:*:*) amd64:Isilon\ OneFS:*:*)
echo x86_64-unknown-onefs echo x86_64-unknown-onefs
exit ;; exit ;;
*:Unleashed:*:*)
echo "$UNAME_MACHINE"-unknown-unleashed"$UNAME_RELEASE"
exit ;;
esac esac
# No uname command or uname output not recognized.
set_cc_for_build
cat > "$dummy.c" <<EOF
#ifdef _SEQUENT_
#include <sys/types.h>
#include <sys/utsname.h>
#endif
#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__)
#if defined (vax) || defined (__vax) || defined (__vax__) || defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__)
#include <signal.h>
#if defined(_SIZE_T_) || defined(SIGLOST)
#include <sys/utsname.h>
#endif
#endif
#endif
main ()
{
#if defined (sony)
#if defined (MIPSEB)
/* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed,
I don't know.... */
printf ("mips-sony-bsd\n"); exit (0);
#else
#include <sys/param.h>
printf ("m68k-sony-newsos%s\n",
#ifdef NEWSOS4
"4"
#else
""
#endif
); exit (0);
#endif
#endif
#if defined (NeXT)
#if !defined (__ARCHITECTURE__)
#define __ARCHITECTURE__ "m68k"
#endif
int version;
version=$( (hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null);
if (version < 4)
printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version);
else
printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version);
exit (0);
#endif
#if defined (MULTIMAX) || defined (n16)
#if defined (UMAXV)
printf ("ns32k-encore-sysv\n"); exit (0);
#else
#if defined (CMU)
printf ("ns32k-encore-mach\n"); exit (0);
#else
printf ("ns32k-encore-bsd\n"); exit (0);
#endif
#endif
#endif
#if defined (__386BSD__)
printf ("i386-pc-bsd\n"); exit (0);
#endif
#if defined (sequent)
#if defined (i386)
printf ("i386-sequent-dynix\n"); exit (0);
#endif
#if defined (ns32000)
printf ("ns32k-sequent-dynix\n"); exit (0);
#endif
#endif
#if defined (_SEQUENT_)
struct utsname un;
uname(&un);
if (strncmp(un.version, "V2", 2) == 0) {
printf ("i386-sequent-ptx2\n"); exit (0);
}
if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */
printf ("i386-sequent-ptx1\n"); exit (0);
}
printf ("i386-sequent-ptx\n"); exit (0);
#endif
#if defined (vax)
#if !defined (ultrix)
#include <sys/param.h>
#if defined (BSD)
#if BSD == 43
printf ("vax-dec-bsd4.3\n"); exit (0);
#else
#if BSD == 199006
printf ("vax-dec-bsd4.3reno\n"); exit (0);
#else
printf ("vax-dec-bsd\n"); exit (0);
#endif
#endif
#else
printf ("vax-dec-bsd\n"); exit (0);
#endif
#else
#if defined(_SIZE_T_) || defined(SIGLOST)
struct utsname un;
uname (&un);
printf ("vax-dec-ultrix%s\n", un.release); exit (0);
#else
printf ("vax-dec-ultrix\n"); exit (0);
#endif
#endif
#endif
#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__)
#if defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__)
#if defined(_SIZE_T_) || defined(SIGLOST)
struct utsname *un;
uname (&un);
printf ("mips-dec-ultrix%s\n", un.release); exit (0);
#else
printf ("mips-dec-ultrix\n"); exit (0);
#endif
#endif
#endif
#if defined (alliant) && defined (i860)
printf ("i860-alliant-bsd\n"); exit (0);
#endif
exit (1);
}
EOF
$CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null && SYSTEM_NAME=$($dummy) &&
{ echo "$SYSTEM_NAME"; exit; }
# Apollos put the system type in the environment.
test -d /usr/apollo && { echo "$ISP-apollo-$SYSTYPE"; exit; }
echo "$0: unable to guess system type" >&2 echo "$0: unable to guess system type" >&2
case "$UNAME_MACHINE:$UNAME_SYSTEM" in case "$UNAME_MACHINE:$UNAME_SYSTEM" in
@ -1445,9 +1650,15 @@ This script (version $timestamp), has failed to recognize the
operating system you are using. If your script is old, overwrite *all* operating system you are using. If your script is old, overwrite *all*
copies of config.guess and config.sub with the latest versions from: copies of config.guess and config.sub with the latest versions from:
https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess https://git.savannah.gnu.org/cgit/config.git/plain/config.guess
and and
https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub https://git.savannah.gnu.org/cgit/config.git/plain/config.sub
EOF
year=$(echo $timestamp | sed 's,-.*,,')
# shellcheck disable=SC2003
if test "$(expr "$(date +%Y)" - "$year")" -lt 3 ; then
cat >&2 <<EOF
If $0 has already been updated, send the following data and any If $0 has already been updated, send the following data and any
information you think might be pertinent to config-patches@gnu.org to information you think might be pertinent to config-patches@gnu.org to
@ -1455,26 +1666,27 @@ provide the necessary information to handle your system.
config.guess timestamp = $timestamp config.guess timestamp = $timestamp
uname -m = `(uname -m) 2>/dev/null || echo unknown` uname -m = $( (uname -m) 2>/dev/null || echo unknown)
uname -r = `(uname -r) 2>/dev/null || echo unknown` uname -r = $( (uname -r) 2>/dev/null || echo unknown)
uname -s = `(uname -s) 2>/dev/null || echo unknown` uname -s = $( (uname -s) 2>/dev/null || echo unknown)
uname -v = `(uname -v) 2>/dev/null || echo unknown` uname -v = $( (uname -v) 2>/dev/null || echo unknown)
/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` /usr/bin/uname -p = $( (/usr/bin/uname -p) 2>/dev/null)
/bin/uname -X = `(/bin/uname -X) 2>/dev/null` /bin/uname -X = $( (/bin/uname -X) 2>/dev/null)
hostinfo = `(hostinfo) 2>/dev/null` hostinfo = $( (hostinfo) 2>/dev/null)
/bin/universe = `(/bin/universe) 2>/dev/null` /bin/universe = $( (/bin/universe) 2>/dev/null)
/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` /usr/bin/arch -k = $( (/usr/bin/arch -k) 2>/dev/null)
/bin/arch = `(/bin/arch) 2>/dev/null` /bin/arch = $( (/bin/arch) 2>/dev/null)
/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` /usr/bin/oslevel = $( (/usr/bin/oslevel) 2>/dev/null)
/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` /usr/convex/getsysinfo = $( (/usr/convex/getsysinfo) 2>/dev/null)
UNAME_MACHINE = "$UNAME_MACHINE" UNAME_MACHINE = "$UNAME_MACHINE"
UNAME_RELEASE = "$UNAME_RELEASE" UNAME_RELEASE = "$UNAME_RELEASE"
UNAME_SYSTEM = "$UNAME_SYSTEM" UNAME_SYSTEM = "$UNAME_SYSTEM"
UNAME_VERSION = "$UNAME_VERSION" UNAME_VERSION = "$UNAME_VERSION"
EOF EOF
fi
exit 1 exit 1

1834
config/config.sub vendored

File diff suppressed because it is too large Load diff

View file

@ -255,6 +255,7 @@ if test -n "$enable_s3"; then
declare -a aws_version_tokens=($(printf '#include <aws/core/VersionConfig.h>\nAWS_SDK_VERSION_STRING' | $CPP $CPPFLAGS - | grep -v '^#.*' | sed 's/"//g' | tr '.' ' ')) declare -a aws_version_tokens=($(printf '#include <aws/core/VersionConfig.h>\nAWS_SDK_VERSION_STRING' | $CPP $CPPFLAGS - | grep -v '^#.*' | sed 's/"//g' | tr '.' ' '))
AC_DEFINE_UNQUOTED([AWS_VERSION_MAJOR], ${aws_version_tokens@<:@0@:>@}, [Major version of aws-sdk-cpp.]) AC_DEFINE_UNQUOTED([AWS_VERSION_MAJOR], ${aws_version_tokens@<:@0@:>@}, [Major version of aws-sdk-cpp.])
AC_DEFINE_UNQUOTED([AWS_VERSION_MINOR], ${aws_version_tokens@<:@1@:>@}, [Minor version of aws-sdk-cpp.]) AC_DEFINE_UNQUOTED([AWS_VERSION_MINOR], ${aws_version_tokens@<:@1@:>@}, [Minor version of aws-sdk-cpp.])
AC_DEFINE_UNQUOTED([AWS_VERSION_PATCH], ${aws_version_tokens@<:@2@:>@}, [Patch version of aws-sdk-cpp.])
fi fi

View file

@ -1,33 +1,40 @@
command:
with builtins; with builtins;
with import ./utils.nix; with import ./utils.nix;
let let
showCommand = showCommand =
{ command, section, def }: { command, def, filename }:
"${section} Name\n\n" "# Name\n\n"
+ "`${command}` - ${def.description}\n\n" + "`${command}` - ${def.description}\n\n"
+ "${section} Synopsis\n\n" + "# Synopsis\n\n"
+ showSynopsis { inherit command; args = def.args; } + showSynopsis { inherit command; args = def.args; }
+ (if def ? doc + (if def.commands or {} != {}
then "${section} Description\n\n" + def.doc + "\n\n" then
else "") "where *subcommand* is one of the following:\n\n"
+ (let s = showFlags def.flags; in # FIXME: group by category
if s != "" + concatStrings (map (name:
then "${section} Flags\n\n${s}" "* [`${command} ${name}`](./${appendName filename name}.md) - ${def.commands.${name}.description}\n")
(attrNames def.commands))
+ "\n"
else "") else "")
+ (if def.examples or [] != [] + (if def.examples or [] != []
then then
"${section} Examples\n\n" "# Examples\n\n"
+ concatStrings (map ({ description, command }: "${description}\n\n```console\n${command}\n```\n\n") def.examples) + concatStrings (map ({ description, command }: "${description}\n\n```console\n${command}\n```\n\n") def.examples)
else "") else "")
+ (if def.commands or [] != [] + (if def ? doc
then concatStrings ( then def.doc + "\n\n"
map (name: else "")
"# Subcommand `${command} ${name}`\n\n" + (let s = showFlags def.flags; in
+ showCommand { command = command + " " + name; section = "##"; def = def.commands.${name}; }) if s != ""
(attrNames def.commands)) then "# Flags\n\n${s}"
else ""); else "")
;
appendName = filename: name: (if filename == "nix" then "nix3" else filename) + "-" + name;
showFlags = flags: showFlags = flags:
concatStrings concatStrings
@ -48,8 +55,20 @@ let
"`${command}` [*flags*...] ${concatStringsSep " " "`${command}` [*flags*...] ${concatStringsSep " "
(map (arg: "*${arg.label}*" + (if arg ? arity then "" else "...")) args)}\n\n"; (map (arg: "*${arg.label}*" + (if arg ? arity then "" else "...")) args)}\n\n";
processCommand = { command, def, filename }:
[ { name = filename + ".md"; value = showCommand { inherit command def filename; }; inherit command; } ]
++ concatMap
(name: processCommand {
filename = appendName filename name;
command = command + " " + name;
def = def.commands.${name};
})
(attrNames def.commands or {});
in in
command: let
manpages = processCommand { filename = "nix"; command = "nix"; def = command; };
showCommand { command = "nix"; section = "#"; def = command; } summary = concatStrings (map (manpage: " - [${manpage.command}](command-ref/new-cli/${manpage.name})\n") manpages);
in
(listToAttrs manpages) // { "SUMMARY.md" = summary; }

View file

@ -4,7 +4,7 @@ MANUAL_SRCS := $(call rwildcard, $(d)/src, *.md)
# Generate man pages. # Generate man pages.
man-pages := $(foreach n, \ man-pages := $(foreach n, \
nix-env.1 nix-build.1 nix-shell.1 nix-store.1 nix-instantiate.1 nix.1 \ nix-env.1 nix-build.1 nix-shell.1 nix-store.1 nix-instantiate.1 \
nix-collect-garbage.1 \ nix-collect-garbage.1 \
nix-prefetch-url.1 nix-channel.1 \ nix-prefetch-url.1 nix-channel.1 \
nix-hash.1 nix-copy-closure.1 \ nix-hash.1 nix-copy-closure.1 \
@ -13,8 +13,6 @@ man-pages := $(foreach n, \
clean-files += $(d)/*.1 $(d)/*.5 $(d)/*.8 clean-files += $(d)/*.1 $(d)/*.5 $(d)/*.8
dist-files += $(man-pages)
# Provide a dummy environment for nix, so that it will not access files outside the macOS sandbox. # Provide a dummy environment for nix, so that it will not access files outside the macOS sandbox.
dummy-env = env -i \ dummy-env = env -i \
HOME=/dummy \ HOME=/dummy \
@ -22,7 +20,7 @@ dummy-env = env -i \
NIX_SSL_CERT_FILE=/dummy/no-ca-bundle.crt \ NIX_SSL_CERT_FILE=/dummy/no-ca-bundle.crt \
NIX_STATE_DIR=/dummy NIX_STATE_DIR=/dummy
nix-eval = $(dummy-env) $(bindir)/nix eval --experimental-features nix-command -I nix/corepkgs=corepkgs --store dummy:// --impure --raw --expr nix-eval = $(dummy-env) $(bindir)/nix eval --experimental-features nix-command -I nix/corepkgs=corepkgs --store dummy:// --impure --raw
$(d)/%.1: $(d)/src/command-ref/%.md $(d)/%.1: $(d)/src/command-ref/%.md
@printf "Title: %s\n\n" "$$(basename $@ .1)" > $^.tmp @printf "Title: %s\n\n" "$$(basename $@ .1)" > $^.tmp
@ -42,13 +40,17 @@ $(d)/nix.conf.5: $(d)/src/command-ref/conf-file.md
$(trace-gen) lowdown -sT man $^.tmp -o $@ $(trace-gen) lowdown -sT man $^.tmp -o $@
@rm $^.tmp @rm $^.tmp
$(d)/src/command-ref/nix.md: $(d)/nix.json $(d)/generate-manpage.nix $(bindir)/nix $(d)/src/SUMMARY.md: $(d)/src/SUMMARY.md.in $(d)/src/command-ref/new-cli
$(trace-gen) $(nix-eval) 'import doc/manual/generate-manpage.nix (builtins.fromJSON (builtins.readFile $<))' > $@.tmp $(trace-gen) cat doc/manual/src/SUMMARY.md.in | while IFS= read line; do if [[ $$line = @manpages@ ]]; then cat doc/manual/src/command-ref/new-cli/SUMMARY.md; else echo "$$line"; fi; done > $@.tmp
@mv $@.tmp $@ @mv $@.tmp $@
$(d)/src/command-ref/new-cli: $(d)/nix.json $(d)/generate-manpage.nix $(bindir)/nix
@rm -rf $@
$(trace-gen) $(nix-eval) --write-to $@ --expr 'import doc/manual/generate-manpage.nix (builtins.fromJSON (builtins.readFile $<))'
$(d)/src/command-ref/conf-file.md: $(d)/conf-file.json $(d)/generate-options.nix $(d)/src/command-ref/conf-file-prefix.md $(bindir)/nix $(d)/src/command-ref/conf-file.md: $(d)/conf-file.json $(d)/generate-options.nix $(d)/src/command-ref/conf-file-prefix.md $(bindir)/nix
@cat doc/manual/src/command-ref/conf-file-prefix.md > $@.tmp @cat doc/manual/src/command-ref/conf-file-prefix.md > $@.tmp
$(trace-gen) $(nix-eval) 'import doc/manual/generate-options.nix (builtins.fromJSON (builtins.readFile $<))' >> $@.tmp $(trace-gen) $(nix-eval) --expr 'import doc/manual/generate-options.nix (builtins.fromJSON (builtins.readFile $<))' >> $@.tmp
@mv $@.tmp $@ @mv $@.tmp $@
$(d)/nix.json: $(bindir)/nix $(d)/nix.json: $(bindir)/nix
@ -61,18 +63,28 @@ $(d)/conf-file.json: $(bindir)/nix
$(d)/src/expressions/builtins.md: $(d)/builtins.json $(d)/generate-builtins.nix $(d)/src/expressions/builtins-prefix.md $(bindir)/nix $(d)/src/expressions/builtins.md: $(d)/builtins.json $(d)/generate-builtins.nix $(d)/src/expressions/builtins-prefix.md $(bindir)/nix
@cat doc/manual/src/expressions/builtins-prefix.md > $@.tmp @cat doc/manual/src/expressions/builtins-prefix.md > $@.tmp
$(trace-gen) $(nix-eval) 'import doc/manual/generate-builtins.nix (builtins.fromJSON (builtins.readFile $<))' >> $@.tmp $(trace-gen) $(nix-eval) --expr 'import doc/manual/generate-builtins.nix (builtins.fromJSON (builtins.readFile $<))' >> $@.tmp
@mv $@.tmp $@ @mv $@.tmp $@
$(d)/builtins.json: $(bindir)/nix $(d)/builtins.json: $(bindir)/nix
$(trace-gen) $(dummy-env) NIX_PATH=nix/corepkgs=corepkgs $(bindir)/nix __dump-builtins > $@.tmp $(trace-gen) $(dummy-env) NIX_PATH=nix/corepkgs=corepkgs $(bindir)/nix __dump-builtins > $@.tmp
mv $@.tmp $@ @mv $@.tmp $@
# Generate the HTML manual. # Generate the HTML manual.
install: $(docdir)/manual/index.html install: $(docdir)/manual/index.html
$(docdir)/manual/index.html: $(MANUAL_SRCS) $(d)/book.toml $(d)/custom.css $(d)/src/command-ref/nix.md $(d)/src/command-ref/conf-file.md $(d)/src/expressions/builtins.md # Generate 'nix' manpages.
$(trace-gen) mdbook build doc/manual -d $(docdir)/manual install: $(d)/src/command-ref/new-cli
$(trace-gen) for i in doc/manual/src/command-ref/new-cli/*.md; do \
name=$$(basename $$i .md); \
if [[ $$name = SUMMARY ]]; then continue; fi; \
printf "Title: %s\n\n" "$$name" > $$i.tmp; \
cat $$i >> $$i.tmp; \
lowdown -sT man $$i.tmp -o $(mandir)/man1/$$name.1; \
done
$(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
$(trace-gen) RUST_LOG=warn mdbook build doc/manual -d $(docdir)/manual
@cp doc/manual/highlight.pack.js $(docdir)/manual/highlight.js @cp doc/manual/highlight.pack.js $(docdir)/manual/highlight.js
endif endif

View file

@ -62,12 +62,12 @@
- [nix-instantiate](command-ref/nix-instantiate.md) - [nix-instantiate](command-ref/nix-instantiate.md)
- [nix-prefetch-url](command-ref/nix-prefetch-url.md) - [nix-prefetch-url](command-ref/nix-prefetch-url.md)
- [Experimental Commands](command-ref/experimental-commands.md) - [Experimental Commands](command-ref/experimental-commands.md)
- [nix](command-ref/nix.md)
- [CLI guideline](command-ref/cli-guideline.md)
- [Files](command-ref/files.md) - [Files](command-ref/files.md)
- [nix.conf](command-ref/conf-file.md) - [nix.conf](command-ref/conf-file.md)
- [Glossary](glossary.md) - [Glossary](glossary.md)
- [Hacking](hacking.md) - [Contributing](contributing/contributing.md)
- [Hacking](contributing/hacking.md)
- [CLI guideline](contributing/cli-guideline.md)
- [Release Notes](release-notes/release-notes.md) - [Release Notes](release-notes/release-notes.md)
- [Release 2.3 (2019-09-04)](release-notes/rl-2.3.md) - [Release 2.3 (2019-09-04)](release-notes/rl-2.3.md)
- [Release 2.2 (2019-01-11)](release-notes/rl-2.2.md) - [Release 2.2 (2019-01-11)](release-notes/rl-2.2.md)

View file

@ -466,6 +466,8 @@
postInstall = '' postInstall = ''
mkdir -p $doc/nix-support mkdir -p $doc/nix-support
echo "doc manual $doc/share/doc/nix/manual" >> $doc/nix-support/hydra-build-products echo "doc manual $doc/share/doc/nix/manual" >> $doc/nix-support/hydra-build-products
mkdir -p $out/nix-support
echo "file binary-dist $out/bin/nix" >> $out/nix-support/hydra-build-products
''; '';
doInstallCheck = true; doInstallCheck = true;

View file

@ -1,9 +1,3 @@
ifeq ($(MAKECMDGOALS), dist)
dist-files += $(shell cat .dist-files)
endif
dist-files += configure config.h.in perl/configure
clean-files += Makefile.config clean-files += Makefile.config
GLOBAL_CXXFLAGS += -Wno-deprecated-declarations GLOBAL_CXXFLAGS += -Wno-deprecated-declarations

View file

@ -1,17 +0,0 @@
ifdef PACKAGE_NAME
dist-name = $(PACKAGE_NAME)-$(PACKAGE_VERSION)
dist: $(dist-name).tar.bz2 $(dist-name).tar.xz
$(dist-name).tar.bz2: $(dist-files)
$(trace-gen) tar cfj $@ $(sort $(dist-files)) --transform 's,^,$(dist-name)/,'
$(dist-name).tar.xz: $(dist-files)
$(trace-gen) tar cfJ $@ $(sort $(dist-files)) --transform 's,^,$(dist-name)/,'
clean-files += $(dist-name).tar.bz2 $(dist-name).tar.xz
print-top-help += echo " dist: Generate a source distribution";
endif

View file

@ -10,7 +10,6 @@ bin-scripts :=
noinst-scripts := noinst-scripts :=
man-pages := man-pages :=
install-tests := install-tests :=
dist-files :=
OS = $(shell uname -s) OS = $(shell uname -s)
@ -112,9 +111,6 @@ $(foreach test, $(install-tests), $(eval $(call run-install-test,$(test))))
$(foreach file, $(man-pages), $(eval $(call install-data-in, $(file), $(mandir)/man$(patsubst .%,%,$(suffix $(file)))))) $(foreach file, $(man-pages), $(eval $(call install-data-in, $(file), $(mandir)/man$(patsubst .%,%,$(suffix $(file))))))
include mk/dist.mk
.PHONY: default all man help .PHONY: default all man help
all: $(programs-list) $(libs-list) $(jars-list) $(man-pages) all: $(programs-list) $(libs-list) $(jars-list) $(man-pages)

View file

@ -159,5 +159,4 @@ define build-library
libs-list += $$($(1)_PATH) libs-list += $$($(1)_PATH)
endif endif
clean-files += $$(_d)/*.a $$(_d)/*.$(SO_EXT) $$(_d)/*.o $$(_d)/.*.dep $$($(1)_DEPS) $$($(1)_OBJS) clean-files += $$(_d)/*.a $$(_d)/*.$(SO_EXT) $$(_d)/*.o $$(_d)/.*.dep $$($(1)_DEPS) $$($(1)_OBJS)
dist-files += $$(_srcs)
endef endef

View file

@ -79,7 +79,6 @@ define build-program
programs-list += $$($(1)_PATH) programs-list += $$($(1)_PATH)
clean-files += $$($(1)_PATH) $$(_d)/*.o $$(_d)/.*.dep $$($(1)_DEPS) $$($(1)_OBJS) clean-files += $$($(1)_PATH) $$(_d)/*.o $$(_d)/.*.dep $$($(1)_DEPS) $$($(1)_OBJS)
dist-files += $$(_srcs)
# Phony target to run this program (typically as a dependency of 'check'). # Phony target to run this program (typically as a dependency of 'check').
.PHONY: $(1)_RUN .PHONY: $(1)_RUN

View file

@ -30,8 +30,6 @@ ifeq ($(OS), Darwin)
install_name_tool -id $@ $@ install_name_tool -id $@ $@
endif endif
dist-files += $(d)/vendor
clean: clean-rust clean: clean-rust
clean-rust: clean-rust:

View file

@ -12,7 +12,9 @@
%{ %{
#ifdef __clang__
#pragma clang diagnostic ignored "-Wunneeded-internal-declaration" #pragma clang diagnostic ignored "-Wunneeded-internal-declaration"
#endif
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>

View file

@ -35,8 +35,6 @@ $(d)/lexer-tab.cc $(d)/lexer-tab.hh: $(d)/lexer.l
clean-files += $(d)/parser-tab.cc $(d)/parser-tab.hh $(d)/lexer-tab.cc $(d)/lexer-tab.hh clean-files += $(d)/parser-tab.cc $(d)/parser-tab.hh $(d)/lexer-tab.cc $(d)/lexer-tab.hh
dist-files += $(d)/parser-tab.cc $(d)/parser-tab.hh $(d)/lexer-tab.cc $(d)/lexer-tab.hh
$(eval $(call install-file-in, $(d)/nix-expr.pc, $(prefix)/lib/pkgconfig, 0644)) $(eval $(call install-file-in, $(d)/nix-expr.pc, $(prefix)/lib/pkgconfig, 0644))
$(foreach i, $(wildcard src/libexpr/flake/*.hh), \ $(foreach i, $(wildcard src/libexpr/flake/*.hh), \

View file

@ -86,8 +86,7 @@ void BinaryCacheStore::getFile(const std::string & path, Sink & sink)
promise.set_exception(std::current_exception()); promise.set_exception(std::current_exception());
} }
}}); }});
auto data = promise.get_future().get(); sink(*promise.get_future().get());
sink((unsigned char *) data->data(), data->size());
} }
std::shared_ptr<std::string> BinaryCacheStore::getFile(const std::string & path) std::shared_ptr<std::string> BinaryCacheStore::getFile(const std::string & path)

View file

@ -916,10 +916,8 @@ void DerivationGoal::buildDone()
LogSink(Activity & act) : act(act) { } LogSink(Activity & act) : act(act) { }
void operator() (const unsigned char * data, size_t len) override { void operator() (std::string_view data) override {
for (size_t i = 0; i < len; i++) { for (auto c : data) {
auto c = data[i];
if (c == '\n') { if (c == '\n') {
flushLine(); flushLine();
} else { } else {
@ -3127,7 +3125,7 @@ void DerivationGoal::registerOutputs()
StringSink sink; StringSink sink;
dumpPath(actualPath, sink); dumpPath(actualPath, sink);
RewritingSink rsink2(oldHashPart, std::string(newInfo0.path.hashPart()), nextSink); RewritingSink rsink2(oldHashPart, std::string(newInfo0.path.hashPart()), nextSink);
rsink2((unsigned char *) sink.s->data(), sink.s->size()); rsink2(*sink.s);
rsink2.flush(); rsink2.flush();
}); });
Path tmpPath = actualPath + ".tmp"; Path tmpPath = actualPath + ".tmp";

View file

@ -223,11 +223,6 @@ void Worker::run(const Goals & _topGoals)
uint64_t downloadSize, narSize; uint64_t downloadSize, narSize;
store.queryMissing(topPaths, willBuild, willSubstitute, unknown, downloadSize, narSize); store.queryMissing(topPaths, willBuild, willSubstitute, unknown, downloadSize, narSize);
if (!willBuild.empty() && 0 == settings.maxBuildJobs && getMachines().empty())
throw Error(
"%d derivations need to be built, but neither local builds ('--max-jobs') "
"nor remote builds ('--builders') are enabled", willBuild.size());
debug("entered goal loop"); debug("entered goal loop");
while (1) { while (1) {

View file

@ -153,10 +153,10 @@ struct TunnelSink : Sink
{ {
Sink & to; Sink & to;
TunnelSink(Sink & to) : to(to) { } TunnelSink(Sink & to) : to(to) { }
virtual void operator () (const unsigned char * data, size_t len) void operator () (std::string_view data)
{ {
to << STDERR_WRITE; to << STDERR_WRITE;
writeString(data, len, to); writeString(data, to);
} }
}; };
@ -165,7 +165,7 @@ struct TunnelSource : BufferedSource
Source & from; Source & from;
BufferedSink & to; BufferedSink & to;
TunnelSource(Source & from, BufferedSink & to) : from(from), to(to) { } TunnelSource(Source & from, BufferedSink & to) : from(from), to(to) { }
size_t readUnbuffered(unsigned char * data, size_t len) override size_t readUnbuffered(char * data, size_t len) override
{ {
to << STDERR_READ << len; to << STDERR_READ << len;
to.flush(); to.flush();
@ -215,6 +215,8 @@ struct ClientSettings
for (auto & s : ss) for (auto & s : ss)
if (trusted.count(s)) if (trusted.count(s))
subs.push_back(s); subs.push_back(s);
else if (!hasSuffix(s, "/") && trusted.count(s + "/"))
subs.push_back(s + "/");
else else
warn("ignoring untrusted substituter '%s'", s); warn("ignoring untrusted substituter '%s'", s);
res = subs; res = subs;

View file

@ -95,18 +95,18 @@ struct curlFileTransfer : public FileTransfer
fmt(request.data ? "uploading '%s'" : "downloading '%s'", request.uri), fmt(request.data ? "uploading '%s'" : "downloading '%s'", request.uri),
{request.uri}, request.parentAct) {request.uri}, request.parentAct)
, callback(std::move(callback)) , callback(std::move(callback))
, finalSink([this](const unsigned char * data, size_t len) { , finalSink([this](std::string_view data) {
if (this->request.dataCallback) { if (this->request.dataCallback) {
auto httpStatus = getHTTPStatus(); auto httpStatus = getHTTPStatus();
/* Only write data to the sink if this is a /* Only write data to the sink if this is a
successful response. */ successful response. */
if (successfulStatuses.count(httpStatus)) { if (successfulStatuses.count(httpStatus)) {
writtenToSink += len; writtenToSink += data.size();
this->request.dataCallback((char *) data, len); this->request.dataCallback(data);
} }
} else } else
this->result.data->append((char *) data, len); this->result.data->append(data);
}) })
{ {
if (!request.expectedETag.empty()) if (!request.expectedETag.empty())
@ -171,8 +171,8 @@ struct curlFileTransfer : public FileTransfer
} }
if (errorSink) if (errorSink)
(*errorSink)((unsigned char *) contents, realSize); (*errorSink)({(char *) contents, realSize});
(*decompressionSink)((unsigned char *) contents, realSize); (*decompressionSink)({(char *) contents, realSize});
return realSize; return realSize;
} catch (...) { } catch (...) {
@ -776,7 +776,7 @@ void FileTransfer::download(FileTransferRequest && request, Sink & sink)
state->request.notify_one(); state->request.notify_one();
}); });
request.dataCallback = [_state](char * buf, size_t len) { request.dataCallback = [_state](std::string_view data) {
auto state(_state->lock()); auto state(_state->lock());
@ -794,7 +794,7 @@ void FileTransfer::download(FileTransferRequest && request, Sink & sink)
/* Append data to the buffer and wake up the calling /* Append data to the buffer and wake up the calling
thread. */ thread. */
state->data.append(buf, len); state->data.append(data);
state->avail.notify_one(); state->avail.notify_one();
}; };
@ -840,7 +840,7 @@ void FileTransfer::download(FileTransferRequest && request, Sink & sink)
if it's blocked on a full buffer. We don't hold the state if it's blocked on a full buffer. We don't hold the state
lock while doing this to prevent blocking the download lock while doing this to prevent blocking the download
thread if sink() takes a long time. */ thread if sink() takes a long time. */
sink((unsigned char *) chunk.data(), chunk.size()); sink(chunk);
} }
} }

View file

@ -61,7 +61,7 @@ struct FileTransferRequest
bool decompress = true; bool decompress = true;
std::shared_ptr<std::string> data; std::shared_ptr<std::string> data;
std::string mimeType; std::string mimeType;
std::function<void(char *, size_t)> dataCallback; std::function<void(std::string_view data)> dataCallback;
FileTransferRequest(const std::string & uri) FileTransferRequest(const std::string & uri)
: uri(uri), parentAct(getCurActivity()) { } : uri(uri), parentAct(getCurActivity()) { }

View file

@ -583,7 +583,7 @@ public:
Setting<Strings> substituters{ Setting<Strings> substituters{
this, this,
nixStore == "/nix/store" ? Strings{"https://cache.nixos.org/"} : Strings(), Strings{"https://cache.nixos.org/"},
"substituters", "substituters",
R"( R"(
A list of URLs of substituters, separated by whitespace. The default A list of URLs of substituters, separated by whitespace. The default
@ -867,7 +867,7 @@ public:
Example `~/.config/nix/nix.conf`: Example `~/.config/nix/nix.conf`:
``` ```
access-tokens = "github.com=23ac...b289 gitlab.mycompany.com=PAT:A123Bp_Cd..EfG gitlab.com=OAuth2:1jklw3jk" access-tokens = github.com=23ac...b289 gitlab.mycompany.com=PAT:A123Bp_Cd..EfG gitlab.com=OAuth2:1jklw3jk
``` ```
Example `~/code/flake.nix`: Example `~/code/flake.nix`:

View file

@ -1143,7 +1143,7 @@ StorePath LocalStore::addToStoreFromDump(Source & source0, const string & name,
dump.resize(oldSize + want); dump.resize(oldSize + want);
auto got = 0; auto got = 0;
try { try {
got = source.read((uint8_t *) dump.data() + oldSize, want); got = source.read(dump.data() + oldSize, want);
} catch (EndOfFile &) { } catch (EndOfFile &) {
inMemory = true; inMemory = true;
break; break;

View file

@ -87,7 +87,7 @@ struct NarAccessor : public FSAccessor
parents.top()->start = pos; parents.top()->start = pos;
} }
void receiveContents(unsigned char * data, size_t len) override void receiveContents(std::string_view data) override
{ } { }
void createSymlink(const Path & path, const string & target) override void createSymlink(const Path & path, const string & target) override
@ -96,7 +96,7 @@ struct NarAccessor : public FSAccessor
NarMember{FSAccessor::Type::tSymlink, false, 0, 0, target}); NarMember{FSAccessor::Type::tSymlink, false, 0, 0, target});
} }
size_t read(unsigned char * data, size_t len) override size_t read(char * data, size_t len) override
{ {
auto n = source.read(data, len); auto n = source.read(data, len);
pos += n; pos += n;

View file

@ -55,25 +55,21 @@ struct RefScanSink : Sink
RefScanSink() { } RefScanSink() { }
void operator () (const unsigned char * data, size_t len); void operator () (std::string_view data) override
}; {
void RefScanSink::operator () (const unsigned char * data, size_t len)
{
/* It's possible that a reference spans the previous and current /* It's possible that a reference spans the previous and current
fragment, so search in the concatenation of the tail of the fragment, so search in the concatenation of the tail of the
previous fragment and the start of the current fragment. */ previous fragment and the start of the current fragment. */
string s = tail + string((const char *) data, len > refLength ? refLength : len); string s = tail + std::string(data, 0, refLength);
search((const unsigned char *) s.data(), s.size(), hashes, seen); search((const unsigned char *) s.data(), s.size(), hashes, seen);
search(data, len, hashes, seen); search((const unsigned char *) data.data(), data.size(), hashes, seen);
size_t tailLen = len <= refLength ? len : refLength; size_t tailLen = data.size() <= refLength ? data.size() : refLength;
tail = tail = std::string(tail, tail.size() < refLength - tailLen ? 0 : tail.size() - (refLength - tailLen));
string(tail, tail.size() < refLength - tailLen ? 0 : tail.size() - (refLength - tailLen)) + tail.append({data.data() + data.size() - tailLen, tailLen});
string((const char *) data + len - tailLen, tailLen); }
} };
std::pair<PathSet, HashResult> scanForReferences(const string & path, std::pair<PathSet, HashResult> scanForReferences(const string & path,
@ -129,10 +125,10 @@ RewritingSink::RewritingSink(const std::string & from, const std::string & to, S
assert(from.size() == to.size()); assert(from.size() == to.size());
} }
void RewritingSink::operator () (const unsigned char * data, size_t len) void RewritingSink::operator () (std::string_view data)
{ {
std::string s(prev); std::string s(prev);
s.append((const char *) data, len); s.append(data);
size_t j = 0; size_t j = 0;
while ((j = s.find(from, j)) != string::npos) { while ((j = s.find(from, j)) != string::npos) {
@ -146,14 +142,14 @@ void RewritingSink::operator () (const unsigned char * data, size_t len)
pos += consumed; pos += consumed;
if (consumed) nextSink((unsigned char *) s.data(), consumed); if (consumed) nextSink(s.substr(0, consumed));
} }
void RewritingSink::flush() void RewritingSink::flush()
{ {
if (prev.empty()) return; if (prev.empty()) return;
pos += prev.size(); pos += prev.size();
nextSink((unsigned char *) prev.data(), prev.size()); nextSink(prev);
prev.clear(); prev.clear();
} }
@ -163,9 +159,9 @@ HashModuloSink::HashModuloSink(HashType ht, const std::string & modulus)
{ {
} }
void HashModuloSink::operator () (const unsigned char * data, size_t len) void HashModuloSink::operator () (std::string_view data)
{ {
rewritingSink(data, len); rewritingSink(data);
} }
HashResult HashModuloSink::finish() HashResult HashModuloSink::finish()
@ -176,10 +172,8 @@ HashResult HashModuloSink::finish()
NAR with self-references and a NAR with some of the NAR with self-references and a NAR with some of the
self-references already zeroed out do not produce a hash self-references already zeroed out do not produce a hash
collision. FIXME: proof. */ collision. FIXME: proof. */
for (auto & pos : rewritingSink.matches) { for (auto & pos : rewritingSink.matches)
auto s = fmt("|%d", pos); hashSink(fmt("|%d", pos));
hashSink((unsigned char *) s.data(), s.size());
}
auto h = hashSink.finish(); auto h = hashSink.finish();
return {h.first, rewritingSink.pos}; return {h.first, rewritingSink.pos};

View file

@ -19,7 +19,7 @@ struct RewritingSink : Sink
RewritingSink(const std::string & from, const std::string & to, Sink & nextSink); RewritingSink(const std::string & from, const std::string & to, Sink & nextSink);
void operator () (const unsigned char * data, size_t len) override; void operator () (std::string_view data) override;
void flush(); void flush();
}; };
@ -31,7 +31,7 @@ struct HashModuloSink : AbstractHashSink
HashModuloSink(HashType ht, const std::string & modulus); HashModuloSink(HashType ht, const std::string & modulus);
void operator () (const unsigned char * data, size_t len) override; void operator () (std::string_view data) override;
HashResult finish() override; HashResult finish() override;
}; };

View file

@ -75,7 +75,7 @@ std::pair<ref<FSAccessor>, Path> RemoteFSAccessor::fetch(const Path & path_)
throw SysError("seeking in '%s'", cacheFile); throw SysError("seeking in '%s'", cacheFile);
std::string buf(length, 0); std::string buf(length, 0);
readFull(fd.get(), (unsigned char *) buf.data(), length); readFull(fd.get(), buf.data(), length);
return buf; return buf;
}); });

View file

@ -856,8 +856,8 @@ std::exception_ptr RemoteStore::Connection::processStderr(Sink * sink, Source *
else if (msg == STDERR_READ) { else if (msg == STDERR_READ) {
if (!source) throw Error("no source"); if (!source) throw Error("no source");
size_t len = readNum<size_t>(from); size_t len = readNum<size_t>(from);
auto buf = std::make_unique<unsigned char[]>(len); auto buf = std::make_unique<char[]>(len);
writeString(buf.get(), source->read(buf.get(), len), to); writeString({(const char *) buf.get(), source->read(buf.get(), len)}, to);
to.flush(); to.flush();
} }

View file

@ -57,6 +57,10 @@ class AwsLogger : public Aws::Utils::Logging::FormattedLogSystem
{ {
debug("AWS: %s", chomp(statement)); debug("AWS: %s", chomp(statement));
} }
#if !(AWS_VERSION_MAJOR <= 1 && AWS_VERSION_MINOR <= 7 && AWS_VERSION_PATCH <= 115)
void Flush() override {}
#endif
}; };
static void initAWS() static void initAWS()
@ -398,7 +402,7 @@ struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore, virtual S3BinaryCache
printTalkative("downloaded 's3://%s/%s' (%d bytes) in %d ms", printTalkative("downloaded 's3://%s/%s' (%d bytes) in %d ms",
bucketName, path, res.data->size(), res.durationMs); bucketName, path, res.data->size(), res.durationMs);
sink((unsigned char *) res.data->data(), res.data->size()); sink(*res.data);
} else } else
throw NoSuchBinaryCacheFile("file '%s' does not exist in binary cache '%s'", path, getUri()); throw NoSuchBinaryCacheFile("file '%s' does not exist in binary cache '%s'", path, getUri());
} }

View file

@ -772,8 +772,8 @@ void copyStorePath(ref<Store> srcStore, ref<Store> dstStore,
} }
auto source = sinkToSource([&](Sink & sink) { auto source = sinkToSource([&](Sink & sink) {
LambdaSink progressSink([&](const unsigned char * data, size_t len) { LambdaSink progressSink([&](std::string_view data) {
total += len; total += data.size();
act.progress(total, info->narSize); act.progress(total, info->narSize);
}); });
TeeSink tee { sink, progressSink }; TeeSink tee { sink, progressSink };

View file

@ -50,14 +50,14 @@ static void dumpContents(const Path & path, size_t size,
AutoCloseFD fd = open(path.c_str(), O_RDONLY | O_CLOEXEC); AutoCloseFD fd = open(path.c_str(), O_RDONLY | O_CLOEXEC);
if (!fd) throw SysError("opening file '%1%'", path); if (!fd) throw SysError("opening file '%1%'", path);
std::vector<unsigned char> buf(65536); std::vector<char> buf(65536);
size_t left = size; size_t left = size;
while (left > 0) { while (left > 0) {
auto n = std::min(left, buf.size()); auto n = std::min(left, buf.size());
readFull(fd.get(), buf.data(), n); readFull(fd.get(), buf.data(), n);
left -= n; left -= n;
sink(buf.data(), n); sink({buf.data(), n});
} }
writePadding(size, sink); writePadding(size, sink);
@ -155,14 +155,14 @@ static void parseContents(ParseSink & sink, Source & source, const Path & path)
sink.preallocateContents(size); sink.preallocateContents(size);
uint64_t left = size; uint64_t left = size;
std::vector<unsigned char> buf(65536); std::vector<char> buf(65536);
while (left) { while (left) {
checkInterrupt(); checkInterrupt();
auto n = buf.size(); auto n = buf.size();
if ((uint64_t)n > left) n = left; if ((uint64_t)n > left) n = left;
source(buf.data(), n); source(buf.data(), n);
sink.receiveContents(buf.data(), n); sink.receiveContents({buf.data(), n});
left -= n; left -= n;
} }
@ -300,21 +300,21 @@ struct RestoreSink : ParseSink
Path dstPath; Path dstPath;
AutoCloseFD fd; AutoCloseFD fd;
void createDirectory(const Path & path) void createDirectory(const Path & path) override
{ {
Path p = dstPath + path; Path p = dstPath + path;
if (mkdir(p.c_str(), 0777) == -1) if (mkdir(p.c_str(), 0777) == -1)
throw SysError("creating directory '%1%'", p); throw SysError("creating directory '%1%'", p);
}; };
void createRegularFile(const Path & path) void createRegularFile(const Path & path) override
{ {
Path p = dstPath + path; Path p = dstPath + path;
fd = open(p.c_str(), O_CREAT | O_EXCL | O_WRONLY | O_CLOEXEC, 0666); fd = open(p.c_str(), O_CREAT | O_EXCL | O_WRONLY | O_CLOEXEC, 0666);
if (!fd) throw SysError("creating file '%1%'", p); if (!fd) throw SysError("creating file '%1%'", p);
} }
void isExecutable() void isExecutable() override
{ {
struct stat st; struct stat st;
if (fstat(fd.get(), &st) == -1) if (fstat(fd.get(), &st) == -1)
@ -323,7 +323,7 @@ struct RestoreSink : ParseSink
throw SysError("fchmod"); throw SysError("fchmod");
} }
void preallocateContents(uint64_t len) void preallocateContents(uint64_t len) override
{ {
if (!archiveSettings.preallocateContents) if (!archiveSettings.preallocateContents)
return; return;
@ -341,12 +341,12 @@ struct RestoreSink : ParseSink
#endif #endif
} }
void receiveContents(unsigned char * data, size_t len) void receiveContents(std::string_view data) override
{ {
writeFull(fd.get(), data, len); writeFull(fd.get(), data);
} }
void createSymlink(const Path & path, const string & target) void createSymlink(const Path & path, const string & target) override
{ {
Path p = dstPath + path; Path p = dstPath + path;
nix::createSymlink(target, p); nix::createSymlink(target, p);

View file

@ -58,7 +58,7 @@ struct ParseSink
virtual void createRegularFile(const Path & path) { }; virtual void createRegularFile(const Path & path) { };
virtual void isExecutable() { }; virtual void isExecutable() { };
virtual void preallocateContents(uint64_t size) { }; virtual void preallocateContents(uint64_t size) { };
virtual void receiveContents(unsigned char * data, size_t len) { }; virtual void receiveContents(std::string_view data) { };
virtual void createSymlink(const Path & path, const string & target) { }; virtual void createSymlink(const Path & path, const string & target) { };
}; };
@ -72,17 +72,17 @@ struct RetrieveRegularNARSink : ParseSink
RetrieveRegularNARSink(Sink & sink) : sink(sink) { } RetrieveRegularNARSink(Sink & sink) : sink(sink) { }
void createDirectory(const Path & path) void createDirectory(const Path & path) override
{ {
regular = false; regular = false;
} }
void receiveContents(unsigned char * data, size_t len) void receiveContents(std::string_view data) override
{ {
sink(data, len); sink(data);
} }
void createSymlink(const Path & path, const string & target) void createSymlink(const Path & path, const string & target) override
{ {
regular = false; regular = false;
} }

View file

@ -86,6 +86,7 @@ void Args::parseCmdline(const Strings & _cmdline)
throw UsageError("unrecognised flag '%1%'", arg); throw UsageError("unrecognised flag '%1%'", arg);
} }
else { else {
pos = rewriteArgs(cmdline, pos);
pendingArgs.push_back(*pos++); pendingArgs.push_back(*pos++);
if (processArgs(pendingArgs, false)) if (processArgs(pendingArgs, false))
pendingArgs.clear(); pendingArgs.clear();
@ -390,10 +391,6 @@ MultiCommand::MultiCommand(const Commands & commands)
.optional = true, .optional = true,
.handler = {[=](std::string s) { .handler = {[=](std::string s) {
assert(!command); assert(!command);
if (auto alias = get(deprecatedAliases, s)) {
warn("'%s' is a deprecated alias for '%s'", s, *alias);
s = *alias;
}
if (auto prefix = needsCompletion(s)) { if (auto prefix = needsCompletion(s)) {
for (auto & [name, command] : commands) for (auto & [name, command] : commands)
if (hasPrefix(name, *prefix)) if (hasPrefix(name, *prefix))

View file

@ -115,6 +115,9 @@ protected:
virtual bool processArgs(const Strings & args, bool finish); virtual bool processArgs(const Strings & args, bool finish);
virtual Strings::iterator rewriteArgs(Strings & args, Strings::iterator pos)
{ return pos; }
std::set<std::string> hiddenCategories; std::set<std::string> hiddenCategories;
public: public:
@ -257,8 +260,6 @@ public:
std::map<Command::Category, std::string> categories; std::map<Command::Category, std::string> categories;
std::map<std::string, std::string> deprecatedAliases;
// Selected command, if any. // Selected command, if any.
std::optional<std::pair<std::string, ref<Command>>> command; std::optional<std::pair<std::string, ref<Command>>> command;

View file

@ -22,18 +22,17 @@ struct ChunkedCompressionSink : CompressionSink
{ {
uint8_t outbuf[32 * 1024]; uint8_t outbuf[32 * 1024];
void write(const unsigned char * data, size_t len) override void write(std::string_view data) override
{ {
const size_t CHUNK_SIZE = sizeof(outbuf) << 2; const size_t CHUNK_SIZE = sizeof(outbuf) << 2;
while (len) { while (!data.empty()) {
size_t n = std::min(CHUNK_SIZE, len); size_t n = std::min(CHUNK_SIZE, data.size());
writeInternal(data, n); writeInternal(data);
data += n; data.remove_prefix(n);
len -= n;
} }
} }
virtual void writeInternal(const unsigned char * data, size_t len) = 0; virtual void writeInternal(std::string_view data) = 0;
}; };
struct NoneSink : CompressionSink struct NoneSink : CompressionSink
@ -41,7 +40,7 @@ struct NoneSink : CompressionSink
Sink & nextSink; Sink & nextSink;
NoneSink(Sink & nextSink) : nextSink(nextSink) { } NoneSink(Sink & nextSink) : nextSink(nextSink) { }
void finish() override { flush(); } void finish() override { flush(); }
void write(const unsigned char * data, size_t len) override { nextSink(data, len); } void write(std::string_view data) override { nextSink(data); }
}; };
struct GzipDecompressionSink : CompressionSink struct GzipDecompressionSink : CompressionSink
@ -75,28 +74,28 @@ struct GzipDecompressionSink : CompressionSink
void finish() override void finish() override
{ {
CompressionSink::flush(); CompressionSink::flush();
write(nullptr, 0); write({});
} }
void write(const unsigned char * data, size_t len) override void write(std::string_view data) override
{ {
assert(len <= std::numeric_limits<decltype(strm.avail_in)>::max()); assert(data.size() <= std::numeric_limits<decltype(strm.avail_in)>::max());
strm.next_in = (Bytef *) data; strm.next_in = (Bytef *) data.data();
strm.avail_in = len; strm.avail_in = data.size();
while (!finished && (!data || strm.avail_in)) { while (!finished && (!data.data() || strm.avail_in)) {
checkInterrupt(); checkInterrupt();
int ret = inflate(&strm,Z_SYNC_FLUSH); int ret = inflate(&strm,Z_SYNC_FLUSH);
if (ret != Z_OK && ret != Z_STREAM_END) if (ret != Z_OK && ret != Z_STREAM_END)
throw CompressionError("error while decompressing gzip file: %d (%d, %d)", throw CompressionError("error while decompressing gzip file: %d (%d, %d)",
zError(ret), len, strm.avail_in); zError(ret), data.size(), strm.avail_in);
finished = ret == Z_STREAM_END; finished = ret == Z_STREAM_END;
if (strm.avail_out < sizeof(outbuf) || strm.avail_in == 0) { if (strm.avail_out < sizeof(outbuf) || strm.avail_in == 0) {
nextSink(outbuf, sizeof(outbuf) - strm.avail_out); nextSink({(char *) outbuf, sizeof(outbuf) - strm.avail_out});
strm.next_out = (Bytef *) outbuf; strm.next_out = (Bytef *) outbuf;
strm.avail_out = sizeof(outbuf); strm.avail_out = sizeof(outbuf);
} }
@ -130,25 +129,25 @@ struct XzDecompressionSink : CompressionSink
void finish() override void finish() override
{ {
CompressionSink::flush(); CompressionSink::flush();
write(nullptr, 0); write({});
} }
void write(const unsigned char * data, size_t len) override void write(std::string_view data) override
{ {
strm.next_in = data; strm.next_in = (const unsigned char *) data.data();
strm.avail_in = len; strm.avail_in = data.size();
while (!finished && (!data || strm.avail_in)) { while (!finished && (!data.data() || strm.avail_in)) {
checkInterrupt(); checkInterrupt();
lzma_ret ret = lzma_code(&strm, data ? LZMA_RUN : LZMA_FINISH); lzma_ret ret = lzma_code(&strm, data.data() ? LZMA_RUN : LZMA_FINISH);
if (ret != LZMA_OK && ret != LZMA_STREAM_END) if (ret != LZMA_OK && ret != LZMA_STREAM_END)
throw CompressionError("error %d while decompressing xz file", ret); throw CompressionError("error %d while decompressing xz file", ret);
finished = ret == LZMA_STREAM_END; finished = ret == LZMA_STREAM_END;
if (strm.avail_out < sizeof(outbuf) || strm.avail_in == 0) { if (strm.avail_out < sizeof(outbuf) || strm.avail_in == 0) {
nextSink(outbuf, sizeof(outbuf) - strm.avail_out); nextSink({(char *) outbuf, sizeof(outbuf) - strm.avail_out});
strm.next_out = outbuf; strm.next_out = outbuf;
strm.avail_out = sizeof(outbuf); strm.avail_out = sizeof(outbuf);
} }
@ -181,15 +180,15 @@ struct BzipDecompressionSink : ChunkedCompressionSink
void finish() override void finish() override
{ {
flush(); flush();
write(nullptr, 0); write({});
} }
void writeInternal(const unsigned char * data, size_t len) override void writeInternal(std::string_view data) override
{ {
assert(len <= std::numeric_limits<decltype(strm.avail_in)>::max()); assert(data.size() <= std::numeric_limits<decltype(strm.avail_in)>::max());
strm.next_in = (char *) data; strm.next_in = (char *) data.data();
strm.avail_in = len; strm.avail_in = data.size();
while (strm.avail_in) { while (strm.avail_in) {
checkInterrupt(); checkInterrupt();
@ -201,7 +200,7 @@ struct BzipDecompressionSink : ChunkedCompressionSink
finished = ret == BZ_STREAM_END; finished = ret == BZ_STREAM_END;
if (strm.avail_out < sizeof(outbuf) || strm.avail_in == 0) { if (strm.avail_out < sizeof(outbuf) || strm.avail_in == 0) {
nextSink(outbuf, sizeof(outbuf) - strm.avail_out); nextSink({(char *) outbuf, sizeof(outbuf) - strm.avail_out});
strm.next_out = (char *) outbuf; strm.next_out = (char *) outbuf;
strm.avail_out = sizeof(outbuf); strm.avail_out = sizeof(outbuf);
} }
@ -230,17 +229,17 @@ struct BrotliDecompressionSink : ChunkedCompressionSink
void finish() override void finish() override
{ {
flush(); flush();
writeInternal(nullptr, 0); writeInternal({});
} }
void writeInternal(const unsigned char * data, size_t len) override void writeInternal(std::string_view data) override
{ {
const uint8_t * next_in = data; auto next_in = (const uint8_t *) data.data();
size_t avail_in = len; size_t avail_in = data.size();
uint8_t * next_out = outbuf; uint8_t * next_out = outbuf;
size_t avail_out = sizeof(outbuf); size_t avail_out = sizeof(outbuf);
while (!finished && (!data || avail_in)) { while (!finished && (!data.data() || avail_in)) {
checkInterrupt(); checkInterrupt();
if (!BrotliDecoderDecompressStream(state, if (!BrotliDecoderDecompressStream(state,
@ -250,7 +249,7 @@ struct BrotliDecompressionSink : ChunkedCompressionSink
throw CompressionError("error while decompressing brotli file"); throw CompressionError("error while decompressing brotli file");
if (avail_out < sizeof(outbuf) || avail_in == 0) { if (avail_out < sizeof(outbuf) || avail_in == 0) {
nextSink(outbuf, sizeof(outbuf) - avail_out); nextSink({(char *) outbuf, sizeof(outbuf) - avail_out});
next_out = outbuf; next_out = outbuf;
avail_out = sizeof(outbuf); avail_out = sizeof(outbuf);
} }
@ -338,25 +337,25 @@ struct XzCompressionSink : CompressionSink
void finish() override void finish() override
{ {
CompressionSink::flush(); CompressionSink::flush();
write(nullptr, 0); write({});
} }
void write(const unsigned char * data, size_t len) override void write(std::string_view data) override
{ {
strm.next_in = data; strm.next_in = (const unsigned char *) data.data();
strm.avail_in = len; strm.avail_in = data.size();
while (!finished && (!data || strm.avail_in)) { while (!finished && (!data.data() || strm.avail_in)) {
checkInterrupt(); checkInterrupt();
lzma_ret ret = lzma_code(&strm, data ? LZMA_RUN : LZMA_FINISH); lzma_ret ret = lzma_code(&strm, data.data() ? LZMA_RUN : LZMA_FINISH);
if (ret != LZMA_OK && ret != LZMA_STREAM_END) if (ret != LZMA_OK && ret != LZMA_STREAM_END)
throw CompressionError("error %d while compressing xz file", ret); throw CompressionError("error %d while compressing xz file", ret);
finished = ret == LZMA_STREAM_END; finished = ret == LZMA_STREAM_END;
if (strm.avail_out < sizeof(outbuf) || strm.avail_in == 0) { if (strm.avail_out < sizeof(outbuf) || strm.avail_in == 0) {
nextSink(outbuf, sizeof(outbuf) - strm.avail_out); nextSink({(const char *) outbuf, sizeof(outbuf) - strm.avail_out});
strm.next_out = outbuf; strm.next_out = outbuf;
strm.avail_out = sizeof(outbuf); strm.avail_out = sizeof(outbuf);
} }
@ -389,27 +388,27 @@ struct BzipCompressionSink : ChunkedCompressionSink
void finish() override void finish() override
{ {
flush(); flush();
writeInternal(nullptr, 0); writeInternal({});
} }
void writeInternal(const unsigned char * data, size_t len) override void writeInternal(std::string_view data) override
{ {
assert(len <= std::numeric_limits<decltype(strm.avail_in)>::max()); assert(data.size() <= std::numeric_limits<decltype(strm.avail_in)>::max());
strm.next_in = (char *) data; strm.next_in = (char *) data.data();
strm.avail_in = len; strm.avail_in = data.size();
while (!finished && (!data || strm.avail_in)) { while (!finished && (!data.data() || strm.avail_in)) {
checkInterrupt(); checkInterrupt();
int ret = BZ2_bzCompress(&strm, data ? BZ_RUN : BZ_FINISH); int ret = BZ2_bzCompress(&strm, data.data() ? BZ_RUN : BZ_FINISH);
if (ret != BZ_RUN_OK && ret != BZ_FINISH_OK && ret != BZ_STREAM_END) if (ret != BZ_RUN_OK && ret != BZ_FINISH_OK && ret != BZ_STREAM_END)
throw CompressionError("error %d while compressing bzip2 file", ret); throw CompressionError("error %d while compressing bzip2 file", ret);
finished = ret == BZ_STREAM_END; finished = ret == BZ_STREAM_END;
if (strm.avail_out < sizeof(outbuf) || strm.avail_in == 0) { if (strm.avail_out < sizeof(outbuf) || strm.avail_in == 0) {
nextSink(outbuf, sizeof(outbuf) - strm.avail_out); nextSink({(const char *) outbuf, sizeof(outbuf) - strm.avail_out});
strm.next_out = (char *) outbuf; strm.next_out = (char *) outbuf;
strm.avail_out = sizeof(outbuf); strm.avail_out = sizeof(outbuf);
} }
@ -439,28 +438,28 @@ struct BrotliCompressionSink : ChunkedCompressionSink
void finish() override void finish() override
{ {
flush(); flush();
writeInternal(nullptr, 0); writeInternal({});
} }
void writeInternal(const unsigned char * data, size_t len) override void writeInternal(std::string_view data) override
{ {
const uint8_t * next_in = data; auto next_in = (const uint8_t *) data.data();
size_t avail_in = len; size_t avail_in = data.size();
uint8_t * next_out = outbuf; uint8_t * next_out = outbuf;
size_t avail_out = sizeof(outbuf); size_t avail_out = sizeof(outbuf);
while (!finished && (!data || avail_in)) { while (!finished && (!data.data() || avail_in)) {
checkInterrupt(); checkInterrupt();
if (!BrotliEncoderCompressStream(state, if (!BrotliEncoderCompressStream(state,
data ? BROTLI_OPERATION_PROCESS : BROTLI_OPERATION_FINISH, data.data() ? BROTLI_OPERATION_PROCESS : BROTLI_OPERATION_FINISH,
&avail_in, &next_in, &avail_in, &next_in,
&avail_out, &next_out, &avail_out, &next_out,
nullptr)) nullptr))
throw CompressionError("error while compressing brotli compression"); throw CompressionError("error while compressing brotli compression");
if (avail_out < sizeof(outbuf) || avail_in == 0) { if (avail_out < sizeof(outbuf) || avail_in == 0) {
nextSink(outbuf, sizeof(outbuf) - avail_out); nextSink({(const char *) outbuf, sizeof(outbuf) - avail_out});
next_out = outbuf; next_out = outbuf;
avail_out = sizeof(outbuf); avail_out = sizeof(outbuf);
} }

View file

@ -291,12 +291,12 @@ static void start(HashType ht, Ctx & ctx)
static void update(HashType ht, Ctx & ctx, static void update(HashType ht, Ctx & ctx,
const unsigned char * bytes, size_t len) std::string_view data)
{ {
if (ht == htMD5) MD5_Update(&ctx.md5, bytes, len); if (ht == htMD5) MD5_Update(&ctx.md5, data.data(), data.size());
else if (ht == htSHA1) SHA1_Update(&ctx.sha1, bytes, len); else if (ht == htSHA1) SHA1_Update(&ctx.sha1, data.data(), data.size());
else if (ht == htSHA256) SHA256_Update(&ctx.sha256, bytes, len); else if (ht == htSHA256) SHA256_Update(&ctx.sha256, data.data(), data.size());
else if (ht == htSHA512) SHA512_Update(&ctx.sha512, bytes, len); else if (ht == htSHA512) SHA512_Update(&ctx.sha512, data.data(), data.size());
} }
@ -314,7 +314,7 @@ Hash hashString(HashType ht, std::string_view s)
Ctx ctx; Ctx ctx;
Hash hash(ht); Hash hash(ht);
start(ht, ctx); start(ht, ctx);
update(ht, ctx, (const unsigned char *) s.data(), s.length()); update(ht, ctx, s);
finish(ht, ctx, hash.hash); finish(ht, ctx, hash.hash);
return hash; return hash;
} }
@ -341,10 +341,10 @@ HashSink::~HashSink()
delete ctx; delete ctx;
} }
void HashSink::write(const unsigned char * data, size_t len) void HashSink::write(std::string_view data)
{ {
bytes += len; bytes += data.size();
update(ht, *ctx, data, len); update(ht, *ctx, data);
} }
HashResult HashSink::finish() HashResult HashSink::finish()

View file

@ -156,7 +156,7 @@ public:
HashSink(HashType ht); HashSink(HashType ht);
HashSink(const HashSink & h); HashSink(const HashSink & h);
~HashSink(); ~HashSink();
void write(const unsigned char * data, size_t len) override; void write(std::string_view data) override;
HashResult finish() override; HashResult finish() override;
HashResult currentHash(); HashResult currentHash();
}; };

View file

@ -11,23 +11,23 @@
namespace nix { namespace nix {
void BufferedSink::operator () (const unsigned char * data, size_t len) void BufferedSink::operator () (std::string_view data)
{ {
if (!buffer) buffer = decltype(buffer)(new unsigned char[bufSize]); if (!buffer) buffer = decltype(buffer)(new char[bufSize]);
while (len) { while (!data.empty()) {
/* Optimisation: bypass the buffer if the data exceeds the /* Optimisation: bypass the buffer if the data exceeds the
buffer size. */ buffer size. */
if (bufPos + len >= bufSize) { if (bufPos + data.size() >= bufSize) {
flush(); flush();
write(data, len); write(data);
break; break;
} }
/* Otherwise, copy the bytes to the buffer. Flush the buffer /* Otherwise, copy the bytes to the buffer. Flush the buffer
when it's full. */ when it's full. */
size_t n = bufPos + len > bufSize ? bufSize - bufPos : len; size_t n = bufPos + data.size() > bufSize ? bufSize - bufPos : data.size();
memcpy(buffer.get() + bufPos, data, n); memcpy(buffer.get() + bufPos, data.data(), n);
data += n; bufPos += n; len -= n; data.remove_prefix(n); bufPos += n;
if (bufPos == bufSize) flush(); if (bufPos == bufSize) flush();
} }
} }
@ -38,7 +38,7 @@ void BufferedSink::flush()
if (bufPos == 0) return; if (bufPos == 0) return;
size_t n = bufPos; size_t n = bufPos;
bufPos = 0; // don't trigger the assert() in ~BufferedSink() bufPos = 0; // don't trigger the assert() in ~BufferedSink()
write(buffer.get(), n); write({buffer.get(), n});
} }
@ -59,9 +59,9 @@ static void warnLargeDump()
} }
void FdSink::write(const unsigned char * data, size_t len) void FdSink::write(std::string_view data)
{ {
written += len; written += data.size();
static bool warned = false; static bool warned = false;
if (warn && !warned) { if (warn && !warned) {
if (written > threshold) { if (written > threshold) {
@ -70,7 +70,7 @@ void FdSink::write(const unsigned char * data, size_t len)
} }
} }
try { try {
writeFull(fd, data, len); writeFull(fd, data);
} catch (SysError & e) { } catch (SysError & e) {
_good = false; _good = false;
throw; throw;
@ -84,7 +84,7 @@ bool FdSink::good()
} }
void Source::operator () (unsigned char * data, size_t len) void Source::operator () (char * data, size_t len)
{ {
while (len) { while (len) {
size_t n = read(data, len); size_t n = read(data, len);
@ -96,12 +96,12 @@ void Source::operator () (unsigned char * data, size_t len)
void Source::drainInto(Sink & sink) void Source::drainInto(Sink & sink)
{ {
std::string s; std::string s;
std::vector<unsigned char> buf(8192); std::vector<char> buf(8192);
while (true) { while (true) {
size_t n; size_t n;
try { try {
n = read(buf.data(), buf.size()); n = read(buf.data(), buf.size());
sink(buf.data(), n); sink({buf.data(), n});
} catch (EndOfFile &) { } catch (EndOfFile &) {
break; break;
} }
@ -117,9 +117,9 @@ std::string Source::drain()
} }
size_t BufferedSource::read(unsigned char * data, size_t len) size_t BufferedSource::read(char * data, size_t len)
{ {
if (!buffer) buffer = decltype(buffer)(new unsigned char[bufSize]); if (!buffer) buffer = decltype(buffer)(new char[bufSize]);
if (!bufPosIn) bufPosIn = readUnbuffered(buffer.get(), bufSize); if (!bufPosIn) bufPosIn = readUnbuffered(buffer.get(), bufSize);
@ -138,12 +138,12 @@ bool BufferedSource::hasData()
} }
size_t FdSource::readUnbuffered(unsigned char * data, size_t len) size_t FdSource::readUnbuffered(char * data, size_t len)
{ {
ssize_t n; ssize_t n;
do { do {
checkInterrupt(); checkInterrupt();
n = ::read(fd, (char *) data, len); n = ::read(fd, data, len);
} while (n == -1 && errno == EINTR); } while (n == -1 && errno == EINTR);
if (n == -1) { _good = false; throw SysError("reading from file"); } if (n == -1) { _good = false; throw SysError("reading from file"); }
if (n == 0) { _good = false; throw EndOfFile("unexpected end-of-file"); } if (n == 0) { _good = false; throw EndOfFile("unexpected end-of-file"); }
@ -158,10 +158,10 @@ bool FdSource::good()
} }
size_t StringSource::read(unsigned char * data, size_t len) size_t StringSource::read(char * data, size_t len)
{ {
if (pos == s.size()) throw EndOfFile("end of string reached"); if (pos == s.size()) throw EndOfFile("end of string reached");
size_t n = s.copy((char *) data, len, pos); size_t n = s.copy(data, len, pos);
pos += n; pos += n;
return n; return n;
} }
@ -225,12 +225,12 @@ std::unique_ptr<Source> sinkToSource(
std::string cur; std::string cur;
size_t pos = 0; size_t pos = 0;
size_t read(unsigned char * data, size_t len) override size_t read(char * data, size_t len) override
{ {
if (!coro) if (!coro)
coro = coro_t::pull_type(VirtualStackAllocator{}, [&](coro_t::push_type & yield) { coro = coro_t::pull_type(VirtualStackAllocator{}, [&](coro_t::push_type & yield) {
LambdaSink sink([&](const unsigned char * data, size_t len) { LambdaSink sink([&](std::string_view data) {
if (len) yield(std::string((const char *) data, len)); if (!data.empty()) yield(std::string(data));
}); });
fun(sink); fun(sink);
}); });
@ -244,7 +244,7 @@ std::unique_ptr<Source> sinkToSource(
} }
auto n = std::min(cur.size() - pos, len); auto n = std::min(cur.size() - pos, len);
memcpy(data, (unsigned char *) cur.data() + pos, n); memcpy(data, cur.data() + pos, n);
pos += n; pos += n;
return n; return n;
@ -258,24 +258,24 @@ std::unique_ptr<Source> sinkToSource(
void writePadding(size_t len, Sink & sink) void writePadding(size_t len, Sink & sink)
{ {
if (len % 8) { if (len % 8) {
unsigned char zero[8]; char zero[8];
memset(zero, 0, sizeof(zero)); memset(zero, 0, sizeof(zero));
sink(zero, 8 - (len % 8)); sink({zero, 8 - (len % 8)});
} }
} }
void writeString(const unsigned char * buf, size_t len, Sink & sink) void writeString(std::string_view data, Sink & sink)
{ {
sink << len; sink << data.size();
sink(buf, len); sink(data);
writePadding(len, sink); writePadding(data.size(), sink);
} }
Sink & operator << (Sink & sink, const string & s) Sink & operator << (Sink & sink, const string & s)
{ {
writeString((const unsigned char *) s.data(), s.size(), sink); writeString(s, sink);
return sink; return sink;
} }
@ -321,7 +321,7 @@ Sink & operator << (Sink & sink, const Error & ex)
void readPadding(size_t len, Source & source) void readPadding(size_t len, Source & source)
{ {
if (len % 8) { if (len % 8) {
unsigned char zero[8]; char zero[8];
size_t n = 8 - (len % 8); size_t n = 8 - (len % 8);
source(zero, n); source(zero, n);
for (unsigned int i = 0; i < n; i++) for (unsigned int i = 0; i < n; i++)
@ -330,7 +330,7 @@ void readPadding(size_t len, Source & source)
} }
size_t readString(unsigned char * buf, size_t max, Source & source) size_t readString(char * buf, size_t max, Source & source)
{ {
auto len = readNum<size_t>(source); auto len = readNum<size_t>(source);
if (len > max) throw SerialisationError("string is too long"); if (len > max) throw SerialisationError("string is too long");
@ -345,7 +345,7 @@ string readString(Source & source, size_t max)
auto len = readNum<size_t>(source); auto len = readNum<size_t>(source);
if (len > max) throw SerialisationError("string is too long"); if (len > max) throw SerialisationError("string is too long");
std::string res(len, 0); std::string res(len, 0);
source((unsigned char*) res.data(), len); source(res.data(), len);
readPadding(len, source); readPadding(len, source);
return res; return res;
} }
@ -394,17 +394,17 @@ Error readError(Source & source)
} }
void StringSink::operator () (const unsigned char * data, size_t len) void StringSink::operator () (std::string_view data)
{ {
static bool warned = false; static bool warned = false;
if (!warned && s->size() > threshold) { if (!warned && s->size() > threshold) {
warnLargeDump(); warnLargeDump();
warned = true; warned = true;
} }
s->append((const char *) data, len); s->append(data);
} }
size_t ChainSource::read(unsigned char * data, size_t len) size_t ChainSource::read(char * data, size_t len)
{ {
if (useSecond) { if (useSecond) {
return source2.read(data, len); return source2.read(data, len);

View file

@ -14,19 +14,14 @@ namespace nix {
struct Sink struct Sink
{ {
virtual ~Sink() { } virtual ~Sink() { }
virtual void operator () (const unsigned char * data, size_t len) = 0; virtual void operator () (std::string_view data) = 0;
virtual bool good() { return true; } virtual bool good() { return true; }
void operator () (const std::string & s)
{
(*this)((const unsigned char *) s.data(), s.size());
}
}; };
/* Just throws away data. */ /* Just throws away data. */
struct NullSink : Sink struct NullSink : Sink
{ {
void operator () (const unsigned char * data, size_t len) override void operator () (std::string_view data) override
{ } { }
}; };
@ -35,21 +30,16 @@ struct NullSink : Sink
struct BufferedSink : virtual Sink struct BufferedSink : virtual Sink
{ {
size_t bufSize, bufPos; size_t bufSize, bufPos;
std::unique_ptr<unsigned char[]> buffer; std::unique_ptr<char[]> buffer;
BufferedSink(size_t bufSize = 32 * 1024) BufferedSink(size_t bufSize = 32 * 1024)
: bufSize(bufSize), bufPos(0), buffer(nullptr) { } : bufSize(bufSize), bufPos(0), buffer(nullptr) { }
void operator () (const unsigned char * data, size_t len) override; void operator () (std::string_view data) override;
void operator () (const std::string & s)
{
Sink::operator()(s);
}
void flush(); void flush();
virtual void write(const unsigned char * data, size_t len) = 0; virtual void write(std::string_view data) = 0;
}; };
@ -61,12 +51,12 @@ struct Source
/* Store exactly len bytes in the buffer pointed to by data. /* Store exactly len bytes in the buffer pointed to by data.
It blocks until all the requested data is available, or throws It blocks until all the requested data is available, or throws
an error if it is not going to be available. */ an error if it is not going to be available. */
void operator () (unsigned char * data, size_t len); void operator () (char * data, size_t len);
/* Store up to len in the buffer pointed to by data, and /* Store up to len in the buffer pointed to by data, and
return the number of bytes stored. It blocks until at least return the number of bytes stored. It blocks until at least
one byte is available. */ one byte is available. */
virtual size_t read(unsigned char * data, size_t len) = 0; virtual size_t read(char * data, size_t len) = 0;
virtual bool good() { return true; } virtual bool good() { return true; }
@ -81,18 +71,18 @@ struct Source
struct BufferedSource : Source struct BufferedSource : Source
{ {
size_t bufSize, bufPosIn, bufPosOut; size_t bufSize, bufPosIn, bufPosOut;
std::unique_ptr<unsigned char[]> buffer; std::unique_ptr<char[]> buffer;
BufferedSource(size_t bufSize = 32 * 1024) BufferedSource(size_t bufSize = 32 * 1024)
: bufSize(bufSize), bufPosIn(0), bufPosOut(0), buffer(nullptr) { } : bufSize(bufSize), bufPosIn(0), bufPosOut(0), buffer(nullptr) { }
size_t read(unsigned char * data, size_t len) override; size_t read(char * data, size_t len) override;
bool hasData(); bool hasData();
protected: protected:
/* Underlying read call, to be overridden. */ /* Underlying read call, to be overridden. */
virtual size_t readUnbuffered(unsigned char * data, size_t len) = 0; virtual size_t readUnbuffered(char * data, size_t len) = 0;
}; };
@ -119,7 +109,7 @@ struct FdSink : BufferedSink
~FdSink(); ~FdSink();
void write(const unsigned char * data, size_t len) override; void write(std::string_view data) override;
bool good() override; bool good() override;
@ -148,7 +138,7 @@ struct FdSource : BufferedSource
bool good() override; bool good() override;
protected: protected:
size_t readUnbuffered(unsigned char * data, size_t len) override; size_t readUnbuffered(char * data, size_t len) override;
private: private:
bool _good = true; bool _good = true;
}; };
@ -163,7 +153,7 @@ struct StringSink : Sink
s->reserve(reservedSize); s->reserve(reservedSize);
}; };
StringSink(ref<std::string> s) : s(s) { }; StringSink(ref<std::string> s) : s(s) { };
void operator () (const unsigned char * data, size_t len) override; void operator () (std::string_view data) override;
}; };
@ -173,7 +163,7 @@ struct StringSource : Source
const string & s; const string & s;
size_t pos; size_t pos;
StringSource(const string & _s) : s(_s), pos(0) { } StringSource(const string & _s) : s(_s), pos(0) { }
size_t read(unsigned char * data, size_t len) override; size_t read(char * data, size_t len) override;
}; };
@ -182,10 +172,10 @@ struct TeeSink : Sink
{ {
Sink & sink1, & sink2; Sink & sink1, & sink2;
TeeSink(Sink & sink1, Sink & sink2) : sink1(sink1), sink2(sink2) { } TeeSink(Sink & sink1, Sink & sink2) : sink1(sink1), sink2(sink2) { }
virtual void operator () (const unsigned char * data, size_t len) virtual void operator () (std::string_view data)
{ {
sink1(data, len); sink1(data);
sink2(data, len); sink2(data);
} }
}; };
@ -197,10 +187,10 @@ struct TeeSource : Source
Sink & sink; Sink & sink;
TeeSource(Source & orig, Sink & sink) TeeSource(Source & orig, Sink & sink)
: orig(orig), sink(sink) { } : orig(orig), sink(sink) { }
size_t read(unsigned char * data, size_t len) size_t read(char * data, size_t len)
{ {
size_t n = orig.read(data, len); size_t n = orig.read(data, len);
sink(data, n); sink({data, n});
return n; return n;
} }
}; };
@ -212,7 +202,7 @@ struct SizedSource : Source
size_t remain; size_t remain;
SizedSource(Source & orig, size_t size) SizedSource(Source & orig, size_t size)
: orig(orig), remain(size) { } : orig(orig), remain(size) { }
size_t read(unsigned char * data, size_t len) size_t read(char * data, size_t len)
{ {
if (this->remain <= 0) { if (this->remain <= 0) {
throw EndOfFile("sized: unexpected end-of-file"); throw EndOfFile("sized: unexpected end-of-file");
@ -226,7 +216,7 @@ struct SizedSource : Source
/* Consume the original source until no remain data is left to consume. */ /* Consume the original source until no remain data is left to consume. */
size_t drainAll() size_t drainAll()
{ {
std::vector<unsigned char> buf(8192); std::vector<char> buf(8192);
size_t sum = 0; size_t sum = 0;
while (this->remain > 0) { while (this->remain > 0) {
size_t n = read(buf.data(), buf.size()); size_t n = read(buf.data(), buf.size());
@ -241,24 +231,24 @@ struct LengthSink : Sink
{ {
uint64_t length = 0; uint64_t length = 0;
virtual void operator () (const unsigned char * _, size_t len) void operator () (std::string_view data) override
{ {
length += len; length += data.size();
} }
}; };
/* Convert a function into a sink. */ /* Convert a function into a sink. */
struct LambdaSink : Sink struct LambdaSink : Sink
{ {
typedef std::function<void(const unsigned char *, size_t)> lambda_t; typedef std::function<void(std::string_view data)> lambda_t;
lambda_t lambda; lambda_t lambda;
LambdaSink(const lambda_t & lambda) : lambda(lambda) { } LambdaSink(const lambda_t & lambda) : lambda(lambda) { }
virtual void operator () (const unsigned char * data, size_t len) void operator () (std::string_view data) override
{ {
lambda(data, len); lambda(data);
} }
}; };
@ -266,13 +256,13 @@ struct LambdaSink : Sink
/* Convert a function into a source. */ /* Convert a function into a source. */
struct LambdaSource : Source struct LambdaSource : Source
{ {
typedef std::function<size_t(unsigned char *, size_t)> lambda_t; typedef std::function<size_t(char *, size_t)> lambda_t;
lambda_t lambda; lambda_t lambda;
LambdaSource(const lambda_t & lambda) : lambda(lambda) { } LambdaSource(const lambda_t & lambda) : lambda(lambda) { }
size_t read(unsigned char * data, size_t len) override size_t read(char * data, size_t len) override
{ {
return lambda(data, len); return lambda(data, len);
} }
@ -288,7 +278,7 @@ struct ChainSource : Source
: source1(s1), source2(s2) : source1(s1), source2(s2)
{ } { }
size_t read(unsigned char * data, size_t len) override; size_t read(char * data, size_t len) override;
}; };
@ -302,7 +292,7 @@ std::unique_ptr<Source> sinkToSource(
void writePadding(size_t len, Sink & sink); void writePadding(size_t len, Sink & sink);
void writeString(const unsigned char * buf, size_t len, Sink & sink); void writeString(std::string_view s, Sink & sink);
inline Sink & operator << (Sink & sink, uint64_t n) inline Sink & operator << (Sink & sink, uint64_t n)
{ {
@ -315,7 +305,7 @@ inline Sink & operator << (Sink & sink, uint64_t n)
buf[5] = (n >> 40) & 0xff; buf[5] = (n >> 40) & 0xff;
buf[6] = (n >> 48) & 0xff; buf[6] = (n >> 48) & 0xff;
buf[7] = (unsigned char) (n >> 56) & 0xff; buf[7] = (unsigned char) (n >> 56) & 0xff;
sink(buf, sizeof(buf)); sink({(char *) buf, sizeof(buf)});
return sink; return sink;
} }
@ -332,7 +322,7 @@ template<typename T>
T readNum(Source & source) T readNum(Source & source)
{ {
unsigned char buf[8]; unsigned char buf[8];
source(buf, sizeof(buf)); source((char *) buf, sizeof(buf));
uint64_t n = uint64_t n =
((uint64_t) buf[0]) | ((uint64_t) buf[0]) |
@ -364,7 +354,7 @@ inline uint64_t readLongLong(Source & source)
void readPadding(size_t len, Source & source); void readPadding(size_t len, Source & source);
size_t readString(unsigned char * buf, size_t max, Source & source); size_t readString(char * buf, size_t max, Source & source);
string readString(Source & source, size_t max = std::numeric_limits<size_t>::max()); string readString(Source & source, size_t max = std::numeric_limits<size_t>::max());
template<class T> T readStrings(Source & source); template<class T> T readStrings(Source & source);
@ -396,9 +386,9 @@ struct StreamToSourceAdapter : Source
: istream(istream) : istream(istream)
{ } { }
size_t read(unsigned char * data, size_t len) override size_t read(char * data, size_t len) override
{ {
if (!istream->read((char *) data, len)) { if (!istream->read(data, len)) {
if (istream->eof()) { if (istream->eof()) {
if (istream->gcount() == 0) if (istream->gcount() == 0)
throw EndOfFile("end of file"); throw EndOfFile("end of file");
@ -421,7 +411,7 @@ struct FramedSource : Source
{ {
Source & from; Source & from;
bool eof = false; bool eof = false;
std::vector<unsigned char> pending; std::vector<char> pending;
size_t pos = 0; size_t pos = 0;
FramedSource(Source & from) : from(from) FramedSource(Source & from) : from(from)
@ -433,13 +423,13 @@ struct FramedSource : Source
while (true) { while (true) {
auto n = readInt(from); auto n = readInt(from);
if (!n) break; if (!n) break;
std::vector<unsigned char> data(n); std::vector<char> data(n);
from(data.data(), n); from(data.data(), n);
} }
} }
} }
size_t read(unsigned char * data, size_t len) override size_t read(char * data, size_t len) override
{ {
if (eof) throw EndOfFile("reached end of FramedSource"); if (eof) throw EndOfFile("reached end of FramedSource");
@ -449,7 +439,7 @@ struct FramedSource : Source
eof = true; eof = true;
return 0; return 0;
} }
pending = std::vector<unsigned char>(len); pending = std::vector<char>(len);
pos = 0; pos = 0;
from(pending.data(), len); from(pending.data(), len);
} }
@ -484,7 +474,7 @@ struct FramedSink : nix::BufferedSink
} }
} }
void write(const unsigned char * data, size_t len) override void write(std::string_view data) override
{ {
/* Don't send more data if the remote has /* Don't send more data if the remote has
encountered an error. */ encountered an error. */
@ -493,8 +483,8 @@ struct FramedSink : nix::BufferedSink
ex = nullptr; ex = nullptr;
std::rethrow_exception(ex2); std::rethrow_exception(ex2);
} }
to << len; to << data.size();
to(data, len); to(data);
}; };
}; };

View file

@ -66,7 +66,7 @@ private:
*buffer = self->buffer.data(); *buffer = self->buffer.data();
try { try {
return self->source->read(self->buffer.data(), 4096); return self->source->read((char *) self->buffer.data(), 4096);
} catch (EndOfFile &) { } catch (EndOfFile &) {
return 0; return 0;
} catch (std::exception & err) { } catch (std::exception & err) {

View file

@ -320,7 +320,7 @@ void readFile(const Path & path, Sink & sink)
} }
void writeFile(const Path & path, const string & s, mode_t mode) void writeFile(const Path & path, std::string_view s, mode_t mode)
{ {
AutoCloseFD fd = open(path.c_str(), O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, mode); AutoCloseFD fd = open(path.c_str(), O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, mode);
if (!fd) if (!fd)
@ -340,13 +340,13 @@ void writeFile(const Path & path, Source & source, mode_t mode)
if (!fd) if (!fd)
throw SysError("opening file '%1%'", path); throw SysError("opening file '%1%'", path);
std::vector<unsigned char> buf(64 * 1024); std::vector<char> buf(64 * 1024);
try { try {
while (true) { while (true) {
try { try {
auto n = source.read(buf.data(), buf.size()); auto n = source.read(buf.data(), buf.size());
writeFull(fd.get(), (unsigned char *) buf.data(), n); writeFull(fd.get(), {buf.data(), n});
} catch (EndOfFile &) { break; } } catch (EndOfFile &) { break; }
} }
} catch (Error & e) { } catch (Error & e) {
@ -632,11 +632,11 @@ void replaceSymlink(const Path & target, const Path & link,
} }
void readFull(int fd, unsigned char * buf, size_t count) void readFull(int fd, char * buf, size_t count)
{ {
while (count) { while (count) {
checkInterrupt(); checkInterrupt();
ssize_t res = read(fd, (char *) buf, count); ssize_t res = read(fd, buf, count);
if (res == -1) { if (res == -1) {
if (errno == EINTR) continue; if (errno == EINTR) continue;
throw SysError("reading from file"); throw SysError("reading from file");
@ -648,24 +648,16 @@ void readFull(int fd, unsigned char * buf, size_t count)
} }
void writeFull(int fd, const unsigned char * buf, size_t count, bool allowInterrupts) void writeFull(int fd, std::string_view s, bool allowInterrupts)
{ {
while (count) { while (!s.empty()) {
if (allowInterrupts) checkInterrupt(); if (allowInterrupts) checkInterrupt();
ssize_t res = write(fd, (char *) buf, count); ssize_t res = write(fd, s.data(), s.size());
if (res == -1 && errno != EINTR) if (res == -1 && errno != EINTR)
throw SysError("writing to file"); throw SysError("writing to file");
if (res > 0) { if (res > 0)
count -= res; s.remove_prefix(res);
buf += res;
} }
}
}
void writeFull(int fd, const string & s, bool allowInterrupts)
{
writeFull(fd, (const unsigned char *) s.data(), s.size(), allowInterrupts);
} }
@ -705,7 +697,7 @@ void drainFD(int fd, Sink & sink, bool block)
throw SysError("reading from file"); throw SysError("reading from file");
} }
else if (rd == 0) break; else if (rd == 0) break;
else sink(buf.data(), rd); else sink({(char *) buf.data(), (size_t) rd});
} }
} }
@ -1145,7 +1137,7 @@ void runProgram2(const RunOptions & options)
in.readSide = -1; in.readSide = -1;
writerThread = std::thread([&]() { writerThread = std::thread([&]() {
try { try {
std::vector<unsigned char> buf(8 * 1024); std::vector<char> buf(8 * 1024);
while (true) { while (true) {
size_t n; size_t n;
try { try {
@ -1153,7 +1145,7 @@ void runProgram2(const RunOptions & options)
} catch (EndOfFile &) { } catch (EndOfFile &) {
break; break;
} }
writeFull(in.writeSide.get(), buf.data(), n); writeFull(in.writeSide.get(), {buf.data(), n});
} }
promise.set_value(); promise.set_value();
} catch (...) { } catch (...) {

View file

@ -106,7 +106,7 @@ string readFile(const Path & path);
void readFile(const Path & path, Sink & sink); void readFile(const Path & path, Sink & sink);
/* Write a string to a file. */ /* Write a string to a file. */
void writeFile(const Path & path, const string & s, mode_t mode = 0666); void writeFile(const Path & path, std::string_view s, mode_t mode = 0666);
void writeFile(const Path & path, Source & source, mode_t mode = 0666); void writeFile(const Path & path, Source & source, mode_t mode = 0666);
@ -155,9 +155,8 @@ void replaceSymlink(const Path & target, const Path & link,
/* Wrappers arount read()/write() that read/write exactly the /* Wrappers arount read()/write() that read/write exactly the
requested number of bytes. */ requested number of bytes. */
void readFull(int fd, unsigned char * buf, size_t count); void readFull(int fd, char * buf, size_t count);
void writeFull(int fd, const unsigned char * buf, size_t count, bool allowInterrupts = true); void writeFull(int fd, std::string_view s, bool allowInterrupts = true);
void writeFull(int fd, const string & s, bool allowInterrupts = true);
MakeError(EndOfFile, Error); MakeError(EndOfFile, Error);

28
src/nix/add-file.md Normal file
View file

@ -0,0 +1,28 @@
R""(
# Description
Copy the regular file *path* to the Nix store, and print the resulting
store path on standard output.
> **Warning**
>
> The resulting store path is not registered as a garbage
> collector root, so it could be deleted before you have a
> chance to register it.
# Examples
Add a regular file to the store:
```console
# echo foo > bar
# nix store add-file ./bar
/nix/store/cbv2s4bsvzjri77s2gb8g8bpcb6dpa8w-bar
# cat /nix/store/cbv2s4bsvzjri77s2gb8g8bpcb6dpa8w-bar
foo
```
)""

29
src/nix/add-path.md Normal file
View file

@ -0,0 +1,29 @@
R""(
# Description
Copy *path* to the Nix store, and print the resulting store path on
standard output.
> **Warning**
>
> The resulting store path is not registered as a garbage
> collector root, so it could be deleted before you have a
> chance to register it.
# Examples
Add a directory to the store:
```console
# mkdir dir
# echo foo > dir/bar
# nix store add-path ./dir
/nix/store/6pmjx56pm94n66n4qw1nff0y1crm8nqg-dir
# cat /nix/store/6pmjx56pm94n66n4qw1nff0y1crm8nqg-dir/bar
foo
```
)""

View file

@ -9,10 +9,11 @@ struct CmdAddToStore : MixDryRun, StoreCommand
{ {
Path path; Path path;
std::optional<std::string> namePart; std::optional<std::string> namePart;
FileIngestionMethod ingestionMethod = FileIngestionMethod::Recursive; FileIngestionMethod ingestionMethod;
CmdAddToStore() CmdAddToStore()
{ {
// FIXME: completion
expectArg("path", &path); expectArg("path", &path);
addFlag({ addFlag({
@ -22,36 +23,8 @@ struct CmdAddToStore : MixDryRun, StoreCommand
.labels = {"name"}, .labels = {"name"},
.handler = {&namePart}, .handler = {&namePart},
}); });
addFlag({
.longName = "flat",
.shortName = 0,
.description = "add flat file to the Nix store",
.handler = {&ingestionMethod, FileIngestionMethod::Flat},
});
} }
std::string description() override
{
return "add a path to the Nix store";
}
std::string doc() override
{
return R"(
Copy the file or directory *path* to the Nix store, and
print the resulting store path on standard output.
)";
}
Examples examples() override
{
return {
};
}
Category category() override { return catUtility; }
void run(ref<Store> store) override void run(ref<Store> store) override
{ {
if (!namePart) namePart = baseNameOf(path); if (!namePart) namePart = baseNameOf(path);
@ -87,4 +60,45 @@ struct CmdAddToStore : MixDryRun, StoreCommand
} }
}; };
static auto rCmdAddToStore = registerCommand<CmdAddToStore>("add-to-store"); struct CmdAddFile : CmdAddToStore
{
CmdAddFile()
{
ingestionMethod = FileIngestionMethod::Flat;
}
std::string description() override
{
return "add a regular file to the Nix store";
}
std::string doc() override
{
return
#include "add-file.md"
;
}
};
struct CmdAddPath : CmdAddToStore
{
CmdAddPath()
{
ingestionMethod = FileIngestionMethod::Recursive;
}
std::string description() override
{
return "add a path to the Nix store";
}
std::string doc() override
{
return
#include "add-path.md"
;
}
};
static auto rCmdAddFile = registerCommand2<CmdAddFile>({"store", "add-file"});
static auto rCmdAddPath = registerCommand2<CmdAddPath>({"store", "add-path"});

View file

@ -37,8 +37,6 @@ struct CmdCatStore : StoreCommand, MixCat
return "print the contents of a file in the Nix store on stdout"; return "print the contents of a file in the Nix store on stdout";
} }
Category category() override { return catUtility; }
void run(ref<Store> store) override void run(ref<Store> store) override
{ {
cat(store->getFSAccessor()); cat(store->getFSAccessor());
@ -64,13 +62,11 @@ struct CmdCatNar : StoreCommand, MixCat
return "print the contents of a file inside a NAR file on stdout"; return "print the contents of a file inside a NAR file on stdout";
} }
Category category() override { return catUtility; }
void run(ref<Store> store) override void run(ref<Store> store) override
{ {
cat(makeNarAccessor(make_ref<std::string>(readFile(narPath)))); cat(makeNarAccessor(make_ref<std::string>(readFile(narPath))));
} }
}; };
static auto rCmdCatStore = registerCommand<CmdCatStore>("cat-store"); static auto rCmdCatStore = registerCommand2<CmdCatStore>({"store", "cat"});
static auto rCmdCatNar = registerCommand<CmdCatNar>("cat-nar"); static auto rCmdCatNar = registerCommand2<CmdCatNar>({"nar", "cat"});

View file

@ -11,7 +11,21 @@ extern char * * environ __attribute__((weak));
namespace nix { namespace nix {
Commands * RegisterCommand::commands = nullptr; RegisterCommand::Commands * RegisterCommand::commands = nullptr;
nix::Commands RegisterCommand::getCommandsFor(const std::vector<std::string> & prefix)
{
nix::Commands res;
for (auto & [name, command] : *RegisterCommand::commands)
if (name.size() == prefix.size() + 1) {
bool equal = true;
for (size_t i = 0; i < prefix.size(); ++i)
if (name[i] != prefix[i]) equal = false;
if (equal)
res.insert_or_assign(name[prefix.size()], command);
}
return res;
}
void NixMultiCommand::printHelp(const string & programName, std::ostream & out) void NixMultiCommand::printHelp(const string & programName, std::ostream & out)
{ {

View file

@ -176,20 +176,29 @@ struct StorePathCommand : public InstallablesCommand
/* A helper class for registering commands globally. */ /* A helper class for registering commands globally. */
struct RegisterCommand struct RegisterCommand
{ {
typedef std::map<std::vector<std::string>, std::function<ref<Command>()>> Commands;
static Commands * commands; static Commands * commands;
RegisterCommand(const std::string & name, RegisterCommand(std::vector<std::string> && name,
std::function<ref<Command>()> command) std::function<ref<Command>()> command)
{ {
if (!commands) commands = new Commands; if (!commands) commands = new Commands;
commands->emplace(name, command); commands->emplace(name, command);
} }
static nix::Commands getCommandsFor(const std::vector<std::string> & prefix);
}; };
template<class T> template<class T>
static RegisterCommand registerCommand(const std::string & name) static RegisterCommand registerCommand(const std::string & name)
{ {
return RegisterCommand(name, [](){ return make_ref<T>(); }); return RegisterCommand({name}, [](){ return make_ref<T>(); });
}
template<class T>
static RegisterCommand registerCommand2(std::vector<std::string> && name)
{
return RegisterCommand(std::move(name), [](){ return make_ref<T>(); });
} }
Buildables build(ref<Store> store, Realise mode, Buildables build(ref<Store> store, Realise mode,

View file

@ -121,14 +121,12 @@ struct CmdDiffClosures : SourceExprCommand
return "show what packages and versions were added and removed between two closures"; return "show what packages and versions were added and removed between two closures";
} }
Category category() override { return catSecondary; }
Examples examples() override Examples examples() override
{ {
return { return {
{ {
"To show what got added and removed between two versions of the NixOS system profile:", "To show what got added and removed between two versions of the NixOS system profile:",
"nix diff-closures /nix/var/nix/profiles/system-655-link /nix/var/nix/profiles/system-658-link", "nix store diff-closures /nix/var/nix/profiles/system-655-link /nix/var/nix/profiles/system-658-link",
}, },
}; };
} }
@ -143,4 +141,4 @@ struct CmdDiffClosures : SourceExprCommand
} }
}; };
static auto rCmdDiffClosures = registerCommand<CmdDiffClosures>("diff-closures"); static auto rCmdDiffClosures = registerCommand2<CmdDiffClosures>({"store", "diff-closures"});

View file

@ -1,5 +1,6 @@
#include "command.hh" #include "command.hh"
#include "store-api.hh" #include "store-api.hh"
#include "archive.hh"
using namespace nix; using namespace nix;
@ -7,7 +8,7 @@ struct CmdDumpPath : StorePathCommand
{ {
std::string description() override std::string description() override
{ {
return "dump a store path to stdout (in NAR format)"; return "serialise a store path to stdout in NAR format";
} }
Examples examples() override Examples examples() override
@ -15,13 +16,11 @@ struct CmdDumpPath : StorePathCommand
return { return {
Example{ Example{
"To get a NAR from the binary cache https://cache.nixos.org/:", "To get a NAR from the binary cache https://cache.nixos.org/:",
"nix dump-path --store https://cache.nixos.org/ /nix/store/7crrmih8c52r8fbnqb933dxrsp44md93-glibc-2.25" "nix store dump-path --store https://cache.nixos.org/ /nix/store/7crrmih8c52r8fbnqb933dxrsp44md93-glibc-2.25"
}, },
}; };
} }
Category category() override { return catUtility; }
void run(ref<Store> store, const StorePath & storePath) override void run(ref<Store> store, const StorePath & storePath) override
{ {
FdSink sink(STDOUT_FILENO); FdSink sink(STDOUT_FILENO);
@ -30,4 +29,42 @@ struct CmdDumpPath : StorePathCommand
} }
}; };
static auto rDumpPath = registerCommand<CmdDumpPath>("dump-path"); static auto rDumpPath = registerCommand2<CmdDumpPath>({"store", "dump-path"});
struct CmdDumpPath2 : Command
{
Path path;
CmdDumpPath2()
{
expectArgs({
.label = "path",
.handler = {&path},
.completer = completePath
});
}
std::string description() override
{
return "serialise a path to stdout in NAR format";
}
Examples examples() override
{
return {
Example{
"To serialise directory 'foo' as a NAR:",
"nix nar dump-path ./foo"
},
};
}
void run() override
{
FdSink sink(STDOUT_FILENO);
dumpPath(path, sink);
sink.flush();
}
};
static auto rDumpPath2 = registerCommand2<CmdDumpPath2>({"nar", "dump-path"});

View file

@ -3,6 +3,7 @@
#include "shared.hh" #include "shared.hh"
#include "store-api.hh" #include "store-api.hh"
#include "eval.hh" #include "eval.hh"
#include "eval-inline.hh"
#include "json.hh" #include "json.hh"
#include "value-to-json.hh" #include "value-to-json.hh"
#include "progress-bar.hh" #include "progress-bar.hh"
@ -13,6 +14,7 @@ struct CmdEval : MixJSON, InstallableCommand
{ {
bool raw = false; bool raw = false;
std::optional<std::string> apply; std::optional<std::string> apply;
std::optional<Path> writeTo;
CmdEval() CmdEval()
{ {
@ -24,6 +26,13 @@ struct CmdEval : MixJSON, InstallableCommand
.labels = {"expr"}, .labels = {"expr"},
.handler = {&apply}, .handler = {&apply},
}); });
addFlag({
.longName = "write-to",
.description = "write a string or attrset of strings to 'path'",
.labels = {"path"},
.handler = {&writeTo},
});
} }
std::string description() override std::string description() override
@ -66,7 +75,7 @@ struct CmdEval : MixJSON, InstallableCommand
auto state = getEvalState(); auto state = getEvalState();
auto v = installable->toValue(*state).first; auto [v, pos] = installable->toValue(*state);
PathSet context; PathSet context;
if (apply) { if (apply) {
@ -77,13 +86,51 @@ struct CmdEval : MixJSON, InstallableCommand
v = vRes; v = vRes;
} }
if (raw) { if (writeTo) {
stopProgressBar();
if (pathExists(*writeTo))
throw Error("path '%s' already exists", *writeTo);
std::function<void(Value & v, const Pos & pos, const Path & path)> recurse;
recurse = [&](Value & v, const Pos & pos, const Path & path)
{
state->forceValue(v);
if (v.type == tString)
// FIXME: disallow strings with contexts?
writeFile(path, v.string.s);
else if (v.type == tAttrs) {
if (mkdir(path.c_str(), 0777) == -1)
throw SysError("creating directory '%s'", path);
for (auto & attr : *v.attrs)
try {
if (attr.name == "." || attr.name == "..")
throw Error("invalid file name '%s'", attr.name);
recurse(*attr.value, *attr.pos, path + "/" + std::string(attr.name));
} catch (Error & e) {
e.addTrace(*attr.pos, hintfmt("while evaluating the attribute '%s'", attr.name));
throw;
}
}
else
throw TypeError("value at '%s' is not a string or an attribute set", pos);
};
recurse(*v, pos, *writeTo);
}
else if (raw) {
stopProgressBar(); stopProgressBar();
std::cout << state->coerceToString(noPos, *v, context); std::cout << state->coerceToString(noPos, *v, context);
} else if (json) { }
else if (json) {
JSONPlaceholder jsonOut(std::cout); JSONPlaceholder jsonOut(std::cout);
printValueAsJSON(*state, true, *v, jsonOut, context); printValueAsJSON(*state, true, *v, jsonOut, context);
} else { }
else {
state->forceValueDeep(*v); state->forceValueDeep(*v);
logger->cout("%s", *v); logger->cout("%s", *v);
} }

View file

@ -8,7 +8,7 @@
using namespace nix; using namespace nix;
struct CmdHash : Command struct CmdHashBase : Command
{ {
FileIngestionMethod mode; FileIngestionMethod mode;
Base base = SRI; Base base = SRI;
@ -17,7 +17,7 @@ struct CmdHash : Command
std::vector<std::string> paths; std::vector<std::string> paths;
std::optional<std::string> modulus; std::optional<std::string> modulus;
CmdHash(FileIngestionMethod mode) : mode(mode) CmdHashBase(FileIngestionMethod mode) : mode(mode)
{ {
mkFlag(0, "sri", "print hash in SRI format", &base, SRI); mkFlag(0, "sri", "print hash in SRI format", &base, SRI);
mkFlag(0, "base64", "print hash in base-64", &base, Base64); mkFlag(0, "base64", "print hash in base-64", &base, Base64);
@ -51,8 +51,6 @@ struct CmdHash : Command
return d; return d;
} }
Category category() override { return catUtility; }
void run() override void run() override
{ {
for (auto path : paths) { for (auto path : paths) {
@ -79,9 +77,6 @@ struct CmdHash : Command
} }
}; };
static RegisterCommand rCmdHashFile("hash-file", [](){ return make_ref<CmdHash>(FileIngestionMethod::Flat); });
static RegisterCommand rCmdHashPath("hash-path", [](){ return make_ref<CmdHash>(FileIngestionMethod::Recursive); });
struct CmdToBase : Command struct CmdToBase : Command
{ {
Base base; Base base;
@ -103,8 +98,6 @@ struct CmdToBase : Command
"SRI"); "SRI");
} }
Category category() override { return catUtility; }
void run() override void run() override
{ {
for (auto s : args) for (auto s : args)
@ -112,10 +105,41 @@ struct CmdToBase : Command
} }
}; };
static RegisterCommand rCmdToBase16("to-base16", [](){ return make_ref<CmdToBase>(Base16); }); struct CmdHash : NixMultiCommand
static RegisterCommand rCmdToBase32("to-base32", [](){ return make_ref<CmdToBase>(Base32); }); {
static RegisterCommand rCmdToBase64("to-base64", [](){ return make_ref<CmdToBase>(Base64); }); CmdHash()
static RegisterCommand rCmdToSRI("to-sri", [](){ return make_ref<CmdToBase>(SRI); }); : MultiCommand({
{"file", []() { return make_ref<CmdHashBase>(FileIngestionMethod::Flat);; }},
{"path", []() { return make_ref<CmdHashBase>(FileIngestionMethod::Recursive); }},
{"to-base16", []() { return make_ref<CmdToBase>(Base16); }},
{"to-base32", []() { return make_ref<CmdToBase>(Base32); }},
{"to-base64", []() { return make_ref<CmdToBase>(Base64); }},
{"to-sri", []() { return make_ref<CmdToBase>(SRI); }},
})
{ }
std::string description() override
{
return "compute and convert cryptographic hashes";
}
Category category() override { return catUtility; }
void run() override
{
if (!command)
throw UsageError("'nix hash' requires a sub-command.");
command->second->prepare();
command->second->run();
}
void printHelp(const string & programName, std::ostream & out) override
{
MultiCommand::printHelp(programName, out);
}
};
static auto rCmdHash = registerCommand<CmdHash>("hash");
/* Legacy nix-hash command. */ /* Legacy nix-hash command. */
static int compatNixHash(int argc, char * * argv) static int compatNixHash(int argc, char * * argv)
@ -149,7 +173,7 @@ static int compatNixHash(int argc, char * * argv)
}); });
if (op == opHash) { if (op == opHash) {
CmdHash cmd(flat ? FileIngestionMethod::Flat : FileIngestionMethod::Recursive); CmdHashBase cmd(flat ? FileIngestionMethod::Flat : FileIngestionMethod::Recursive);
cmd.ht = ht; cmd.ht = ht;
cmd.base = base32 ? Base32 : Base16; cmd.base = base32 ? Base32 : Base16;
cmd.truncate = truncate; cmd.truncate = truncate;

View file

@ -97,7 +97,7 @@ struct CmdLsStore : StoreCommand, MixLs
return { return {
Example{ Example{
"To list the contents of a store path in a binary cache:", "To list the contents of a store path in a binary cache:",
"nix ls-store --store https://cache.nixos.org/ -lR /nix/store/0i2jd68mp5g6h2sa5k9c85rb80sn8hi9-hello-2.10" "nix store ls --store https://cache.nixos.org/ -lR /nix/store/0i2jd68mp5g6h2sa5k9c85rb80sn8hi9-hello-2.10"
}, },
}; };
} }
@ -107,8 +107,6 @@ struct CmdLsStore : StoreCommand, MixLs
return "show information about a path in the Nix store"; return "show information about a path in the Nix store";
} }
Category category() override { return catUtility; }
void run(ref<Store> store) override void run(ref<Store> store) override
{ {
list(store->getFSAccessor()); list(store->getFSAccessor());
@ -134,7 +132,7 @@ struct CmdLsNar : Command, MixLs
return { return {
Example{ Example{
"To list a specific file in a NAR:", "To list a specific file in a NAR:",
"nix ls-nar -l hello.nar /bin/hello" "nix nar ls -l hello.nar /bin/hello"
}, },
}; };
} }
@ -144,13 +142,11 @@ struct CmdLsNar : Command, MixLs
return "show information about a path inside a NAR file"; return "show information about a path inside a NAR file";
} }
Category category() override { return catUtility; }
void run() override void run() override
{ {
list(makeNarAccessor(make_ref<std::string>(readFile(narPath)))); list(makeNarAccessor(make_ref<std::string>(readFile(narPath))));
} }
}; };
static auto rCmdLsStore = registerCommand<CmdLsStore>("ls-store"); static auto rCmdLsStore = registerCommand2<CmdLsStore>({"store", "ls"});
static auto rCmdLsNar = registerCommand<CmdLsNar>("ls-nar"); static auto rCmdLsNar = registerCommand2<CmdLsNar>({"nar", "ls"});

View file

@ -59,7 +59,7 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
bool useNet = true; bool useNet = true;
bool refresh = false; bool refresh = false;
NixArgs() : MultiCommand(*RegisterCommand::commands), MixCommonArgs("nix") NixArgs() : MultiCommand(RegisterCommand::getCommandsFor({})), MixCommonArgs("nix")
{ {
categories.clear(); categories.clear();
categories[Command::catDefault] = "Main commands"; categories[Command::catDefault] = "Main commands";
@ -112,8 +112,45 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
.description = "consider all previously downloaded files out-of-date", .description = "consider all previously downloaded files out-of-date",
.handler = {[&]() { refresh = true; }}, .handler = {[&]() { refresh = true; }},
}); });
}
deprecatedAliases.insert({"dev-shell", "develop"}); std::map<std::string, std::vector<std::string>> aliases = {
{"add-to-store", {"store", "add-path"}},
{"cat-nar", {"nar", "cat"}},
{"cat-store", {"store", "cat"}},
{"copy-sigs", {"store", "copy-sigs"}},
{"dev-shell", {"develop"}},
{"diff-closures", {"store", "diff-closures"}},
{"dump-path", {"store", "dump-path"}},
{"hash-file", {"hash", "file"}},
{"hash-path", {"hash", "path"}},
{"ls-nar", {"nar", "ls"}},
{"ls-store", {"store", "ls"}},
{"make-content-addressable", {"store", "make-content-addressable"}},
{"optimise-store", {"store", "optimise"}},
{"ping-store", {"store", "ping"}},
{"sign-paths", {"store", "sign-paths"}},
{"to-base16", {"hash", "to-base16"}},
{"to-base32", {"hash", "to-base32"}},
{"to-base64", {"hash", "to-base64"}},
{"verify", {"store", "verify"}},
};
bool aliasUsed = false;
Strings::iterator rewriteArgs(Strings & args, Strings::iterator pos) override
{
if (aliasUsed || command || pos == args.end()) return pos;
auto arg = *pos;
auto i = aliases.find(arg);
if (i == aliases.end()) return pos;
warn("'%s' is a deprecated alias for '%s'",
arg, concatStringsSep(" ", i->second));
pos = args.erase(pos);
for (auto j = i->second.rbegin(); j != i->second.rend(); ++j)
pos = args.insert(pos, *j);
aliasUsed = true;
return pos;
} }
void printFlags(std::ostream & out) override void printFlags(std::ostream & out) override
@ -149,6 +186,50 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
} }
}; };
static void showHelp(std::vector<std::string> subcommand)
{
showManPage(subcommand.empty() ? "nix" : fmt("nix3-%s", concatStringsSep("-", subcommand)));
}
struct CmdHelp : Command
{
std::vector<std::string> subcommand;
CmdHelp()
{
expectArgs({
.label = "subcommand",
.handler = {&subcommand},
});
}
std::string description() override
{
return "show help about 'nix' or a particular subcommand";
}
Examples examples() override
{
return {
Example{
"To show help about 'nix' in general:",
"nix help"
},
Example{
"To show help about a particular subcommand:",
"nix help run"
},
};
}
void run() override
{
showHelp(subcommand);
}
};
static auto rCmdHelp = registerCommand<CmdHelp>("help");
void mainWrapped(int argc, char * * argv) void mainWrapped(int argc, char * * argv)
{ {
/* The chroot helper needs to be run before any threads have been /* The chroot helper needs to be run before any threads have been

View file

@ -23,17 +23,15 @@ struct CmdMakeContentAddressable : StorePathsCommand, MixJSON
return { return {
Example{ Example{
"To create a content-addressable representation of GNU Hello (but not its dependencies):", "To create a content-addressable representation of GNU Hello (but not its dependencies):",
"nix make-content-addressable nixpkgs#hello" "nix store make-content-addressable nixpkgs#hello"
}, },
Example{ Example{
"To compute a content-addressable representation of the current NixOS system closure:", "To compute a content-addressable representation of the current NixOS system closure:",
"nix make-content-addressable -r /run/current-system" "nix store make-content-addressable -r /run/current-system"
}, },
}; };
} }
Category category() override { return catUtility; }
void run(ref<Store> store, StorePaths storePaths) override void run(ref<Store> store, StorePaths storePaths) override
{ {
auto paths = store->topoSortPaths(StorePathSet(storePaths.begin(), storePaths.end())); auto paths = store->topoSortPaths(StorePathSet(storePaths.begin(), storePaths.end()));
@ -73,7 +71,7 @@ struct CmdMakeContentAddressable : StorePathsCommand, MixJSON
*sink.s = rewriteStrings(*sink.s, rewrites); *sink.s = rewriteStrings(*sink.s, rewrites);
HashModuloSink hashModuloSink(htSHA256, oldHashPart); HashModuloSink hashModuloSink(htSHA256, oldHashPart);
hashModuloSink((unsigned char *) sink.s->data(), sink.s->size()); hashModuloSink(*sink.s);
auto narHash = hashModuloSink.finish().first; auto narHash = hashModuloSink.finish().first;
@ -94,7 +92,7 @@ struct CmdMakeContentAddressable : StorePathsCommand, MixJSON
auto source = sinkToSource([&](Sink & nextSink) { auto source = sinkToSource([&](Sink & nextSink) {
RewritingSink rsink2(oldHashPart, std::string(info.path.hashPart()), nextSink); RewritingSink rsink2(oldHashPart, std::string(info.path.hashPart()), nextSink);
rsink2((unsigned char *) sink.s->data(), sink.s->size()); rsink2(*sink.s);
rsink2.flush(); rsink2.flush();
}); });
@ -108,4 +106,4 @@ struct CmdMakeContentAddressable : StorePathsCommand, MixJSON
} }
}; };
static auto rCmdMakeContentAddressable = registerCommand<CmdMakeContentAddressable>("make-content-addressable"); static auto rCmdMakeContentAddressable = registerCommand2<CmdMakeContentAddressable>({"store", "make-content-addressable"});

31
src/nix/nar.cc Normal file
View file

@ -0,0 +1,31 @@
#include "command.hh"
using namespace nix;
struct CmdNar : NixMultiCommand
{
CmdNar() : MultiCommand(RegisterCommand::getCommandsFor({"nar"}))
{ }
std::string description() override
{
return "query the contents of NAR files";
}
Category category() override { return catUtility; }
void run() override
{
if (!command)
throw UsageError("'nix nar' requires a sub-command.");
command->second->prepare();
command->second->run();
}
void printHelp(const string & programName, std::ostream & out) override
{
MultiCommand::printHelp(programName, out);
}
};
static auto rCmdNar = registerCommand<CmdNar>("nar");

View file

@ -18,17 +18,15 @@ struct CmdOptimiseStore : StoreCommand
return { return {
Example{ Example{
"To optimise the Nix store:", "To optimise the Nix store:",
"nix optimise-store" "nix store optimise"
}, },
}; };
} }
Category category() override { return catUtility; }
void run(ref<Store> store) override void run(ref<Store> store) override
{ {
store->optimiseStore(); store->optimiseStore();
} }
}; };
static auto rCmdOptimiseStore = registerCommand<CmdOptimiseStore>("optimise-store"); static auto rCmdOptimiseStore = registerCommand2<CmdOptimiseStore>({"store", "optimise"});

View file

@ -16,17 +16,15 @@ struct CmdPingStore : StoreCommand
return { return {
Example{ Example{
"To test whether connecting to a remote Nix store via SSH works:", "To test whether connecting to a remote Nix store via SSH works:",
"nix ping-store --store ssh://mac1" "nix store ping --store ssh://mac1"
}, },
}; };
} }
Category category() override { return catUtility; }
void run(ref<Store> store) override void run(ref<Store> store) override
{ {
store->connect(); store->connect();
} }
}; };
static auto rCmdPingStore = registerCommand<CmdPingStore>("ping-store"); static auto rCmdPingStore = registerCommand2<CmdPingStore>({"store", "ping"});

View file

@ -413,7 +413,7 @@ struct CmdProfileDiffClosures : virtual StoreCommand, MixDefaultProfile
return { return {
Example{ Example{
"To show what changed between each generation of the NixOS system profile:", "To show what changed between each generation of the NixOS system profile:",
"nix profile diff-closure --profile /nix/var/nix/profiles/system" "nix profile diff-closures --profile /nix/var/nix/profiles/system"
}, },
}; };
} }

View file

@ -1,4 +1,5 @@
// FIXME: integrate this with nix path-info? // FIXME: integrate this with nix path-info?
// FIXME: rename to 'nix store show-derivation' or 'nix debug show-derivation'?
#include "command.hh" #include "command.hh"
#include "common-args.hh" #include "common-args.hh"

View file

@ -27,8 +27,6 @@ struct CmdCopySigs : StorePathsCommand
return "copy path signatures from substituters (like binary caches)"; return "copy path signatures from substituters (like binary caches)";
} }
Category category() override { return catUtility; }
void run(ref<Store> store, StorePaths storePaths) override void run(ref<Store> store, StorePaths storePaths) override
{ {
if (substituterUris.empty()) if (substituterUris.empty())
@ -92,7 +90,7 @@ struct CmdCopySigs : StorePathsCommand
} }
}; };
static auto rCmdCopySigs = registerCommand<CmdCopySigs>("copy-sigs"); static auto rCmdCopySigs = registerCommand2<CmdCopySigs>({"store", "copy-sigs"});
struct CmdSignPaths : StorePathsCommand struct CmdSignPaths : StorePathsCommand
{ {
@ -115,8 +113,6 @@ struct CmdSignPaths : StorePathsCommand
return "sign the specified paths"; return "sign the specified paths";
} }
Category category() override { return catUtility; }
void run(ref<Store> store, StorePaths storePaths) override void run(ref<Store> store, StorePaths storePaths) override
{ {
if (secretKeyFile.empty()) if (secretKeyFile.empty())
@ -144,4 +140,4 @@ struct CmdSignPaths : StorePathsCommand
} }
}; };
static auto rCmdSignPaths = registerCommand<CmdSignPaths>("sign-paths"); static auto rCmdSignPaths = registerCommand2<CmdSignPaths>({"store", "sign-paths"});

31
src/nix/store.cc Normal file
View file

@ -0,0 +1,31 @@
#include "command.hh"
using namespace nix;
struct CmdStore : virtual NixMultiCommand
{
CmdStore() : MultiCommand(RegisterCommand::getCommandsFor({"store"}))
{ }
std::string description() override
{
return "manipulate a Nix store";
}
Category category() override { return catUtility; }
void run() override
{
if (!command)
throw UsageError("'nix store' requires a sub-command.");
command->second->prepare();
command->second->run();
}
void printHelp(const string & programName, std::ostream & out) override
{
MultiCommand::printHelp(programName, out);
}
};
static auto rCmdStore = registerCommand<CmdStore>("store");

View file

@ -40,17 +40,15 @@ struct CmdVerify : StorePathsCommand
return { return {
Example{ Example{
"To verify the entire Nix store:", "To verify the entire Nix store:",
"nix verify --all" "nix store verify --all"
}, },
Example{ Example{
"To check whether each path in the closure of Firefox has at least 2 signatures:", "To check whether each path in the closure of Firefox has at least 2 signatures:",
"nix verify -r -n2 --no-contents $(type -p firefox)" "nix store verify -r -n2 --no-contents $(type -p firefox)"
}, },
}; };
} }
Category category() override { return catSecondary; }
void run(ref<Store> store, StorePaths storePaths) override void run(ref<Store> store, StorePaths storePaths) override
{ {
std::vector<ref<Store>> substituters; std::vector<ref<Store>> substituters;
@ -189,4 +187,4 @@ struct CmdVerify : StorePathsCommand
} }
}; };
static auto rCmdVerify = registerCommand<CmdVerify>("verify"); static auto rCmdVerify = registerCommand2<CmdVerify>({"store", "verify"});

View file

@ -188,7 +188,7 @@ unset _NIX_FORCE_HTTP
# Test 'nix verify --all' on a binary cache. # Test 'nix verify --all' on a binary cache.
nix verify -vvvvv --all --store file://$cacheDir --no-trust nix store verify -vvvvv --all --store file://$cacheDir --no-trust
# Test local NAR caching. # Test local NAR caching.
@ -196,13 +196,13 @@ narCache=$TEST_ROOT/nar-cache
rm -rf $narCache rm -rf $narCache
mkdir $narCache mkdir $narCache
[[ $(nix cat-store --store "file://$cacheDir?local-nar-cache=$narCache" $outPath/foobar) = FOOBAR ]] [[ $(nix store cat --store "file://$cacheDir?local-nar-cache=$narCache" $outPath/foobar) = FOOBAR ]]
rm -rfv "$cacheDir/nar" rm -rfv "$cacheDir/nar"
[[ $(nix cat-store --store "file://$cacheDir?local-nar-cache=$narCache" $outPath/foobar) = FOOBAR ]] [[ $(nix store cat --store "file://$cacheDir?local-nar-cache=$narCache" $outPath/foobar) = FOOBAR ]]
(! nix cat-store --store file://$cacheDir $outPath/foobar) (! nix store cat --store file://$cacheDir $outPath/foobar)
# Test NAR listing generation. # Test NAR listing generation.

View file

@ -9,13 +9,13 @@ outPath=$(nix-build dependencies.nix --no-out-link)
nix copy --to $cacheURI $outPath nix copy --to $cacheURI $outPath
HASH=$(nix hash-path $outPath) HASH=$(nix hash path $outPath)
clearStore clearStore
clearCacheCache clearCacheCache
nix copy --from $cacheURI $outPath --no-check-sigs nix copy --from $cacheURI $outPath --no-check-sigs
HASH2=$(nix hash-path $outPath) HASH2=$(nix hash path $outPath)
[[ $HASH = $HASH2 ]] [[ $HASH = $HASH2 ]]

View file

@ -7,30 +7,32 @@ nix --experimental-features 'nix-command ca-derivations' show-derivation --deriv
buildAttr () { buildAttr () {
local derivationPath=$1 local derivationPath=$1
shift local seedValue=$2
local args=("--experimental-features" "ca-derivations" "./content-addressed.nix" "-A" "$derivationPath" "--no-out-link") shift; shift
local args=("--experimental-features" "ca-derivations" "./content-addressed.nix" "-A" "$derivationPath" --arg seed "$seedValue" "--no-out-link")
args+=("$@") args+=("$@")
nix-build "${args[@]}" nix-build "${args[@]}"
} }
testRemoteCache () { testRemoteCache () {
clearCache clearCache
local outPath=$(buildAttr dependentNonCA) local outPath=$(buildAttr dependentNonCA 1)
nix copy --to file://$cacheDir $outPath nix copy --to file://$cacheDir $outPath
clearStore clearStore
buildAttr dependentNonCA --option substituters file://$cacheDir --no-require-sigs |& (! grep "building dependent-non-ca") buildAttr dependentNonCA 1 --option substituters file://$cacheDir --no-require-sigs |& (! grep "building dependent-non-ca")
} }
testDeterministicCA () { testDeterministicCA () {
[[ $(buildAttr rootCA) = $(buildAttr rootCA) ]] [[ $(buildAttr rootCA 1) = $(buildAttr rootCA 2) ]]
} }
testCutoffFor () { testCutoffFor () {
local out1 out2 local out1 out2
out1=$(buildAttr $1) out1=$(buildAttr $1 1)
# The seed only changes the root derivation, and not it's output, so the # The seed only changes the root derivation, and not it's output, so the
# dependent derivations should only need to be built once. # dependent derivations should only need to be built once.
out2=$(buildAttr $1 -j0) buildAttr rootCA 2
out2=$(buildAttr $1 2 -j0)
test "$out1" == "$out2" test "$out1" == "$out2"
} }

View file

@ -12,7 +12,7 @@ cmp $outPath fetchurl.sh
# Now using a base-64 hash. # Now using a base-64 hash.
clearStore clearStore
hash=$(nix hash-file --type sha512 --base64 ./fetchurl.sh) hash=$(nix hash file --type sha512 --base64 ./fetchurl.sh)
outPath=$(nix-build '<nix/fetchurl.nix>' --argstr url file://$(pwd)/fetchurl.sh --argstr sha512 $hash --no-out-link) outPath=$(nix-build '<nix/fetchurl.nix>' --argstr url file://$(pwd)/fetchurl.sh --argstr sha512 $hash --no-out-link)
@ -21,7 +21,7 @@ cmp $outPath fetchurl.sh
# Now using an SRI hash. # Now using an SRI hash.
clearStore clearStore
hash=$(nix hash-file ./fetchurl.sh) hash=$(nix hash file ./fetchurl.sh)
[[ $hash =~ ^sha256- ]] [[ $hash =~ ^sha256- ]]
@ -34,14 +34,14 @@ clearStore
other_store=file://$TEST_ROOT/other_store?store=/fnord/store other_store=file://$TEST_ROOT/other_store?store=/fnord/store
hash=$(nix hash-file --type sha256 --base16 ./fetchurl.sh) hash=$(nix hash file --type sha256 --base16 ./fetchurl.sh)
storePath=$(nix --store $other_store add-to-store --flat ./fetchurl.sh) storePath=$(nix --store $other_store store add-file ./fetchurl.sh)
outPath=$(nix-build '<nix/fetchurl.nix>' --argstr url file:///no-such-dir/fetchurl.sh --argstr sha256 $hash --no-out-link --substituters $other_store) outPath=$(nix-build '<nix/fetchurl.nix>' --argstr url file:///no-such-dir/fetchurl.sh --argstr sha256 $hash --no-out-link --substituters $other_store)
# Test hashed mirrors with an SRI hash. # Test hashed mirrors with an SRI hash.
nix-build '<nix/fetchurl.nix>' --argstr url file:///no-such-dir/fetchurl.sh --argstr hash $(nix to-sri --type sha256 $hash) \ nix-build '<nix/fetchurl.nix>' --argstr url file:///no-such-dir/fetchurl.sh --argstr hash $(nix hash to-sri --type sha256 $hash) \
--no-out-link --substituters $other_store --no-out-link --substituters $other_store
# Test unpacking a NAR. # Test unpacking a NAR.

View file

@ -2,9 +2,9 @@ source common.sh
clearStore clearStore
garbage1=$(nix add-to-store --name garbage1 ./nar-access.sh) garbage1=$(nix store add-path --name garbage1 ./nar-access.sh)
garbage2=$(nix add-to-store --name garbage2 ./nar-access.sh) garbage2=$(nix store add-path --name garbage2 ./nar-access.sh)
garbage3=$(nix add-to-store --name garbage3 ./nar-access.sh) garbage3=$(nix store add-path --name garbage3 ./nar-access.sh)
ls -l $garbage3 ls -l $garbage3
POSIXLY_CORRECT=1 du $garbage3 POSIXLY_CORRECT=1 du $garbage3

View file

@ -2,7 +2,7 @@ source common.sh
try () { try () {
printf "%s" "$2" > $TEST_ROOT/vector printf "%s" "$2" > $TEST_ROOT/vector
hash=$(nix hash-file --base16 $EXTRA --type "$1" $TEST_ROOT/vector) hash=$(nix hash file --base16 $EXTRA --type "$1" $TEST_ROOT/vector)
if test "$hash" != "$3"; then if test "$hash" != "$3"; then
echo "hash $1, expected $3, got $hash" echo "hash $1, expected $3, got $hash"
exit 1 exit 1
@ -69,17 +69,17 @@ try2 md5 "f78b733a68f5edbdf9413899339eaa4a"
# Conversion. # Conversion.
try3() { try3() {
h64=$(nix to-base64 --type "$1" "$2") h64=$(nix hash to-base64 --type "$1" "$2")
[ "$h64" = "$4" ] [ "$h64" = "$4" ]
sri=$(nix to-sri --type "$1" "$2") sri=$(nix hash to-sri --type "$1" "$2")
[ "$sri" = "$1-$4" ] [ "$sri" = "$1-$4" ]
h32=$(nix-hash --type "$1" --to-base32 "$2") h32=$(nix-hash --type "$1" --to-base32 "$2")
[ "$h32" = "$3" ] [ "$h32" = "$3" ]
h16=$(nix-hash --type "$1" --to-base16 "$h32") h16=$(nix-hash --type "$1" --to-base16 "$h32")
[ "$h16" = "$2" ] [ "$h16" = "$2" ]
h16=$(nix to-base16 --type "$1" "$h64") h16=$(nix hash to-base16 --type "$1" "$h64")
[ "$h16" = "$2" ] [ "$h16" = "$2" ]
h16=$(nix to-base16 "$sri") h16=$(nix hash to-base16 "$sri")
[ "$h16" = "$2" ] [ "$h16" = "$2" ]
} }
try3 sha1 "800d59cfcd3c05e900cb4e214be48f6b886a08df" "vw46m23bizj4n8afrc0fj19wrp7mj3c0" "gA1Zz808BekAy04hS+SPa4hqCN8=" try3 sha1 "800d59cfcd3c05e900cb4e214be48f6b886a08df" "vw46m23bizj4n8afrc0fj19wrp7mj3c0" "gA1Zz808BekAy04hS+SPa4hqCN8="

View file

@ -22,9 +22,9 @@ outPath=$(nix-build dependencies.nix --no-out-link --sandbox-paths /nix/store)
nix path-info -r $outPath | grep input-2 nix path-info -r $outPath | grep input-2
nix ls-store -R -l $outPath | grep foobar nix store ls -R -l $outPath | grep foobar
nix cat-store $outPath/foobar | grep FOOBAR nix store cat $outPath/foobar | grep FOOBAR
# Test --check without hash rewriting. # Test --check without hash rewriting.
nix-build dependencies.nix --no-out-link --check --sandbox-paths /nix/store nix-build dependencies.nix --no-out-link --check --sandbox-paths /nix/store

View file

@ -9,45 +9,45 @@ cd "$TEST_ROOT"
narFile="$TEST_ROOT/path.nar" narFile="$TEST_ROOT/path.nar"
nix-store --dump $storePath > $narFile nix-store --dump $storePath > $narFile
# Check that find and ls-nar match. # Check that find and nar ls match.
( cd $storePath; find . | sort ) > files.find ( cd $storePath; find . | sort ) > files.find
nix ls-nar -R -d $narFile "" | sort > files.ls-nar nix nar ls -R -d $narFile "" | sort > files.ls-nar
diff -u files.find files.ls-nar diff -u files.find files.ls-nar
# Check that file contents of data match. # Check that file contents of data match.
nix cat-nar $narFile /foo/data > data.cat-nar nix nar cat $narFile /foo/data > data.cat-nar
diff -u data.cat-nar $storePath/foo/data diff -u data.cat-nar $storePath/foo/data
# Check that file contents of baz match. # Check that file contents of baz match.
nix cat-nar $narFile /foo/baz > baz.cat-nar nix nar cat $narFile /foo/baz > baz.cat-nar
diff -u baz.cat-nar $storePath/foo/baz diff -u baz.cat-nar $storePath/foo/baz
nix cat-store $storePath/foo/baz > baz.cat-nar nix store cat $storePath/foo/baz > baz.cat-nar
diff -u baz.cat-nar $storePath/foo/baz diff -u baz.cat-nar $storePath/foo/baz
# Test --json. # Test --json.
diff -u \ diff -u \
<(nix ls-nar --json $narFile / | jq -S) \ <(nix nar ls --json $narFile / | jq -S) \
<(echo '{"type":"directory","entries":{"foo":{},"foo-x":{},"qux":{},"zyx":{}}}' | jq -S) <(echo '{"type":"directory","entries":{"foo":{},"foo-x":{},"qux":{},"zyx":{}}}' | jq -S)
diff -u \ diff -u \
<(nix ls-nar --json -R $narFile /foo | jq -S) \ <(nix nar ls --json -R $narFile /foo | jq -S) \
<(echo '{"type":"directory","entries":{"bar":{"type":"regular","size":0,"narOffset":368},"baz":{"type":"regular","size":0,"narOffset":552},"data":{"type":"regular","size":58,"narOffset":736}}}' | jq -S) <(echo '{"type":"directory","entries":{"bar":{"type":"regular","size":0,"narOffset":368},"baz":{"type":"regular","size":0,"narOffset":552},"data":{"type":"regular","size":58,"narOffset":736}}}' | jq -S)
diff -u \ diff -u \
<(nix ls-nar --json -R $narFile /foo/bar | jq -S) \ <(nix nar ls --json -R $narFile /foo/bar | jq -S) \
<(echo '{"type":"regular","size":0,"narOffset":368}' | jq -S) <(echo '{"type":"regular","size":0,"narOffset":368}' | jq -S)
diff -u \ diff -u \
<(nix ls-store --json $storePath | jq -S) \ <(nix store ls --json $storePath | jq -S) \
<(echo '{"type":"directory","entries":{"foo":{},"foo-x":{},"qux":{},"zyx":{}}}' | jq -S) <(echo '{"type":"directory","entries":{"foo":{},"foo-x":{},"qux":{},"zyx":{}}}' | jq -S)
diff -u \ diff -u \
<(nix ls-store --json -R $storePath/foo | jq -S) \ <(nix store ls --json -R $storePath/foo | jq -S) \
<(echo '{"type":"directory","entries":{"bar":{"type":"regular","size":0},"baz":{"type":"regular","size":0},"data":{"type":"regular","size":58}}}' | jq -S) <(echo '{"type":"directory","entries":{"bar":{"type":"regular","size":0},"baz":{"type":"regular","size":0},"data":{"type":"regular","size":58}}}' | jq -S)
diff -u \ diff -u \
<(nix ls-store --json -R $storePath/foo/bar| jq -S) \ <(nix store ls --json -R $storePath/foo/bar| jq -S) \
<(echo '{"type":"regular","size":0}' | jq -S) <(echo '{"type":"regular","size":0}' | jq -S)
# Test missing files. # Test missing files.
nix ls-store --json -R $storePath/xyzzy 2>&1 | grep 'does not exist in NAR' nix store ls --json -R $storePath/xyzzy 2>&1 | grep 'does not exist in NAR'
nix ls-store $storePath/xyzzy 2>&1 | grep 'does not exist' nix store ls $storePath/xyzzy 2>&1 | grep 'does not exist'
# Test failure to dump. # Test failure to dump.
if nix-store --dump $storePath >/dev/full ; then if nix-store --dump $storePath >/dev/full ; then

View file

@ -15,4 +15,12 @@ nix eval --expr 'assert 1 + 2 == 3; true'
[[ $(nix eval --impure --expr "(import (builtins.fetchurl { url = file://$(pwd)/pure-eval.nix; })).x") == 123 ]] [[ $(nix eval --impure --expr "(import (builtins.fetchurl { url = file://$(pwd)/pure-eval.nix; })).x") == 123 ]]
(! nix eval --expr "(import (builtins.fetchurl { url = file://$(pwd)/pure-eval.nix; })).x") (! nix eval --expr "(import (builtins.fetchurl { url = file://$(pwd)/pure-eval.nix; })).x")
nix eval --expr "(import (builtins.fetchurl { url = file://$(pwd)/pure-eval.nix; sha256 = \"$(nix hash-file pure-eval.nix --type sha256)\"; })).x" nix eval --expr "(import (builtins.fetchurl { url = file://$(pwd)/pure-eval.nix; sha256 = \"$(nix hash file pure-eval.nix --type sha256)\"; })).x"
rm -rf $TEST_ROOT/eval-out
nix eval --store dummy:// --write-to $TEST_ROOT/eval-out --expr '{ x = "foo" + "bar"; y = { z = "bla"; }; }'
[[ $(cat $TEST_ROOT/eval-out/x) = foobar ]]
[[ $(cat $TEST_ROOT/eval-out/y/z) = bla ]]
rm -rf $TEST_ROOT/eval-out
(! nix eval --store dummy:// --write-to $TEST_ROOT/eval-out --expr '{ "." = "bla"; }')

View file

@ -7,7 +7,7 @@ clearStore
rm -f $TEST_ROOT/result rm -f $TEST_ROOT/result
export unreachable=$(nix add-to-store ./recursive.sh) export unreachable=$(nix store add-path ./recursive.sh)
NIX_BIN_DIR=$(dirname $(type -p nix)) nix --experimental-features 'nix-command recursive-nix' build -o $TEST_ROOT/result -L --impure --expr ' NIX_BIN_DIR=$(dirname $(type -p nix)) nix --experimental-features 'nix-command recursive-nix' build -o $TEST_ROOT/result -L --impure --expr '
with import ./config.nix; with import ./config.nix;
@ -38,7 +38,7 @@ NIX_BIN_DIR=$(dirname $(type -p nix)) nix --experimental-features 'nix-command r
# Add something to the store. # Add something to the store.
echo foobar > foobar echo foobar > foobar
foobar=$(nix $opts add-to-store ./foobar) foobar=$(nix $opts store add-path ./foobar)
nix $opts path-info $foobar nix $opts path-info $foobar
nix $opts build $foobar nix $opts build $foobar

View file

@ -17,40 +17,40 @@ info=$(nix path-info --json $outPath)
[[ $info =~ 'cache1.example.org' ]] [[ $info =~ 'cache1.example.org' ]]
[[ $info =~ 'cache2.example.org' ]] [[ $info =~ 'cache2.example.org' ]]
# Test "nix verify". # Test "nix store verify".
nix verify -r $outPath nix store verify -r $outPath
expect 2 nix verify -r $outPath --sigs-needed 1 expect 2 nix store verify -r $outPath --sigs-needed 1
nix verify -r $outPath --sigs-needed 1 --trusted-public-keys $pk1 nix store verify -r $outPath --sigs-needed 1 --trusted-public-keys $pk1
expect 2 nix verify -r $outPath --sigs-needed 2 --trusted-public-keys $pk1 expect 2 nix store verify -r $outPath --sigs-needed 2 --trusted-public-keys $pk1
nix verify -r $outPath --sigs-needed 2 --trusted-public-keys "$pk1 $pk2" nix store verify -r $outPath --sigs-needed 2 --trusted-public-keys "$pk1 $pk2"
nix verify --all --sigs-needed 2 --trusted-public-keys "$pk1 $pk2" nix store verify --all --sigs-needed 2 --trusted-public-keys "$pk1 $pk2"
# Build something unsigned. # Build something unsigned.
outPath2=$(nix-build simple.nix --no-out-link) outPath2=$(nix-build simple.nix --no-out-link)
nix verify -r $outPath nix store verify -r $outPath
# Verify that the path did not get signed but does have the ultimate bit. # Verify that the path did not get signed but does have the ultimate bit.
info=$(nix path-info --json $outPath2) info=$(nix path-info --json $outPath2)
[[ $info =~ '"ultimate":true' ]] [[ $info =~ '"ultimate":true' ]]
(! [[ $info =~ 'signatures' ]]) (! [[ $info =~ 'signatures' ]])
# Test "nix verify". # Test "nix store verify".
nix verify -r $outPath2 nix store verify -r $outPath2
expect 2 nix verify -r $outPath2 --sigs-needed 1 expect 2 nix store verify -r $outPath2 --sigs-needed 1
expect 2 nix verify -r $outPath2 --sigs-needed 1 --trusted-public-keys $pk1 expect 2 nix store verify -r $outPath2 --sigs-needed 1 --trusted-public-keys $pk1
# Test "nix sign-paths". # Test "nix store sign-paths".
nix sign-paths --key-file $TEST_ROOT/sk1 $outPath2 nix store sign-paths --key-file $TEST_ROOT/sk1 $outPath2
nix verify -r $outPath2 --sigs-needed 1 --trusted-public-keys $pk1 nix store verify -r $outPath2 --sigs-needed 1 --trusted-public-keys $pk1
# Build something content-addressed. # Build something content-addressed.
outPathCA=$(IMPURE_VAR1=foo IMPURE_VAR2=bar nix-build ./fixed.nix -A good.0 --no-out-link) outPathCA=$(IMPURE_VAR1=foo IMPURE_VAR2=bar nix-build ./fixed.nix -A good.0 --no-out-link)
@ -59,12 +59,12 @@ outPathCA=$(IMPURE_VAR1=foo IMPURE_VAR2=bar nix-build ./fixed.nix -A good.0 --no
# Content-addressed paths don't need signatures, so they verify # Content-addressed paths don't need signatures, so they verify
# regardless of --sigs-needed. # regardless of --sigs-needed.
nix verify $outPathCA nix store verify $outPathCA
nix verify $outPathCA --sigs-needed 1000 nix store verify $outPathCA --sigs-needed 1000
# Check that signing a content-addressed path doesn't overflow validSigs # Check that signing a content-addressed path doesn't overflow validSigs
nix sign-paths --key-file $TEST_ROOT/sk1 $outPathCA nix store sign-paths --key-file $TEST_ROOT/sk1 $outPathCA
nix verify -r $outPathCA --sigs-needed 1000 --trusted-public-keys $pk1 nix store verify -r $outPathCA --sigs-needed 1000 --trusted-public-keys $pk1
# Copy to a binary cache. # Copy to a binary cache.
nix copy --to file://$cacheDir $outPath2 nix copy --to file://$cacheDir $outPath2
@ -76,7 +76,7 @@ info=$(nix path-info --store file://$cacheDir --json $outPath2)
(! [[ $info =~ 'cache2.example.org' ]]) (! [[ $info =~ 'cache2.example.org' ]])
# Verify that adding a signature to a path in a binary cache works. # Verify that adding a signature to a path in a binary cache works.
nix sign-paths --store file://$cacheDir --key-file $TEST_ROOT/sk2 $outPath2 nix store sign-paths --store file://$cacheDir --key-file $TEST_ROOT/sk2 $outPath2
info=$(nix path-info --store file://$cacheDir --json $outPath2) info=$(nix path-info --store file://$cacheDir --json $outPath2)
[[ $info =~ 'cache1.example.org' ]] [[ $info =~ 'cache1.example.org' ]]
[[ $info =~ 'cache2.example.org' ]] [[ $info =~ 'cache2.example.org' ]]
@ -89,17 +89,17 @@ rm -rf $TEST_ROOT/store0
# But succeed if we supply the public keys. # But succeed if we supply the public keys.
nix copy --to $TEST_ROOT/store0 $outPath --trusted-public-keys $pk1 nix copy --to $TEST_ROOT/store0 $outPath --trusted-public-keys $pk1
expect 2 nix verify --store $TEST_ROOT/store0 -r $outPath expect 2 nix store verify --store $TEST_ROOT/store0 -r $outPath
nix verify --store $TEST_ROOT/store0 -r $outPath --trusted-public-keys $pk1 nix store verify --store $TEST_ROOT/store0 -r $outPath --trusted-public-keys $pk1
nix verify --store $TEST_ROOT/store0 -r $outPath --sigs-needed 2 --trusted-public-keys "$pk1 $pk2" nix store verify --store $TEST_ROOT/store0 -r $outPath --sigs-needed 2 --trusted-public-keys "$pk1 $pk2"
# It should also succeed if we disable signature checking. # It should also succeed if we disable signature checking.
(! nix copy --to $TEST_ROOT/store0 $outPath2) (! nix copy --to $TEST_ROOT/store0 $outPath2)
nix copy --to $TEST_ROOT/store0?require-sigs=false $outPath2 nix copy --to $TEST_ROOT/store0?require-sigs=false $outPath2
# But signatures should still get copied. # But signatures should still get copied.
nix verify --store $TEST_ROOT/store0 -r $outPath2 --trusted-public-keys $pk1 nix store verify --store $TEST_ROOT/store0 -r $outPath2 --trusted-public-keys $pk1
# Content-addressed stuff can be copied without signatures. # Content-addressed stuff can be copied without signatures.
nix copy --to $TEST_ROOT/store0 $outPathCA nix copy --to $TEST_ROOT/store0 $outPathCA

View file

@ -11,6 +11,6 @@ store+=$remote_store
store+=$remote_store store+=$remote_store
store+=$remote_store store+=$remote_store
out=$(nix add-to-store --store "$store" $TEST_ROOT/hello.sh) out=$(nix store add-path --store "$store" $TEST_ROOT/hello.sh)
[ foo = $(< $out) ] [ foo = $(< $out) ]

View file

@ -10,7 +10,7 @@ mkdir -p $tarroot
cp dependencies.nix $tarroot/default.nix cp dependencies.nix $tarroot/default.nix
cp config.nix dependencies.builder*.sh $tarroot/ cp config.nix dependencies.builder*.sh $tarroot/
hash=$(nix hash-path $tarroot) hash=$(nix hash path $tarroot)
test_tarball() { test_tarball() {
local ext="$1" local ext="$1"