diff --git a/CHANGELOG.md b/CHANGELOG.md index 8240ac3..1ae6ecb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ `pkgs = import nixpkgs { system = "aarch64-linux"; };` as an argument to `nixOnDroidConfiguration`. If in doubt, refer to the `templates`. +* `config.arch` option has been dropped. Consider using `pkgs.system` instead. ## Release 23.11 diff --git a/docs/default.nix b/docs/default.nix index 1b11db1..980e96b 100644 --- a/docs/default.nix +++ b/docs/default.nix @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2023, see AUTHORS. Licensed under MIT License, see LICENSE. +# Copyright (c) 2019-2024, see AUTHORS. Licensed under MIT License, see LICENSE. { pkgs, home-manager, nmdSrc }: @@ -18,6 +18,7 @@ let inherit pkgs; home-manager-path = home-manager.outPath; isFlake = true; + targetSystem = "aarch64-linux/x86_64-linux"; }; modulesDocs = nmd.buildModulesDocs { diff --git a/flake.nix b/flake.nix index 72717ea..e62d314 100644 --- a/flake.nix +++ b/flake.nix @@ -99,10 +99,9 @@ See the 22.11 release notes for more. '' (import ./modules { + targetSystem = pkgs.system; # system to cross-compile to inherit extraSpecialArgs home-manager-path pkgs; config.imports = modules; - config.build.arch = - nixpkgs.lib.strings.removeSuffix "-linux" pkgs.system; isFlake = true; }); @@ -118,7 +117,8 @@ derivationAttrset; perArchCustomPkgs = arch: flattenArch arch (import ./pkgs { - inherit system arch; + _nativeSystem = system; # system to cross-compile from + system = "${arch}-linux"; # system to cross-compile to nixpkgs = nixpkgs-for-bootstrap; }).customPkgs; diff --git a/modules/build/config.nix b/modules/build/config.nix index 751be14..ea971ee 100644 --- a/modules/build/config.nix +++ b/modules/build/config.nix @@ -11,13 +11,6 @@ with lib; options = { build = { - arch = mkOption { - type = types.enum [ "aarch64" "x86_64" ]; - default = strings.removeSuffix "-linux" builtins.currentSystem; - internal = true; - description = "Destination arch."; - }; - initialBuild = mkOption { type = types.bool; default = false; diff --git a/modules/default.nix b/modules/default.nix index 0ad1872..c56a387 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -1,6 +1,7 @@ -# Copyright (c) 2019-2022, see AUTHORS. Licensed under MIT License, see LICENSE. +# Copyright (c) 2019-2024, see AUTHORS. Licensed under MIT License, see LICENSE. -{ config ? null +{ targetSystem ? builtins.currentSystem # system to compile for +, config ? null , extraSpecialArgs ? { } , pkgs ? import { } , home-manager-path ? @@ -17,7 +18,9 @@ let else if builtins.pathExists defaultConfigFile then defaultConfigFile 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; }; + nodModules = import ./module-list.nix { + inherit pkgs home-manager-path isFlake targetSystem; + }; rawModule = evalModules { modules = [ configModule ] ++ nodModules; diff --git a/modules/environment/login/default.nix b/modules/environment/login/default.nix index 78348cd..c47d2d1 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, ... }: +{ config, lib, pkgs, initialPackageInfo, targetSystem, ... }: with lib; @@ -9,7 +9,9 @@ let login = pkgs.callPackage ./login.nix { inherit config; }; - loginInner = pkgs.callPackage ./login-inner.nix { inherit config initialPackageInfo; }; + loginInner = pkgs.callPackage ./login-inner.nix { + inherit config initialPackageInfo targetSystem; + }; in { @@ -85,11 +87,11 @@ in prootStatic = let crossCompiledPaths = { - aarch64 = "/nix/store/7w09z1kw62wg7nv3q3z2p6kxf1ihk178-proot-termux-static-aarch64-unknown-linux-android-unstable-2023-11-11"; - x86_64 = "/nix/store/i6jppi627sakbgm5x2a8jjdfyv8571zc-proot-termux-static-x86_64-unknown-linux-android-unstable-2023-11-11"; + aarch64-linux = "/nix/store/7w09z1kw62wg7nv3q3z2p6kxf1ihk178-proot-termux-static-aarch64-unknown-linux-android-unstable-2023-11-11"; + x86_64-linux = "/nix/store/i6jppi627sakbgm5x2a8jjdfyv8571zc-proot-termux-static-x86_64-unknown-linux-android-unstable-2023-11-11"; }; in - "${crossCompiledPaths.${config.build.arch}}"; + "${crossCompiledPaths.${targetSystem}}"; }; }; diff --git a/modules/environment/login/login-inner.nix b/modules/environment/login/login-inner.nix index e1bddee..81d12a9 100644 --- a/modules/environment/login/login-inner.nix +++ b/modules/environment/login/login-inner.nix @@ -1,6 +1,6 @@ # Copyright (c) 2019-2024, see AUTHORS. Licensed under MIT License, see LICENSE. -{ config, lib, initialPackageInfo, writeText }: +{ config, lib, initialPackageInfo, writeText, targetSystem }: let inherit (initialPackageInfo) cacert nix; @@ -80,15 +80,20 @@ writeText "login-inner" '' ${nixCmd} flake new ${config.user.home}/.config/nix-on-droid --template ${config.build.flake.nix-on-droid} ${lib.optionalString config.build.flake.inputOverrides '' - echo "Overriding input urls / arch in flake..." + echo "Overriding input urls in the flake..." ${nixCmd} run nixpkgs#gnused -- \ -i \ - -e 's,\"aarch64-linux",\"${config.build.arch}-linux\",' \ -e 's,\"github:NixOS/nixpkgs.*\",\"${config.build.flake.nixpkgs}\",' \ -e 's,\"github:nix-community/nix-on-droid.*\",\"${config.build.flake.nix-on-droid}\",' \ "${config.user.home}/.config/nix-on-droid/flake.nix" ''} + echo "Overriding system value in the flake..." + ${nixCmd} run nixpkgs#gnused -- \ + -i \ + -e 's,\"aarch64-linux",\"${targetSystem}\",' \ + "${config.user.home}/.config/nix-on-droid/flake.nix" + echo "Installing first Nix-on-Droid generation..." ${nixCmd} run ${config.build.flake.nix-on-droid} -- switch --flake ${config.user.home}/.config/nix-on-droid diff --git a/modules/module-list.nix b/modules/module-list.nix index ac7575f..20dfdd0 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -1,6 +1,10 @@ -# Copyright (c) 2019-2022, see AUTHORS. Licensed under MIT License, see LICENSE. +# Copyright (c) 2019-2024, see AUTHORS. Licensed under MIT License, see LICENSE. -{ pkgs, home-manager-path, isFlake }: +{ pkgs +, home-manager-path +, isFlake +, targetSystem # system to cross-compile to +}: [ ./build/activation.nix @@ -26,7 +30,7 @@ { _file = ./module-list.nix; _module.args = { - inherit home-manager-path isFlake; + inherit home-manager-path isFlake targetSystem; pkgs = pkgs.lib.mkDefault pkgs; }; } diff --git a/pkgs/bootstrap-zip.nix b/pkgs/bootstrap-zip.nix index 04b7c98..a16ec3e 100644 --- a/pkgs/bootstrap-zip.nix +++ b/pkgs/bootstrap-zip.nix @@ -1,9 +1,12 @@ -# Copyright (c) 2019-2020, see AUTHORS. Licensed under MIT License, see LICENSE. +# Copyright (c) 2019-2024, see AUTHORS. Licensed under MIT License, see LICENSE. -{ config, runCommand, zip, bootstrap }: +{ lib, runCommand, zip, bootstrap, targetSystem }: +let + arch = lib.strings.removeSuffix "-linux" targetSystem; +in runCommand "bootstrap-zip" { } '' mkdir $out cd ${bootstrap} - ${zip}/bin/zip -q -9 -r $out/bootstrap-${config.build.arch} ./* ./.l2s + ${zip}/bin/zip -q -9 -r $out/bootstrap-${arch} ./* ./.l2s '' diff --git a/pkgs/cross-compiling/cross-pkgs-args.nix b/pkgs/cross-compiling/cross-pkgs-args.nix index c0c1bba..2dd40de 100644 --- a/pkgs/cross-compiling/cross-pkgs-args.nix +++ b/pkgs/cross-compiling/cross-pkgs-args.nix @@ -1,12 +1,15 @@ # Copyright (c) 2019-2024, see AUTHORS. Licensed under MIT License, see LICENSE. -{ config, system }: +{ lib, config, system, targetSystem }: +let + arch = lib.strings.removeSuffix "-linux" targetSystem; +in { inherit system; crossSystem = { - config = "${config.build.arch}-unknown-linux-android"; + config = "${arch}-unknown-linux-android"; sdkVer = "32"; libc = "bionic"; useAndroidPrebuilt = false; diff --git a/pkgs/cross-compiling/cross-pkgs.nix b/pkgs/cross-compiling/cross-pkgs.nix index 66c29af..9a14cee 100644 --- a/pkgs/cross-compiling/cross-pkgs.nix +++ b/pkgs/cross-compiling/cross-pkgs.nix @@ -1,6 +1,6 @@ # Copyright (c) 2019-2024, see AUTHORS. Licensed under MIT License, see LICENSE. -{ callPackage, nixpkgs, system }: +{ callPackage, nixpkgs }: let args = callPackage ./cross-pkgs-args.nix { }; diff --git a/pkgs/default.nix b/pkgs/default.nix index b5353f5..cafa602 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -1,18 +1,19 @@ # Copyright (c) 2019-2024, see AUTHORS. Licensed under MIT License, see LICENSE. { nixpkgs -, system -, arch ? "aarch64" +, system # system to compile for, user-facing name of targetSystem +, _nativeSystem ? null # system to cross-compile from, see flake.nix , nixOnDroidChannelURL ? null , nixpkgsChannelURL ? null , nixOnDroidFlakeURL ? null }: let - nixDirectory = callPackage ./nix-directory.nix { }; + nativeSystem = if _nativeSystem == null then system else _nativeSystem; + nixDirectory = callPackage ./nix-directory.nix { inherit system; }; initialPackageInfo = import "${nixDirectory}/nix-support/package-info.nix"; - pkgs = import nixpkgs { inherit system; }; + pkgs = import nixpkgs { system = nativeSystem; }; urlOptionValue = url: envVar: let @@ -24,6 +25,7 @@ let modules = import ../modules { inherit pkgs; + targetSystem = system; isFlake = true; @@ -41,11 +43,6 @@ let user.shell = "${initialPackageInfo.bash}/bin/bash"; build = { - arch = - if arch != null - then arch - else nixpkgs.lib.strings.removeSuffix "-linux" builtins.currentSystem; - channel = { nixpkgs = urlOptionValue nixpkgsChannelURL "NIXPKGS_CHANNEL_URL"; nix-on-droid = urlOptionValue nixOnDroidChannelURL "NIX_ON_DROID_CHANNEL_URL"; @@ -60,6 +57,7 @@ let pkgs // customPkgs // { inherit (modules) config; inherit callPackage nixpkgs nixDirectory initialPackageInfo; + targetSystem = system; } ); diff --git a/pkgs/nix-directory.nix b/pkgs/nix-directory.nix index 03e9fd8..932966c 100644 --- a/pkgs/nix-directory.nix +++ b/pkgs/nix-directory.nix @@ -1,6 +1,6 @@ # Copyright (c) 2019-2024, see AUTHORS. Licensed under MIT License, see LICENSE. -{ config, lib, stdenv, closureInfo, prootTermux, proot, pkgsStatic }: +{ config, lib, stdenv, closureInfo, prootTermux, proot, pkgsStatic, system }: let buildRootDirectory = "root-directory"; @@ -24,15 +24,15 @@ stdenv.mkDerivation { name = "nix-directory"; src = builtins.fetchurl { - url = "https://nixos.org/releases/nix/nix-2.20.5/nix-2.20.5-${config.build.arch}-linux.tar.xz"; + url = "https://nixos.org/releases/nix/nix-2.20.5/nix-2.20.5-${system}.tar.xz"; sha256 = let - archShas = { - aarch64 = "sha256:168wjfj3xsc8hq1y6cq59iipjp1g9hmj4n5wdn9c47ad9gbc9cvh"; - x86_64 = "sha256:0dax9n562ldj53ap6lz0cwwsfx4d8j1267g9s6lg3zs237yyzw61"; + nixShas = { + aarch64-linux = "sha256:168wjfj3xsc8hq1y6cq59iipjp1g9hmj4n5wdn9c47ad9gbc9cvh"; + x86_64-linux = "sha256:0dax9n562ldj53ap6lz0cwwsfx4d8j1267g9s6lg3zs237yyzw61"; }; in - archShas.${config.build.arch}; + nixShas.${system}; }; PROOT_NO_SECCOMP = 1; # see https://github.com/proot-me/PRoot/issues/106 diff --git a/scripts/deploy.sh b/scripts/deploy.sh index fbda16a..b54479f 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -61,14 +61,14 @@ for arch in $ARCHES; do log "building $arch proot..." proot="$(nix build --no-link --print-out-paths ".#prootTermux-${arch}")" - if grep -q "$arch = \"$proot\";" "$PROOT_HASH_FILE"; then + if grep -q "$arch-linux = \"$proot\";" "$PROOT_HASH_FILE"; then log "keeping $arch proot path in $PROOT_HASH_FILE" - elif grep -q "$arch = \"/nix/store/" "$PROOT_HASH_FILE"; then + elif grep -q "$arch-linux = \"/nix/store/" "$PROOT_HASH_FILE"; then log "patching $arch proot path in $PROOT_HASH_FILE..." - grep "$arch = \"/nix/store/" "$PROOT_HASH_FILE" - sed -i "s|$arch = \"/nix/store/.*\";|$arch = \"$proot\";|" "$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 = \"/nix/store/" "$PROOT_HASH_FILE" + grep "$arch-linux = \"/nix/store/" "$PROOT_HASH_FILE" else log "no $arch proot hash found in $PROOT_HASH_FILE!" exit 1 diff --git a/tests/emulator/bootstrap_flakes.py b/tests/emulator/bootstrap_flakes.py index 505de74..348e590 100644 --- a/tests/emulator/bootstrap_flakes.py +++ b/tests/emulator/bootstrap_flakes.py @@ -30,9 +30,9 @@ def run(d): wait_for(d, 'Setting up Nix-on-Droid with flakes...') wait_for(d, 'Installing flake from default template...') - wait_for(d, 'Overriding input urls / arch in flake...') - wait_for(d, 'Installing first Nix-on-Droid generation...', timeout=600) - wait_for(d, 'Building activation package') + wait_for(d, 'Overriding system value in the flake...', timeout=600) + wait_for(d, 'Installing first Nix-on-Droid generation...') + wait_for(d, 'Building activation package', timeout=180) wait_for(d, 'Congratulations!', timeout=900) wait_for(d, 'bash-5.2$') screenshot(d, 'bootstrap-ends')