From da878afb9dd9d2c53e0559a4aa9d410fbd33e2f1 Mon Sep 17 00:00:00 2001 From: Tobias Happ Date: Sat, 5 Nov 2022 21:03:41 +0100 Subject: [PATCH] simplify usage of lib.nixOnDroidConfiguration --- CHANGELOG.md | 3 ++ README.md | 3 +- flake.nix | 32 ++++++++++++++++------ modules/default.nix | 3 +- pkgs/default.nix | 13 +++++---- templates/advanced/flake.nix | 7 ++--- templates/home-manager/flake.nix | 3 +- templates/minimal/flake.nix | 3 +- tests/on-device/config-flake-h-m.flake.nix | 3 +- tests/on-device/config-flake.nix | 3 +- 10 files changed, 43 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d99e522..a50a44e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,9 @@ * Fix usage of `extraSpecialArgs`: All values were previously set in `_module.args` instead of passing them as `specialArgs` into `evalModules`. This enables usage of `specialArgs` to use in `imports` in module defintions. +* In an effort to reduce the number of arguments to `lib.nixOnDroidConfiguration` + function in flake configurations, `system` is now inferred from `pkgs.system` + and `config` and `extraModules` are now combined into `modules` ## Release 22.05 diff --git a/README.md b/README.md index 8a41eb3..8e8323e 100644 --- a/README.md +++ b/README.md @@ -193,8 +193,7 @@ A minimal example could look like the following: outputs = { self, nixpkgs, nix-on-droid }: { nixOnDroidConfigurations.deviceName = nix-on-droid.lib.nixOnDroidConfiguration { - system = "aarch64-linux"; - config = ./nix-on-droid.nix; + modules = [ ./nix-on-droid.nix ]; }; }; diff --git a/flake.nix b/flake.nix index 4150d3d..4c5b34a 100644 --- a/flake.nix +++ b/flake.nix @@ -72,20 +72,36 @@ formatter = forEachSystem (system: nix-formatter-pack.lib.mkFormatter formatterPackArgsFor.${system}); lib.nixOnDroidConfiguration = - { config - , system ? "aarch64-linux" # unused, only supported variant - , extraModules ? [ ] + { modules ? [ ] , extraSpecialArgs ? { } , pkgs ? pkgs' , home-manager-path ? home-manager.outPath + # deprecated: + , config ? null + , extraModules ? null + , system ? null }: - if system != "aarch64-linux" then + if pkgs.system != "aarch64-linux" then throw "aarch64-linux is the only currently supported system type" else - import ./modules { - inherit config extraModules extraSpecialArgs home-manager-path pkgs; - isFlake = true; - }; + pkgs.lib.throwIf + (config != null || extraModules != null) + '' + The 'nixOnDroidConfiguration' arguments + + - 'config' + - 'extraModules' + - 'system' + + have been removed. Instead use the argument 'modules'. The + 'system' will be inferred by 'pkgs.system'. + See the 22.11 release notes for more. + '' + (import ./modules { + inherit extraSpecialArgs home-manager-path pkgs; + config.imports = modules; + isFlake = true; + }); overlays.default = overlay; diff --git a/modules/default.nix b/modules/default.nix index c94f30b..50e28bc 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -1,7 +1,6 @@ # Copyright (c) 2019-2022, see AUTHORS. Licensed under MIT License, see LICENSE. { config ? null -, extraModules ? [ ] , extraSpecialArgs ? { } , pkgs ? import { } , home-manager-path ? @@ -21,7 +20,7 @@ let nodModules = import ./module-list.nix { inherit pkgs home-manager-path isFlake; }; rawModule = evalModules { - modules = [ configModule ] ++ extraModules ++ nodModules; + modules = [ configModule ] ++ nodModules; specialArgs = extraSpecialArgs; }; diff --git a/pkgs/default.nix b/pkgs/default.nix index ed965b6..92d5c7c 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -25,15 +25,16 @@ let modules = import ../modules { inherit pkgs; - extraModules = [ ../modules/build/initial-build.nix ]; - extraSpecialArgs = { - inherit initialPackageInfo; - pkgs = pkgs.lib.mkForce pkgs; # to override ./modules/nixpkgs/config.nix - }; - isFlake = true; config = { + imports = [ ../modules/build/initial-build.nix ]; + + _module.args = { + inherit initialPackageInfo; + pkgs = pkgs.lib.mkForce pkgs; # to override ./modules/nixpkgs/config.nix + }; + # Fix invoking bash after initial build. user.shell = "${initialPackageInfo.bash}/bin/bash"; diff --git a/templates/advanced/flake.nix b/templates/advanced/flake.nix index e7362ae..7f4eea4 100644 --- a/templates/advanced/flake.nix +++ b/templates/advanced/flake.nix @@ -19,11 +19,10 @@ outputs = { self, nixpkgs, home-manager, nix-on-droid }: { nixOnDroidConfigurations.deviceName = nix-on-droid.lib.nixOnDroidConfiguration { - system = "aarch64-linux"; - config = ./nix-on-droid.nix; + modules = [ + ./nix-on-droid.nix - # list of extra modules for nix-on-droid system - extraModules = [ + # list of extra modules for nix-on-droid system # { nix.registry.nixpkgs.flake = nixpkgs; } # ./path/to/module.nix diff --git a/templates/home-manager/flake.nix b/templates/home-manager/flake.nix index 9ed5d8f..e73f02b 100644 --- a/templates/home-manager/flake.nix +++ b/templates/home-manager/flake.nix @@ -19,8 +19,7 @@ outputs = { self, nixpkgs, home-manager, nix-on-droid }: { nixOnDroidConfigurations.deviceName = nix-on-droid.lib.nixOnDroidConfiguration { - system = "aarch64-linux"; - config = ./nix-on-droid.nix; + modules = [ ./nix-on-droid.nix ]; }; }; diff --git a/templates/minimal/flake.nix b/templates/minimal/flake.nix index 1a6ed46..9b0ed34 100644 --- a/templates/minimal/flake.nix +++ b/templates/minimal/flake.nix @@ -13,8 +13,7 @@ outputs = { self, nixpkgs, nix-on-droid }: { nixOnDroidConfigurations.deviceName = nix-on-droid.lib.nixOnDroidConfiguration { - system = "aarch64-linux"; - config = ./nix-on-droid.nix; + modules = [ ./nix-on-droid.nix ]; }; }; diff --git a/tests/on-device/config-flake-h-m.flake.nix b/tests/on-device/config-flake-h-m.flake.nix index 6b060c7..7bc2ae0 100644 --- a/tests/on-device/config-flake-h-m.flake.nix +++ b/tests/on-device/config-flake-h-m.flake.nix @@ -12,8 +12,7 @@ outputs = { nix-on-droid, ... }: { nixOnDroidConfigurations = { device = nix-on-droid.lib.nixOnDroidConfiguration { - config = ./nix-on-droid.nix; - system = "aarch64-linux"; + modules = [ ./nix-on-droid.nix ]; }; }; }; diff --git a/tests/on-device/config-flake.nix b/tests/on-device/config-flake.nix index ef616c6..5408232 100644 --- a/tests/on-device/config-flake.nix +++ b/tests/on-device/config-flake.nix @@ -10,8 +10,7 @@ outputs = { nix-on-droid, ... }: { nixOnDroidConfigurations = { device = nix-on-droid.lib.nixOnDroidConfiguration { - config = ./nix-on-droid.nix; - system = "aarch64-linux"; + modules = [ ./nix-on-droid.nix ]; }; }; };