diff --git a/.gitignore b/.gitignore index cb3d983..cfa7b0d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ result result-* out +flake.lock diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b766d1..c0e1437 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ if the `system.stateVersion` option is set to `"20.09"` or later. either or attempt an upgrade to `release-19.09` and follow the instructions, or backup and reinstall (preferred). +## Nix flakes support + +* A `flake.nix` file was added. + ## Known issues: * If `make` fails on your device with `Function not implemented`, diff --git a/README.md b/README.md index 9d90a31..f4f4076 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,23 @@ if you are planning to maintain a long-term fork that users can update from. In case you only care about updates through wiping the data, you shouldn't need a binary cache for that. +## Nix flakes +Example, to use with nix flakes: + +```nix +{ + description = "nix-on-droid configuration"; + + inputs.nix-on-droid.url = "/home/bbigras/src/nix-on-droid"; + + outputs = { nix-on-droid, ... }: { + nix-on-droid = (nix-on-droid.lib.aarch64-linux.nix-on-droid { config = ./your_config.nix; } ).activationPackage; + }; +} +``` + +Build with `nix build .#nix-on-droid --impure`. ## Tips diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..bcb7a8d --- /dev/null +++ b/flake.nix @@ -0,0 +1,36 @@ +{ + description = "Nix-enabled environment for your Android device"; + + inputs = { + flake-utils.url = "github:numtide/flake-utils"; + home-manager = { + url = "github:nix-community/home-manager"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, home-manager, flake-utils }: + flake-utils.lib.eachSystem [ + "aarch64-linux" + "i686-linux" + ] + (system: + let pkgs = nixpkgs.legacyPackages.${system}; in + rec { + lib = { + nix-on-droid = { config }: import ./modules { + inherit pkgs config; + isFlake = true; + home-manager = (import home-manager { }); + }; + }; + + overlays = ./overlays; + + apps.nix-on-droid = flake-utils.lib.mkApp { + drv = (pkgs.callPackage ./nix-on-droid { }); + }; + defaultApp = apps.nix-on-droid; + } + ); +} diff --git a/modules/default.nix b/modules/default.nix index 2c099f2..24defb3 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -1,6 +1,6 @@ # Copyright (c) 2019-2020, see AUTHORS. Licensed under MIT License, see LICENSE. -{ pkgs ? import { }, home-manager ? import { }, config ? null }: +{ pkgs ? import { }, home-manager ? import { }, config ? null, isFlake ? false }: with pkgs.lib; @@ -20,7 +20,7 @@ let _module.args.pkgs = mkDefault pkgs; } configModule - ] ++ import ./module-list.nix { inherit pkgs; }; + ] ++ import ./module-list.nix { inherit pkgs isFlake; }; }; failedAssertions = map (x: x.message) (filter (x: !x.assertion) rawModule.config.assertions); diff --git a/modules/module-list.nix b/modules/module-list.nix index 082ebc5..34f12fe 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -1,6 +1,6 @@ # Copyright (c) 2019-2020, see AUTHORS. Licensed under MIT License, see LICENSE. -{ pkgs }: +{ pkgs, isFlake }: [ ./build/activation.nix @@ -12,10 +12,9 @@ ./environment/path.nix ./environment/session-init.nix ./home-manager.nix - ./nixpkgs.nix ./time.nix ./user.nix ./version.nix ./workaround-make.nix (pkgs.path + "/nixos/modules/misc/assertions.nix") -] +] ++ pkgs.lib.optionals (!isFlake) [ ./nixpkgs.nix ]