From 4aa419c04630436af36c233a21573b20301bfbca Mon Sep 17 00:00:00 2001 From: Franz Pletz Date: Sat, 20 Jul 2024 16:09:09 +0200 Subject: [PATCH 1/3] nixos/proxmox-lxc: reformat --- nixos/modules/virtualisation/proxmox-lxc.nix | 42 +++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/nixos/modules/virtualisation/proxmox-lxc.nix b/nixos/modules/virtualisation/proxmox-lxc.nix index 548421e48e2b3..f5a3e9941566b 100644 --- a/nixos/modules/virtualisation/proxmox-lxc.nix +++ b/nixos/modules/virtualisation/proxmox-lxc.nix @@ -1,4 +1,9 @@ -{ config, pkgs, lib, ... }: +{ + config, + pkgs, + lib, + ... +}: with lib; @@ -42,15 +47,19 @@ with lib; in mkIf cfg.enable { system.build.tarball = pkgs.callPackage ../../lib/make-system-tarball.nix { - storeContents = [{ - object = config.system.build.toplevel; - symlink = "none"; - }]; + storeContents = [ + { + object = config.system.build.toplevel; + symlink = "none"; + } + ]; - contents = [{ - source = config.system.build.toplevel + "/init"; - target = "/sbin/init"; - }]; + contents = [ + { + source = config.system.build.toplevel + "/init"; + target = "/sbin/init"; + } + ]; extraCommands = "mkdir -p root etc/systemd/network"; }; @@ -84,11 +93,16 @@ with lib; }; systemd = { - mounts = mkIf (!cfg.privileged) [{ - enable = false; - where = "/sys/kernel/debug"; - }]; - services."getty@".unitConfig.ConditionPathExists = [ "" "/dev/%I" ]; + mounts = mkIf (!cfg.privileged) [ + { + enable = false; + where = "/sys/kernel/debug"; + } + ]; + services."getty@".unitConfig.ConditionPathExists = [ + "" + "/dev/%I" + ]; }; }; From c501d3fa9798c3e198369a76b6b2cc7fcf6faf62 Mon Sep 17 00:00:00 2001 From: Franz Pletz Date: Sat, 20 Jul 2024 16:09:56 +0200 Subject: [PATCH 2/3] nixos/proxmox-lxc: fix getty start Otherwise there is no getty on tty1 in Proxmox. --- nixos/modules/virtualisation/proxmox-lxc.nix | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nixos/modules/virtualisation/proxmox-lxc.nix b/nixos/modules/virtualisation/proxmox-lxc.nix index f5a3e9941566b..d9d60b52e3aec 100644 --- a/nixos/modules/virtualisation/proxmox-lxc.nix +++ b/nixos/modules/virtualisation/proxmox-lxc.nix @@ -99,10 +99,16 @@ with lib; where = "/sys/kernel/debug"; } ]; - services."getty@".unitConfig.ConditionPathExists = [ + + # By default only starts getty on tty0 but first on LXC is tty1 + services."autovt@".unitConfig.ConditionPathExists = [ "" "/dev/%I" ]; + + # These are disabled by `console.enable` but console via tty is the default in Proxmox + services."getty@tty1".enable = lib.mkForce true; + services."autovt@".enable = lib.mkForce true; }; }; From ceafec213ff2514791848b1999e01ebf17dd6ceb Mon Sep 17 00:00:00 2001 From: Franz Pletz Date: Sat, 20 Jul 2024 16:16:21 +0200 Subject: [PATCH 3/3] nixos/proxmox-lxc: fix nixos-rebuild Same is being done in lxc-container module. --- nixos/modules/virtualisation/proxmox-lxc.nix | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/nixos/modules/virtualisation/proxmox-lxc.nix b/nixos/modules/virtualisation/proxmox-lxc.nix index d9d60b52e3aec..9a8325f92636d 100644 --- a/nixos/modules/virtualisation/proxmox-lxc.nix +++ b/nixos/modules/virtualisation/proxmox-lxc.nix @@ -64,6 +64,18 @@ with lib; extraCommands = "mkdir -p root etc/systemd/network"; }; + boot.postBootCommands = '' + # After booting, register the contents of the Nix store in the Nix + # database. + if [ -f /nix-path-registration ]; then + ${config.nix.package.out}/bin/nix-store --load-db < /nix-path-registration && + rm /nix-path-registration + fi + + # nixos-rebuild also requires a "system" profile + ${config.nix.package.out}/bin/nix-env -p /nix/var/nix/profiles/system --set /run/current-system + ''; + boot = { isContainer = true; loader.initScript.enable = true;