forked from fediversity/fediversity
un-generators
Signed-off-by: Kiara Grouwstra <kiara@procolix.eu>
This commit is contained in:
parent
b5d2b2cb87
commit
98d8a91a80
1 changed files with 186 additions and 212 deletions
|
|
@ -286,231 +286,205 @@ let
|
||||||
};
|
};
|
||||||
tf-proxmox-host = mkOption {
|
tf-proxmox-host = mkOption {
|
||||||
description = "A Terraform deployment by SSH to update a single existing NixOS host.";
|
description = "A Terraform deployment by SSH to update a single existing NixOS host.";
|
||||||
# type = submodule (tf-host: {
|
type = submodule (tf-host: {
|
||||||
type = submodule (
|
options = {
|
||||||
tf-host:
|
system = mkOption {
|
||||||
let
|
description = "The architecture of the system to deploy to.";
|
||||||
# raw = {
|
type = types.str;
|
||||||
# # formatConfig = "${pkgs.nixos-generators}/share/nixos-generator/formats/raw.nix";
|
};
|
||||||
# formatConfig = "${pkgs.nixos-generators}/share/nixos-generator/formats/raw-efi.nix";
|
inherit nixos-configuration;
|
||||||
# formatAttr = "raw";
|
ssh = host-ssh;
|
||||||
# fileExtension = ".img";
|
# TODO: add proxmox info
|
||||||
# };
|
module = mkOption {
|
||||||
# format = raw;
|
description = "The module to call to obtain the NixOS configuration from.";
|
||||||
# qcow = {
|
type = types.str;
|
||||||
# formatConfig = "${pkgs.nixos-generators}/share/nixos-generator/formats/qcow.nix";
|
};
|
||||||
# formatAttr = "qcow";
|
args = mkOption {
|
||||||
# fileExtension = ".qcow2";
|
description = "The arguments with which to call the module to obtain the NixOS configuration.";
|
||||||
# };
|
type = types.attrs;
|
||||||
# format = qcow;
|
};
|
||||||
# qcow-efi = {
|
deployment-name = mkOption {
|
||||||
# formatConfig = "${pkgs.nixos-generators}/share/nixos-generator/formats/qcow-efi.nix";
|
description = "The name of the deployment for which to obtain the NixOS configuration.";
|
||||||
# formatAttr = "qcow-efi";
|
type = types.str;
|
||||||
# fileExtension = ".qcow2";
|
};
|
||||||
# };
|
root-path = mkOption {
|
||||||
# format = qcow-efi;
|
description = "The path to the root of the repository.";
|
||||||
# inherit (format) formatConfig fileExtension formatAttr;
|
type = types.path;
|
||||||
in
|
};
|
||||||
{
|
proxmox-user = mkOption {
|
||||||
options = {
|
description = "The ProxmoX user to use.";
|
||||||
system = mkOption {
|
type = types.str;
|
||||||
description = "The architecture of the system to deploy to.";
|
default = "root@pam";
|
||||||
type = types.str;
|
};
|
||||||
};
|
# TODO: is sensitivity here handled properly?
|
||||||
inherit nixos-configuration;
|
proxmox-password = mkOption {
|
||||||
ssh = host-ssh;
|
description = "The ProxmoX password to use.";
|
||||||
# TODO: add proxmox info
|
type = types.str;
|
||||||
module = mkOption {
|
};
|
||||||
description = "The module to call to obtain the NixOS configuration from.";
|
node-name = mkOption {
|
||||||
type = types.str;
|
description = "the name of the ProxmoX node to use.";
|
||||||
};
|
type = types.str;
|
||||||
args = mkOption {
|
};
|
||||||
description = "The arguments with which to call the module to obtain the NixOS configuration.";
|
httpBackend = mkOption {
|
||||||
type = types.attrs;
|
description = "environment variables to configure the TF HTTP back-end, see <https://developer.hashicorp.com/terraform/language/backend/http#configuration-variables>";
|
||||||
};
|
type = types.attrsOf (types.either types.str types.int);
|
||||||
deployment-name = mkOption {
|
};
|
||||||
description = "The name of the deployment for which to obtain the NixOS configuration.";
|
bridge = mkOption {
|
||||||
type = types.str;
|
description = "The name of the network bridge (defaults to vmbr0).";
|
||||||
};
|
type = types.str;
|
||||||
root-path = mkOption {
|
default = "vmbr0";
|
||||||
description = "The path to the root of the repository.";
|
};
|
||||||
type = types.path;
|
vlanId = mkOption {
|
||||||
};
|
description = "The VLAN identifier.";
|
||||||
proxmox-user = mkOption {
|
type = types.int;
|
||||||
description = "The ProxmoX user to use.";
|
default = 0;
|
||||||
type = types.str;
|
};
|
||||||
default = "root@pam";
|
imageDatastoreId = mkOption {
|
||||||
};
|
description = "ID of the datastore of the image.";
|
||||||
# TODO: is sensitivity here handled properly?
|
type = types.str;
|
||||||
proxmox-password = mkOption {
|
default = "local";
|
||||||
description = "The ProxmoX password to use.";
|
};
|
||||||
type = types.str;
|
vmDatastoreId = mkOption {
|
||||||
};
|
description = "ID of the datastore of the VM.";
|
||||||
node-name = mkOption {
|
type = types.str;
|
||||||
description = "the name of the ProxmoX node to use.";
|
default = "local";
|
||||||
type = types.str;
|
};
|
||||||
};
|
run = mkOption {
|
||||||
httpBackend = mkOption {
|
type = types.package;
|
||||||
description = "environment variables to configure the TF HTTP back-end, see <https://developer.hashicorp.com/terraform/language/backend/http#configuration-variables>";
|
# error: The option `tf-deployment.tf-host.run' is read-only, but it's set multiple times.
|
||||||
type = types.attrsOf (types.either types.str types.int);
|
# readOnly = true;
|
||||||
};
|
default =
|
||||||
bridge = mkOption {
|
let
|
||||||
description = "The name of the network bridge (defaults to vmbr0).";
|
inherit (tf-host.config)
|
||||||
type = types.str;
|
system
|
||||||
default = "vmbr0";
|
ssh
|
||||||
};
|
module
|
||||||
vlanId = mkOption {
|
args
|
||||||
description = "The VLAN identifier.";
|
deployment-name
|
||||||
type = types.int;
|
httpBackend
|
||||||
default = 0;
|
root-path
|
||||||
};
|
proxmox-user
|
||||||
imageDatastoreId = mkOption {
|
proxmox-password
|
||||||
description = "ID of the datastore of the image.";
|
node-name
|
||||||
type = types.str;
|
bridge
|
||||||
default = "local";
|
vlanId
|
||||||
};
|
imageDatastoreId
|
||||||
vmDatastoreId = mkOption {
|
vmDatastoreId
|
||||||
description = "ID of the datastore of the VM.";
|
;
|
||||||
type = types.str;
|
inherit (ssh)
|
||||||
default = "local";
|
host
|
||||||
};
|
username
|
||||||
run = mkOption {
|
key-file
|
||||||
type = types.package;
|
sshOpts
|
||||||
# error: The option `tf-deployment.tf-host.run' is read-only, but it's set multiple times.
|
;
|
||||||
# readOnly = true;
|
deployment-type = "tf-proxmox-host";
|
||||||
default =
|
nixos_conf = writeConfig {
|
||||||
let
|
inherit
|
||||||
inherit (tf-host.config)
|
|
||||||
system
|
system
|
||||||
ssh
|
|
||||||
module
|
module
|
||||||
args
|
args
|
||||||
deployment-name
|
deployment-name
|
||||||
httpBackend
|
|
||||||
root-path
|
root-path
|
||||||
proxmox-user
|
deployment-type
|
||||||
proxmox-password
|
|
||||||
node-name
|
|
||||||
bridge
|
|
||||||
vlanId
|
|
||||||
imageDatastoreId
|
|
||||||
vmDatastoreId
|
|
||||||
;
|
;
|
||||||
inherit (ssh)
|
};
|
||||||
host
|
# machine = import nixos_conf;
|
||||||
username
|
machine = import ./nixos.nix {
|
||||||
key-file
|
inherit sources system;
|
||||||
sshOpts
|
configuration = tf-host.config.nixos-configuration;
|
||||||
;
|
# configuration = { ... }: {
|
||||||
deployment-type = "tf-proxmox-host";
|
# imports = [
|
||||||
nixos_conf = writeConfig {
|
# tf-host.config.nixos-configuration
|
||||||
inherit
|
# ../infra/common/nixos/repart.nix
|
||||||
system
|
# ];
|
||||||
module
|
|
||||||
args
|
|
||||||
deployment-name
|
|
||||||
root-path
|
|
||||||
deployment-type
|
|
||||||
;
|
|
||||||
};
|
|
||||||
# machine = import nixos_conf;
|
|
||||||
machine = import ./nixos.nix {
|
|
||||||
inherit sources system;
|
|
||||||
configuration = tf-host.config.nixos-configuration;
|
|
||||||
# configuration = { ... }: {
|
|
||||||
# imports = [
|
|
||||||
# tf-host.config.nixos-configuration
|
|
||||||
# ../infra/common/nixos/repart.nix
|
|
||||||
# ];
|
|
||||||
# };
|
|
||||||
};
|
|
||||||
# inherit (machine.config.boot.uki) name;
|
|
||||||
name = "monkey";
|
|
||||||
|
|
||||||
# # systemd-repart
|
|
||||||
# better for cross-compilation, worse for pre-/post-processing, doesn't support MBR: https://github.com/nix-community/disko/issues/550#issuecomment-2503736973
|
|
||||||
# raw = "${machine.config.system.build.image}/${name}.raw";
|
|
||||||
|
|
||||||
# disko
|
|
||||||
# worse for cross-compilation, better for pre-/post-processing, needs manual `imageSize`, random failures: https://github.com/nix-community/disko/issues/550#issuecomment-2503736973
|
|
||||||
raw = "${machine.config.system.build.diskoImages}/main.raw";
|
|
||||||
|
|
||||||
# # nixos-generators: note it can straight-up do qcow2 as well, if we settle for nixos-generators
|
|
||||||
# # `mount: /run/nixos-etc-metadata.J3iARWBtna: failed to setup loop device for /nix/store/14ka2bmx6lcnyr8ah2yl787sqcgxz5ni-etc-metadata.erofs.`
|
|
||||||
# # [`Error: Failed to parse os-release`](https://github.com/NixOS/nixpkgs/blob/5b1861820a3bc4ef2f60b0afcffb71ea43f5d000/pkgs/by-name/sw/switch-to-configuration-ng/src/src/main.rs#L151)
|
|
||||||
# raw = let
|
|
||||||
# # TODO parameterize things to let this flow into the terraform
|
|
||||||
# # btw qcow can be made by nixos-generators (qcow, qcow-efi) or by `image.repart`
|
|
||||||
# # wait, so i generate an image for the nixos config from the data model? how would i then propagate that to deploy?
|
|
||||||
# gen = import "${pkgs.nixos-generators}/share/nixos-generator/nixos-generate.nix" {
|
|
||||||
# inherit system formatConfig;
|
|
||||||
# inherit (sources) nixpkgs;
|
|
||||||
# configuration = tf-host.config.nixos-configuration;
|
|
||||||
# };
|
# };
|
||||||
# in
|
};
|
||||||
# "${gen.config.system.build.${formatAttr}}/nixos${fileExtension}";
|
# inherit (machine.config.boot.uki) name;
|
||||||
|
name = "monkey";
|
||||||
|
|
||||||
environment = {
|
# # systemd-repart
|
||||||
key_file = key-file;
|
# better for cross-compilation, worse for pre-/post-processing, doesn't support MBR: https://github.com/nix-community/disko/issues/550#issuecomment-2503736973
|
||||||
ssh_opts = sshOpts;
|
# raw = "${machine.config.system.build.image}/${name}.raw";
|
||||||
inherit
|
|
||||||
host
|
|
||||||
nixos_conf
|
|
||||||
bridge
|
|
||||||
;
|
|
||||||
node_name = node-name;
|
|
||||||
proxmox_user = proxmox-user;
|
|
||||||
proxmox_password = proxmox-password;
|
|
||||||
ssh_user = username;
|
|
||||||
vlan_id = vlanId;
|
|
||||||
image_datastore_id = imageDatastoreId;
|
|
||||||
vm_datastore_id = vmDatastoreId;
|
|
||||||
};
|
|
||||||
tf-env = pkgs.callPackage ./run/tf-env.nix {
|
|
||||||
inherit httpBackend;
|
|
||||||
tfPackage = pkgs.callPackage ./run/tf-proxmox/tf.nix { };
|
|
||||||
tfDirs = [
|
|
||||||
"deployment/run/tf-single-host"
|
|
||||||
"deployment/run/tf-proxmox"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
vm_name = "test14";
|
|
||||||
in
|
|
||||||
lib.trace (lib.strings.toJSON environment) pkgs.writers.writeBashBin "deploy-tf-proxmox.sh"
|
|
||||||
(withPackages [
|
|
||||||
pkgs.jq
|
|
||||||
pkgs.qemu
|
|
||||||
pkgs.nixos-generators
|
|
||||||
pkgs.httpie
|
|
||||||
(pkgs.callPackage ./run/tf-proxmox/tf.nix { inherit sources; })
|
|
||||||
])
|
|
||||||
''
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# TODO after install: $nix_host_keys
|
# disko
|
||||||
# cp $tmpdir/${vm_name}_host_key /mnt/etc/ssh/ssh_host_ed25519_key
|
# worse for cross-compilation, better for pre-/post-processing, needs manual `imageSize`, random failures: https://github.com/nix-community/disko/issues/550#issuecomment-2503736973
|
||||||
# chmod 600 /mnt/etc/ssh/ssh_host_ed25519_key
|
raw = "${machine.config.system.build.diskoImages}/main.raw";
|
||||||
# cp $tmpdir/${vm_name}_host_key.pub /mnt/etc/ssh/ssh_host_ed25519_key.pub
|
|
||||||
# chmod 644 /mnt/etc/ssh/ssh_host_ed25519_key.pub
|
|
||||||
|
|
||||||
# nixos-generate gives the burden of building revisions, while systemd-repart handles partitioning ~~at the burden of version revisions~~
|
# # nixos-generators: note it can straight-up do qcow2 as well, if we settle for nixos-generators
|
||||||
# .qcow2 is around half the size of .raw, on top of supporting backups - be it apparently at the cost of performance
|
# # `mount: /run/nixos-etc-metadata.J3iARWBtna: failed to setup loop device for /nix/store/14ka2bmx6lcnyr8ah2yl787sqcgxz5ni-etc-metadata.erofs.`
|
||||||
qemu-img convert -f raw -O qcow2 -C "${raw}" /tmp/${name}.qcow2
|
# # [`Error: Failed to parse os-release`](https://github.com/NixOS/nixpkgs/blob/5b1861820a3bc4ef2f60b0afcffb71ea43f5d000/pkgs/by-name/sw/switch-to-configuration-ng/src/src/main.rs#L151)
|
||||||
|
# raw = let
|
||||||
|
# # TODO parameterize things to let this flow into the terraform
|
||||||
|
# # btw qcow can be made by nixos-generators (qcow, qcow-efi) or by `image.repart`
|
||||||
|
# # wait, so i generate an image for the nixos config from the data model? how would i then propagate that to deploy?
|
||||||
|
# gen = import "${pkgs.nixos-generators}/share/nixos-generator/nixos-generate.nix" {
|
||||||
|
# inherit system formatConfig;
|
||||||
|
# inherit (sources) nixpkgs;
|
||||||
|
# configuration = tf-host.config.nixos-configuration;
|
||||||
|
# };
|
||||||
|
# in
|
||||||
|
# "${gen.config.system.build.${formatAttr}}/nixos${fileExtension}";
|
||||||
|
|
||||||
ls -l ${raw}
|
environment = {
|
||||||
ls -l /tmp/${name}.qcow2
|
key_file = key-file;
|
||||||
|
ssh_opts = sshOpts;
|
||||||
|
inherit
|
||||||
|
host
|
||||||
|
nixos_conf
|
||||||
|
bridge
|
||||||
|
;
|
||||||
|
node_name = node-name;
|
||||||
|
proxmox_user = proxmox-user;
|
||||||
|
proxmox_password = proxmox-password;
|
||||||
|
ssh_user = username;
|
||||||
|
vlan_id = vlanId;
|
||||||
|
image_datastore_id = imageDatastoreId;
|
||||||
|
vm_datastore_id = vmDatastoreId;
|
||||||
|
};
|
||||||
|
tf-env = pkgs.callPackage ./run/tf-env.nix {
|
||||||
|
inherit httpBackend;
|
||||||
|
tfPackage = pkgs.callPackage ./run/tf-proxmox/tf.nix { };
|
||||||
|
tfDirs = [
|
||||||
|
"deployment/run/tf-single-host"
|
||||||
|
"deployment/run/tf-proxmox"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
vm_name = "test14";
|
||||||
|
in
|
||||||
|
lib.trace (lib.strings.toJSON environment) pkgs.writers.writeBashBin "deploy-tf-proxmox.sh"
|
||||||
|
(withPackages [
|
||||||
|
pkgs.jq
|
||||||
|
pkgs.qemu
|
||||||
|
pkgs.nixos-generators
|
||||||
|
pkgs.httpie
|
||||||
|
(pkgs.callPackage ./run/tf-proxmox/tf.nix { inherit sources; })
|
||||||
|
])
|
||||||
|
''
|
||||||
|
set -e
|
||||||
|
|
||||||
env ${toString (lib.mapAttrsToList (k: v: "TF_VAR_${k}=\"${toBash v}\"") environment)} \
|
# TODO after install: $nix_host_keys
|
||||||
${toString (lib.mapAttrsToList (k: v: "${k}=\"${toBash v}\"") httpBackend)} \
|
# cp $tmpdir/${vm_name}_host_key /mnt/etc/ssh/ssh_host_ed25519_key
|
||||||
TF_VAR_image=/tmp/${name}.qcow2 \
|
# chmod 600 /mnt/etc/ssh/ssh_host_ed25519_key
|
||||||
tf_env=${tf-env} bash ./deployment/run/tf-proxmox/run.sh
|
# cp $tmpdir/${vm_name}_host_key.pub /mnt/etc/ssh/ssh_host_ed25519_key.pub
|
||||||
'';
|
# chmod 644 /mnt/etc/ssh/ssh_host_ed25519_key.pub
|
||||||
# # don't really wanna deal with having to do versioned updates for now
|
|
||||||
# qemu-img convert -f raw -O qcow2 -C "${machine.config.system.build.image}/${name}.raw" /tmp/${name}.qcow2
|
# nixos-generate gives the burden of building revisions, while systemd-repart handles partitioning ~~at the burden of version revisions~~
|
||||||
};
|
# .qcow2 is around half the size of .raw, on top of supporting backups - be it apparently at the cost of performance
|
||||||
|
qemu-img convert -f raw -O qcow2 -C "${raw}" /tmp/${name}.qcow2
|
||||||
|
|
||||||
|
ls -l ${raw}
|
||||||
|
ls -l /tmp/${name}.qcow2
|
||||||
|
|
||||||
|
env ${toString (lib.mapAttrsToList (k: v: "TF_VAR_${k}=\"${toBash v}\"") environment)} \
|
||||||
|
${toString (lib.mapAttrsToList (k: v: "${k}=\"${toBash v}\"") httpBackend)} \
|
||||||
|
TF_VAR_image=/tmp/${name}.qcow2 \
|
||||||
|
tf_env=${tf-env} bash ./deployment/run/tf-proxmox/run.sh
|
||||||
|
'';
|
||||||
|
# # don't really wanna deal with having to do versioned updates for now
|
||||||
|
# qemu-img convert -f raw -O qcow2 -C "${machine.config.system.build.image}/${name}.raw" /tmp/${name}.qcow2
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
);
|
});
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue