diff options
author | Adam Stephens <adam@valkor.net> | 2023-09-04 11:58:53 -0400 |
---|---|---|
committer | Anderson Torres <torres.anderson.85@protonmail.com> | 2023-09-05 15:28:00 +0000 |
commit | a90385c62b75df48f3ebd29f99d017f06966c569 (patch) | |
tree | d77e4850b09e7b5ef3f985e5901fdf289fab0606 /nixos/modules/virtualisation | |
parent | 85c14ff2ff52d44ed05990ea57f1551f175ecece (diff) | |
download | nixpkgs-a90385c62b75df48f3ebd29f99d017f06966c569.tar nixpkgs-a90385c62b75df48f3ebd29f99d017f06966c569.tar.gz nixpkgs-a90385c62b75df48f3ebd29f99d017f06966c569.tar.bz2 nixpkgs-a90385c62b75df48f3ebd29f99d017f06966c569.tar.lz nixpkgs-a90385c62b75df48f3ebd29f99d017f06966c569.tar.xz nixpkgs-a90385c62b75df48f3ebd29f99d017f06966c569.tar.zst nixpkgs-a90385c62b75df48f3ebd29f99d017f06966c569.zip |
nixos/lxd: add preseed option
Diffstat (limited to 'nixos/modules/virtualisation')
-rw-r--r-- | nixos/modules/virtualisation/lxd.nix | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/nixos/modules/virtualisation/lxd.nix b/nixos/modules/virtualisation/lxd.nix index 11ac692d120..e30fbebb662 100644 --- a/nixos/modules/virtualisation/lxd.nix +++ b/nixos/modules/virtualisation/lxd.nix @@ -4,6 +4,7 @@ let cfg = config.virtualisation.lxd; + preseedFormat = pkgs.formats.yaml {}; in { imports = [ (lib.mkRemovedOptionModule [ "virtualisation" "lxd" "zfsPackage" ] "Override zfs in an overlay instead to override it globally") @@ -73,6 +74,65 @@ in { ''; }; + preseed = lib.mkOption { + type = lib.types.nullOr (lib.types.submodule { + freeformType = preseedFormat.type; + }); + + default = null; + + description = lib.mdDoc '' + Configuration for LXD preseed, see + <https://documentation.ubuntu.com/lxd/en/latest/howto/initialize/#initialize-preseed> + for supported values. + + Changes to this will be re-applied to LXD which will overwrite existing entities or create missing ones, + but entities will *not* be removed by preseed. + ''; + + example = lib.literalExpression '' + { + networks = [ + { + name = "lxdbr0"; + type = "bridge"; + config = { + "ipv4.address" = "10.0.100.1/24"; + "ipv4.nat" = "true"; + }; + } + ]; + profiles = [ + { + name = "default"; + devices = { + eth0 = { + name = "eth0"; + network = "lxdbr0"; + type = "nic"; + }; + root = { + path = "/"; + pool = "default"; + size = "35GiB"; + type = "disk"; + }; + }; + } + ]; + storage_pools = [ + { + name = "default"; + driver = "dir"; + config = { + source = "/var/lib/lxd/storage-pools/default"; + }; + } + ]; + } + ''; + }; + startTimeout = lib.mkOption { type = lib.types.int; default = 600; @@ -176,6 +236,21 @@ in { }; }; + systemd.services.lxd-preseed = lib.mkIf (cfg.preseed != null) { + description = "LXD initialization with preseed file"; + wantedBy = ["multi-user.target"]; + requires = ["lxd.service"]; + after = ["lxd.service"]; + + script = '' + ${pkgs.coreutils}/bin/cat ${preseedFormat.generate "lxd-preseed.yaml" cfg.preseed} | ${cfg.package}/bin/lxd init --preseed + ''; + + serviceConfig = { + Type = "oneshot"; + }; + }; + users.groups.lxd = {}; users.users.root = { |