nixpkgs/nixos/modules/virtualisation/proxmox-lxc.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

110 lines
2.5 KiB
Nix
Raw Normal View History

2024-07-20 16:09:09 +02:00
{
config,
pkgs,
lib,
...
}:
2022-02-15 23:44:26 +05:30
with lib;
{
options.proxmoxLXC = {
enable = mkOption {
default = true;
type = types.bool;
description = lib.mdDoc "Whether to enable the Proxmox VE LXC module.";
};
2022-02-15 23:44:26 +05:30
privileged = mkOption {
type = types.bool;
default = false;
description = ''
2022-02-15 23:44:26 +05:30
Whether to enable privileged mounts
'';
};
manageNetwork = mkOption {
type = types.bool;
default = false;
description = ''
2022-02-15 23:44:26 +05:30
Whether to manage network interfaces through nix options
When false, systemd-networkd is enabled to accept network
configuration from proxmox.
'';
};
manageHostName = mkOption {
type = types.bool;
default = false;
description = ''
Whether to manage hostname through nix options
When false, the hostname is picked up from /etc/hostname
populated by proxmox.
'';
};
2022-02-15 23:44:26 +05:30
};
config =
let
cfg = config.proxmoxLXC;
in
mkIf cfg.enable {
2022-02-15 23:44:26 +05:30
system.build.tarball = pkgs.callPackage ../../lib/make-system-tarball.nix {
2024-07-20 16:09:09 +02:00
storeContents = [
{
object = config.system.build.toplevel;
symlink = "none";
}
];
2022-02-15 23:44:26 +05:30
2024-07-20 16:09:09 +02:00
contents = [
{
source = config.system.build.toplevel + "/init";
target = "/sbin/init";
}
];
2022-02-15 23:44:26 +05:30
extraCommands = "mkdir -p root etc/systemd/network";
};
boot = {
isContainer = true;
loader.initScript.enable = true;
};
console.enable = true;
2022-02-15 23:44:26 +05:30
networking = mkIf (!cfg.manageNetwork) {
useDHCP = false;
useHostResolvConf = false;
useNetworkd = true;
# pick up hostname from /etc/hostname generated by proxmox
hostName = mkIf (!cfg.manageHostName) (mkForce "");
2022-02-15 23:44:26 +05:30
};
# unprivileged LXCs can't set net.ipv4.ping_group_range
security.wrappers.ping = mkIf (!cfg.privileged) {
owner = "root";
group = "root";
capabilities = "cap_net_raw+p";
source = "${pkgs.iputils.out}/bin/ping";
};
2022-02-15 23:44:26 +05:30
services.openssh = {
enable = mkDefault true;
startWhenNeeded = mkDefault true;
};
systemd = {
2024-07-20 16:09:09 +02:00
mounts = mkIf (!cfg.privileged) [
{
enable = false;
where = "/sys/kernel/debug";
}
];
services."getty@".unitConfig.ConditionPathExists = [
""
"/dev/%I"
];
};
2022-02-15 23:44:26 +05:30
};
}