diff --git a/docs/default.nix b/docs/default.nix index 980e96bf..06283d81 100644 --- a/docs/default.nix +++ b/docs/default.nix @@ -1,6 +1,6 @@ # Copyright (c) 2019-2024, see AUTHORS. Licensed under MIT License, see LICENSE. -{ pkgs, home-manager, nmdSrc }: +{ pkgs, crossPkgs ? pkgs, home-manager, nmdSrc }: let nmd = import nmdSrc { inherit pkgs; }; @@ -15,7 +15,7 @@ let }; modules = import ../modules/module-list.nix { - inherit pkgs; + inherit pkgs crossPkgs; home-manager-path = home-manager.outPath; isFlake = true; targetSystem = "aarch64-linux/x86_64-linux"; diff --git a/flake.lock b/flake.lock index 888acaed..e41c3cfd 100644 --- a/flake.lock +++ b/flake.lock @@ -46,11 +46,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1708172716, - "narHash": "sha256-3M94oln0b61m3dUmLyECCA9hYAHXZEszM4saE3CmQO4=", + "lastModified": 1771712298, + "narHash": "sha256-USw1VAQmEDAXWqABVo55IL6cFbKXVQI/50Q9VZY6XYw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "5d874ac46894c896119bce68e758e9e80bdb28f1", + "rev": "9a5af763ecccc2d58a13d1233c07172223733e98", "type": "github" }, "original": { @@ -77,17 +77,17 @@ }, "nixpkgs-for-bootstrap": { "locked": { - "lastModified": 1720244366, - "narHash": "sha256-WrDV0FPMVd2Sq9hkR5LNHudS3OSMmUrs90JUTN+MXpA=", + "lastModified": 1771208521, + "narHash": "sha256-X01Q3DgSpjeBpapoGA4rzKOn25qdKxbPnxHeMLNoHTU=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "49ee0e94463abada1de470c9c07bfc12b36dcf40", + "rev": "fa56d7d6de78f5a7f997b0ea2bc6efd5868ad9e8", "type": "github" }, "original": { "owner": "NixOS", "repo": "nixpkgs", - "rev": "49ee0e94463abada1de470c9c07bfc12b36dcf40", + "rev": "fa56d7d6de78f5a7f997b0ea2bc6efd5868ad9e8", "type": "github" } }, diff --git a/flake.nix b/flake.nix index cd093990..cf487498 100644 --- a/flake.nix +++ b/flake.nix @@ -5,9 +5,8 @@ nixpkgs.url = "github:NixOS/nixpkgs"; # for bootstrap zip ball creation and proot-termux builds, we use a fixed version of nixpkgs to ease maintanence. - # head of nixos-24.05 as of 2024-07-06 - # note: when updating nixpkgs-for-bootstrap, update store paths of proot-termux in modules/environment/login/default.nix - nixpkgs-for-bootstrap.url = "github:NixOS/nixpkgs/49ee0e94463abada1de470c9c07bfc12b36dcf40"; + # head of nixos-25.11 as of 2026-02-16 + nixpkgs-for-bootstrap.url = "github:NixOS/nixpkgs/fa56d7d6de78f5a7f997b0ea2bc6efd5868ad9e8"; home-manager = { url = "github:nix-community/home-manager"; @@ -78,6 +77,7 @@ , config ? null , extraModules ? null , system ? null # pkgs.stdenv.hostPlatform.system is used to detect user's arch + , bootstrapSystem ? pkgs.stdenv.hostPlatform.system }: if ! (builtins.elem pkgs.stdenv.hostPlatform.system [ "aarch64-linux" "x86_64-linux" ]) then throw @@ -104,6 +104,7 @@ inherit extraSpecialArgs home-manager-path pkgs; config.imports = modules; isFlake = true; + crossPkgs = import nixpkgs-for-bootstrap { crossSystem = pkgs.stdenv.hostPlatform.system; localSystem = bootstrapSystem; }; }); overlays.default = overlay; @@ -118,9 +119,14 @@ derivationAttrset; perArchCustomPkgs = arch: flattenArch arch (import ./pkgs { - _nativeSystem = system; # system to cross-compile from - system = "${arch}-linux"; # system to cross-compile to - nixpkgs = nixpkgs-for-bootstrap; + pkgs = import nixpkgs-for-bootstrap { inherit system; }; + crossPkgs = import nixpkgs-for-bootstrap { + crossSystem = "${arch}-linux"; + localSystem = system; + }; + targetPkgs = import nixpkgs-for-bootstrap { + system = "${arch}-linux"; + }; }).customPkgs; docs = import ./docs { diff --git a/modules/default.nix b/modules/default.nix index 3613feef..08419496 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -6,6 +6,7 @@ , pkgs ? import { } , home-manager-path ? , isFlake ? false +, crossPkgs }: with pkgs.lib; @@ -19,7 +20,7 @@ let else pkgs.config.nix-on-droid or (throw "No config file found! Create one in ~/.config/nixpkgs/nix-on-droid.nix"); nodModules = import ./module-list.nix { - inherit pkgs home-manager-path isFlake targetSystem; + inherit pkgs home-manager-path isFlake targetSystem crossPkgs; }; rawModule = evalModules { diff --git a/modules/environment/login/default.nix b/modules/environment/login/default.nix index b4f7a936..08718729 100644 --- a/modules/environment/login/default.nix +++ b/modules/environment/login/default.nix @@ -1,6 +1,6 @@ # Copyright (c) 2019-2024, see AUTHORS. Licensed under MIT License, see LICENSE. -{ config, lib, pkgs, initialPackageInfo, targetSystem, ... }: +{ config, lib, pkgs, initialPackageInfo, targetSystem, crossPkgs, ... }: with lib; @@ -12,6 +12,10 @@ let loginInner = pkgs.callPackage ./login-inner.nix { inherit config initialPackageInfo targetSystem; }; + + tallocStatic = crossPkgs.pkgsStatic.pkgsLLVM.callPackage ../../../pkgs/talloc { }; + + prootStatic = crossPkgs.pkgsStatic.pkgsLLVM.callPackage ../../../pkgs/proot-termux { talloc = tallocStatic; }; in { @@ -82,16 +86,7 @@ in }; environment.files = { - inherit login loginInner; - - prootStatic = - let - crossCompiledPaths = { - aarch64-linux = "/nix/store/7qd99m1w65x2vgqg453nd70y60sm3kay-proot-termux-static-aarch64-unknown-linux-android-unstable-2024-05-04"; - x86_64-linux = "/nix/store/pakj3svvw84rhkzdc6211yhc2cgvc21f-proot-termux-static-x86_64-unknown-linux-android-unstable-2024-05-04"; - }; - in - "${crossCompiledPaths.${targetSystem}}"; + inherit login loginInner prootStatic; }; }; diff --git a/modules/environment/login/login-inner.nix b/modules/environment/login/login-inner.nix index 70879125..4c12655e 100644 --- a/modules/environment/login/login-inner.nix +++ b/modules/environment/login/login-inner.nix @@ -33,6 +33,9 @@ writeText "login-inner" '' # To prevent gc warnings of nix, see https://github.com/NixOS/nix/issues/3237 export GC_NPROCS=1 + echo "Setting up Nix store..." + ${nix}/bin/nix-store --init + echo "Setting default user profile..." ${nix}/bin/nix-env --switch-profile /nix/var/nix/profiles/per-user/$USER/profile diff --git a/modules/module-list.nix b/modules/module-list.nix index 14003530..2924f65d 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -4,6 +4,7 @@ , home-manager-path , isFlake , targetSystem # system to cross-compile to +, crossPkgs }: [ @@ -31,7 +32,7 @@ { _file = ./module-list.nix; _module.args = { - inherit home-manager-path isFlake targetSystem; + inherit home-manager-path isFlake targetSystem crossPkgs; pkgs = pkgs.lib.mkDefault pkgs; }; } diff --git a/pkgs/bootstrap.nix b/pkgs/bootstrap.nix index 74c47fa3..fd23c390 100644 --- a/pkgs/bootstrap.nix +++ b/pkgs/bootstrap.nix @@ -1,13 +1,13 @@ # Copyright (c) 2019-2024, see AUTHORS. Licensed under MIT License, see LICENSE. -{ runCommand, nixDirectory, prootTermux, bash, pkgs, config, initialPackageInfo }: +{ runCommand, closureInfo, prootTermux, bash, config, initialPackageInfo }: runCommand "bootstrap" { } '' mkdir --parents $out/{.l2s,bin,dev/shm,etc,root,tmp,usr/{bin,lib}} mkdir --parents $out/nix/var/nix/{profiles,gcroots}/per-user/nix-on-droid - cp --recursive ${nixDirectory}/store $out/nix/store - cp --recursive ${nixDirectory}/var $out/nix/var + mkdir --parents $out/nix/store + cp --recursive $(cat ${closureInfo}/store-paths) $out/nix/store chmod --recursive u+w $out/nix ln --symbolic ${initialPackageInfo.bash}/bin/sh $out/bin/sh diff --git a/pkgs/cross-compiling/compiler-rt.patch b/pkgs/cross-compiling/compiler-rt.patch deleted file mode 100644 index 31af4e31..00000000 --- a/pkgs/cross-compiling/compiler-rt.patch +++ /dev/null @@ -1,15 +0,0 @@ -diff --git a/pkgs/development/compilers/llvm/common/compiler-rt/default.nix b/pkgs/development/compilers/llvm/common/compiler-rt/default.nix -index 7d47436b714f..d30df471e92a 100644 ---- a/pkgs/development/compilers/llvm/common/compiler-rt/default.nix -+++ b/pkgs/development/compilers/llvm/common/compiler-rt/default.nix -@@ -155,8 +155,8 @@ stdenv.mkDerivation ({ - # The presence of crtbegin_shared has been added and removed; it's possible - # people have added/removed it to get it working on their platforms. - # Try each in turn for now. -- ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbeginS.o -- ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtendS.o -+ #ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbeginS.o -+ #ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtendS.o - ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o - ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o - '' + lib.optionalString doFakeLibgcc '' diff --git a/pkgs/cross-compiling/cross-pkgs-args.nix b/pkgs/cross-compiling/cross-pkgs-args.nix deleted file mode 100644 index 2dd40def..00000000 --- a/pkgs/cross-compiling/cross-pkgs-args.nix +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (c) 2019-2024, see AUTHORS. Licensed under MIT License, see LICENSE. - -{ lib, config, system, targetSystem }: - -let - arch = lib.strings.removeSuffix "-linux" targetSystem; -in -{ - inherit system; - - crossSystem = { - config = "${arch}-unknown-linux-android"; - sdkVer = "32"; - libc = "bionic"; - useAndroidPrebuilt = false; - useLLVM = true; - isStatic = true; - }; -} diff --git a/pkgs/cross-compiling/cross-pkgs.nix b/pkgs/cross-compiling/cross-pkgs.nix deleted file mode 100644 index 9a14cee5..00000000 --- a/pkgs/cross-compiling/cross-pkgs.nix +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright (c) 2019-2024, see AUTHORS. Licensed under MIT License, see LICENSE. - -{ callPackage, nixpkgs }: - -let - args = callPackage ./cross-pkgs-args.nix { }; - pkgsCross-imported = import nixpkgs args; - pkgsCross-patched = pkgsCross-imported.applyPatches { - name = "nixpkgs-crosscompilation-patched"; - src = nixpkgs; - patches = [ - ./compiler-rt.patch - ./libunwind.patch - ]; - }; - pkgsCross = import pkgsCross-patched args; -in -pkgsCross diff --git a/pkgs/cross-compiling/libunwind.patch b/pkgs/cross-compiling/libunwind.patch deleted file mode 100644 index 2d510fa6..00000000 --- a/pkgs/cross-compiling/libunwind.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/pkgs/development/compilers/llvm/common/libunwind/default.nix b/pkgs/development/compilers/llvm/common/libunwind/default.nix -index 515914e6acb6..ca53043bd278 100644 ---- a/pkgs/development/compilers/llvm/common/libunwind/default.nix -+++ b/pkgs/development/compilers/llvm/common/libunwind/default.nix -@@ -67,6 +67,8 @@ stdenv.mkDerivation (rec { - ninja python3 - ]; - -+ LDFLAGS = "-unwindlib=none"; -+ - cmakeFlags = lib.optional (lib.versionAtLeast release_version "15") "-DLLVM_ENABLE_RUNTIMES=libunwind" - ++ lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF"; - diff --git a/pkgs/cross-compiling/proot-termux.nix b/pkgs/cross-compiling/proot-termux.nix deleted file mode 100644 index 8bbce24f..00000000 --- a/pkgs/cross-compiling/proot-termux.nix +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright (c) 2019-2022, see AUTHORS. Licensed under MIT License, see LICENSE. - -{ callPackage, tallocStatic }: - -let - pkgsCross = callPackage ./cross-pkgs.nix { }; - stdenv = pkgsCross.stdenvAdapters.makeStaticBinaries pkgsCross.stdenv; -in - -pkgsCross.callPackage ../proot-termux { - talloc = tallocStatic; - inherit stdenv; -} diff --git a/pkgs/default.nix b/pkgs/default.nix index 1840faa9..611aed58 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -1,19 +1,24 @@ # Copyright (c) 2019-2024, see AUTHORS. Licensed under MIT License, see LICENSE. -{ nixpkgs -, system # system to compile for, user-facing name of targetSystem -, _nativeSystem ? null # system to cross-compile from, see flake.nix +{ pkgs +, crossPkgs +, targetPkgs , nixOnDroidChannelURL ? null , nixpkgsChannelURL ? null , nixOnDroidFlakeURL ? null }: let - nativeSystem = if _nativeSystem == null then system else _nativeSystem; - nixDirectory = callPackage ./nix-directory.nix { inherit system; }; - initialPackageInfo = import "${nixDirectory}/nix-support/package-info.nix"; + targetSystem = crossPkgs.stdenv.hostPlatform.system; - pkgs = import nixpkgs { system = nativeSystem; }; + # Use prebuilt bootstrap packages from nixpkgs cache + closureInfo = pkgs.closureInfo { + rootPaths = with targetPkgs; [ bash cacert nix ]; + }; + initialPackageInfo = { + inherit (targetPkgs) bash nix; + cacert = "${targetPkgs.cacert}/etc/ssl/certs/ca-bundle.crt"; + }; urlOptionValue = url: envVar: let @@ -24,8 +29,7 @@ let (if url == null then envValue else url); modules = import ../modules { - inherit pkgs; - targetSystem = system; + inherit pkgs crossPkgs targetSystem; isFlake = true; @@ -56,16 +60,14 @@ let callPackage = pkgs.lib.callPackageWith ( pkgs // customPkgs // { inherit (modules) config; - inherit callPackage nixpkgs nixDirectory initialPackageInfo; - targetSystem = system; + inherit callPackage closureInfo initialPackageInfo targetSystem; } ); customPkgs = { bootstrap = callPackage ./bootstrap.nix { }; bootstrapZip = callPackage ./bootstrap-zip.nix { }; - prootTermux = callPackage ./cross-compiling/proot-termux.nix { }; - tallocStatic = callPackage ./cross-compiling/talloc-static.nix { }; + prootTermux = modules.config.environment.files.prootStatic; }; in diff --git a/pkgs/nix-directory.nix b/pkgs/nix-directory.nix deleted file mode 100644 index a9d54e5a..00000000 --- a/pkgs/nix-directory.nix +++ /dev/null @@ -1,84 +0,0 @@ -# Copyright (c) 2019-2024, see AUTHORS. Licensed under MIT License, see LICENSE. - -{ config -, lib -, stdenvNoCC -, closureInfo -, prootTermux -, proot -, pkgsStatic -, system -}: - -let - buildRootDirectory = "root-directory"; - - prootCommand = lib.concatStringsSep " " [ - "${proot}/bin/proot" - "-b ${pkgsStatic.nix}:/static-nix" - "-b /proc:/proc" # needed because tries to access /proc/self/exe - "-r ${buildRootDirectory}" - "-w /" - ]; - - prootTermuxClosure = closureInfo { - rootPaths = [ - prootTermux - ]; - }; -in - -stdenvNoCC.mkDerivation { - name = "nix-directory"; - - src = builtins.fetchurl { - url = "https://nixos.org/releases/nix/nix-2.20.5/nix-2.20.5-${system}.tar.xz"; - sha256 = - let - nixShas = { - aarch64-linux = "sha256:168wjfj3xsc8hq1y6cq59iipjp1g9hmj4n5wdn9c47ad9gbc9cvh"; - x86_64-linux = "sha256:0dax9n562ldj53ap6lz0cwwsfx4d8j1267g9s6lg3zs237yyzw61"; - }; - in - nixShas.${system}; - }; - - PROOT_NO_SECCOMP = 1; # see https://github.com/proot-me/PRoot/issues/106 - - buildPhase = '' - # create nix state directory to satisfy nix heuristics to recognize the manual create /nix directory as valid nix store - mkdir --parents ${buildRootDirectory}/nix/var/nix/db - 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_NIX=$(find ${buildRootDirectory}/nix/store -path '*/bin/nix' | sed 's,^${buildRootDirectory},,') - PKG_NIX=''${PKG_NIX%/bin/nix} - - for i in $(< ${prootTermuxClosure}/store-paths); do - cp --archive "$i" "${buildRootDirectory}$i" - done - - USER=${config.user.userName} ${prootCommand} "/static-nix/bin/nix-store" --init - USER=${config.user.userName} ${prootCommand} "/static-nix/bin/nix-store" --load-db < .reginfo - USER=${config.user.userName} ${prootCommand} "/static-nix/bin/nix-store" --load-db < ${prootTermuxClosure}/registration - - cat > package-info.nix < fake-ashmem/linux/ashmem.h << EOF #include - #include + #include #include #define __ASHMEMIOC 0x77 #define ASHMEM_NAME_LEN 256 @@ -38,8 +38,24 @@ stdenv.mkDerivation { buildInputs = [ talloc ]; patches = [ ./detranslate-empty.patch ]; makeFlags = [ "-Csrc" "V=1" ]; - CFLAGS = [ "-O3" "-I../fake-ashmem" ] ++ - (if static then [ "-static" ] else [ ]); + CFLAGS = [ + "-O3" + "-I../fake-ashmem" + "-D_LARGEFILE64_SOURCE" + "-DMSG_COPY=040000" + "-DTEMP_FAILURE_RETRY=" + "-D__ANDROID__" + # Copied from linux/include/uapi/asm-generic/ioctls.h + "-DTCGETS=0x5401" + "-DTCSETS=0x5402" + "-DTCSETSW=0x5403" + "-DTCSETSF=0x5404" + "-DTCGETS2=0x802C542A" + "-DTCSETS2=0x402C542B" + "-DTCSETSW2=0x402C542C" + "-DTCSETSF2=0x402C542D" + ] ++ + (if static then [ "-static" ] else [ ]); LDFLAGS = if static then [ "-static" ] else [ ]; preInstall = "${stdenv.cc.targetPrefix}strip src/proot"; installPhase = "install -D -m 0755 src/proot $out/bin/${outputBinaryName}"; diff --git a/pkgs/cross-compiling/talloc-static.nix b/pkgs/talloc/default.nix similarity index 87% rename from pkgs/cross-compiling/talloc-static.nix rename to pkgs/talloc/default.nix index ffea6509..89917ba8 100644 --- a/pkgs/cross-compiling/talloc-static.nix +++ b/pkgs/talloc/default.nix @@ -1,23 +1,19 @@ # Copyright (c) 2019-2024, see AUTHORS. Licensed under MIT License, see LICENSE. -{ callPackage +{ stdenv , fetchurl , python3 , pkg-config , wafHook }: -let - pkgsCross = callPackage ./cross-pkgs.nix { }; -in - -pkgsCross.stdenv.mkDerivation rec { +stdenv.mkDerivation rec { pname = "talloc"; - version = "2.4.2"; + version = "2.4.3"; src = fetchurl { url = "mirror://samba/talloc/${pname}-${version}.tar.gz"; - sha256 = "sha256-hez55GXiD5j5lQpS6aQR4UMgvFVfolfYdpe356mx2KY="; + sha256 = "sha256-3EbEC59GuzTdl/5B9Uiw6LJHt3qRhXZzPFKOg6vYVN0="; }; nativeBuildInputs = [ pkg-config python3 wafHook ]; @@ -66,7 +62,7 @@ pkgsCross.stdenv.mkDerivation rec { buildPhase = "python ./buildtools/bin/waf build || true"; installPhase = '' mkdir -p $out/lib $out/include - ${pkgsCross.stdenv.cc.targetPrefix}ar q $out/lib/libtalloc.a \ + ${stdenv.cc.targetPrefix}ar q $out/lib/libtalloc.a \ bin/default/talloc.c.[0-9]*.o cp talloc.h $out/include/ ''; diff --git a/scripts/deploy.sh b/scripts/deploy.sh index b54479fa..e4f7b7d9 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -55,24 +55,10 @@ log "NIX_ON_DROID_CHANNEL_URL=$NIX_ON_DROID_CHANNEL_URL" log "NIX_ON_DROID_FLAKE_URL=$NIX_ON_DROID_FLAKE_URL" -PROOT_HASH_FILE="modules/environment/login/default.nix" UPLOADS=() for arch in $ARCHES; do log "building $arch proot..." - proot="$(nix build --no-link --print-out-paths ".#prootTermux-${arch}")" - - if grep -q "$arch-linux = \"$proot\";" "$PROOT_HASH_FILE"; then - log "keeping $arch proot path in $PROOT_HASH_FILE" - elif grep -q "$arch-linux = \"/nix/store/" "$PROOT_HASH_FILE"; then - log "patching $arch proot path in $PROOT_HASH_FILE..." - grep "$arch-linux = \"/nix/store/" "$PROOT_HASH_FILE" - sed -i "s|$arch-linux = \"/nix/store/.*\";|$arch-linux = \"$proot\";|" "$PROOT_HASH_FILE" - log " ->" - grep "$arch-linux = \"/nix/store/" "$PROOT_HASH_FILE" - else - log "no $arch proot hash found in $PROOT_HASH_FILE!" - exit 1 - fi + nix build --no-link --print-out-paths ".#prootTermux-${arch}" log "building $arch bootstrapZip..." BOOTSTRAP_ZIP="$(nix build --no-link --print-out-paths --impure ".#bootstrapZip-${arch}")"