about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorFranz Pletz <fpletz@fnordicwalking.de>2023-11-30 20:48:24 +0100
committerGitHub <noreply@github.com>2023-11-30 20:48:24 +0100
commit32caf62376eef2e14d1bfcd459b36783aa705d83 (patch)
tree91499f21b5e7db05662304ced92914d7d0b60b6d /nixos
parente1e0c7325a0d4a81720c3868640b7290813eea12 (diff)
parent412543ddd83f4ee235ee32772afc19483aaf83ab (diff)
downloadnixlib-32caf62376eef2e14d1bfcd459b36783aa705d83.tar
nixlib-32caf62376eef2e14d1bfcd459b36783aa705d83.tar.gz
nixlib-32caf62376eef2e14d1bfcd459b36783aa705d83.tar.bz2
nixlib-32caf62376eef2e14d1bfcd459b36783aa705d83.tar.lz
nixlib-32caf62376eef2e14d1bfcd459b36783aa705d83.tar.xz
nixlib-32caf62376eef2e14d1bfcd459b36783aa705d83.tar.zst
nixlib-32caf62376eef2e14d1bfcd459b36783aa705d83.zip
Merge pull request #268887 from jchw-forks/libvirt-nss
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/virtualisation/libvirtd.nix39
-rw-r--r--nixos/tests/libvirtd.nix2
2 files changed, 40 insertions, 1 deletions
diff --git a/nixos/modules/virtualisation/libvirtd.nix b/nixos/modules/virtualisation/libvirtd.nix
index fa5947e546c1..56b8a043db08 100644
--- a/nixos/modules/virtualisation/libvirtd.nix
+++ b/nixos/modules/virtualisation/libvirtd.nix
@@ -172,6 +172,31 @@ let
       };
     };
   };
+
+  nssModule = types.submodule {
+    options = {
+      enable = mkOption {
+        type = types.bool;
+        default = false;
+        description = lib.mdDoc ''
+          This option enables the older libvirt NSS module. This method uses
+          DHCP server records, therefore is dependent on the hostname provided
+          by the guest.
+          Please see https://libvirt.org/nss.html for more information.
+        '';
+      };
+
+      enableGuest = mkOption {
+        type = types.bool;
+        default = false;
+        description = lib.mdDoc ''
+          This option enables the newer libvirt_guest NSS module. This module
+          uses the libvirt guest name instead of the hostname of the guest.
+          Please see https://libvirt.org/nss.html for more information.
+        '';
+      };
+    };
+  };
 in
 {
 
@@ -290,6 +315,14 @@ in
         Hooks related options.
       '';
     };
+
+    nss = mkOption {
+      type = nssModule;
+      default = { };
+      description = lib.mdDoc ''
+        libvirt NSS module options.
+      '';
+    };
   };
 
 
@@ -480,5 +513,11 @@ in
         });
       '';
     };
+
+    system.nssModules = optional (cfg.nss.enable or cfg.nss.enableGuest) cfg.package;
+    system.nssDatabases.hosts = builtins.concatLists [
+      (optional cfg.nss.enable "libvirt")
+      (optional cfg.nss.enableGuest "libvirt_guest")
+    ];
   };
 }
diff --git a/nixos/tests/libvirtd.nix b/nixos/tests/libvirtd.nix
index 41d06cc9643f..df80dcc21a2e 100644
--- a/nixos/tests/libvirtd.nix
+++ b/nixos/tests/libvirtd.nix
@@ -14,10 +14,10 @@ import ./make-test-python.nix ({ pkgs, ... }: {
           libvirtd.hooks.qemu.is_working = "${pkgs.writeShellScript "testHook.sh" ''
             touch /tmp/qemu_hook_is_working
           ''}";
+          libvirtd.nss.enable = true;
         };
         boot.supportedFilesystems = [ "zfs" ];
         networking.hostId = "deadbeef"; # needed for zfs
-        networking.nameservers = [ "192.168.122.1" ];
         security.polkit.enable = true;
         environment.systemPackages = with pkgs; [ virt-manager ];
       };