mirror of
https://github.com/nix-community/nix-on-droid.git
synced 2025-11-08 11:36:07 +01:00
add support for default configuration in flake.nix
This commit is contained in:
parent
ffac515cfb
commit
6a345626c0
9 changed files with 51 additions and 13 deletions
|
|
@ -21,6 +21,9 @@
|
|||
and `config` and `extraModules` are now combined into `modules`
|
||||
* Add option `environment.motd` to edit the startup message that is printed in
|
||||
every shell
|
||||
* For flake setups, the output `nixOnDroidConfigurations.default` will be used
|
||||
when `nix-on-droid switch --flake path/to/flake` is called without attribute
|
||||
name
|
||||
|
||||
## Release 22.05
|
||||
|
||||
|
|
|
|||
|
|
@ -192,7 +192,7 @@ A minimal example could look like the following:
|
|||
|
||||
outputs = { self, nixpkgs, nix-on-droid }: {
|
||||
|
||||
nixOnDroidConfigurations.deviceName = nix-on-droid.lib.nixOnDroidConfiguration {
|
||||
nixOnDroidConfigurations.default = nix-on-droid.lib.nixOnDroidConfiguration {
|
||||
modules = [ ./nix-on-droid.nix ];
|
||||
};
|
||||
|
||||
|
|
@ -208,8 +208,9 @@ nix flake init --template github:t184256/nix-on-droid#advanced
|
|||
|
||||
### Usage with `nix-on-droid`
|
||||
|
||||
Use `nix-on-droid switch --flake .#device` to build and activate your configuration (`.#device` will expand to
|
||||
`.#nixOnDroidConfigurations.device`).
|
||||
Use `nix-on-droid switch --flake path/to/flake#device` to build and activate your configuration (`path/to/flake#device`
|
||||
will expand to `.#nixOnDroidConfigurations.device`). If you run `nix-on-droid switch --flake path/to/flake`, the
|
||||
`default` configuration will be used.
|
||||
|
||||
**Note:** Currently, nix-on-droid can not be built with an pure flake build because of hardcoded store paths for proot.
|
||||
Therefore, every evaluation of a flake configuration will be executed with `--impure` flag. (This behaviour will be
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ writeText "login-inner" ''
|
|||
''}
|
||||
|
||||
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
|
||||
|
||||
. "${config.user.home}/.nix-profile/etc/profile.d/nix-on-droid-session-init.sh"
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,8 @@ function doHelp() {
|
|||
echo " -n|--dry-run Do a dry run, only prints what actions would be taken"
|
||||
echo " -v|--verbose Verbose output"
|
||||
echo " -f|--file FILE Path to config file"
|
||||
echo " -F|--flake FLAKE Path to flake and device name (e.g. path/to/flake#device)"
|
||||
echo " -F|--flake FLAKE Path to flake and device name (e.g. path/to/flake#device),"
|
||||
echo " device 'default' will be used if no attribute name is given"
|
||||
echo
|
||||
echo "Options passed on to nix build"
|
||||
echo
|
||||
|
|
@ -139,7 +140,12 @@ while [[ $# -gt 0 ]]; do
|
|||
PASSTHROUGH_OPTS+=(--extra-experimental-features "flakes nix-command")
|
||||
# add "nixOnDroidConfigurations." as prefix in attribute name, e.g.
|
||||
# /path/to/flake#device -> /path/to/flake#nixOnDroidConfigurations.device
|
||||
FLAKE_CONFIG_URI="${1%#*}#nixOnDroidConfigurations.${1#*#}"
|
||||
# if no attribute name given, use "default"
|
||||
if [[ "$1" =~ \# ]]; then
|
||||
FLAKE_CONFIG_URI="${1%#*}#nixOnDroidConfigurations.${1#*#}"
|
||||
else
|
||||
FLAKE_CONFIG_URI="${1}#nixOnDroidConfigurations.default"
|
||||
fi
|
||||
shift
|
||||
;;
|
||||
-h|--help)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
outputs = { self, nixpkgs, home-manager, nix-on-droid }: {
|
||||
|
||||
nixOnDroidConfigurations.deviceName = nix-on-droid.lib.nixOnDroidConfiguration {
|
||||
nixOnDroidConfigurations.default = nix-on-droid.lib.nixOnDroidConfiguration {
|
||||
modules = [
|
||||
./nix-on-droid.nix
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
outputs = { self, nixpkgs, home-manager, nix-on-droid }: {
|
||||
|
||||
nixOnDroidConfigurations.deviceName = nix-on-droid.lib.nixOnDroidConfiguration {
|
||||
nixOnDroidConfigurations.default = nix-on-droid.lib.nixOnDroidConfiguration {
|
||||
modules = [ ./nix-on-droid.nix ];
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
outputs = { self, nixpkgs, nix-on-droid }: {
|
||||
|
||||
nixOnDroidConfigurations.deviceName = nix-on-droid.lib.nixOnDroidConfiguration {
|
||||
nixOnDroidConfigurations.default = nix-on-droid.lib.nixOnDroidConfiguration {
|
||||
modules = [ ./nix-on-droid.nix ];
|
||||
};
|
||||
|
||||
|
|
|
|||
17
tests/on-device/config-flake-default.nix
Normal file
17
tests/on-device/config-flake-default.nix
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
description = "nix-on-droid configuration";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/release-22.05";
|
||||
nix-on-droid.url = "<<FLAKE_URL>>";
|
||||
nix-on-droid.inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
outputs = { nix-on-droid, ... }: {
|
||||
nixOnDroidConfigurations = {
|
||||
default = nix-on-droid.lib.nixOnDroidConfiguration {
|
||||
modules = [ ./nix-on-droid.nix ];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -1,8 +1,11 @@
|
|||
# Copyright (c) 2019-2021, see AUTHORS. Licensed under MIT License, see LICENSE.
|
||||
# Copyright (c) 2019-2022, see AUTHORS. Licensed under MIT License, see LICENSE.
|
||||
|
||||
load lib
|
||||
|
||||
@test 'flake example works' {
|
||||
function flake_example() {
|
||||
local flake_url="$1"
|
||||
local flake_file_name="$2"
|
||||
|
||||
# assertions to verify initial state is as expected
|
||||
assert_command vi
|
||||
assert_no_command unzip
|
||||
|
|
@ -15,10 +18,10 @@ load lib
|
|||
> ~/.config/nixpkgs/nix-on-droid.nix
|
||||
|
||||
_sed "s|<<FLAKE_URL>>|$FLAKE_URL|g" \
|
||||
"$ON_DEVICE_TESTS_DIR/config-flake.nix" \
|
||||
"$ON_DEVICE_TESTS_DIR/$flake_file_name" \
|
||||
> ~/.config/nixpkgs/flake.nix
|
||||
|
||||
nix-on-droid switch --flake ~/.config/nixpkgs#device
|
||||
nix-on-droid switch --flake "$flake_url"
|
||||
|
||||
# test presence of several crucial commands
|
||||
assert_command nix-on-droid nix-shell bash
|
||||
|
|
@ -32,3 +35,11 @@ load lib
|
|||
assert_command vi
|
||||
assert_no_command unzip
|
||||
}
|
||||
|
||||
@test 'flake example works' {
|
||||
flake_example ~/.config/nixpkgs#device config-flake.nix
|
||||
}
|
||||
|
||||
@test 'flake with default config works' {
|
||||
flake_example ~/.config/nixpkgs config-flake-default.nix
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue