1
1
mirror of https://github.com/NixOS/mobile-nixos.git synced 2024-12-14 09:16:39 +03:00
mobile-nixos/modules/lib.nix
2021-07-13 17:22:58 -07:00

39 lines
1.3 KiB
Nix

parentArgs@{ config, lib, pkgs, baseModules, modules, ... }:
let
# Keep modules from this eval around
modules' = modules;
inherit (config.nixpkgs.localSystem) system;
# We can make use the normal NixOS evalConfig here.
evalConfig = import "${toString pkgs.path}/nixos/lib/eval-config.nix";
in
{
lib = {
mobile-nixos = {
# `config.lib.mobile-nixos.composeConfig` is the supported method used to
# re-evaluate a configuration with additional configuration.
# Can be used exactly like `evalConfig`, with one additional param.
# The `config` param directly takes a module (attrset or function).
composeConfig = { config ? {}, modules ? [], ... }@args:
let
filteredArgs = lib.filterAttrs (k: v: k != "config") args;
in
evalConfig (
filteredArgs // {
# Needed for hermetic eval, otherwise `eval-config.nix` will try
# to use `builtins.currentSystem`.
inherit system;
inherit baseModules;
# Newer versions of module system pass specialArgs to modules, so try
# to pass that to eval if possible.
specialArgs = parentArgs.specialArgs or { };
# Merge in this eval's modules with the argument's modules, and finally
# with the given config.
modules = modules' ++ modules ++ [ config ];
});
};
};
}