{"id":13440492,"url":"https://github.com/nix-community/nix-on-droid","last_synced_at":"2025-05-15T15:02:24.484Z","repository":{"id":37993145,"uuid":"174202140","full_name":"nix-community/nix-on-droid","owner":"nix-community","description":"Nix-enabled environment for your Android device. [maintainers=@t184256,@Gerschtli] ","archived":false,"fork":false,"pushed_at":"2024-09-10T22:30:54.000Z","size":545,"stargazers_count":1317,"open_issues_count":86,"forks_count":74,"subscribers_count":28,"default_branch":"master","last_synced_at":"2024-10-29T15:18:20.779Z","etag":null,"topics":["android","home-manager","nix","nix-on-droid"],"latest_commit_sha":null,"homepage":"https://nix-on-droid.unboiled.info","language":"Nix","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nix-community.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null},"funding":{"open_collective":"nix-community"}},"created_at":"2019-03-06T18:52:50.000Z","updated_at":"2024-10-29T07:40:02.000Z","dependencies_parsed_at":"2023-09-13T22:24:42.280Z","dependency_job_id":"ff71ff9b-f677-4cd5-a135-e7b607983431","html_url":"https://github.com/nix-community/nix-on-droid","commit_stats":{"total_commits":450,"total_committers":18,"mean_commits":25.0,"dds":0.5066666666666666,"last_synced_commit":"5d88ff2519e4952f8d22472b52c531bb5f1635fc"},"previous_names":["nix-community/nix-on-droid","t184256/nix-on-droid"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nix-community%2Fnix-on-droid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nix-community%2Fnix-on-droid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nix-community%2Fnix-on-droid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nix-community%2Fnix-on-droid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nix-community","download_url":"https://codeload.github.com/nix-community/nix-on-droid/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248502410,"owners_count":21114809,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","home-manager","nix","nix-on-droid"],"created_at":"2024-07-31T03:01:23.255Z","updated_at":"2025-04-12T01:56:32.072Z","avatar_url":"https://github.com/nix-community.png","language":"Nix","funding_links":["https://opencollective.com/nix-community"],"categories":["HarmonyOS","Nix","nix","Distributions","android"],"sub_categories":["Windows Manager"],"readme":"# Nix-on-Droid\n\n[\u003cimg src=\"https://fdroid.gitlab.io/artwork/badge/get-it-on.png\"\n    alt=\"Get it on F-Droid\"\n    height=\"80\"\u003e](https://f-droid.org/packages/com.termux.nix)\n\nNix package manager on Android, in a single-click installable package. This is\nnot full [NixOS](https://nixos.org/) running inside Android, but you get easy\naccess to [nixpkgs](https://github.com/NixOS/nixpkgs)' vast collection of\n(precompiled!) software and the best package manager under the sun. It's\nprototype-grade quality as of now, but hey, it works!\n\nIt does not require root, user namespaces support or disabling SELinux,\nbut it relies on `proot` and other hacks instead.\nIt uses [a fork](https://github.com/nix-community/nix-on-droid-app)\nof [Termux-the-terminal-emulator app](https://github.com/termux/termux-app),\nbut has no relation to [Termux-the-distro](https://termux.com/).\nPlease do not pester Termux folks about Nix-on-Droid.\n\nThis repository contains:\n\n1. Nix expressions that generate a bootstrap zipball,\n   which is then used to install Nix package manager on Android\n   along with the `nix-on-droid` executable.\n2. A module system for configuring the local Nix-on-Droid installation directly\n   on the device.\n\nIt is only tested with aarch64 (64-bit ARM devices).\nIt also used to compile for i686 devices, but the developers don't own any\nand nobody has reported whether it actually worked or not,\nso it's no longer built unless a user shows up.\nSorry, it would not work on 32-bit ARM devices\nand it's not an easy feat to pull off.\n\n\n## Try it out\n\n[Install it from F-Droid](https://f-droid.org/packages/com.termux.nix),\nlaunch the app, press OK,\nexpect many hundreds megabytes of downloads to happen.\n\n\n## Nix-on-Droid and the module system\n\n### Config file\n\nThe Nix-on-Droid system can be managed through a custom config\nfile in `~/.config/nixpkgs/nix-on-droid.nix` as generated on first build,\nfor example:\n\n```nix\n{ pkgs, ... }:\n\n{\n  environment.packages = [ pkgs.vim ];\n  system.stateVersion = \"24.05\";\n}\n```\n\nAn alternative location is `~/.config/nixpkgs/config.nix` with the key\n`nix-on-droid`, for example:\n\n```nix\n{\n  nix-on-droid =\n    { pkgs, ... }:\n\n    {\n      environment.packages = [ pkgs.vim ];\n      system.stateVersion = \"24.05\";\n    };\n}\n```\n\nSee \u003chttps://nix-community.github.io/nix-on-droid/\u003e for list of all available options.\n\n### [`home-manager`](https://github.com/nix-community/home-manager) integration\n\nTo enable `home-manager` you simply need to follow the instructions already provided in the example `nix-on-droid.nix`:\n\n1.  Add `home-manager` channel:\n    ```sh\n    nix-channel --add https://github.com/nix-community/home-manager/archive/release-24.05.tar.gz home-manager\n    nix-channel --update\n    ```\n2.  Configure `home-manager`:\n    ```nix\n    { pkgs, ... }:\n\n    {\n      # Read Nix-on-Droid changelog before changing this value\n      system.stateVersion = \"24.05\";\n\n      # insert Nix-on-Droid config\n\n      home-manager.config =\n        { pkgs, ... }:\n        {\n          # Read home-manager changelog before changing this value\n          home.stateVersion = \"24.05\";\n\n          # insert home-manager config\n        };\n\n      # or if you have a separate home.nix already present:\n      home-manager.config = ./home.nix;\n    }\n    ```\n\n### `nix-on-droid` executable\n\nThis executable is responsible for activating new configurations:\nUse `nix-on-droid switch` to activate the current configuration and\n`nix-on-droid rollback` to rollback to the latest build.\n\nFor more information, please run `nix-on-droid help`.\n\n\n## Build Nix-on-Droid on your own\n\nThe [terminal emulator part](https://github.com/nix-community/nix-on-droid-app)\nis probably not interesting for you, just download and use a prebuilt one.\nIf you really want to rebuild it, you can just use Android Studio for that.\n\nThe zipball generation is probably what you are after.\nGet an x86_64 computer with flake-enabled Nix.\n\n\u003e **tl;dr**: Use the deploy app like the following which executes all steps mentioned below:\n\u003e\n\u003e ```sh\n\u003e nix run \".#deploy\" -- \u003cpublic_url\u003e \u003crsync_target\u003e\n\u003e # or run the following for explanation of this script\n\u003e nix run \".#deploy\"\n\u003e ```\n\nRun\n\n```sh\nnix build \".#bootstrapZip-aarch64\" --impure\n```\n\nPut the zip file from `result` on some HTTP server\nand specify the parent directory URL during the installation.\nTo re-trigger the installation, you can use\n'clear data' on the Android app (after backing stuff up, obviously).\n\nIf you want to change the Nix-on-Droid channel to your custom one,\nyou can do that either with `nix-channel` after the installation,\nor by setting the environment variable `NIX_ON_DROID_CHANNEL_URL`.\nOther environment variables are `NIXPKGS_CHANNEL_URL` an\n`NIX_ON_DROID_FLAKE_URL`.\n\n**Note**: The `proot` binary is not built on the android device\n(NDK is required for building it, and it's not available on mobile platforms).\nThe way we work around it is to push proot derivation to cachix.\nThe current workaround is to hardcode the path to the wanted `proot` nix store\npath in `modules/environment/login/default.nix`. During evaluation time on\nthe android device this store path will be downloaded from the binary cache\n(\u003chttps://nix-on-droid.cachix.org/\u003e). This in return means the `proot`\nderivation has to be present there or in any other binary cache configured\nin the `nix.conf` on the device.\n\nObviously it's an annoyance if one wants to fork this repo and test something.\nTo minimize the hassle with this scenario, proot derivation is also bundled\nwith the bootstrap zipball. This way you only need your own binary cache\nif you are planning to maintain a long-term fork that users can update from.\nIn case you only care about updates through wiping the data,\nor are forking to submit a one-off pull request,\nyou shouldn't need a binary cache for that.\n\n## Nix flakes\n\n**Note:** Nix flake support is still experimental at the moment and subject to change.\n\n### Examples / templates\n\nA minimal example could look like the following:\n\n```nix\n{\n  description = \"Minimal example of Nix-on-Droid system config.\";\n\n  inputs = {\n    nixpkgs.url = \"github:NixOS/nixpkgs/nixos-24.05\";\n\n    nix-on-droid = {\n      url = \"github:nix-community/nix-on-droid/release-24.05\";\n      inputs.nixpkgs.follows = \"nixpkgs\";\n    };\n  };\n\n  outputs = { self, nixpkgs, nix-on-droid }: {\n\n    nixOnDroidConfigurations.default = nix-on-droid.lib.nixOnDroidConfiguration {\n      pkgs = import nixpkgs { system = \"aarch64-linux\"; };\n      modules = [ ./nix-on-droid.nix ];\n    };\n\n  };\n}\n```\n\nFor more examples and nix flake templates, see [`templates`](./templates) directory or explore with:\n\n```sh\nnix flake init --template github:nix-community/nix-on-droid#advanced\n```\n\n### Usage with `nix-on-droid`\n\nUse `nix-on-droid switch --flake path/to/flake#device` to build and activate your configuration (`path/to/flake#device`\nwill expand to `.#nixOnDroidConfigurations.device`). If you run `nix-on-droid switch --flake path/to/flake`, the\n`default` configuration will be used.\n\n**Note:** Currently, Nix-on-Droid can not be built with an pure flake build because of hardcoded store paths for proot.\nTherefore, every evaluation of a flake configuration will be executed with `--impure` flag. (This behaviour will be\ndropped as soon as the default setup does not require it anymore.)\n\n## Testing\n\nIn the [./tests/on-device](./tests/on-device) directory, there is small set\nof [bats](https://github.com/bats-core/bats-core) tests\nthat can be executed on a real or emulated android device.\n\nTo run the tests, execute\n\n```sh\nnix-on-droid on-device-test\n```\n\n**Note:** This currently requires a channel setup and should only be executed on\nclean, disposable installations.\n\n## Tips\n\n* To grant the app access to the storage, use the toggle in the app settings\n  (reachable from Android settings).\n* If the terminal freezes, use 'Acquire wakelock' button in the notification\n  and/or tone down your device's aggressive power saving measures.\n* We have a [wiki](https://github.com/nix-community/nix-on-droid/wiki)\n  with tips and success stories, you're encouraged to add yours as well.\n\n\n## Technical overview\n\nOK, real brief.\n\nDeveloper's device:\n\n1. `proot` for the target platform is cross-compiled against `bionic`,\n   (to fake file paths like `/nix/store`; think 'userspace `chroot`')\n2. Target `nix` is taken from the original release tarball\n3. Target `nix` database is initialized\n4. Support scripts and config files are built with `nix` and the Nix-on-Droid\n   module system\n5. From these, a bootstrap zipball is built and published on an HTTP server\n\nUser's device:\n\n6. Android app is installed and launched, bootstrap URL is entered\n7. Bootstrap zipball gets downloaded and unpacked\n8. 'First boot' begins, Nix builds the environment\n   (or, possibly, pulls it from Cachix)\n9. Nix installs the environment (login scripts, config files, etc.)\n\nYou can refer to a\n[NixCon 2019 presentation talk](https://nix-on-droid.unboiled.info/nixcon-2019-nix-on-droid.slides.pdf)\nfor a more extensive overview of the subject.\n\n\n## Licensing and credits\n\nLicensed under MIT License, see LICENSE.\nCopyright (c) 2019-2021 Alexander Sosedkin and other contributors, see AUTHORS.\n\nTwo rewrites ago it was based off the official Nix install script\n(https://nixos.org/nix/install),\npresumably written by Eelco Dolstra.\n\nIs deployed and used with [a fork](https://github.com/nix-community/nix-on-droid-app)\nof [Termux-the-terminal-emulator app](https://github.com/termux/termux-app),\nbut has no relation to Termux-the-distro.\n\nPrevious project that did use Termux-the-distro:\nhttps://github.com/t184256/nix-in-termux\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnix-community%2Fnix-on-droid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnix-community%2Fnix-on-droid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnix-community%2Fnix-on-droid/lists"}