nix-community / nix-on-droid

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

Way to run fakedroid from users's flake #274

Closed kurnevsky closed 4 months ago

kurnevsky commented 1 year ago

Currently fakedroid is supposed to be run from the clone of nix-on-droid repository.

I tried to add fakedroid to outputs of my flake with my system configs but it obviously didn't work - fakedroid expects to have some scripts in the repo.

Th reason I want it is to experiment quickly with configs without uploading and rebuilding them to my phone - it would be handy to have a single command that will create a VM (or sandbox) with my custom configs, not default ones.

Nixos-mobile has this with their config.mobile.outputs.uefi.vm package.

Gerschtli commented 1 year ago

Have a look at https://github.com/t184256/nix-on-droid/pull/275 :)

kurnevsky commented 1 year ago

Thanks! It's an improvement, but it still uses the default config, and I have to clone my config inside manually. Ideally I'd want to have some output of my flake that I could run that would use this flake inside fakedroid.

Also it would be good if it used my host nix daemon to build it to use my host /nix cache, but I guess this might be a non trivial change :)

kurnevsky commented 1 year ago

Tried it with my home, but got a permission error:

➜  STATE_DIR=~/tmp USE_FLAKE=1 nix run --impure github:t184256/nix-on-droid/add-support-for-fakedroid-usage'#fakedroid'
mkdir: cannot create directory β€˜/home/kurnevsky/tmp/inj’: Permission denied

Changing it to /tmp/fakedroid worked.

Gerschtli commented 1 year ago

Thanks! It's an improvement, but it still uses the default config, and I have to clone my config inside manually. Ideally I'd want to have some output of my flake that I could run that would use this flake inside fakedroid.

We could add reading an environment variable for the flake uri and use it instead of

https://github.com/t184256/nix-on-droid/blob/master/modules/environment/login/login-inner.nix#L79-L92

Also it would be good if it used my host nix daemon to build it to use my host /nix cache, but I guess this might be a non trivial change :)

That is not possible AFAIK because the build needs to run in the proot environment.

Tried it with my home, but got a permission error:

That is strange can you show me the permissons and owner of ~/tmp, /tmp/fakedroid and /tmp/fakedroid/*?

kurnevsky commented 1 year ago

That is not possible AFAIK because the build needs to run in the proot environment.

I built everything remotely for my phone using my x86-64 pc, so it doesn't seem to matter :)

In theory it should possible to have a completely built output by main nix daemon, but I have no idea how difficult it is.

That is strange can you show me the permissons and owner of ~/tmp, /tmp/fakedroid and /tmp/fakedroid/*?

That's quite strange. All of them are owned by my main user. But I can remove files in /tmp/fakedroid only with root:

kurnevsky in 🌐 pc in ~ ➜  ls -la /tmp/fakedroid/env/1/data/data/com.termux.nix/files/usr/nix/store/n9dk853bl3ny2mqv4pjh7440jglm8wz8-source/nixos/modules/services/hardware/power-profiles-daemon.nix 
-rwxrwxrwx 1 kurnevsky users 994 Jan  1  1970 /tmp/fakedroid/env/1/data/data/com.termux.nix/files/usr/nix/store/n9dk853bl3ny2mqv4pjh7440jglm8wz8-source/nixos/modules/services/hardware/power-profiles-daemon.nix
kurnevsky in 🌐 pc in ~ ➜  lsattr /tmp/fakedroid/env/1/data/data/com.termux.nix/files/usr/nix/store/n9dk853bl3ny2mqv4pjh7440jglm8wz8-source/nixos/modules/services/hardware/power-profiles-daemon.nix
---------------------- /tmp/fakedroid/env/1/data/data/com.termux.nix/files/usr/nix/store/n9dk853bl3ny2mqv4pjh7440jglm8wz8-source/nixos/modules/services/hardware/power-profiles-daemon.nix
kurnevsky in 🌐 pc in ~ ➜  rm -rf /tmp/fakedroid/env/1/data/data/com.termux.nix/files/usr/nix/store/n9dk853bl3ny2mqv4pjh7440jglm8wz8-source/nixos/modules/services/hardware/power-profiles-daemon.nix
rm: cannot remove '/tmp/fakedroid/env/1/data/data/com.termux.nix/files/usr/nix/store/n9dk853bl3ny2mqv4pjh7440jglm8wz8-source/nixos/modules/services/hardware/power-profiles-daemon.nix': Permission denied
Gerschtli commented 1 year ago

In theory it should possible to have a completely built output by main nix daemon, but I have no idea how difficult it is.

This is exceeding my knowledge..

That's quite strange. All of them are owned by my main user. But I can remove files in /tmp/fakedroid only with root:

It is hard to tell what could cause this because I can not reproduce this behaviour.. If you find a way to reproduce it or if you find a difference between ~/tmp and /tmp/fakedroid, I can have another look. (Maybe these are on different devices which are mounted differently?).

When trying to remove the state directories, it usually fails because of missing writable bits for the nix store paths. chmod -R +w * and then rm as my user works for me without any problems.

kurnevsky commented 1 year ago

When trying to remove the state directories, it usually fails because of missing writable bits for the nix store paths. chmod -R +w * and then rm as my user works for me without any problems.

It's not the case, I did chmod 777 to this file. It worked from my user, but I still can't delete this file...

kurnevsky commented 1 year ago

Oops, I indeed had wrong permissions for ~/tmp. Though it doesn't explain why I can't remove created files :)

t184256 commented 4 months ago

we don't have fakedroid anymore