From 216f1bd706579cc237c6210e9410031eb223f91b Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 30 Jun 2024 20:16:17 +0100 Subject: [PATCH] incus preseed reload not working --- hosts/common/containers/postgres.yaml | 38 ++++++++++++++ hosts/common/disks/zfs/zspeed.nix | 2 +- hosts/common/optional/lxd/lxd-preseed.nix | 7 ++- .../common/optional/lxd/profiles/default.nix | 14 ++---- .../common/optional/lxd/profiles/postgres.nix | 49 +++++++++++++++++++ psql.nix | 49 +++++++++++++++++++ 6 files changed, 147 insertions(+), 12 deletions(-) create mode 100644 hosts/common/containers/postgres.yaml create mode 100644 hosts/common/optional/lxd/profiles/postgres.nix create mode 100644 psql.nix diff --git a/hosts/common/containers/postgres.yaml b/hosts/common/containers/postgres.yaml new file mode 100644 index 0000000..9378f06 --- /dev/null +++ b/hosts/common/containers/postgres.yaml @@ -0,0 +1,38 @@ +architecture: x86_64 +config: + boot.autostart: "true" + image.architecture: amd64 + image.description: Nixos unstable amd64 (20240630_01:00) + image.os: Nixos + image.release: unstable + image.requirements.secureboot: "false" + image.serial: "20240630_01:00" + image.type: squashfs + image.variant: default + security.nesting: "true" + volatile.base_image: bbd293f2d08dfe82b4d81f28aeb3f1f7fef829f717e3073423c59fd6a7794749 + volatile.cloud-init.instance-id: 90575adf-c804-483b-bb95-a188cdc47101 + volatile.eth0.host_name: veth79bf6370 + volatile.eth0.hwaddr: 00:16:3e:17:c1:da + volatile.idmap.base: "0" + volatile.idmap.current: '[{"Isuid":true,"Isgid":false,"Hostid":1000000,"Nsid":0,"Maprange":1000000000},{"Isuid":false,"Isgid":true,"Hostid":1000000,"Nsid":0,"Maprange":1000000000}]' + volatile.idmap.next: '[{"Isuid":true,"Isgid":false,"Hostid":1000000,"Nsid":0,"Maprange":1000000000},{"Isuid":false,"Isgid":true,"Hostid":1000000,"Nsid":0,"Maprange":1000000000}]' + volatile.last_state.idmap: '[]' + volatile.last_state.power: RUNNING + volatile.uuid: 62db570b-8c46-4199-8657-1c387f6fddba + volatile.uuid.generation: 62db570b-8c46-4199-8657-1c387f6fddba +devices: + eth0: + name: eth0 + nictype: bridged + parent: lxdBrDefault + type: nic + root: + path: / + pool: test + type: disk +ephemeral: false +profiles: +- default +stateful: false +description: "" diff --git a/hosts/common/disks/zfs/zspeed.nix b/hosts/common/disks/zfs/zspeed.nix index 006ad7b..ead5709 100644 --- a/hosts/common/disks/zfs/zspeed.nix +++ b/hosts/common/disks/zfs/zspeed.nix @@ -58,7 +58,7 @@ "volblocksize" = "8k"; }; }; - test = { + lxc = { type = "zfs_volume"; size = "10G -s"; options = { diff --git a/hosts/common/optional/lxd/lxd-preseed.nix b/hosts/common/optional/lxd/lxd-preseed.nix index 4ba186c..70da6d6 100644 --- a/hosts/common/optional/lxd/lxd-preseed.nix +++ b/hosts/common/optional/lxd/lxd-preseed.nix @@ -2,6 +2,7 @@ let lxd_profiles = { + "postgres" = (import ./profiles/postgres.nix); "default" = (import ./profiles/default.nix); }; in @@ -17,13 +18,17 @@ in networks = [ lxd_profiles.default.network + lxd_profiles.postgres.network ]; profiles = [ lxd_profiles.default.profile + lxd_profiles.postgres.profile ]; - storage_pools = lxd_profiles.default.storage_pools; + storage_pools = + lxd_profiles.default.storage_pools ++ + lxd_profiles.postgres.storage_pools; }; }; }; diff --git a/hosts/common/optional/lxd/profiles/default.nix b/hosts/common/optional/lxd/profiles/default.nix index c651859..e541ef0 100644 --- a/hosts/common/optional/lxd/profiles/default.nix +++ b/hosts/common/optional/lxd/profiles/default.nix @@ -4,7 +4,7 @@ type = "bridge"; config = { - "ipv4.address" = "10.100.1.1/8"; + "ipv4.address" = "10.100.2.1/8"; "ipv4.nat" = "true"; "ipv4.firewall" = "false"; }; @@ -17,14 +17,14 @@ config.source = "/dev/zvol/zspeed/postgres"; } { - name = "default"; + name = "lxc"; driver = "btrfs"; - config.source = "/dev/zvol/zspeed/default"; + config.source = "/dev/zvol/zspeed/lxc"; } ]; profile = { - name = "postgres"; + name = "default"; devices = { "eth0" = { name = "eth0"; @@ -38,12 +38,6 @@ size = "8GiB"; type = "disk"; }; - "db" = { - path = "/var/lib/postgresql/16/"; - pool = "postgres"; - source = "db"; - type = "disk"; - }; }; }; } diff --git a/hosts/common/optional/lxd/profiles/postgres.nix b/hosts/common/optional/lxd/profiles/postgres.nix new file mode 100644 index 0000000..3cf5151 --- /dev/null +++ b/hosts/common/optional/lxd/profiles/postgres.nix @@ -0,0 +1,49 @@ +{ + network = { + name = "lxdBrPsql"; + type = "bridge"; + + config = { + "ipv4.address" = "10.100.1.1/8"; + "ipv4.nat" = "true"; + "ipv4.firewall" = "false"; + }; + }; + + storage_pools = [ + { + name = "postgres"; + driver = "btrfs"; + config.source = "/dev/zvol/zspeed/postgres"; + } + { + name = "lxc"; + driver = "btrfs"; + config.source = "/dev/zvol/zspeed/lxc"; + } + ]; + + profile = { + name = "postgres"; + devices = { + "eth0" = { + name = "eth0"; + nictype = "bridged"; + parent = "lxdBrPsql"; + type = "nic"; + }; + "root" = { + path = "/"; + pool = "default"; + size = "8GiB"; + type = "disk"; + }; + "db" = { + path = "/var/lib/postgresql/16/"; + pool = "postgres"; + source = "db"; + type = "disk"; + }; + }; + }; +} diff --git a/psql.nix b/psql.nix new file mode 100644 index 0000000..2bce321 --- /dev/null +++ b/psql.nix @@ -0,0 +1,49 @@ +# Edit this configuration file to define what should be installed on +# your system. Help is available in the configuration.nix(5) man page +# and in the NixOS manual (accessible by running ‘nixos-help’). + +{ config, pkgs, lib, modulesPath, ... }: + +{ + imports = + [ + # Include the default lxd configuration. + "${modulesPath}/virtualisation/lxc-container.nix" + # Include the container-specific autogenerated configuration. + ./lxd.nix + ]; + + networking = { + dhcpcd.enable = false; + useDHCP = false; + useHostResolvConf = false; + }; + + systemd.network = { + enable = true; + networks."50-eth0" = { + matchConfig.Name = "eth0"; + networkConfig = { + DHCP = "ipv4"; + IPv6AcceptRA = true; + }; + linkConfig.RequiredForOnline = "routable"; + }; + }; + + environment.systemPackages = [ + pkgs.vim + ]; + + services.postgresql = { + enable = true; + package = pkgs.postgresql_16; + ensureDatabases = [ "default" ]; + authentication = pkgs.lib.mkOverride 10 '' + #type database DBuser auth-method + local all all trust + ''; + }; + + system.stateVersion = "24.11"; # Did you read the comment? +}