nix-community / nix-on-droid

Nix-enabled environment for your Android device. [maintainers=@t184256,@Gerschtli]
https://nix-on-droid.unboiled.info
MIT License
1.25k stars 69 forks source link

Confusion on the usage of Flakes #111

Closed bobbbay closed 2 years ago

bobbbay commented 3 years ago

Hey y'all, I have a feeling this is a stupid question...

So, I activated Flakes. Well, actually, it errored out:

error: selector 'result' matches no derivations

But it seems Flakes have been activated? I can run nix flake, anyhow.

Now, I'm slightly confused as to where to continue from there. On my NixOS computers, I run nixos-rebuild switch and we're good from there. However, nix-on-droid switch still seems to be using a non-flaked config.

Super confused as to my next steps :D

t184256 commented 3 years ago

Figure it out and tell us =) Flakes are not supported yet; patches are welcome.

Gerschtli commented 3 years ago

Have a look at nix-on-droid/nix-on-droid.sh. There is all the init logic. Try adding set -x at the top (prints all executed statements) to find the line that is causing the problem. Maybe there are nix commands which are incompatible with nix flakes. We are using the new unstable nix cli interface which changes its behaviour when flakes are enabled.

Once you found the issue, I am sure we can work out a solution :)

Thanks for having a look into the flakes stuff, I added this to my todo list quite a while ago :D

ShamrockLee commented 3 years ago

I can confirm this issue. Things seems work except the confusing error following the long process time trying to Activate linkProfile.

ShamrockLee commented 3 years ago

The problem seems to lie in the activation script instead of the nix-on-droid command.

The corresponding content of the activation script read

noteEcho "Activating linkProfile"
generationDir="$(dirname $0)"

if [[ $generationDir =~ ^/nix/var/nix/profiles/nix-on-droid-([0-9]+)-link$ ]]; then
  $DRY_RUN_CMD nix-env --profile "/nix/var/nix/profiles/nix-on-droid" --switch-generation "${BASH_REMATCH[1]}"
else
  $DRY_RUN_CMD nix-env --profile "/nix/var/nix/profiles/nix-on-droid" --set "$generationDir"
fi

it seems to expect the symbolic link to the script to appear at /nix/var/nix/profiles/nix-on-droid-[generation number]-link/activate instead of some/where/result/activate.

It seems that activationPackage is an attribute of the output of modules/default.nix, and the Nix expressions related to the activationPackage generation is mainly inside modules/build/activation.nix.

Gerschtli commented 3 years ago

That is not entirely true. The main reason for this switch is to allow rollbacks to reuse the already built generation. The problem when your building your nix-on-droid build may be that generationDir is the path to your "result" symlink instead of the /nix/store path. Maybe you can try resolving the symlink of generationDir in the else case.

ShamrockLee commented 2 years ago

@t184256 @Gerschtli

Sorry for not well-testing the commit.

For some strange reason, the "$PWD" inside the result/activation script is "$HOME", but the path given by $(dirname $0) is result, which is relative to the "$PWD" outside, and $(dirname $0) thus does not exist for the tooling inside the script. My above PR (#135) needs to be reverted.

ShamrockLee commented 2 years ago

@t184256 I'm not sure if the revert help, since the problem had already been there before the commit was made. What I'm sure is that my above commit doesn't solve the problem.

t184256 commented 2 years ago

Then reason is https://github.com/t184256/nix-on-droid/blob/3aa377bf01ce82da48567d026ab9f2ad3f1befc2/modules/build/activation.nix#L38. Drop it from the activation script, run it from non-$HOME and see what breaks?

ShamrockLee commented 2 years ago

It works after dropping the line cd $HOME. Nothing breaks running from non-$HOME CWD. It doesn't matter if the activation package is checked into the channel with

$DRY_RUN_CMD nix-env --profile "${profileDirectory}" --set "$(realpath "$generationDir")"

or

$DRY_RUN_CMD nix-env --profile "${profileDirectory}" --set "$generationDir"
t184256 commented 2 years ago

OK, file another PR and I'll test later with and without flakes + clean install. (I should really start automating these things)

Gerschtli commented 2 years ago

Do we have any clue, why the cd is causing the problem? I do not really get your explanation.. :D

bobbbay commented 2 years ago

Closing because my issue seems to have been resolved. For other problems, let's open separate issues :)!