From b01a2a8a57b0854be4bb6c87b3de76fc43d7b211 Mon Sep 17 00:00:00 2001 From: Tobias Happ Date: Thu, 27 Oct 2022 12:33:17 +0200 Subject: [PATCH] bootstrap: use env vars to set custom channel urls --- README.md | 4 +++- pkgs/default.nix | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 921f31c..9ebe633 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,9 @@ To re-trigger the installation, you can use If you want to change the nix-on-droid channel to your custom one, you can do that either with `nix-channel` after the installation, -or by using `--argstr nixOnDroidChannelURL `. +or by setting the environment variable `NIX_ON_DROID_CHANNEL_URL`. +Other environment variables are `NIXPKGS_CHANNEL_URL` an +`NIX_ON_DROID_FLAKE_URL`. **Note**: The `proot` binary is not built on the android device (NDK is required for building it, and it's not available on mobile platforms). diff --git a/pkgs/default.nix b/pkgs/default.nix index ef88518..ed965b6 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -14,6 +14,14 @@ let pkgs = import nixpkgs { inherit system; }; + urlOptionValue = url: envVar: + let + envValue = builtins.getEnv envVar; + in + pkgs.lib.mkIf + (envValue != "" || url != null) + (if url == null then envValue else url); + modules = import ../modules { inherit pkgs; @@ -29,15 +37,15 @@ let # Fix invoking bash after initial build. user.shell = "${initialPackageInfo.bash}/bin/bash"; - build = with pkgs.lib; { + build = { inherit arch; channel = { - nixpkgs = mkIf (nixpkgsChannelURL != null) nixpkgsChannelURL; - nix-on-droid = mkIf (nixOnDroidChannelURL != null) nixOnDroidChannelURL; + nixpkgs = urlOptionValue nixpkgsChannelURL "NIXPKGS_CHANNEL_URL"; + nix-on-droid = urlOptionValue nixOnDroidChannelURL "NIX_ON_DROID_CHANNEL_URL"; }; - flake.nix-on-droid = mkIf (nixOnDroidFlakeURL != null) nixOnDroidFlakeURL; + flake.nix-on-droid = urlOptionValue nixOnDroidFlakeURL "NIX_ON_DROID_FLAKE_URL"; }; }; };