bootstrap: override flake inputs if needed

This commit is contained in:
Tobias Happ 2022-10-27 20:29:34 +02:00
parent 3e4331b313
commit a321893a32
2 changed files with 42 additions and 4 deletions

View file

@ -4,6 +4,17 @@
with lib; with lib;
let
defaultNixpkgsBranch = "nixos-22.05";
defaultNixOnDroidBranch = "release-22.05";
defaultNixpkgsChannel = "https://nixos.org/channels/${defaultNixpkgsBranch}";
defaultNixOnDroidChannel = "https://github.com/t184256/nix-on-droid/archive/${defaultNixOnDroidBranch}.tar.gz";
defaultNixpkgsFlake = "github:NixOS/nixpkgs/${defaultNixpkgsBranch}";
defaultNixOnDroidFlake = "github:t184256/nix-on-droid/${defaultNixOnDroidBranch}";
in
{ {
###### interface ###### interface
@ -14,23 +25,35 @@ with lib;
channel = { channel = {
nixpkgs = mkOption { nixpkgs = mkOption {
type = types.str; type = types.str;
default = "https://nixos.org/channels/nixos-22.05"; default = defaultNixpkgsChannel;
description = "Channel URL for nixpkgs."; description = "Channel URL for nixpkgs.";
}; };
nix-on-droid = mkOption { nix-on-droid = mkOption {
type = types.str; type = types.str;
default = "https://github.com/t184256/nix-on-droid/archive/release-22.05.tar.gz"; default = defaultNixOnDroidChannel;
description = "Channel URL for nix-on-droid."; description = "Channel URL for nix-on-droid.";
}; };
}; };
flake = { flake = {
nixpkgs = mkOption {
type = types.str;
default = defaultNixpkgsFlake;
description = "Flake URL for nixpkgs.";
};
nix-on-droid = mkOption { nix-on-droid = mkOption {
type = types.str; type = types.str;
default = "github:t184256/nix-on-droid/release-22.05"; default = defaultNixOnDroidFlake;
description = "Flake URL for nix-on-droid."; description = "Flake URL for nix-on-droid.";
}; };
inputOverrides = mkEnableOption "" // {
description = ''
Whether to override the standard input URLs in the initial <filename>flake.nix</filename>.
'';
};
}; };
}; };
@ -41,7 +64,13 @@ with lib;
config = { config = {
build.initialBuild = true; build = {
initialBuild = true;
flake.inputOverrides =
config.build.flake.nixpkgs != defaultNixpkgsFlake
|| config.build.flake.nix-on-droid != defaultNixOnDroidFlake;
};
# /etc/group and /etc/passwd need to be build on target machine because # /etc/group and /etc/passwd need to be build on target machine because
# uid and gid need to be determined. # uid and gid need to be determined.

View file

@ -78,6 +78,15 @@ writeText "login-inner" ''
echo "Installing flake from default template..." echo "Installing flake from default template..."
${nixCmd} flake new ${config.user.home}/.config/nix-on-droid --template ${config.build.flake.nix-on-droid} ${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 in flake..."
${nixCmd} run nixpkgs#gnused -- \
-i \
-e 's,\"github:NixOS/nixpkgs.*\",\"${config.build.flake.nixpkgs}\",' \
-e 's,\"github:t184256/nix-on-droid.*\",\"${config.build.flake.nix-on-droid}\",' \
"${config.user.home}/.config/nix-on-droid/flake.nix"
''}
echo "Installing first nix-on-droid generation..." echo "Installing first nix-on-droid generation..."
${nixCmd} run ${config.build.flake.nix-on-droid} -- switch --flake ${config.user.home}/.config/nix-on-droid#deviceName ${nixCmd} run ${config.build.flake.nix-on-droid} -- switch --flake ${config.user.home}/.config/nix-on-droid#deviceName