From 4110def2ac2c6b93fc8ef362a2ec20e7df145182 Mon Sep 17 00:00:00 2001 From: Tobias Happ Date: Sun, 3 Nov 2019 18:03:40 +0100 Subject: [PATCH] Refactor directory structure Benefits of this refactoring: - argument list is now comprehensibly as there is now only one nixpkgs version flying around - common config and lib functions got abstracted away - clearer intent when to use pinned or unpinned packages - allows better configurability for the future through config attr set --- default.nix | 4 +- src/default.nix | 27 +++++---- src/lib/default.nix | 6 +- src/pkgs-list.nix | 47 --------------- src/pkgs/default.nix | 30 ---------- src/pkgs/files/default.nix | 27 +-------- src/pkgs/files/etc-group.nix | 4 +- src/pkgs/files/etc-passwd.nix | 10 +--- src/pkgs/files/hm-install.nix | 2 +- src/pkgs/files/login-inner.nix | 58 ++++++++----------- src/pkgs/files/login.nix | 10 ++-- src/pkgs/ids.nix | 13 ----- .../{ => initial-build}/bootstrap-zip.nix | 6 +- src/pkgs/{ => initial-build}/bootstrap.nix | 6 +- .../initial-build/cross-compiling/pkgs.nix | 30 ++++++++++ .../cross-compiling/proot-termux.nix} | 10 +++- .../cross-compiling}/talloc.nix | 18 +++--- .../{ => initial-build}/nix-directory.nix | 18 +++--- .../qemu-aarch64-static.nix | 4 +- src/pkgs/top-level/all-packages.nix | 42 ++++++++++++++ 20 files changed, 163 insertions(+), 209 deletions(-) delete mode 100644 src/pkgs-list.nix delete mode 100644 src/pkgs/default.nix delete mode 100644 src/pkgs/ids.nix rename src/pkgs/{ => initial-build}/bootstrap-zip.nix (56%) rename src/pkgs/{ => initial-build}/bootstrap.nix (88%) create mode 100644 src/pkgs/initial-build/cross-compiling/pkgs.nix rename src/pkgs/{proot.nix => initial-build/cross-compiling/proot-termux.nix} (78%) rename src/pkgs/{ => initial-build/cross-compiling}/talloc.nix (82%) rename src/pkgs/{ => initial-build}/nix-directory.nix (86%) rename src/pkgs/{ => initial-build}/qemu-aarch64-static.nix (91%) create mode 100644 src/pkgs/top-level/all-packages.nix diff --git a/default.nix b/default.nix index 2675e4f..838711f 100644 --- a/default.nix +++ b/default.nix @@ -13,7 +13,7 @@ let in { - inherit (pkgs) proot; + inherit (pkgs) proot-termux; basic-environment = nixpkgs.buildEnv { name = "basic-environment"; @@ -23,7 +23,7 @@ in nixpkgs.cacert nixpkgs.coreutils nixpkgs.nix - # pkgs.proot + # pkgs.proot-termux pkgs.files.etc-group pkgs.files.etc-passwd pkgs.files.hm-install diff --git a/src/default.nix b/src/default.nix index 10e573d..7640907 100644 --- a/src/default.nix +++ b/src/default.nix @@ -1,25 +1,24 @@ # Licensed under GNU Lesser General Public License v3 or later, see COPYING. # Copyright (c) 2019 Alexander Sosedkin and other contributors, see AUTHORS. -{ arch -, nixOnDroidChannelURL ? https://github.com/t184256/nix-on-droid-bootstrap/archive/testing.tar.gz -, nixpkgsChannelURL ? https://nixos.org/channels/nixos-19.09 -, initialBuild ? true -}: +{ arch, initialBuild ? true, nixOnDroidChannelURL ? "https://github.com/t184256/nix-on-droid-bootstrap/archive/master.tar.gz" }: assert builtins.elem arch [ "aarch64" "i686" ]; let - pkgs = import { }; + currentNixpkgs = import { }; + currentNixpkgsLib = currentNixpkgs.callPackage ./lib { }; - pkgsList = import ./pkgs-list.nix { - inherit arch; - inherit (pkgs) fetchFromGitHub; - }; + pinnedNixpkgs = currentNixpkgsLib.loadNixpkgs { }; + pinnedNixpkgsLib = pinnedNixpkgs.callPackage ./lib { }; + + # use pinned nixpkgs only for initial build + nixpkgs = if initialBuild then pinnedNixpkgs else currentNixpkgs; + lib = if initialBuild then pinnedNixpkgsLib else currentNixpkgsLib; + + config = lib.buildConfig { inherit arch initialBuild nixOnDroidChannelURL; }; in -import ./pkgs { - inherit arch initialBuild nixOnDroidChannelURL nixpkgsChannelURL; - inherit (pkgsList) pinnedPkgs crossPkgs crossStaticPkgs; - buildPkgs = if initialBuild then pkgsList.pinnedPkgs else pkgs; +import ./pkgs/top-level/all-packages.nix { + inherit nixpkgs lib config; } diff --git a/src/lib/default.nix b/src/lib/default.nix index 09365b4..661967d 100644 --- a/src/lib/default.nix +++ b/src/lib/default.nix @@ -10,12 +10,12 @@ let in { - buildConfig = { arch, initialBuild, channelConfig ? { } }: ( + buildConfig = { arch, initialBuild, nixOnDroidChannelURL }: ( { channel = { - nix-on-droid = "https://github.com/t184256/nix-on-droid-bootstrap/archive/testing.tar.gz"; + nix-on-droid = nixOnDroidChannelURL; nixpkgs = "https://nixos.org/channels/nixos-19.09"; - } // channelConfig; + }; core = { inherit arch initialBuild; diff --git a/src/pkgs-list.nix b/src/pkgs-list.nix deleted file mode 100644 index 2183171..0000000 --- a/src/pkgs-list.nix +++ /dev/null @@ -1,47 +0,0 @@ -# Licensed under GNU Lesser General Public License v3 or later, see COPYING. -# Copyright (c) 2019 Alexander Sosedkin and other contributors, see AUTHORS. - -{ fetchFromGitHub, arch }: - -let - # head of nixos-19.09 as of 2019-10-14 - pinnedPkgsSrc = fetchFromGitHub { - owner = "NixOS"; - repo = "nixpkgs"; - rev = "45a25ff41a2309099ff2e70b2f37debd5e567618"; - sha256 = "0w37p98i47d7snhckz8a3a60v0f05b5047vsm4rczink9mk9x7r3"; - }; - - defaultNixpkgsArgs = { - config = { }; - overlays = [ ]; - }; - - pinnedPkgs = import pinnedPkgsSrc defaultNixpkgsArgs; - - overlayJpegNoStatic = self: super: { - inherit (pinnedPkgs) libjpeg; - }; - - crossSystem = { - config = "${arch}-unknown-linux-android"; - sdkVer = "24"; - ndkVer = "18b"; - useAndroidPrebuilt = true; - }; -in - -{ - inherit pinnedPkgs; - - crossPkgs = import pinnedPkgsSrc ({ inherit crossSystem; } // defaultNixpkgsArgs); - - crossStaticPkgs = import pinnedPkgsSrc ({ - inherit crossSystem; - - crossOverlays = [ - (import "${pinnedPkgsSrc}/pkgs/top-level/static.nix") - overlayJpegNoStatic - ]; - } // defaultNixpkgsArgs); -} diff --git a/src/pkgs/default.nix b/src/pkgs/default.nix deleted file mode 100644 index 869e3f2..0000000 --- a/src/pkgs/default.nix +++ /dev/null @@ -1,30 +0,0 @@ -# Licensed under GNU Lesser General Public License v3 or later, see COPYING. -# Copyright (c) 2019 Alexander Sosedkin and other contributors, see AUTHORS. - -{ arch, buildPkgs, crossPkgs, crossStaticPkgs, initialBuild, pinnedPkgs -, nixOnDroidChannelURL, nixpkgsChannelURL -} @ args: - -let - callPackage = buildPkgs.lib.callPackageWith (args // pkgs); - - pkgs = rec { - bootstrap = callPackage ./bootstrap.nix { }; - - bootstrapZip = callPackage ./bootstrap-zip.nix { }; - - files = callPackage ./files { } // { recurseForDerivations = true; }; - - ids = callPackage ./ids.nix { }; - - nixDirectory = callPackage ./nix-directory.nix { }; - - proot = callPackage ./proot.nix { }; - - qemuAarch64Static = callPackage ./qemu-aarch64-static.nix { }; - - talloc = callPackage ./talloc.nix { }; - }; -in - -pkgs diff --git a/src/pkgs/files/default.nix b/src/pkgs/files/default.nix index 43ef5d8..40703c6 100644 --- a/src/pkgs/files/default.nix +++ b/src/pkgs/files/default.nix @@ -1,32 +1,7 @@ # Licensed under GNU Lesser General Public License v3 or later, see COPYING. # Copyright (c) 2019 Alexander Sosedkin and other contributors, see AUTHORS. -{ buildPkgs, initialBuild, nixDirectory -, nixOnDroidChannelURL, nixpkgsChannelURL -, ids }: - -let - instDir = "/data/data/com.termux.nix/files/usr"; - userName = "nix-on-droid"; - groupName = "nix-on-droid"; - shell = "/bin/sh"; - - packageInfo = import "${nixDirectory}/nix-support/package-info.nix"; - - # TODO: remove when https://github.com/NixOS/nixpkgs/pull/64421 got merged into stable - writeTextDir = path: text: buildPkgs.writeTextFile { - inherit text; - name = builtins.baseNameOf path; - destination = "/${path}"; - }; - - callPackage = buildPkgs.lib.callPackageWith (buildPkgs // { - inherit initialBuild instDir packageInfo writeTextDir; - inherit groupName userName ids; - inherit shell; - inherit nixOnDroidChannelURL nixpkgsChannelURL; - }); -in +{ callPackage, writeTextDir }: { etc-group = callPackage ./etc-group.nix { }; diff --git a/src/pkgs/files/etc-group.nix b/src/pkgs/files/etc-group.nix index 160a20b..625f902 100644 --- a/src/pkgs/files/etc-group.nix +++ b/src/pkgs/files/etc-group.nix @@ -1,9 +1,9 @@ # Licensed under GNU Lesser General Public License v3 or later, see COPYING. # Copyright (c) 2019 Alexander Sosedkin and other contributors, see AUTHORS. -{ writeTextDir, userName, groupName, ids }: +{ config, writeTextDir }: writeTextDir "etc/group" '' root:x:0: - ${groupName}:x:${(import ids).gid}:${userName} + ${config.user.group}:x:${config.user.gid}:${config.user.user} '' diff --git a/src/pkgs/files/etc-passwd.nix b/src/pkgs/files/etc-passwd.nix index d64c4fa..6e815bb 100644 --- a/src/pkgs/files/etc-passwd.nix +++ b/src/pkgs/files/etc-passwd.nix @@ -1,13 +1,9 @@ # Licensed under GNU Lesser General Public License v3 or later, see COPYING. # Copyright (c) 2019 Alexander Sosedkin and other contributors, see AUTHORS. -{ writeTextDir, instDir, userName, shell, ids }: - -let - idSet = import ids; -in +{ config, writeTextDir }: writeTextDir "etc/passwd" '' - root:x:0:0:System administrator:${instDir}/root:/bin/sh - ${userName}:x:${idSet.uid}:${idSet.gid}:${userName}:/data/data/com.termux.nix/files/home:${shell} + root:x:0:0:System administrator:${config.core.installation}/root:/bin/sh + ${config.user.user}:x:${config.user.uid}:${config.user.gid}:${config.user.user}:${config.user.home}:${config.user.shell} '' diff --git a/src/pkgs/files/hm-install.nix b/src/pkgs/files/hm-install.nix index 6413d59..f2114c1 100644 --- a/src/pkgs/files/hm-install.nix +++ b/src/pkgs/files/hm-install.nix @@ -1,7 +1,7 @@ # Licensed under GNU Lesser General Public License v3 or later, see COPYING. # Copyright (c) 2019 Alexander Sosedkin and other contributors, see AUTHORS. -{ coreutils, instDir, nix, writeScriptBin }: +{ coreutils, nix, writeScriptBin }: writeScriptBin "hm-install" '' #!/usr/bin/env sh diff --git a/src/pkgs/files/login-inner.nix b/src/pkgs/files/login-inner.nix index c4a719b..2ac88da 100644 --- a/src/pkgs/files/login-inner.nix +++ b/src/pkgs/files/login-inner.nix @@ -1,53 +1,45 @@ # Licensed under GNU Lesser General Public License v3 or later, see COPYING. # Copyright (c) 2019 Alexander Sosedkin and other contributors, see AUTHORS. -{ initialBuild -, nixpkgsChannelURL, nixOnDroidChannelURL -, instDir -, packageInfo -, writeTextDir -}: +{ config, lib, packageInfo, writeTextDir }: writeTextDir "usr/lib/login-inner" '' set -e [ "$#" -gt 0 ] || echo "Welcome to Nix-on-Droid!" - [ "$#" -gt 0 ] || echo "If nothing works, use the rescue shell and read ${instDir}/usr/lib/login-inner" + [ "$#" -gt 0 ] || echo "If nothing works, use the rescue shell and read ${config.core.installation}/usr/lib/login-inner" [ "$#" -gt 0 ] || echo "If it does not help, report bugs at https://github.com/t184256/nix-on-droid-bootstrap/issues" - export USER='nix-on-droid' - export HOME='/data/data/com.termux.nix/files/home' + export USER="${config.user.user}" + export HOME="${config.user.home}" - ${ - if initialBuild - then '' - [ "$#" -gt 0 ] || echo "Sourcing Nix environment..." - . ${packageInfo.nix}/etc/profile.d/nix.sh + ${lib.optionalString config.core.initialBuild '' + [ "$#" -gt 0 ] || echo "Sourcing Nix environment..." + . ${packageInfo.nix}/etc/profile.d/nix.sh - export NIX_SSL_CERT_FILE=${packageInfo.cacert} + export NIX_SSL_CERT_FILE=${packageInfo.cacert} - echo "Installing and updating nix-channels..." - ${packageInfo.nix}/bin/nix-channel --add ${nixpkgsChannelURL} nixpkgs - ${packageInfo.nix}/bin/nix-channel --add ${nixOnDroidChannelURL} nix-on-droid - ${packageInfo.nix}/bin/nix-channel --update + echo "Installing and updating nix-channels..." + ${packageInfo.nix}/bin/nix-channel --add ${config.channel.nixpkgs} nixpkgs + ${packageInfo.nix}/bin/nix-channel --add ${config.channel.nix-on-droid} nix-on-droid + ${packageInfo.nix}/bin/nix-channel --update - echo "Installing nix-on-droid.basic-environment..." - ${packageInfo.nix}/bin/nix-env -iA nix-on-droid.basic-environment + echo "Installing nix-on-droid.basic-environment..." + ${packageInfo.nix}/bin/nix-env -iA nix-on-droid.basic-environment - echo "Setting up dynamic symlinks via nix-on-droid-linker" - nix-on-droid-linker + echo "Setting up dynamic symlinks via nix-on-droid-linker" + nix-on-droid-linker - echo - echo "Congratulations! Now you have Nix installed with some basic packages like" - echo "bashInteractive, coreutils, cacert and some scripts provided by nix-on-droid" - echo "itself." - echo - echo "You can go for the bare Nix setup or you can configure your phone via" - echo "home-manager. For that simply run hm-install." - echo - '' else "" - } + echo + echo "Congratulations! Now you have Nix installed with some basic packages like" + echo "bashInteractive, coreutils, cacert and some scripts provided by nix-on-droid" + echo "itself." + echo + echo "You can go for the bare Nix setup or you can configure your phone via" + echo "home-manager. For that simply run hm-install." + echo + ''} [ "$#" -gt 0 ] || echo "Sourcing Nix environment..." . $HOME/.nix-profile/etc/profile.d/nix.sh diff --git a/src/pkgs/files/login.nix b/src/pkgs/files/login.nix index f98c8b6..205597f 100644 --- a/src/pkgs/files/login.nix +++ b/src/pkgs/files/login.nix @@ -1,7 +1,11 @@ # Licensed under GNU Lesser General Public License v3 or later, see COPYING. # Copyright (c) 2019 Alexander Sosedkin and other contributors, see AUTHORS. -{ instDir, writeScriptBin }: +{ config, writeScriptBin }: + +let + instDir = config.core.installation; +in writeScriptBin "login" '' #!/system/bin/sh @@ -57,9 +61,7 @@ writeScriptBin "login" '' fi } - instDir=/data/data/com.termux.nix/files/usr - - export USER=nix-on-droid + export USER="${config.user.user}" export PROOT_TMP_DIR=${instDir}/tmp export PROOT_L2S_DIR=${instDir}/.l2s diff --git a/src/pkgs/ids.nix b/src/pkgs/ids.nix deleted file mode 100644 index 7baea41..0000000 --- a/src/pkgs/ids.nix +++ /dev/null @@ -1,13 +0,0 @@ -# Licensed under GNU Lesser General Public License v3 or later, see COPYING. -# Copyright (c) 2019 Alexander Sosedkin and other contributors, see AUTHORS. - -{ buildPkgs }: - -buildPkgs.runCommand "ids.nix" {} '' - cat > $out <