From c6e56b163790f98d2cce7c0949b09248b474c882 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sun, 25 Sep 2022 11:22:15 +0100 Subject: [PATCH] merge-modules accepts >1 module --- default.nix | 13 ++++--------- merge-modules.nix | 14 +++++++------- modules/base.nix | 17 +++++++++++++++++ tests/module/test.nix | 6 +++--- tests/smoke/configuration.nix | 2 +- 5 files changed, 32 insertions(+), 20 deletions(-) create mode 100644 modules/base.nix diff --git a/default.nix b/default.nix index f768fc5..ca105eb 100644 --- a/default.nix +++ b/default.nix @@ -4,15 +4,10 @@ let overlay = import ./overlay.nix; nixpkgs = import ( device.system // {overlays = [overlay]; }); - baseConfig = { - systemPackages = []; - services = {}; - kernel = device.kernel; - }; - config = baseConfig // (import ) { - config = baseConfig; - inherit (nixpkgs) pkgs; - }; + config = (import ./merge-modules.nix) [ + (import ./modules/base.nix { inherit device; }) + + ] nixpkgs.pkgs; finalConfig = config // { packages = (with nixpkgs.pkgs; [ s6-rc ]) ++ config.systemPackages ++ diff --git a/merge-modules.nix b/merge-modules.nix index d4fef55..5b93339 100644 --- a/merge-modules.nix +++ b/merge-modules.nix @@ -1,8 +1,8 @@ -module : initial : pkgs : +modules : pkgs : let evalModules = (import ).evalModules; -in evalModules { - modules = [ - { _module.args = { inherit pkgs; }; } - module - ]; -} +in (evalModules { + modules = + [ + { _module.args = { inherit pkgs; lib = pkgs.lib; }; } + ] ++ modules; +}).config diff --git a/modules/base.nix b/modules/base.nix new file mode 100644 index 0000000..da63c88 --- /dev/null +++ b/modules/base.nix @@ -0,0 +1,17 @@ +{ device } : +{ lib, ...}: +let inherit (lib) mkEnableOption mkOption types; +in { + options = { + systemPackages = mkOption { + type = types.listOf types.package; + }; + services = mkOption { + type = types.anything; + }; + kernel = mkOption { + type = types.anything; + default = { inherit (device.kernel) config checkedConfig; }; + }; + }; +} diff --git a/tests/module/test.nix b/tests/module/test.nix index a5adb20..e3d72ba 100644 --- a/tests/module/test.nix +++ b/tests/module/test.nix @@ -5,11 +5,11 @@ let inherit (nixpkgs) lib pkgs; inherit (lib.asserts) assertMsg; config = - (import ) ./configuration.nix {} pkgs; + (import ) [./configuration.nix] pkgs; res1 = assertMsg # check we have packages from both modules - (config.config.systemPackages == ( with pkgs; [ units hello ])) "failed"; - res2 = let s = config.config.services; + (config.systemPackages == ( with pkgs; [ units hello ])) "failed"; + res2 = let s = config.services; in assertMsg (s.a.enable && s.b.enable && (s.z != null) ) "failed"; in pkgs.writeText "foo" '' ${if res1 then "OK" else "not OK"} diff --git a/tests/smoke/configuration.nix b/tests/smoke/configuration.nix index c384e47..e56d8ff 100644 --- a/tests/smoke/configuration.nix +++ b/tests/smoke/configuration.nix @@ -1,4 +1,4 @@ -{ config, pkgs } : +{ config, pkgs, ... } : let inherit (pkgs.liminix.networking) interface address udhcpc odhcpc; inherit (pkgs.liminix.services) oneshot longrun bundle target output;