aboutsummaryrefslogtreecommitdiff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2020-11-28 18:10:38 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2020-11-28 18:10:38 +0000
commit8ddf5c69077a6afda88a3ae72f10fdff031f75b8 (patch)
treeb18dd7d549baa53756eb3c53d0f2932feab52e91 /pkgs/build-support
parentc6617d28ef3762bbd5cb11dd3c56afb778ff42cc (diff)
parent2622548c138fbf151fd3f130fe41864590520121 (diff)
Merge remote-tracking branch 'upstream/master' into aj-rust-custom-target
Diffstat (limited to 'pkgs/build-support')
-rwxr-xr-xpkgs/build-support/appimage/appimage-exec.sh10
-rw-r--r--pkgs/build-support/bintools-wrapper/default.nix4
-rw-r--r--pkgs/build-support/build-fhs-userenv-bubblewrap/default.nix43
-rw-r--r--pkgs/build-support/cc-wrapper/default.nix2
-rw-r--r--pkgs/build-support/docker/default.nix36
-rw-r--r--pkgs/build-support/docker/detjson.py2
-rw-r--r--pkgs/build-support/docker/examples.nix14
-rw-r--r--pkgs/build-support/fetchfossil/default.nix4
-rw-r--r--pkgs/build-support/fetchsvnrevision/default.nix2
-rw-r--r--pkgs/build-support/install-shell-files/default.nix12
-rw-r--r--pkgs/build-support/make-desktopitem/default.nix21
-rw-r--r--pkgs/build-support/setup-hooks/install-shell-files.sh125
-rw-r--r--pkgs/build-support/singularity-tools/default.nix4
-rw-r--r--pkgs/build-support/vm/default.nix32
14 files changed, 209 insertions, 102 deletions
diff --git a/pkgs/build-support/appimage/appimage-exec.sh b/pkgs/build-support/appimage/appimage-exec.sh
index 82ebdd0bbe4a..7986c589667b 100755
--- a/pkgs/build-support/appimage/appimage-exec.sh
+++ b/pkgs/build-support/appimage/appimage-exec.sh
@@ -1,4 +1,6 @@
#!@shell@
+# shellcheck shell=bash
+
if [ -n "$DEBUG" ] ; then
set -x
fi
@@ -13,8 +15,10 @@ unpack() {
local out="$2"
# https://github.com/AppImage/libappimage/blob/ca8d4b53bed5cbc0f3d0398e30806e0d3adeaaab/src/libappimage/utils/MagicBytesChecker.cpp#L45-L63
- local appimageSignature=$(readelf -h "$src" | awk 'NR==2{print $10$11;}')
- local appimageType=$(readelf -h "$src" | awk 'NR==2{print $12;}')
+ local appimageSignature;
+ appimageSignature="$(LC_ALL=C readelf -h "$src" | awk 'NR==2{print $10$11;}')"
+ local appimageType;
+ appimageType="$(LC_ALL=C readelf -h "$src" | awk 'NR==2{print $12;}')"
# check AppImage signature
if [ "$appimageSignature" != "4149" ]; then
@@ -35,7 +39,7 @@ unpack() {
# multiarch offset one-liner using same method as AppImage
# see https://gist.github.com/probonopd/a490ba3401b5ef7b881d5e603fa20c93
- offset=$(readelf -h "$src" | awk 'NR==13{e_shoff=$5} NR==18{e_shentsize=$5} NR==19{e_shnum=$5} END{print e_shoff+e_shentsize*e_shnum}')
+ offset=$(LC_ALL=C readelf -h "$src" | awk 'NR==13{e_shoff=$5} NR==18{e_shentsize=$5} NR==19{e_shnum=$5} END{print e_shoff+e_shentsize*e_shnum}')
echo "Uncompress $(basename "$src") of type $appimageType @ offset $offset"
unsquashfs -q -d "$out" -o "$offset" "$src"
chmod go-w "$out"
diff --git a/pkgs/build-support/bintools-wrapper/default.nix b/pkgs/build-support/bintools-wrapper/default.nix
index 786f0f9c5983..3b1b8ff570a8 100644
--- a/pkgs/build-support/bintools-wrapper/default.nix
+++ b/pkgs/build-support/bintools-wrapper/default.nix
@@ -179,12 +179,14 @@ stdenv.mkDerivation {
mips64 = "btsmip";
mips64el = "ltsmip";
}.${targetPlatform.parsed.cpu.name}
+ else if targetPlatform.isMmix then "mmix"
else if targetPlatform.isPower then if targetPlatform.isBigEndian then "ppc" else "lppc"
else if targetPlatform.isSparc then "sparc"
else if targetPlatform.isMsp430 then "msp430"
else if targetPlatform.isAvr then "avr"
else if targetPlatform.isAlpha then "alpha"
else if targetPlatform.isVc4 then "vc4"
+ else if targetPlatform.isOr1k then "or1k"
else throw "unknown emulation for platform: ${targetPlatform.config}";
in if targetPlatform.useLLVM or false then ""
else targetPlatform.platform.bfdEmulation or (fmt + sep + arch);
@@ -252,7 +254,7 @@ stdenv.mkDerivation {
# Ensure consistent LC_VERSION_MIN_MACOSX and remove LC_UUID.
+ optionalString stdenv.targetPlatform.isMacOS ''
- echo "-macosx_version_min 10.12 -sdk_version 10.12 -no_uuid" >> $out/nix-support/libc-ldflags-before
+ echo "-sdk_version 10.12 -no_uuid" >> $out/nix-support/libc-ldflags-before
''
##
diff --git a/pkgs/build-support/build-fhs-userenv-bubblewrap/default.nix b/pkgs/build-support/build-fhs-userenv-bubblewrap/default.nix
index c7cfd27d3faa..3a3c9e932fdb 100644
--- a/pkgs/build-support/build-fhs-userenv-bubblewrap/default.nix
+++ b/pkgs/build-support/build-fhs-userenv-bubblewrap/default.nix
@@ -50,7 +50,7 @@ let
"ssl/certs"
"pki"
];
- in concatStringsSep " \\\n "
+ in concatStringsSep "\n "
(map (file: "--ro-bind-try /etc/${file} /etc/${file}") files);
init = run: writeShellScriptBin "${name}-init" ''
@@ -59,46 +59,49 @@ let
'';
bwrapCmd = { initArgs ? "" }: ''
- blacklist="/nix /dev /proc /etc"
- ro_mounts=""
+ blacklist=(/nix /dev /proc /etc)
+ ro_mounts=()
for i in ${env}/*; do
path="/''${i##*/}"
if [[ $path == '/etc' ]]; then
continue
fi
- ro_mounts="$ro_mounts --ro-bind $i $path"
- blacklist="$blacklist $path"
+ ro_mounts+=(--ro-bind "$i" "$path")
+ blacklist+=("$path")
done
if [[ -d ${env}/etc ]]; then
for i in ${env}/etc/*; do
path="/''${i##*/}"
- ro_mounts="$ro_mounts --ro-bind $i /etc$path"
+ ro_mounts+=(--ro-bind "$i" "/etc$path")
done
fi
- auto_mounts=""
+ declare -a auto_mounts
# loop through all directories in the root
for dir in /*; do
# if it is a directory and it is not in the blacklist
- if [[ -d "$dir" ]] && grep -v "$dir" <<< "$blacklist" >/dev/null; then
+ if [[ -d "$dir" ]] && [[ ! "''${blacklist[@]}" =~ "$dir" ]]; then
# add it to the mount list
- auto_mounts="$auto_mounts --bind $dir $dir"
+ auto_mounts+=(--bind "$dir" "$dir")
fi
done
- exec ${bubblewrap}/bin/bwrap \
- --dev-bind /dev /dev \
- --proc /proc \
- --chdir "$(pwd)" \
- --unshare-all \
- --share-net \
- --die-with-parent \
- --ro-bind /nix /nix \
- ${etcBindFlags} \
- $ro_mounts \
- $auto_mounts \
+ cmd=(
+ ${bubblewrap}/bin/bwrap
+ --dev-bind /dev /dev
+ --proc /proc
+ --chdir "$(pwd)"
+ --unshare-all
+ --share-net
+ --die-with-parent
+ --ro-bind /nix /nix
+ ${etcBindFlags}
+ "''${ro_mounts[@]}"
+ "''${auto_mounts[@]}"
${init runScript}/bin/${name}-init ${initArgs}
+ )
+ exec "''${cmd[@]}"
'';
bin = writeShellScriptBin name (bwrapCmd { initArgs = ''"$@"''; });
diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix
index 0e4e76d72843..09cef8b8678d 100644
--- a/pkgs/build-support/cc-wrapper/default.nix
+++ b/pkgs/build-support/cc-wrapper/default.nix
@@ -57,7 +57,7 @@ let
suffixSalt = replaceStrings ["-" "."] ["_" "_"] targetPlatform.config;
expand-response-params =
- if buildPackages.stdenv.hasCC && buildPackages.stdenv.cc != "/dev/null"
+ if (buildPackages.stdenv.hasCC or false) && buildPackages.stdenv.cc != "/dev/null"
then import ../expand-response-params { inherit (buildPackages) stdenv; }
else "";
diff --git a/pkgs/build-support/docker/default.nix b/pkgs/build-support/docker/default.nix
index 35382662cf81..db1062e1b5d8 100644
--- a/pkgs/build-support/docker/default.nix
+++ b/pkgs/build-support/docker/default.nix
@@ -15,7 +15,6 @@
moreutils,
nix,
pigz,
- referencesByPopularity,
rsync,
runCommand,
runtimeShell,
@@ -25,12 +24,13 @@
storeDir ? builtins.storeDir,
substituteAll,
symlinkJoin,
- utillinux,
+ util-linux,
vmTools,
writeReferencesToFile,
writeScript,
writeText,
writePython3,
+ system, # Note: This is the cross system we're compiling for
}:
# WARNING: this API is unstable and may be subject to backwards-incompatible changes in the future.
@@ -48,7 +48,7 @@ let
# A user is required by nix
# https://github.com/NixOS/nix/blob/9348f9291e5d9e4ba3c4347ea1b235640f54fd79/src/libutil/util.cc#L478
export USER=nobody
- ${nix}/bin/nix-store --load-db < ${closureInfo {rootPaths = contentsList;}}/registration
+ ${buildPackages.nix}/bin/nix-store --load-db < ${closureInfo {rootPaths = contentsList;}}/registration
mkdir -p nix/var/nix/gcroots/docker/
for i in ${lib.concatStringsSep " " contentsList}; do
@@ -56,6 +56,16 @@ let
done;
'';
+ # Map nixpkgs architecture to Docker notation
+ # Reference: https://github.com/docker-library/official-images#architectures-other-than-amd64
+ getArch = nixSystem: {
+ aarch64-linux = "arm64v8";
+ armv7l-linux = "arm32v7";
+ x86_64-linux = "amd64";
+ powerpc64le-linux = "ppc64le";
+ i686-linux = "i386";
+ }.${nixSystem} or "Can't map Nix system ${nixSystem} to Docker architecture notation. Please check that your input and your requested build are correct or update the mapping in Nixpkgs.";
+
in
rec {
@@ -72,7 +82,7 @@ rec {
, imageDigest
, sha256
, os ? "linux"
- , arch ? buildPackages.go.GOARCH
+ , arch ? getArch system
# This is used to set name to the pulled image
, finalImageName ? imageName
@@ -194,7 +204,7 @@ rec {
};
inherit fromImage fromImageName fromImageTag;
- nativeBuildInputs = [ utillinux e2fsprogs jshon rsync jq ];
+ nativeBuildInputs = [ util-linux e2fsprogs jshon rsync jq ];
} ''
mkdir disk
mkfs /dev/${vmTools.hd}
@@ -340,7 +350,7 @@ rec {
# Tar up the layer and throw it into 'layer.tar'.
echo "Packing layer..."
mkdir $out
- tarhash=$(tar -C layer --hard-dereference --sort=name --mtime="@$SOURCE_DATE_EPOCH" --owner=${toString uid} --group=${toString gid} -cf - . | tee $out/layer.tar | tarsum)
+ tarhash=$(tar -C layer --hard-dereference --sort=name --mtime="@$SOURCE_DATE_EPOCH" --owner=${toString uid} --group=${toString gid} -cf - . | tee -p $out/layer.tar | tarsum)
# Add a 'checksum' field to the JSON, with the value set to the
# checksum of the tarball.
@@ -425,7 +435,7 @@ rec {
echo "Packing layer..."
mkdir -p $out
tarhash=$(tar -C layer --hard-dereference --sort=name --mtime="@$SOURCE_DATE_EPOCH" -cf - . |
- tee $out/layer.tar |
+ tee -p $out/layer.tar |
${tarsum}/bin/tarsum)
cat ${baseJson} | jshon -s "$tarhash" -i checksum > $out/json
@@ -443,7 +453,7 @@ rec {
runCommand "${name}.tar.gz" {
inherit (stream) imageName;
passthru = { inherit (stream) imageTag; };
- buildInputs = [ pigz ];
+ nativeBuildInputs = [ pigz ];
} "${stream} | pigz -nT > $out";
# 1. extract the base image
@@ -488,7 +498,7 @@ rec {
baseJson = let
pure = writeText "${baseName}-config.json" (builtins.toJSON {
inherit created config;
- architecture = buildPackages.go.GOARCH;
+ architecture = getArch system;
os = "linux";
});
impure = runCommand "${baseName}-config.json"
@@ -715,7 +725,7 @@ rec {
streamScript = writePython3 "stream" {} ./stream_layered_image.py;
baseJson = writeText "${name}-base.json" (builtins.toJSON {
inherit config;
- architecture = buildPackages.go.GOARCH;
+ architecture = getArch system;
os = "linux";
});
@@ -761,8 +771,8 @@ rec {
then tag
else
lib.head (lib.strings.splitString "-" (baseNameOf conf.outPath));
- paths = referencesByPopularity overallClosure;
- buildInputs = [ jq ];
+ paths = buildPackages.referencesByPopularity overallClosure;
+ nativeBuildInputs = [ jq ];
} ''
${if (tag == null) then ''
outName="$(basename "$out")"
@@ -826,7 +836,7 @@ rec {
# take images can know in advance how the image is supposed to be used.
isExe = true;
};
- buildInputs = [ makeWrapper ];
+ nativeBuildInputs = [ makeWrapper ];
} ''
makeWrapper ${streamScript} $out --add-flags ${conf}
'';
diff --git a/pkgs/build-support/docker/detjson.py b/pkgs/build-support/docker/detjson.py
index 439c21313878..fe82cbea11bb 100644
--- a/pkgs/build-support/docker/detjson.py
+++ b/pkgs/build-support/docker/detjson.py
@@ -37,4 +37,4 @@ def main():
json.dump(j, sys.stdout, sort_keys=True)
if __name__ == '__main__':
- main() \ No newline at end of file
+ main()
diff --git a/pkgs/build-support/docker/examples.nix b/pkgs/build-support/docker/examples.nix
index 4a611add8a12..3f30f1a2adb4 100644
--- a/pkgs/build-support/docker/examples.nix
+++ b/pkgs/build-support/docker/examples.nix
@@ -7,7 +7,7 @@
# $ nix-build '<nixpkgs>' -A dockerTools.examples.redis
# $ docker load < result
-{ pkgs, buildImage, pullImage, shadowSetup, buildImageWithNixDb }:
+{ pkgs, buildImage, pullImage, shadowSetup, buildImageWithNixDb, pkgsCross }:
rec {
# 1. basic example
@@ -407,4 +407,16 @@ rec {
contents = [ pkgs.bash pkgs.coreutils ] ++ nonRootShadowSetup { uid = 999; user = "somebody"; };
};
+ # basic example, with cross compilation
+ cross = let
+ # Cross compile for x86_64 if on aarch64
+ crossPkgs =
+ if pkgs.system == "aarch64-linux" then pkgsCross.gnu64
+ else pkgsCross.aarch64-multiplatform;
+ in crossPkgs.dockerTools.buildImage {
+ name = "hello-cross";
+ tag = "latest";
+ contents = crossPkgs.hello;
+ };
+
}
diff --git a/pkgs/build-support/fetchfossil/default.nix b/pkgs/build-support/fetchfossil/default.nix
index 27933b47178a..3a4876bc5de3 100644
--- a/pkgs/build-support/fetchfossil/default.nix
+++ b/pkgs/build-support/fetchfossil/default.nix
@@ -1,11 +1,11 @@
-{stdenv, fossil}:
+{stdenv, fossil, cacert}:
{name ? null, url, rev, sha256}:
stdenv.mkDerivation {
name = "fossil-archive" + (if name != null then "-${name}" else "");
builder = ./builder.sh;
- nativeBuildInputs = [fossil];
+ nativeBuildInputs = [fossil cacert];
# Envvar docs are hard to find. A link for the future:
# https://www.fossil-scm.org/index.html/doc/trunk/www/env-opts.md
diff --git a/pkgs/build-support/fetchsvnrevision/default.nix b/pkgs/build-support/fetchsvnrevision/default.nix
index 288451a225c7..f2e2a11da8d5 100644
--- a/pkgs/build-support/fetchsvnrevision/default.nix
+++ b/pkgs/build-support/fetchsvnrevision/default.nix
@@ -7,4 +7,4 @@ runCommand: subversion: repository:
rev=$(echo p | svn ls -v --depth empty ${repository} |awk '{ print $1 }')
echo "[ \"$rev\" ]" > $out
echo Latest revision is $rev
- '') \ No newline at end of file
+ '')
diff --git a/pkgs/build-support/install-shell-files/default.nix b/pkgs/build-support/install-shell-files/default.nix
index e1f2e24dd875..d50661ddc65d 100644
--- a/pkgs/build-support/install-shell-files/default.nix
+++ b/pkgs/build-support/install-shell-files/default.nix
@@ -1,4 +1,12 @@
-{ makeSetupHook }:
+{ makeSetupHook, tests }:
# See the header comment in ../setup-hooks/install-shell-files.sh for example usage.
-makeSetupHook { name = "install-shell-files"; } ../setup-hooks/install-shell-files.sh
+let
+ setupHook = makeSetupHook { name = "install-shell-files"; } ../setup-hooks/install-shell-files.sh;
+in
+
+setupHook.overrideAttrs (oldAttrs: {
+ passthru = (oldAttrs.passthru or {}) // {
+ tests = tests.install-shell-files;
+ };
+})
diff --git a/pkgs/build-support/make-desktopitem/default.nix b/pkgs/build-support/make-desktopitem/default.nix
index 8e51dc1b8480..329286bd3628 100644
--- a/pkgs/build-support/make-desktopitem/default.nix
+++ b/pkgs/build-support/make-desktopitem/default.nix
@@ -12,16 +12,16 @@
, mimeType ? null
, categories ? null
, startupNotify ? null
-, extraDesktopEntries ? {} # Extra key-value pairs to add to the [Desktop Entry] section. This may override other values
+, extraDesktopEntries ? { } # Extra key-value pairs to add to the [Desktop Entry] section. This may override other values
, extraEntries ? "" # Extra configuration. Will be appended to the end of the file and may thus contain extra sections
, fileValidation ? true # whether to validate resulting desktop file.
}:
-
let
# like builtins.toString, but null -> null instead of null -> ""
- nullableToString = value: if value == null then null
- else if builtins.isBool value then lib.boolToString value
- else builtins.toString value;
+ nullableToString = value:
+ if value == null then null
+ else if builtins.isBool value then lib.boolToString value
+ else builtins.toString value;
# The [Desktop entry] section of the desktop file, as attribute set.
mainSection = {
@@ -39,16 +39,19 @@ let
# Map all entries to a list of lines
desktopFileStrings =
- ["[Desktop Entry]"]
+ [ "[Desktop Entry]" ]
++ builtins.filter
(v: v != null)
(lib.mapAttrsToList
(name: value: if value != null then "${name}=${value}" else null)
mainSection
)
- ++ (if extraEntries == "" then [] else ["${extraEntries}"]);
+ ++ (if extraEntries == "" then [ ] else [ "${extraEntries}" ]);
in
-runCommandLocal "${name}.desktop" {}
+runCommandLocal "${name}.desktop"
+{
+ nativeBuildInputs = [ desktop-file-utils ];
+}
(''
mkdir -p "$out/share/applications"
cat > "$out/share/applications/${name}.desktop" <<EOF
@@ -56,5 +59,5 @@ runCommandLocal "${name}.desktop" {}
EOF
'' + lib.optionalString fileValidation ''
echo "Running desktop-file validation"
- ${desktop-file-utils}/bin/desktop-file-validate "$out/share/applications/${name}.desktop"
+ desktop-file-validate "$out/share/applications/${name}.desktop"
'')
diff --git a/pkgs/build-support/setup-hooks/install-shell-files.sh b/pkgs/build-support/setup-hooks/install-shell-files.sh
index e0ea1f7f30a7..194b408b1050 100644
--- a/pkgs/build-support/setup-hooks/install-shell-files.sh
+++ b/pkgs/build-support/setup-hooks/install-shell-files.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+# shellcheck shell=bash
# Setup hook for the `installShellFiles` package.
#
# Example usage in a derivation:
@@ -19,8 +19,8 @@
# installManPage <path> [...<path>]
#
# Each argument is checked for its man section suffix and installed into the appropriate
-# share/man<n>/ directory. The function returns an error if any paths don't have the man section
-# suffix (with optional .gz compression).
+# share/man/man<n>/ directory. The function returns an error if any paths don't have the man
+# section suffix (with optional .gz compression).
installManPage() {
local path
for path in "$@"; do
@@ -49,7 +49,7 @@ installManPage() {
done
}
-# installShellCompletion [--bash|--fish|--zsh] ([--name <name>] <path>)...
+# installShellCompletion [--cmd <name>] ([--bash|--fish|--zsh] [--name <name>] <path>)...
#
# Each path is installed into the appropriate directory for shell completions for the given shell.
# If one of `--bash`, `--fish`, or `--zsh` is given the path is assumed to belong to that shell.
@@ -61,9 +61,20 @@ installManPage() {
# If the shell completion needs to be renamed before installing the optional `--name <name>` flag
# may be given. Any name provided with this flag only applies to the next path.
#
+# If all shell completions need to be renamed before installing the optional `--cmd <name>` flag
+# may be given. This will synthesize a name for each file, unless overridden with an explicit
+# `--name` flag. For example, `--cmd foobar` will synthesize the name `_foobar` for zsh and
+# `foobar.bash` for bash.
+#
# For zsh completions, if the `--name` flag is not given, the path will be automatically renamed
# such that `foobar.zsh` becomes `_foobar`.
#
+# A path may be a named fd, such as produced by the bash construct `<(cmd)`. When using a named fd,
+# the shell type flag must be provided, and either the `--name` or `--cmd` flag must be provided.
+# This might look something like:
+#
+# installShellCompletion --zsh --name _foobar <($out/bin/foobar --zsh-completion)
+#
# This command accepts multiple shell flags in conjunction with multiple paths if you wish to
# install them all in one command:
#
@@ -76,9 +87,16 @@ installManPage() {
# installShellCompletion --fish --name foobar.fish share/completions.fish
# installShellCompletion --zsh --name _foobar share/completions.zsh
#
+# Or to use shell newline escaping to split a single invocation across multiple lines:
+#
+# installShellCompletion --cmd foobar \
+# --bash <($out/bin/foobar --bash-completion) \
+# --fish <($out/bin/foobar --fish-completion) \
+# --zsh <($out/bin/foobar --zsh-completion)
+#
# If any argument is `--` the remaining arguments will be treated as paths.
installShellCompletion() {
- local shell='' name='' retval=0 parseArgs=1 arg
+ local shell='' name='' cmdname='' retval=0 parseArgs=1 arg
while { arg=$1; shift; }; do
# Parse arguments
if (( parseArgs )); then
@@ -97,6 +115,17 @@ installShellCompletion() {
# treat `--name=foo` the same as `--name foo`
name=${arg#--name=}
continue;;
+ --cmd)
+ cmdname=$1
+ shift || {
+ echo 'installShellCompletion: error: --cmd flag expected an argument' >&2
+ return 1
+ }
+ continue;;
+ --cmd=*)
+ # treat `--cmd=foo` the same as `--cmd foo`
+ cmdname=${arg#--cmd=}
+ continue;;
--?*)
echo "installShellCompletion: warning: unknown flag ${arg%%=*}" >&2
retval=2
@@ -110,39 +139,67 @@ installShellCompletion() {
if (( "${NIX_DEBUG:-0}" >= 1 )); then
echo "installShellCompletion: installing $arg${name:+ as $name}"
fi
- # if we get here, this is a path
- # Identify shell
- local basename
- basename=$(stripHash "$arg")
+ # if we get here, this is a path or named pipe
+ # Identify shell and output name
local curShell=$shell
- if [[ -z "$curShell" ]]; then
- # auto-detect the shell
- case "$basename" in
- ?*.bash) curShell=bash;;
- ?*.fish) curShell=fish;;
- ?*.zsh) curShell=zsh;;
+ local outName=''
+ if [[ -z "$arg" ]]; then
+ echo "installShellCompletion: error: empty path is not allowed" >&2
+ return 1
+ elif [[ -p "$arg" ]]; then
+ # this is a named fd or fifo
+ if [[ -z "$curShell" ]]; then
+ echo "installShellCompletion: error: named pipe requires one of --bash, --fish, or --zsh" >&2
+ return 1
+ elif [[ -z "$name" && -z "$cmdname" ]]; then
+ echo "installShellCompletion: error: named pipe requires one of --cmd or --name" >&2
+ return 1
+ fi
+ else
+ # this is a path
+ local argbase
+ argbase=$(stripHash "$arg")
+ if [[ -z "$curShell" ]]; then
+ # auto-detect the shell
+ case "$argbase" in
+ ?*.bash) curShell=bash;;
+ ?*.fish) curShell=fish;;
+ ?*.zsh) curShell=zsh;;
+ *)
+ if [[ "$argbase" = _* && "$argbase" != *.* ]]; then
+ # probably zsh
+ echo "installShellCompletion: warning: assuming path \`$arg' is zsh; please specify with --zsh" >&2
+ curShell=zsh
+ else
+ echo "installShellCompletion: warning: unknown shell for path: $arg" >&2
+ retval=2
+ continue
+ fi;;
+ esac
+ fi
+ outName=$argbase
+ fi
+ # Identify output path
+ if [[ -n "$name" ]]; then
+ outName=$name
+ elif [[ -n "$cmdname" ]]; then
+ case "$curShell" in
+ bash|fish) outName=$cmdname.$curShell;;
+ zsh) outName=_$cmdname;;
*)
- if [[ "$basename" = _* && "$basename" != *.* ]]; then
- # probably zsh
- echo "installShellCompletion: warning: assuming path \`$arg' is zsh; please specify with --zsh" >&2
- curShell=zsh
- else
- echo "installShellCompletion: warning: unknown shell for path: $arg" >&2
- retval=2
- continue
- fi;;
+ # Our list of shells is out of sync with the flags we accept or extensions we detect.
+ echo 'installShellCompletion: internal error' >&2
+ return 1;;
esac
fi
- # Identify output path
- local outName sharePath
- outName=${name:-$basename}
+ local sharePath
case "$curShell" in
bash) sharePath=bash-completion/completions;;
fish) sharePath=fish/vendor_completions.d;;
zsh)
sharePath=zsh/site-functions
# only apply automatic renaming if we didn't have a manual rename
- if test -z "$name"; then
+ if [[ -z "$name" && -z "$cmdname" ]]; then
# convert a name like `foo.zsh` into `_foo`
outName=${outName%.zsh}
outName=_${outName#_}
@@ -153,8 +210,16 @@ installShellCompletion() {
return 1;;
esac
# Install file
- install -Dm644 -T "$arg" "${!outputBin:?}/share/$sharePath/$outName" || return
- # Clear the name, it only applies to one path
+ local outDir="${!outputBin:?}/share/$sharePath"
+ local outPath="$outDir/$outName"
+ if [[ -p "$arg" ]]; then
+ # install handles named pipes on NixOS but not on macOS
+ mkdir -p "$outDir" \
+ && cat "$arg" > "$outPath"
+ else
+ install -Dm644 -T "$arg" "$outPath"
+ fi || return
+ # Clear the per-path flags
name=
done
if [[ -n "$name" ]]; then
diff --git a/pkgs/build-support/singularity-tools/default.nix b/pkgs/build-support/singularity-tools/default.nix
index d937ec626682..4a54498d117c 100644
--- a/pkgs/build-support/singularity-tools/default.nix
+++ b/pkgs/build-support/singularity-tools/default.nix
@@ -7,7 +7,7 @@
, bash
, vmTools
, gawk
-, utillinux
+, util-linux
, runtimeShell
, e2fsprogs }:
@@ -47,7 +47,7 @@ rec {
runScriptFile = shellScript "run-script.sh" runScript;
result = vmTools.runInLinuxVM (
runCommand "singularity-image-${name}.img" {
- buildInputs = [ singularity e2fsprogs utillinux gawk ];
+ buildInputs = [ singularity e2fsprogs util-linux gawk ];
layerClosure = writeReferencesToFile layer;
preVM = vmTools.createEmptyImage {
size = diskSize;
diff --git a/pkgs/build-support/vm/default.nix b/pkgs/build-support/vm/default.nix
index 909cdc6da044..2f18e96e4ce2 100644
--- a/pkgs/build-support/vm/default.nix
+++ b/pkgs/build-support/vm/default.nix
@@ -151,7 +151,7 @@ rec {
# Set the system time from the hardware clock. Works around an
# apparent KVM > 1.5.2 bug.
- ${pkgs.utillinux}/bin/hwclock -s
+ ${pkgs.util-linux}/bin/hwclock -s
export NIX_STORE=${storeDir}
export NIX_BUILD_TOP=/tmp
@@ -270,7 +270,7 @@ rec {
defaultCreateRootFS = ''
mkdir /mnt
${e2fsprogs}/bin/mkfs.ext4 /dev/${hd}
- ${utillinux}/bin/mount -t ext4 /dev/${hd} /mnt
+ ${util-linux}/bin/mount -t ext4 /dev/${hd} /mnt
if test -e /mnt/.debug; then
exec ${bash}/bin/sh
@@ -317,7 +317,7 @@ rec {
with pkgs; runInLinuxVM (
stdenv.mkDerivation {
name = "extract-file";
- buildInputs = [ utillinux ];
+ buildInputs = [ util-linux ];
buildCommand = ''
ln -s ${kernel}/lib /lib
${kmod}/bin/modprobe loop
@@ -342,7 +342,7 @@ rec {
with pkgs; runInLinuxVM (
stdenv.mkDerivation {
name = "extract-file-mtd";
- buildInputs = [ utillinux mtdutils ];
+ buildInputs = [ util-linux mtdutils ];
buildCommand = ''
ln -s ${kernel}/lib /lib
${kmod}/bin/modprobe mtd
@@ -417,7 +417,7 @@ rec {
# Make the Nix store available in /mnt, because that's where the RPMs live.
mkdir -p /mnt${storeDir}
- ${utillinux}/bin/mount -o bind ${storeDir} /mnt${storeDir}
+ ${util-linux}/bin/mount -o bind ${storeDir} /mnt${storeDir}
# Newer distributions like Fedora 18 require /lib etc. to be
# symlinked to /usr.
@@ -427,7 +427,7 @@ rec {
ln -s /usr/sbin /mnt/sbin
ln -s /usr/lib /mnt/lib
ln -s /usr/lib64 /mnt/lib64
- ${utillinux}/bin/mount -t proc none /mnt/proc
+ ${util-linux}/bin/mount -t proc none /mnt/proc
''}
echo "unpacking RPMs..."
@@ -445,7 +445,7 @@ rec {
PATH=/usr/bin:/bin:/usr/sbin:/sbin $chroot /mnt \
rpm --initdb
- ${utillinux}/bin/mount -o bind /tmp /mnt/tmp
+ ${util-linux}/bin/mount -o bind /tmp /mnt/tmp
echo "installing RPMs..."
PATH=/usr/bin:/bin:/usr/sbin:/sbin $chroot /mnt \
@@ -456,8 +456,8 @@ rec {
rm /mnt/.debug
- ${utillinux}/bin/umount /mnt${storeDir} /mnt/tmp ${lib.optionalString unifiedSystemDir "/mnt/proc"}
- ${utillinux}/bin/umount /mnt
+ ${util-linux}/bin/umount /mnt${storeDir} /mnt/tmp ${lib.optionalString unifiedSystemDir "/mnt/proc"}
+ ${util-linux}/bin/umount /mnt
'';
passthru = { inherit fullName; };
@@ -587,9 +587,9 @@ rec {
# Make the Nix store available in /mnt, because that's where the .debs live.
mkdir -p /mnt/inst${storeDir}
- ${utillinux}/bin/mount -o bind ${storeDir} /mnt/inst${storeDir}
- ${utillinux}/bin/mount -o bind /proc /mnt/proc
- ${utillinux}/bin/mount -o bind /dev /mnt/dev
+ ${util-linux}/bin/mount -o bind ${storeDir} /mnt/inst${storeDir}
+ ${util-linux}/bin/mount -o bind /proc /mnt/proc
+ ${util-linux}/bin/mount -o bind /dev /mnt/dev
# Misc. files/directories assumed by various packages.
echo "initialising Dpkg DB..."
@@ -635,10 +635,10 @@ rec {
rm /mnt/.debug
- ${utillinux}/bin/umount /mnt/inst${storeDir}
- ${utillinux}/bin/umount /mnt/proc
- ${utillinux}/bin/umount /mnt/dev
- ${utillinux}/bin/umount /mnt
+ ${util-linux}/bin/umount /mnt/inst${storeDir}
+ ${util-linux}/bin/umount /mnt/proc
+ ${util-linux}/bin/umount /mnt/dev
+ ${util-linux}/bin/umount /mnt
'';
passthru = { inherit fullName; };