From f4ccaa51e00d1fa9dde060a90e4b721ddbe5024a Mon Sep 17 00:00:00 2001 From: digital Date: Tue, 18 Oct 2022 18:24:24 +0200 Subject: nixos/containers: support nixpkgs.hostPlatform Use hostPlatform if both the host and the containers nixpkgs supports hostPlatform, otherwise fall back to localSystem. This preseves backwards compatibility. --- nixos/modules/virtualisation/nixos-containers.nix | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/nixos/modules/virtualisation/nixos-containers.nix b/nixos/modules/virtualisation/nixos-containers.nix index 22be1d5bff9..e7294b30a92 100644 --- a/nixos/modules/virtualisation/nixos-containers.nix +++ b/nixos/modules/virtualisation/nixos-containers.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: +{ config, lib, pkgs, ... }@host: with lib; @@ -284,7 +284,6 @@ let DeviceAllow = map (d: "${d.node} ${d.modifier}") cfg.allowedDevices; }; - inherit (config.nixpkgs) localSystem; kernelVersion = config.boot.kernelPackages.kernel.version; bindMountOpts = { name, ... }: { @@ -480,10 +479,13 @@ in merge = loc: defs: (import "${toString config.nixpkgs}/nixos/lib/eval-config.nix" { modules = let - extraConfig = { + extraConfig = { options, ... }: { _file = "module at ${__curPos.file}:${toString __curPos.line}"; config = { - nixpkgs = { inherit localSystem; }; + nixpkgs = if options.nixpkgs?hostPlatform && host.options.nixpkgs.hostPlatform.isDefined + then { inherit (host.config.nixpkgs) hostPlatform; } + else { inherit (host.config.nixpkgs) localSystem; } + ; boot.isContainer = true; networking.hostName = mkDefault name; networking.useDHCP = false; -- cgit 1.4.1