From 68e5b8302acbaef82026e9eae121b47022340471 Mon Sep 17 00:00:00 2001 From: Tobias Happ Date: Sun, 24 Nov 2019 00:38:27 +0100 Subject: [PATCH] Add updated pkgs tree --- ci.nix | 4 +- pkgs/bootstrap-zip.nix | 10 ++++ pkgs/bootstrap.nix | 39 ++++++++++++++ pkgs/cross-compiling/pkgs.nix | 32 ++++++++++++ pkgs/cross-compiling/proot-termux.nix | 28 ++++++++++ pkgs/cross-compiling/talloc.nix | 73 +++++++++++++++++++++++++++ pkgs/default.nix | 46 +++++++++++++++++ pkgs/lib/load-nixpkgs.nix | 17 +++++++ pkgs/nix-directory.nix | 67 ++++++++++++++++++++++++ pkgs/qemu-aarch64-static.nix | 19 +++++++ 10 files changed, 333 insertions(+), 2 deletions(-) create mode 100644 pkgs/bootstrap-zip.nix create mode 100644 pkgs/bootstrap.nix create mode 100644 pkgs/cross-compiling/pkgs.nix create mode 100644 pkgs/cross-compiling/proot-termux.nix create mode 100644 pkgs/cross-compiling/talloc.nix create mode 100644 pkgs/default.nix create mode 100644 pkgs/lib/load-nixpkgs.nix create mode 100644 pkgs/nix-directory.nix create mode 100644 pkgs/qemu-aarch64-static.nix diff --git a/ci.nix b/ci.nix index 6a934c0..d831bc1 100644 --- a/ci.nix +++ b/ci.nix @@ -6,11 +6,11 @@ with import { }; with lib; let - src = import ./src; + pkgs = import ./pkgs; attrs = genAttrs [ "aarch64" "i686" ] - (arch: (src { inherit arch; }) // { recurseForDerivations = true; }); + (arch: (pkgs { inherit arch; }) // { recurseForDerivations = true; }); isCacheable = p: !(p.preferLocalBuild or false); shouldRecurseForDerivations = p: isAttrs p && p.recurseForDerivations or false; diff --git a/pkgs/bootstrap-zip.nix b/pkgs/bootstrap-zip.nix new file mode 100644 index 0000000..9354bb0 --- /dev/null +++ b/pkgs/bootstrap-zip.nix @@ -0,0 +1,10 @@ +# Licensed under GNU Lesser General Public License v3 or later, see COPYING. +# Copyright (c) 2019 Alexander Sosedkin and other contributors, see AUTHORS. + +{ config, runCommand, zip, bootstrap }: + +runCommand "bootstrap-zip" { } '' + mkdir $out + cd ${bootstrap} + ${zip}/bin/zip -q -9 -r $out/bootstrap-${config.build.arch} ./* ./.l2s +'' diff --git a/pkgs/bootstrap.nix b/pkgs/bootstrap.nix new file mode 100644 index 0000000..8c6f697 --- /dev/null +++ b/pkgs/bootstrap.nix @@ -0,0 +1,39 @@ +# Licensed under GNU Lesser General Public License v3 or later, see COPYING. +# Copyright (c) 2019 Alexander Sosedkin and other contributors, see AUTHORS. + +{ runCommand, nixDirectory, prootTermux, bash, pkgs, config }: + +let + packageInfo = import "${nixDirectory}/nix-support/package-info.nix"; +in + +runCommand "bootstrap" { } '' + mkdir --parents $out/{.l2s,bin,etc,nix,root,tmp,usr/{bin,lib}} + + cp --recursive ${nixDirectory}/store $out/nix/store + cp --recursive ${nixDirectory}/var $out/nix/var + chmod --recursive u+w $out/nix + + ln --symbolic ${packageInfo.bash}/bin/sh $out/bin/sh + ln --symbolic ${packageInfo.coreutils}/bin/env $out/usr/bin/env + + install -D -m 0755 ${prootTermux}/bin/proot-static $out/bin/proot-static + + cp ${config.environment.files.login} $out/bin/login + cp ${config.environment.files.loginInner} $out/usr/lib/login-inner + + ${bash}/bin/bash ${../modules/environment/etc/setup-etc.sh} $out/etc ${config.build.activationPackage}/etc + + cp --dereference --recursive $out/etc/static $out/etc/.static.tmp + rm $out/etc/static + mv $out/etc/.static.tmp $out/etc/static + + find $out -executable -type f | sed s@^$out/@@ > $out/EXECUTABLES.txt + + find $out -type l | while read -r LINK; do + LNK=''${LINK#$out/} + TGT=$(readlink "$LINK") + echo "$TGT←$LNK" >> $out/SYMLINKS.txt + rm "$LINK" + done +'' diff --git a/pkgs/cross-compiling/pkgs.nix b/pkgs/cross-compiling/pkgs.nix new file mode 100644 index 0000000..23053cb --- /dev/null +++ b/pkgs/cross-compiling/pkgs.nix @@ -0,0 +1,32 @@ +# Licensed under GNU Lesser General Public License v3 or later, see COPYING. +# Copyright (c) 2019 Alexander Sosedkin and other contributors, see AUTHORS. + +{ config, libjpeg, path }: + +let + loadNixpkgs = import ../lib/load-nixpkgs.nix; + + overlayJpegNoStatic = self: super: { + inherit libjpeg; + }; + + crossSystem = { + config = "${config.build.arch}-unknown-linux-android"; + sdkVer = "24"; + ndkVer = "18b"; + useAndroidPrebuilt = true; + }; +in + +{ + cross = loadNixpkgs { inherit crossSystem; }; + + crossStatic = loadNixpkgs { + inherit crossSystem; + + crossOverlays = [ + (import "${path}/pkgs/top-level/static.nix") + overlayJpegNoStatic + ]; + }; +} diff --git a/pkgs/cross-compiling/proot-termux.nix b/pkgs/cross-compiling/proot-termux.nix new file mode 100644 index 0000000..5eeebbe --- /dev/null +++ b/pkgs/cross-compiling/proot-termux.nix @@ -0,0 +1,28 @@ +# Licensed under GNU Lesser General Public License v3 or later, see COPYING. +# Copyright (c) 2019 Alexander Sosedkin and other contributors, see AUTHORS. + +{ callPackage, fetchFromGitHub, talloc }: + +let + pkgs = callPackage ./pkgs.nix { }; +in + +pkgs.crossStatic.stdenv.mkDerivation { + pname = "proot-termux"; + version = "unstable-2019-09-05"; + + src = fetchFromGitHub { + repo = "proot"; + owner = "termux"; + rev = "3ea655b1ae40bfa2ee612d45bf1e7ad97c4559f8"; + sha256 = "05y30ifbp4sn1pzy8wlifc5d9n2lrgspqzdjix1kxjj9j9947qgd"; + }; + + buildInputs = [ talloc ]; + + makeFlags = [ "-Csrc CFLAGS=-D__ANDROID__" ]; + + installPhase = '' + install -D -m 0755 src/proot $out/bin/proot-static + ''; +} diff --git a/pkgs/cross-compiling/talloc.nix b/pkgs/cross-compiling/talloc.nix new file mode 100644 index 0000000..828372f --- /dev/null +++ b/pkgs/cross-compiling/talloc.nix @@ -0,0 +1,73 @@ +# Licensed under GNU Lesser General Public License v3 or later, see COPYING. +# Copyright (c) 2019 Alexander Sosedkin and other contributors, see AUTHORS. + +{ callPackage, fetchurl, python2, zlib }: + +let + pkgs = callPackage ./pkgs.nix { }; +in + +pkgs.cross.stdenv.mkDerivation rec { + name = "talloc-2.1.14"; + + src = fetchurl { + url = "mirror://samba/talloc/${name}.tar.gz"; + sha256 = "1kk76dyav41ip7ddbbf04yfydb4jvywzi2ps0z2vla56aqkn11di"; + }; + + depsBuildBuild = [ python2 zlib ]; + + buildDeps = [ pkgs.cross.zlib ]; + + configurePhase = '' + substituteInPlace buildtools/bin/waf \ + --replace "/usr/bin/env python" "${python2}/bin/python" + ./configure --prefix=$out \ + --disable-rpath \ + --disable-python \ + --cross-compile \ + --cross-answers=cross-answers.txt + ''; + + buildPhase = '' + make + ''; + + installPhase = '' + mkdir -p $out/lib + make install + ${pkgs.cross.stdenv.cc.targetPrefix}ar q $out/lib/libtalloc.a bin/default/talloc_[0-9]*.o + ''; + + fixupPhase = ""; + + prePatch = '' + cat < cross-answers.txt + Checking uname sysname type: "Linux" + Checking uname machine type: "dontcare" + Checking uname release type: "dontcare" + Checking uname version type: "dontcare" + Checking simple C program: OK + building library support: OK + Checking for large file support: OK + Checking for -D_FILE_OFFSET_BITS=64: OK + Checking for WORDS_BIGENDIAN: OK + Checking for C99 vsnprintf: OK + Checking for HAVE_SECURE_MKSTEMP: OK + rpath library support: OK + -Wl,--version-script support: FAIL + Checking correct behavior of strtoll: OK + Checking correct behavior of strptime: OK + Checking for HAVE_IFACE_GETIFADDRS: OK + Checking for HAVE_IFACE_IFCONF: OK + Checking for HAVE_IFACE_IFREQ: OK + Checking getconf LFS_CFLAGS: OK + Checking for large file support without additional flags: OK + Checking for working strptime: OK + Checking for HAVE_SHARED_MMAP: OK + Checking for HAVE_MREMAP: OK + Checking for HAVE_INCOHERENT_MMAP: OK + Checking getconf large file support flags work: OK + EOF + ''; +} diff --git a/pkgs/default.nix b/pkgs/default.nix new file mode 100644 index 0000000..0be3a2d --- /dev/null +++ b/pkgs/default.nix @@ -0,0 +1,46 @@ +# Licensed under GNU Lesser General Public License v3 or later, see COPYING. +# Copyright (c) 2019 Alexander Sosedkin and other contributors, see AUTHORS. + +{ arch, nixOnDroidChannelURL ? null, nixpkgsChannelURL ? null }: + +let + loadNixpkgs = import lib/load-nixpkgs.nix; + + nixpkgs = loadNixpkgs { }; + + config = import ../modules { + pkgs = nixpkgs; + initialBuild = true; + + config = { + imports = [ ../modules/build/initial-build ]; + + _module.args = { inherit customPkgs; }; + + build = { + inherit arch; + + channel = with nixpkgs.lib; { + nixpkgs = mkIf (nixpkgsChannelURL != null) nixpkgsChannelURL; + nix-on-droid = mkIf (nixOnDroidChannelURL != null) nixOnDroidChannelURL; + }; + }; + }; + }; + + callPackage = nixpkgs.lib.callPackageWith ( + nixpkgs // customPkgs // { inherit callPackage config; } + ); + + customPkgs = rec { + bootstrap = callPackage ./bootstrap.nix { }; + bootstrapZip = callPackage ./bootstrap-zip.nix { }; + nixDirectory = callPackage ./nix-directory.nix { }; + packageInfo = import "${nixDirectory}/nix-support/package-info.nix"; + prootTermux = callPackage ./cross-compiling/proot-termux.nix { }; + qemuAarch64Static = callPackage ./qemu-aarch64-static.nix { }; + talloc = callPackage ./cross-compiling/talloc.nix { }; + }; +in + +customPkgs diff --git a/pkgs/lib/load-nixpkgs.nix b/pkgs/lib/load-nixpkgs.nix new file mode 100644 index 0000000..1ad68d4 --- /dev/null +++ b/pkgs/lib/load-nixpkgs.nix @@ -0,0 +1,17 @@ +# Licensed under GNU Lesser General Public License v3 or later, see COPYING. +# Copyright (c) 2019 Alexander Sosedkin and other contributors, see AUTHORS. + +let + defaultNixpkgsArgs = { + config = { }; + overlays = [ ]; + }; + + # head of nixos-19.09 as of 2019-10-14 + pinnedPkgsSrc = builtins.fetchTarball { + url = "https://github.com/NixOS/nixpkgs/archive/45a25ff41a2309099ff2e70b2f37debd5e567618.tar.gz"; + sha256 = "0w37p98i47d7snhckz8a3a60v0f05b5047vsm4rczink9mk9x7r3"; + }; +in + +args: import pinnedPkgsSrc (args // defaultNixpkgsArgs) diff --git a/pkgs/nix-directory.nix b/pkgs/nix-directory.nix new file mode 100644 index 0000000..e26238d --- /dev/null +++ b/pkgs/nix-directory.nix @@ -0,0 +1,67 @@ +# Licensed under GNU Lesser General Public License v3 or later, see COPYING. +# Copyright (c) 2019 Alexander Sosedkin and other contributors, see AUTHORS. + +{ config, lib, stdenv, proot, qemuAarch64Static }: + +let + buildRootDirectory = "root-directory"; + + prootCommand = lib.concatStringsSep " " [ + "${proot}/bin/proot" + ( + if config.build.arch == "aarch64" + then "-q ${qemuAarch64Static}/bin/qemu-aarch64-static" + else "-b /dev" + ) + "-r ${buildRootDirectory}" + "-w /" + ]; +in + +stdenv.mkDerivation { + name = "nix-directory"; + + src = builtins.fetchurl { + url = "https://nixos.org/releases/nix/nix-2.3.1/nix-2.3.1-${config.build.arch}-linux.tar.xz"; + sha256 = + if config.build.arch == "aarch64" + then "94a6a525bd0b2df82e14b96b5b0eaae86669b5d4671aacfc4db2db85325a81c1" + else "a5d3f26d4a449616bf654286f2fe29c1c1df4f029b7e29fa3ccf8494d598bfee"; # i686 + }; + + PROOT_NO_SECCOMP = 1; # see https://github.com/proot-me/PRoot/issues/106 + + buildPhase = '' + mkdir --parents ${buildRootDirectory}/nix + cp --recursive store ${buildRootDirectory}/nix/store + + CACERT=$(find ${buildRootDirectory}/nix/store -path '*-nss-cacert-*/ca-bundle.crt' | sed 's,^${buildRootDirectory},,') + PKG_BASH=$(find ${buildRootDirectory}/nix/store -path '*/bin/bash' | sed 's,^${buildRootDirectory},,') + PKG_BASH=''${PKG_BASH%/bin/bash} + PKG_COREUTILS=$(find ${buildRootDirectory}/nix/store -path '*/bin/env' | sed 's,^${buildRootDirectory},,') + PKG_COREUTILS=''${PKG_COREUTILS%/bin/env} + PKG_NIX=$(find ${buildRootDirectory}/nix/store -path '*/bin/nix' | sed 's,^${buildRootDirectory},,') + PKG_NIX=''${PKG_NIX%/bin/nix} + + USER=nix-on-droid ${prootCommand} "$PKG_NIX/bin/nix-store" --init + USER=nix-on-droid ${prootCommand} "$PKG_NIX/bin/nix-store" --load-db < .reginfo + + cat > package-info.nix <