diff options
Diffstat (limited to 'pkgs/build-support')
-rwxr-xr-x | pkgs/build-support/rust/cargo-vendor-normalise.py | 41 | ||||
-rw-r--r-- | pkgs/build-support/rust/default.nix | 18 | ||||
-rwxr-xr-x | pkgs/build-support/rust/fetchcargo-default-config.toml | 7 | ||||
-rw-r--r-- | pkgs/build-support/rust/fetchcargo.nix | 35 | ||||
-rw-r--r-- | pkgs/build-support/setup-hooks/patch-shebangs.sh | 55 | ||||
-rw-r--r-- | pkgs/build-support/vm/default.nix | 16 |
6 files changed, 150 insertions, 22 deletions
diff --git a/pkgs/build-support/rust/cargo-vendor-normalise.py b/pkgs/build-support/rust/cargo-vendor-normalise.py new file mode 100755 index 000000000000..2d7a18957184 --- /dev/null +++ b/pkgs/build-support/rust/cargo-vendor-normalise.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python + +import sys + +import toml + + +def quote(s: str) -> str: + escaped = s.replace('"', r"\"").replace("\n", r"\n").replace("\\", "\\\\") + return '"{}"'.format(escaped) + + +def main() -> None: + data = toml.load(sys.stdin) + + assert list(data.keys()) == ["source"] + + # this value is non deterministic + data["source"]["vendored-sources"]["directory"] = "@vendor@" + + lines = [] + inner = data["source"] + for source, attrs in sorted(inner.items()): + lines.append("[source.{}]".format(quote(source))) + if source == "vendored-sources": + lines.append('"directory" = "@vendor@"\n') + else: + for key, value in sorted(attrs.items()): + attr = "{} = {}".format(quote(key), quote(value)) + lines.append(attr) + lines.append("") + + result = "\n".join(lines) + real = toml.loads(result) + assert real == data, "output = {} while input = {}".format(real, data) + + print(result) + + +if __name__ == "__main__": + main() diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index 820989a76206..1d5de052f893 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -1,7 +1,7 @@ -{ stdenv, cacert, git, rust, cargo-vendor }: +{ stdenv, cacert, git, rust, cargo-vendor, python3 }: let fetchcargo = import ./fetchcargo.nix { - inherit stdenv cacert git rust cargo-vendor; + inherit stdenv cacert git rust cargo-vendor python3; }; in { name, cargoSha256 ? "unset" @@ -61,14 +61,12 @@ in stdenv.mkDerivation (args // { ${setupVendorDir} mkdir .cargo - cat >.cargo/config <<-EOF - [source.crates-io] - registry = 'https://github.com/rust-lang/crates.io-index' - replace-with = 'vendored-sources' - - [source.vendored-sources] - directory = '$(pwd)/$cargoDepsCopy' - EOF + config="$(pwd)/$cargoDepsCopy/.cargo/config"; + if [[ ! -e $config ]]; then + config=${./fetchcargo-default-config.toml}; + fi; + substitute $config .cargo/config \ + --subst-var-by vendor "$(pwd)/$cargoDepsCopy" unset cargoDepsCopy diff --git a/pkgs/build-support/rust/fetchcargo-default-config.toml b/pkgs/build-support/rust/fetchcargo-default-config.toml new file mode 100755 index 000000000000..dd8ebbc32d31 --- /dev/null +++ b/pkgs/build-support/rust/fetchcargo-default-config.toml @@ -0,0 +1,7 @@ +[source."crates-io"] +"replace-with" = "vendored-sources" + +[source."vendored-sources"] +"directory" = "@vendor@" + + diff --git a/pkgs/build-support/rust/fetchcargo.nix b/pkgs/build-support/rust/fetchcargo.nix index 2670ed528640..9e77f8817b24 100644 --- a/pkgs/build-support/rust/fetchcargo.nix +++ b/pkgs/build-support/rust/fetchcargo.nix @@ -1,8 +1,26 @@ -{ stdenv, cacert, git, rust, cargo-vendor }: +{ stdenv, cacert, git, rust, cargo-vendor, python3 }: +let cargo-vendor-normalise = stdenv.mkDerivation { + name = "cargo-vendor-normalise"; + src = ./cargo-vendor-normalise.py; + nativeBuildInputs = [ python3.pkgs.wrapPython ]; + unpackPhase = ":"; + installPhase = "install -D $src $out/bin/cargo-vendor-normalise"; + pythonPath = [ python3.pkgs.toml ]; + postFixup = "wrapPythonPrograms"; + doInstallCheck = true; + installCheckPhase = '' + # check that ./fetchcargo-default-config.toml is a fix point + reference=${./fetchcargo-default-config.toml} + < $reference $out/bin/cargo-vendor-normalise > test; + cmp test $reference + ''; + preferLocalBuild = true; +}; +in { name ? "cargo-deps", src, srcs, patches, sourceRoot, sha256, cargoUpdateHook ? "" }: stdenv.mkDerivation { name = "${name}-vendor"; - nativeBuildInputs = [ cacert cargo-vendor git rust.cargo ]; + nativeBuildInputs = [ cacert cargo-vendor git cargo-vendor-normalise rust.cargo ]; inherit src srcs patches sourceRoot; phases = "unpackPhase patchPhase installPhase"; @@ -23,9 +41,16 @@ stdenv.mkDerivation { ${cargoUpdateHook} - cargo vendor - - cp -ar vendor $out + mkdir -p $out + cargo vendor $out | cargo-vendor-normalise > config + # fetchcargo used to never keep the config output by cargo vendor + # and instead hardcode the config in ./fetchcargo-default-config.toml. + # This broke on packages needing git dependencies, so now we keep the config. + # But not to break old cargoSha256, if the previous behavior was enough, + # we don't store the config. + if ! cmp config ${./fetchcargo-default-config.toml} > /dev/null; then + install -Dt $out/.cargo config; + fi; ''; outputHashAlgo = "sha256"; diff --git a/pkgs/build-support/setup-hooks/patch-shebangs.sh b/pkgs/build-support/setup-hooks/patch-shebangs.sh index 1433d1e1f144..8fecf519e1aa 100644 --- a/pkgs/build-support/setup-hooks/patch-shebangs.sh +++ b/pkgs/build-support/setup-hooks/patch-shebangs.sh @@ -5,10 +5,32 @@ # rewritten to /nix/store/<hash>/bin/python. Interpreters that are # already in the store are left untouched. -fixupOutputHooks+=('if [ -z "$dontPatchShebangs" -a -e "$prefix" ]; then patchShebangs "$prefix"; fi') +fixupOutputHooks+=(patchShebangsAuto) + +# Run patch shebangs on a directory. +# patchShebangs [--build | --host] directory + +# Flags: +# --build : Lookup commands available at build-time +# --host : Lookup commands available at runtime + +# Example use cases, +# $ patchShebangs --host /nix/store/...-hello-1.0/bin +# $ patchShebangs --build configure patchShebangs() { + local pathName + + if [ "$1" = "--host" ]; then + pathName=HOST_PATH + shift + elif [ "$1" = "--build" ]; then + pathName=PATH + shift + fi + local dir="$1" + header "patching script interpreter paths in $dir" local f local oldPath @@ -27,22 +49,33 @@ patchShebangs() { oldInterpreterLine=$(head -1 "$f" | tail -c+3) read -r oldPath arg0 args <<< "$oldInterpreterLine" + if [ -z "$pathName" ]; then + if [ -n "$strictDeps" ] && [[ "$f" = "$NIX_STORE"* ]]; then + pathName=HOST_PATH + else + pathName=PATH + fi + fi + if $(echo "$oldPath" | grep -q "/bin/env$"); then # Check for unsupported 'env' functionality: # - options: something starting with a '-' # - environment variables: foo=bar if $(echo "$arg0" | grep -q -- "^-.*\|.*=.*"); then - echo "unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)" + echo "$f: unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)" exit 1 fi - newPath="$(command -v "$arg0" || true)" + + newPath="$(PATH="${!pathName}" command -v "$arg0" || true)" else if [ "$oldPath" = "" ]; then # If no interpreter is specified linux will use /bin/sh. Set # oldpath="/bin/sh" so that we get /nix/store/.../sh. oldPath="/bin/sh" fi - newPath="$(command -v "$(basename "$oldPath")" || true)" + + newPath="$(PATH="${!pathName}" command -v "$(basename "$oldPath")" || true)" + args="$arg0 $args" fi @@ -65,3 +98,17 @@ patchShebangs() { stopNest } + +patchShebangsAuto () { + if [ -z "$dontPatchShebangs" -a -e "$prefix" ]; then + + # Dev output will end up being run on the build platform. An + # example case of this is sdl2-config. Otherwise, we can just + # use the runtime path (--host). + if [ "$output" != out ] && [ "$output" = "${!outputDev}" ]; then + patchShebangs --build "$prefix" + else + patchShebangs --host "$prefix" + fi + fi +} diff --git a/pkgs/build-support/vm/default.nix b/pkgs/build-support/vm/default.nix index 03b3fb1f9f27..6e98099460f8 100644 --- a/pkgs/build-support/vm/default.nix +++ b/pkgs/build-support/vm/default.nix @@ -3,8 +3,9 @@ , img ? pkgs.stdenv.hostPlatform.platform.kernelTarget , storeDir ? builtins.storeDir , rootModules ? - [ "virtio_pci" "virtio_mmio" "virtio_blk" "virtio_balloon" "virtio_rng" "ext4" "unix" "9p" "9pnet_virtio" "crc32c_generic" ] + [ "virtio_pci" "virtio_mmio" "virtio_blk" "virtio_balloon" "virtio_rng" "ext4" "unix" "9p" "9pnet_virtio" "crc32c_generic" "sym53c8xx" "virtio_scsi" "ahci "] ++ pkgs.lib.optional (pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64) "rtc_cmos" +, config }: with pkgs; @@ -196,9 +197,17 @@ rec { ${qemuBinary qemu} \ -nographic -no-reboot \ -device virtio-rng-pci \ + ${if "$diskInterface" == "scsi" then '' \ + \ # FIXME: /dev/sda is not created within the VM + -device lsi53c895a \ + -device scsi-hd,drive=hd,id=scsi1,bootindex=1 \ + ''${diskImage:+-drive file=$diskImage,media=disk,if=none,id=hd,cache=unsafe,werror=report} \ + '' else '' \ + -drive file=$diskImage,media=disk,if=none,id=hd \ + -device virtio-blk-pci,scsi=off,drive=hd,id=virtio0,bootindex=1 \ + \''} -virtfs local,path=${storeDir},security_model=none,mount_tag=store \ -virtfs local,path=$TMPDIR/xchg,security_model=none,mount_tag=xchg \ - ''${diskImage:+-drive file=$diskImage,if=virtio,cache=unsafe,werror=report} \ -kernel ${kernel}/${img} \ -initrd ${initrd}/initrd \ -append "console=${qemuSerialDevice} panic=1 command=${stage2Init} out=$out mountDisk=$mountDisk loglevel=4" \ @@ -298,12 +307,13 @@ rec { `run-vm' will be left behind in the temporary build directory that allows you to boot into the VM and debug it interactively. */ - runInLinuxVM = drv: lib.overrideDerivation drv ({ memSize ? 512, QEMU_OPTS ? "", args, builder, ... }: { + runInLinuxVM = drv: lib.overrideDerivation drv ({ memSize ? 512, QEMU_OPTS ? "", args, builder, ... } @ moreArgs : { requiredSystemFeatures = [ "kvm" ]; builder = "${bash}/bin/sh"; args = ["-e" (vmRunCommand qemuCommandLinux)]; origArgs = args; origBuilder = builder; + diskInterface = "${moreArgs.diskInterface}"; QEMU_OPTS = "${QEMU_OPTS} -m ${toString memSize}"; passAsFile = []; # HACK fix - see https://github.com/NixOS/nixpkgs/issues/16742 }); |