forked from fediversity/fediversity
continued
Signed-off-by: Kiara Grouwstra <kiara@procolix.eu>
This commit is contained in:
parent
c2510eb346
commit
3ce906adb7
10 changed files with 216 additions and 255 deletions
|
|
@ -5,6 +5,7 @@
|
||||||
sources ? import ../../../npins,
|
sources ? import ../../../npins,
|
||||||
...
|
...
|
||||||
}@args:
|
}@args:
|
||||||
|
# FIXME allow default values for `config` module parameters?
|
||||||
|
|
||||||
let
|
let
|
||||||
# having this module's location (`self`) and (serializable) `args`, we know
|
# having this module's location (`self`) and (serializable) `args`, we know
|
||||||
|
|
@ -25,8 +26,8 @@ let
|
||||||
sshOpts
|
sshOpts
|
||||||
proxmox-user
|
proxmox-user
|
||||||
proxmox-password
|
proxmox-password
|
||||||
node-name
|
|
||||||
;
|
;
|
||||||
|
node-name = nodeName;
|
||||||
inherit (lib) mkOption types;
|
inherit (lib) mkOption types;
|
||||||
eval =
|
eval =
|
||||||
module:
|
module:
|
||||||
|
|
|
||||||
|
|
@ -12,14 +12,15 @@ let
|
||||||
nodeName = "mypve";
|
nodeName = "mypve";
|
||||||
targetSystem = system;
|
targetSystem = system;
|
||||||
sshOpts = [ ];
|
sshOpts = [ ];
|
||||||
|
proxmox-user = "root@pam";
|
||||||
|
proxmox-password = "mytestpw";
|
||||||
|
node-name = "";
|
||||||
};
|
};
|
||||||
|
# FIXME generate the image `nixos-generate` was to make, but now do it for a desired `-c configuration.nix` rather than whatever generic thing now
|
||||||
deployment =
|
deployment =
|
||||||
(import ../common/data-model.nix {
|
(import ../common/data-model.nix {
|
||||||
inherit system;
|
inherit system;
|
||||||
config = deployment-config;
|
config = deployment-config;
|
||||||
proxmox-username = "root@pam";
|
|
||||||
proxmox-password = "mytestpw";
|
|
||||||
node-name = "";
|
|
||||||
# opt not to pass `inputs`, as we could only pass serializable arguments through to its self-call
|
# opt not to pass `inputs`, as we could only pass serializable arguments through to its self-call
|
||||||
})."tf-proxmox-deployment".tf-proxmox-host;
|
})."tf-proxmox-deployment".tf-proxmox-host;
|
||||||
# tracking non-tarball downloads seems unsupported still in npins:
|
# tracking non-tarball downloads seems unsupported still in npins:
|
||||||
|
|
@ -28,13 +29,27 @@ let
|
||||||
url = "https://releases.nixos.org/nixos/24.05/nixos-24.05.7139.bcba2fbf6963/nixos-minimal-24.05.7139.bcba2fbf6963-x86_64-linux.iso";
|
url = "https://releases.nixos.org/nixos/24.05/nixos-24.05.7139.bcba2fbf6963/nixos-minimal-24.05.7139.bcba2fbf6963-x86_64-linux.iso";
|
||||||
hash = "sha256-plre/mIHdIgU4xWU+9xErP+L4i460ZbcKq8iy2n4HT8=";
|
hash = "sha256-plre/mIHdIgU4xWU+9xErP+L4i460ZbcKq8iy2n4HT8=";
|
||||||
};
|
};
|
||||||
|
# machine =
|
||||||
|
# (import "${pkgs.nixos-generators}/share/nixos-generator/nixos-generate.nix" {
|
||||||
|
# inherit system;
|
||||||
|
# inherit (sources) nixpkgs;
|
||||||
|
# formatConfig = "${pkgs.nixos-generators}/share/nixos-generator/formats/proxmox.nix";
|
||||||
|
# configuration = deployment.nixos-configuration; # /nix/store/9nl9q95lvhbr86ys0q2xakr844cg9vym-nixos-generators-1.8.0/share/nixos-generator/configuration.nix
|
||||||
|
# }).config;
|
||||||
|
# .config.system.build.toplevel.drvPath
|
||||||
|
gen = import "${pkgs.nixos-generators}/share/nixos-generator/nixos-generate.nix" {
|
||||||
|
inherit system;
|
||||||
|
inherit (sources) nixpkgs;
|
||||||
|
formatConfig = "${pkgs.nixos-generators}/share/nixos-generator/formats/proxmox.nix";
|
||||||
|
configuration = deployment.nixos-configuration;
|
||||||
|
};
|
||||||
machine =
|
machine =
|
||||||
(import "${pkgs.nixos-generators}/share/nixos-generator/nixos-generate.nix" {
|
# lib.trace ".config: ${builtins.toString (lib.attrNames gen.config)}"
|
||||||
inherit system;
|
# lib.trace ".config.system: ${builtins.toString (lib.attrNames gen.config.system)}"
|
||||||
inherit (sources) nixpkgs;
|
# lib.trace ".config.system.build: ${builtins.toString (lib.attrNames gen.config.system.build)}"
|
||||||
formatConfig = "${pkgs.nixos-generators}/share/nixos-generator/formats/proxmox.nix";
|
# lib.trace ".config.system.build.toplevel: ${builtins.toString (lib.attrNames gen.config.system.build.toplevel)}"
|
||||||
configuration = deployment.nixos-configuration;
|
# lib.trace ".config.system.build.toplevel.drvPath: ${builtins.toString (lib.attrNames gen.config.system.build.toplevel.drvPath)}"
|
||||||
}).config;
|
gen.config;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
_class = "nixosTest";
|
_class = "nixosTest";
|
||||||
|
|
@ -132,69 +147,40 @@ in
|
||||||
lib.trace "no" [ ]
|
lib.trace "no" [ ]
|
||||||
)
|
)
|
||||||
) machine.environment.systemPackages)
|
) machine.environment.systemPackages)
|
||||||
|
# ++ (let
|
||||||
|
# base =
|
||||||
|
# (import "${pkgs.nixos-generators}/share/nixos-generator/nixos-generate.nix" {
|
||||||
|
# inherit system;
|
||||||
|
# inherit (sources) nixpkgs;
|
||||||
|
# formatConfig = "${pkgs.nixos-generators}/share/nixos-generator/formats/proxmox.nix";
|
||||||
|
# configuration = "${pkgs.nixos-generators}/share/nixos-generator/configuration.nix";
|
||||||
|
# }).config;
|
||||||
|
# in [
|
||||||
|
# base.system.build.toplevel.inputDerivation
|
||||||
|
# base.system.build.etc.inputDerivation
|
||||||
|
# base.system.build.etcBasedir.inputDerivation
|
||||||
|
# base.system.build.etcMetadataImage.inputDerivation
|
||||||
|
# base.system.build.extraUtils.inputDerivation
|
||||||
|
# base.system.path.inputDerivation
|
||||||
|
# base.system.build.setEnvironment.inputDerivation
|
||||||
|
# base.system.build.vm.inputDerivation
|
||||||
|
# base.system.build.bootStage1.inputDerivation
|
||||||
|
# base.system.build.bootStage2.inputDerivation
|
||||||
|
# ])
|
||||||
++ [
|
++ [
|
||||||
(
|
# )
|
||||||
(
|
# (
|
||||||
x:
|
# (x: builtins.trace "machine.system.build.vm.inputDerivation: ${builtins.toString (lib.isPath x)}" x)
|
||||||
builtins.trace "machine.system.build.toplevel.inputDerivation: ${builtins.toString (lib.isPath x)}" x
|
machine.system.build.toplevel.inputDerivation
|
||||||
)
|
machine.system.build.etc.inputDerivation
|
||||||
machine.system.build.toplevel.inputDerivation
|
machine.system.build.etcBasedir.inputDerivation
|
||||||
)
|
machine.system.build.etcMetadataImage.inputDerivation
|
||||||
(
|
machine.system.build.extraUtils.inputDerivation
|
||||||
(
|
machine.system.path.inputDerivation
|
||||||
x: builtins.trace "machine.system.build.etc.inputDerivation: ${builtins.toString (lib.isPath x)}" x
|
machine.system.build.setEnvironment.inputDerivation
|
||||||
)
|
machine.system.build.vm.inputDerivation
|
||||||
machine.system.build.etc.inputDerivation
|
machine.system.build.bootStage1.inputDerivation
|
||||||
)
|
machine.system.build.bootStage2.inputDerivation
|
||||||
(
|
|
||||||
(
|
|
||||||
x:
|
|
||||||
builtins.trace "machine.system.build.etcBasedir.inputDerivation: ${builtins.toString (lib.isPath x)}" x
|
|
||||||
)
|
|
||||||
machine.system.build.etcBasedir.inputDerivation
|
|
||||||
)
|
|
||||||
(
|
|
||||||
(
|
|
||||||
x:
|
|
||||||
builtins.trace "machine.system.build.etcMetadataImage.inputDerivation: ${builtins.toString (lib.isPath x)}" x
|
|
||||||
)
|
|
||||||
machine.system.build.etcMetadataImage.inputDerivation
|
|
||||||
)
|
|
||||||
(
|
|
||||||
(
|
|
||||||
x:
|
|
||||||
builtins.trace "machine.system.build.extraUtils.inputDerivation: ${builtins.toString (lib.isPath x)}" x
|
|
||||||
)
|
|
||||||
machine.system.build.extraUtils.inputDerivation
|
|
||||||
)
|
|
||||||
((x: builtins.trace "machine.system.path.inputDerivation: ${builtins.toString (lib.isPath x)}" x)
|
|
||||||
machine.system.path.inputDerivation
|
|
||||||
)
|
|
||||||
(
|
|
||||||
(
|
|
||||||
x:
|
|
||||||
builtins.trace "machine.system.build.setEnvironment.inputDerivation: ${builtins.toString (lib.isPath x)}" x
|
|
||||||
)
|
|
||||||
machine.system.build.setEnvironment.inputDerivation
|
|
||||||
)
|
|
||||||
(
|
|
||||||
(x: builtins.trace "machine.system.build.vm.inputDerivation: ${builtins.toString (lib.isPath x)}" x)
|
|
||||||
machine.system.build.vm.inputDerivation
|
|
||||||
)
|
|
||||||
(
|
|
||||||
(
|
|
||||||
x:
|
|
||||||
builtins.trace "machine.system.build.bootStage1.inputDerivation: ${builtins.toString (lib.isPath x)}" x
|
|
||||||
)
|
|
||||||
machine.system.build.bootStage1.inputDerivation
|
|
||||||
)
|
|
||||||
(
|
|
||||||
(
|
|
||||||
x:
|
|
||||||
builtins.trace "machine.system.build.bootStage2.inputDerivation: ${builtins.toString (lib.isPath x)}" x
|
|
||||||
)
|
|
||||||
machine.system.build.bootStage2.inputDerivation
|
|
||||||
)
|
|
||||||
pkgs.gnu-config
|
pkgs.gnu-config
|
||||||
# pkgs.gnu-config.inputDerivation
|
# pkgs.gnu-config.inputDerivation
|
||||||
pkgs.byacc
|
pkgs.byacc
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,33 @@ let
|
||||||
else
|
else
|
||||||
lib.strings.toJSON v
|
lib.strings.toJSON v
|
||||||
);
|
);
|
||||||
|
withPackages = packages: {
|
||||||
|
makeWrapperArgs = [
|
||||||
|
"--prefix"
|
||||||
|
"PATH"
|
||||||
|
":"
|
||||||
|
"${lib.makeBinPath packages}"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
writeConfig =
|
||||||
|
{
|
||||||
|
system,
|
||||||
|
module,
|
||||||
|
root-path,
|
||||||
|
deployment-type,
|
||||||
|
deployment-name,
|
||||||
|
args,
|
||||||
|
}:
|
||||||
|
builtins.toString (
|
||||||
|
pkgs.writers.writeText "configuration.nix" ''
|
||||||
|
import ${root-path}/deployment/nixos.nix {
|
||||||
|
system = "${system}";
|
||||||
|
configuration = (import "${root-path}/${module}" (builtins.fromJSON "${
|
||||||
|
lib.replaceStrings [ "\"" ] [ "\\\"" ] (lib.strings.toJSON args)
|
||||||
|
}")).${deployment-name}.${deployment-type}.nixos-configuration;
|
||||||
|
}
|
||||||
|
''
|
||||||
|
);
|
||||||
|
|
||||||
functionType = submodule ./function.nix;
|
functionType = submodule ./function.nix;
|
||||||
application-resources = submodule {
|
application-resources = submodule {
|
||||||
|
|
@ -85,6 +112,8 @@ let
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
# FIXME allow custom deployment types
|
||||||
|
# FIXME make deployments environment resources?
|
||||||
deployment-type = attrTag {
|
deployment-type = attrTag {
|
||||||
ssh-host = mkOption {
|
ssh-host = mkOption {
|
||||||
description = "A deployment by SSH to update a single existing NixOS host.";
|
description = "A deployment by SSH to update a single existing NixOS host.";
|
||||||
|
|
@ -134,30 +163,27 @@ let
|
||||||
;
|
;
|
||||||
environment = {
|
environment = {
|
||||||
key_file = key-file;
|
key_file = key-file;
|
||||||
deployment_name = deployment-name;
|
|
||||||
root_path = root-path;
|
|
||||||
ssh_opts = sshOpts;
|
ssh_opts = sshOpts;
|
||||||
inherit
|
inherit
|
||||||
system
|
|
||||||
host
|
host
|
||||||
username
|
username
|
||||||
module
|
|
||||||
args
|
|
||||||
;
|
;
|
||||||
deployment_type = "ssh-host";
|
nixos_conf = writeConfig {
|
||||||
|
inherit
|
||||||
|
system
|
||||||
|
module
|
||||||
|
args
|
||||||
|
deployment-name
|
||||||
|
root-path
|
||||||
|
;
|
||||||
|
deployment-type = "ssh-host";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
pkgs.writers.writeBashBin "deploy-sh.sh"
|
pkgs.writers.writeBashBin "deploy-sh.sh"
|
||||||
{
|
(withPackages [
|
||||||
makeWrapperArgs = [
|
pkgs.jq
|
||||||
"--prefix"
|
])
|
||||||
"PATH"
|
|
||||||
":"
|
|
||||||
"${lib.makeBinPath [
|
|
||||||
pkgs.jq
|
|
||||||
]}"
|
|
||||||
];
|
|
||||||
}
|
|
||||||
''
|
''
|
||||||
env ${
|
env ${
|
||||||
toString (lib.mapAttrsToList (k: v: "${k}=\"${toBash v}\"") environment)
|
toString (lib.mapAttrsToList (k: v: "${k}=\"${toBash v}\"") environment)
|
||||||
|
|
@ -219,32 +245,29 @@ let
|
||||||
;
|
;
|
||||||
environment = {
|
environment = {
|
||||||
key_file = key-file;
|
key_file = key-file;
|
||||||
deployment_name = deployment-name;
|
|
||||||
root_path = root-path;
|
|
||||||
ssh_opts = sshOpts;
|
ssh_opts = sshOpts;
|
||||||
inherit
|
inherit
|
||||||
system
|
|
||||||
host
|
host
|
||||||
username
|
username
|
||||||
module
|
|
||||||
args
|
|
||||||
;
|
;
|
||||||
deployment_type = "tf-host";
|
nixos_conf = writeConfig {
|
||||||
|
inherit
|
||||||
|
system
|
||||||
|
module
|
||||||
|
args
|
||||||
|
deployment-name
|
||||||
|
root-path
|
||||||
|
;
|
||||||
|
deployment-type = "tf-host";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
tf-env = pkgs.callPackage ./run/tf-single-host/tf-env.nix { };
|
tf-env = pkgs.callPackage ./run/tf-single-host/tf-env.nix { };
|
||||||
in
|
in
|
||||||
pkgs.writers.writeBashBin "deploy-tf.sh"
|
pkgs.writers.writeBashBin "deploy-tf.sh"
|
||||||
{
|
(withPackages [
|
||||||
makeWrapperArgs = [
|
pkgs.jq
|
||||||
"--prefix"
|
(pkgs.callPackage ./run/tf-single-host/tf.nix { inherit sources; })
|
||||||
"PATH"
|
])
|
||||||
":"
|
|
||||||
"${lib.makeBinPath [
|
|
||||||
pkgs.jq
|
|
||||||
(pkgs.callPackage ./run/tf-single-host/tf.nix { inherit sources; })
|
|
||||||
]}"
|
|
||||||
];
|
|
||||||
}
|
|
||||||
''
|
''
|
||||||
env ${toString (lib.mapAttrsToList (k: v: "TF_VAR_${k}=\"${toBash v}\"") environment)} \
|
env ${toString (lib.mapAttrsToList (k: v: "TF_VAR_${k}=\"${toBash v}\"") environment)} \
|
||||||
tf_env=${tf-env} bash ./deployment/run/tf-single-host/run.sh
|
tf_env=${tf-env} bash ./deployment/run/tf-single-host/run.sh
|
||||||
|
|
@ -294,6 +317,19 @@ let
|
||||||
description = "the name of the ProxmoX node to use.";
|
description = "the name of the ProxmoX node to use.";
|
||||||
type = types.str;
|
type = types.str;
|
||||||
};
|
};
|
||||||
|
# nixos-conf = mkOption {
|
||||||
|
# type = types.str;
|
||||||
|
# default = writeConfig {
|
||||||
|
# inherit (tf-host.config)
|
||||||
|
# system
|
||||||
|
# module
|
||||||
|
# args
|
||||||
|
# deployment-name
|
||||||
|
# root-path
|
||||||
|
# ;
|
||||||
|
# deployment-type = "tf-proxmox-host";
|
||||||
|
# };
|
||||||
|
# };
|
||||||
run = mkOption {
|
run = mkOption {
|
||||||
type = types.package;
|
type = types.package;
|
||||||
# error: The option `tf-deployment.tf-host.run' is read-only, but it's set multiple times.
|
# error: The option `tf-deployment.tf-host.run' is read-only, but it's set multiple times.
|
||||||
|
|
@ -310,6 +346,7 @@ let
|
||||||
proxmox-user
|
proxmox-user
|
||||||
proxmox-password
|
proxmox-password
|
||||||
node-name
|
node-name
|
||||||
|
# nixos-conf
|
||||||
;
|
;
|
||||||
inherit (ssh)
|
inherit (ssh)
|
||||||
host
|
host
|
||||||
|
|
@ -319,36 +356,34 @@ let
|
||||||
;
|
;
|
||||||
environment = {
|
environment = {
|
||||||
key_file = key-file;
|
key_file = key-file;
|
||||||
deployment_name = deployment-name;
|
|
||||||
root_path = root-path;
|
|
||||||
ssh_opts = sshOpts;
|
ssh_opts = sshOpts;
|
||||||
inherit
|
inherit
|
||||||
system
|
|
||||||
host
|
host
|
||||||
module
|
|
||||||
args
|
|
||||||
;
|
;
|
||||||
proxmox_user = proxmox-user;
|
proxmox_user = proxmox-user;
|
||||||
proxmox_password = proxmox-password;
|
proxmox_password = proxmox-password;
|
||||||
deployment_type = "tf-proxmox-host";
|
|
||||||
ssh_user = username;
|
ssh_user = username;
|
||||||
node_name = node-name;
|
node_name = node-name;
|
||||||
|
# nixos_conf = nixos-conf;
|
||||||
|
nixos_conf = writeConfig {
|
||||||
|
inherit
|
||||||
|
system
|
||||||
|
module
|
||||||
|
args
|
||||||
|
deployment-name
|
||||||
|
root-path
|
||||||
|
;
|
||||||
|
deployment-type = "tf-proxmox-host";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
tf-env = pkgs.callPackage ./run/tf-proxmox/tf-env.nix { };
|
tf-env = pkgs.callPackage ./run/tf-proxmox/tf-env.nix { };
|
||||||
in
|
in
|
||||||
pkgs.writers.writeBashBin "deploy-tf-proxmox.sh"
|
pkgs.writers.writeBashBin "deploy-tf-proxmox.sh"
|
||||||
{
|
(withPackages [
|
||||||
makeWrapperArgs = [
|
pkgs.jq
|
||||||
"--prefix"
|
pkgs.nixos-generators
|
||||||
"PATH"
|
(pkgs.callPackage ./run/tf-proxmox/tf.nix { inherit sources; })
|
||||||
":"
|
])
|
||||||
"${lib.makeBinPath [
|
|
||||||
pkgs.jq
|
|
||||||
pkgs.nixos-generators
|
|
||||||
(pkgs.callPackage ./run/tf-proxmox/tf.nix { inherit sources; })
|
|
||||||
]}"
|
|
||||||
];
|
|
||||||
}
|
|
||||||
''
|
''
|
||||||
env ${toString (lib.mapAttrsToList (k: v: "TF_VAR_${k}=\"${toBash v}\"") environment)} \
|
env ${toString (lib.mapAttrsToList (k: v: "TF_VAR_${k}=\"${toBash v}\"") environment)} \
|
||||||
tf_env=${tf-env} bash ./deployment/run/tf-proxmox/run.sh
|
tf_env=${tf-env} bash ./deployment/run/tf-proxmox/run.sh
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#! /usr/bin/env bash
|
#! /usr/bin/env bash
|
||||||
set -xeuo pipefail
|
set -xeuo pipefail
|
||||||
declare username host system module args deployment_name deployment_type key_file root_path ssh_opts
|
declare username host key_file ssh_opts nixos_conf
|
||||||
IFS=" " read -r -a ssh_opts <<< "$( (echo "$ssh_opts" | jq -r '@sh') | tr -d \'\")"
|
IFS=" " read -r -a ssh_opts <<< "$( (echo "$ssh_opts" | jq -r '@sh') | tr -d \'\")"
|
||||||
|
|
||||||
# DEPLOY
|
# DEPLOY
|
||||||
|
|
@ -20,18 +20,16 @@ if [[ -n "$key_file" ]]; then
|
||||||
fi
|
fi
|
||||||
destination="$username@$host"
|
destination="$username@$host"
|
||||||
|
|
||||||
command=(nix-instantiate --show-trace --expr "
|
command=(nix-instantiate --show-trace "${nixos_conf}")
|
||||||
import $root_path/deployment/nixos.nix {
|
|
||||||
system = \"$system\";
|
|
||||||
configuration = (import \"$root_path/$module\" (builtins.fromJSON ''$args'')).$deployment_name.$deployment_type.nixos-configuration;
|
|
||||||
}
|
|
||||||
")
|
|
||||||
|
|
||||||
# INSTANTIATE
|
# INSTANTIATE
|
||||||
# instantiate the config in /nix/store
|
# instantiate the config in /nix/store
|
||||||
"${command[@]}" -A out_path
|
"${command[@]}" -A out_path
|
||||||
|
|
||||||
# get the realized derivation to deploy
|
# get the realized derivation to deploy
|
||||||
|
"${command[@]}" --show-trace --eval --strict --json
|
||||||
|
|
||||||
|
# FIXME explore import/readFile as ways to instantiate the derivation, potentially allowing to realize the store path up-front from Nix?
|
||||||
outPath=$(nix-store --realize "$("${command[@]}" --show-trace --eval --strict --json | jq -r '.drv_path')")
|
outPath=$(nix-store --realize "$("${command[@]}" --show-trace --eval --strict --json | jq -r '.drv_path')")
|
||||||
# deploy the config by nix-copy-closure
|
# deploy the config by nix-copy-closure
|
||||||
NIX_SSHOPTS="${sshOpts[*]}" nix-copy-closure --to "$destination" "$outPath" --gzip --use-substitutes
|
NIX_SSHOPTS="${sshOpts[*]}" nix-copy-closure --to "$destination" "$outPath" --gzip --use-substitutes
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,9 @@ terraform {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
locals {
|
# locals {
|
||||||
dump_name = "vzdump-qemu-nixos-fediversity-${var.category}.vma.zst"
|
# dump_name = "vzdump-qemu-nixos-fediversity-${var.category}.vma.zst"
|
||||||
}
|
# }
|
||||||
|
|
||||||
provider "proxmox" {
|
provider "proxmox" {
|
||||||
endpoint = "https://${var.host}:8006/"
|
endpoint = "https://${var.host}:8006/"
|
||||||
|
|
@ -29,57 +29,57 @@ provider "proxmox" {
|
||||||
# csrf_prevention_token = var.virtual_environment_csrf_prevention_token
|
# csrf_prevention_token = var.virtual_environment_csrf_prevention_token
|
||||||
}
|
}
|
||||||
|
|
||||||
# FIXME move to host
|
# # FIXME move to host
|
||||||
# FIXME add proxmox
|
# # FIXME add proxmox
|
||||||
data "external" "base-hash" {
|
# data "external" "base-hash" {
|
||||||
program = ["sh", "-c", "echo \"{\\\"hash\\\":\\\"$(nix-hash ${path.module}/../common/nixos/base.nix)\\\"}\""]
|
# program = ["sh", "-c", "echo \"{\\\"hash\\\":\\\"$(nix-hash ${path.module}/../common/nixos/base.nix)\\\"}\""]
|
||||||
}
|
# }
|
||||||
|
|
||||||
# hash of our code directory, used to trigger re-deploy
|
# # hash of our code directory, used to trigger re-deploy
|
||||||
# FIXME calculate separately to reduce false positives
|
# # FIXME calculate separately to reduce false positives
|
||||||
data "external" "hash" {
|
# data "external" "hash" {
|
||||||
program = ["sh", "-c", "echo \"{\\\"hash\\\":\\\"$(nix-hash ..)\\\"}\""]
|
# program = ["sh", "-c", "echo \"{\\\"hash\\\":\\\"$(nix-hash ..)\\\"}\""]
|
||||||
}
|
# }
|
||||||
|
|
||||||
# FIXME move to host
|
# # FIXME move to host
|
||||||
resource "terraform_data" "template" {
|
# resource "terraform_data" "template" {
|
||||||
# triggers_replace = [
|
# # triggers_replace = [
|
||||||
# data.external.base-hash.result,
|
# # data.external.base-hash.result,
|
||||||
# ]
|
# # ]
|
||||||
|
|
||||||
provisioner "local-exec" {
|
# provisioner "local-exec" {
|
||||||
working_dir = path.root
|
# working_dir = path.root
|
||||||
# FIXME configure to use actual base image
|
# # FIXME configure to use actual base image
|
||||||
command = <<-EOF
|
# command = <<-EOF
|
||||||
set -xeuo pipefail
|
# set -xeuo pipefail
|
||||||
|
|
||||||
# XXX nixos-generate needs NIX_PATH to have `nixpkgs` set!
|
# # XXX nixos-generate needs NIX_PATH to have `nixpkgs` set!
|
||||||
nixos-generate -f proxmox -o /tmp/nixos-image
|
# nixos-generate -f proxmox -o /tmp/nixos-image
|
||||||
# the above makes /tmp/nixos-image read-only, so our stable file name needs a different directory
|
# # the above makes /tmp/nixos-image read-only, so our stable file name needs a different directory
|
||||||
mkdir -p /tmp/proxmox-image
|
# mkdir -p /tmp/proxmox-image
|
||||||
ln -sf /tmp/nixos-image/vzdump-qemu-nixos-*.vma.zst /tmp/proxmox-image/${local.dump_name}
|
# ln -sf /tmp/nixos-image/vzdump-qemu-nixos-*.vma.zst /tmp/proxmox-image/${local.dump_name}
|
||||||
EOF
|
# EOF
|
||||||
}
|
# }
|
||||||
}
|
# }
|
||||||
|
|
||||||
# FIXME move to host
|
# # FIXME move to host
|
||||||
resource "proxmox_virtual_environment_file" "upload" {
|
# resource "proxmox_virtual_environment_file" "upload" {
|
||||||
lifecycle {
|
# lifecycle {
|
||||||
replace_triggered_by = [
|
# replace_triggered_by = [
|
||||||
terraform_data.template,
|
# terraform_data.template,
|
||||||
]
|
# ]
|
||||||
}
|
# }
|
||||||
|
|
||||||
content_type = "images"
|
# content_type = "images"
|
||||||
datastore_id = "local"
|
# datastore_id = "local"
|
||||||
node_name = var.node_name
|
# node_name = var.node_name
|
||||||
overwrite = true
|
# overwrite = true
|
||||||
|
|
||||||
source_file {
|
# source_file {
|
||||||
path = "/tmp/proxmox-image/${local.dump_name}"
|
# path = "/tmp/proxmox-image/${local.dump_name}"
|
||||||
file_name = local.dump_name
|
# file_name = local.dump_name
|
||||||
}
|
# }
|
||||||
}
|
# }
|
||||||
|
|
||||||
# FIXME distinguish var.category
|
# FIXME distinguish var.category
|
||||||
data "proxmox_virtual_environment_vms" "nixos_base" {
|
data "proxmox_virtual_environment_vms" "nixos_base" {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
variable "system" {
|
variable "nixos_conf" {
|
||||||
description = "The architecture of the system to deploy to."
|
description = "The path to the NixOS configuration to deploy."
|
||||||
type = string
|
type = string
|
||||||
default = "x86_64-linux"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "ssh_user" {
|
variable "ssh_user" {
|
||||||
|
|
@ -32,44 +31,17 @@ variable "node_name" {
|
||||||
type = string
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "module" {
|
|
||||||
description = "The module to call to obtain the NixOS configuration from."
|
|
||||||
type = string
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "args" {
|
|
||||||
description = "The arguments with which to call the module to obtain the NixOS configuration."
|
|
||||||
type = string
|
|
||||||
default = "{}"
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "key_file" {
|
variable "key_file" {
|
||||||
description = "path to the user's SSH private key"
|
description = "path to the user's SSH private key"
|
||||||
type = string
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "deployment_name" {
|
|
||||||
description = "The name of the deployment for which to obtain the NixOS configuration."
|
|
||||||
type = string
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "root_path" {
|
|
||||||
description = "The path to the root of the repository."
|
|
||||||
type = string
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "ssh_opts" {
|
variable "ssh_opts" {
|
||||||
description = "Extra SSH options (`-o`) to use."
|
description = "Extra SSH options (`-o`) to use."
|
||||||
type = string
|
type = string
|
||||||
default = "[]"
|
default = "[]"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "deployment_type" {
|
|
||||||
description = "A `deployment-type` from the Fediversity data model, for grabbing the desired NixOS configuration."
|
|
||||||
type = string
|
|
||||||
default = "tf-proxmox-host"
|
|
||||||
}
|
|
||||||
|
|
||||||
#########################################
|
#########################################
|
||||||
|
|
||||||
variable "category" {
|
variable "category" {
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,8 @@ resource "terraform_data" "nixos" {
|
||||||
# - `data` always runs, which is slow for deploy and especially build.
|
# - `data` always runs, which is slow for deploy and especially build.
|
||||||
triggers_replace = [
|
triggers_replace = [
|
||||||
data.external.hash.result,
|
data.external.hash.result,
|
||||||
|
var.nixos_conf,
|
||||||
var.host,
|
var.host,
|
||||||
var.module,
|
|
||||||
var.args,
|
|
||||||
var.root_path,
|
|
||||||
var.deployment_type,
|
|
||||||
]
|
]
|
||||||
|
|
||||||
provisioner "local-exec" {
|
provisioner "local-exec" {
|
||||||
|
|
@ -33,17 +30,11 @@ resource "terraform_data" "nixos" {
|
||||||
# so are generally discouraged in TF.
|
# so are generally discouraged in TF.
|
||||||
working_dir = path.root
|
working_dir = path.root
|
||||||
environment = {
|
environment = {
|
||||||
system = var.system
|
nixos_conf = var.nixos_conf
|
||||||
username = var.username
|
username = var.username
|
||||||
host = var.host
|
host = var.host
|
||||||
module = var.module
|
|
||||||
host = var.host
|
|
||||||
args = var.args
|
|
||||||
key_file = var.key_file
|
key_file = var.key_file
|
||||||
deployment_name = var.deployment_name
|
|
||||||
root_path = var.root_path
|
|
||||||
ssh_opts = var.ssh_opts
|
ssh_opts = var.ssh_opts
|
||||||
deployment_type = var.deployment_type
|
|
||||||
}
|
}
|
||||||
# TODO: refactor back to command="ignoreme" interpreter=concat([]) to protect sensitive data from error logs?
|
# TODO: refactor back to command="ignoreme" interpreter=concat([]) to protect sensitive data from error logs?
|
||||||
# TODO: build on target?
|
# TODO: build on target?
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
variable "system" {
|
variable "nixos_conf" {
|
||||||
description = "The architecture of the system to deploy to."
|
description = "The path to the NixOS configuration to deploy."
|
||||||
type = string
|
type = string
|
||||||
default = "x86_64-linux"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "username" {
|
variable "username" {
|
||||||
|
|
@ -15,40 +14,13 @@ variable "host" {
|
||||||
type = string
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "module" {
|
|
||||||
description = "The module to call to obtain the NixOS configuration from."
|
|
||||||
type = string
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "args" {
|
|
||||||
description = "The arguments with which to call the module to obtain the NixOS configuration."
|
|
||||||
type = string
|
|
||||||
default = "{}"
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "key_file" {
|
variable "key_file" {
|
||||||
description = "path to the user's SSH private key"
|
description = "path to the user's SSH private key"
|
||||||
type = string
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "deployment_name" {
|
|
||||||
description = "The name of the deployment for which to obtain the NixOS configuration."
|
|
||||||
type = string
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "root_path" {
|
|
||||||
description = "The path to the root of the repository."
|
|
||||||
type = string
|
|
||||||
}
|
|
||||||
|
|
||||||
variable "ssh_opts" {
|
variable "ssh_opts" {
|
||||||
description = "Extra SSH options (`-o`) to use."
|
description = "Extra SSH options (`-o`) to use."
|
||||||
type = string
|
type = string
|
||||||
default = "[]"
|
default = "[]"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "deployment_type" {
|
|
||||||
description = "A `deployment-type` from the Fediversity data model, for grabbing the desired NixOS configuration."
|
|
||||||
type = string
|
|
||||||
default = "tf-host"
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
{
|
{
|
||||||
nixpkgs,
|
|
||||||
hostKeys ? { },
|
|
||||||
nixosConfiguration,
|
nixosConfiguration,
|
||||||
|
hostKeys ? { },
|
||||||
|
nixpkgs ? (import ../npins).nixpkgs,
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
@ -44,7 +44,7 @@ let
|
||||||
imports = [ "${nixpkgs}/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix" ];
|
imports = [ "${nixpkgs}/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix" ];
|
||||||
nixpkgs.hostPlatform = "x86_64-linux";
|
nixpkgs.hostPlatform = "x86_64-linux";
|
||||||
services.getty.autologinUser = lib.mkForce "root";
|
services.getty.autologinUser = lib.mkForce "root";
|
||||||
programs.bash.loginShellInit = nixpkgs.lib.getExe bootstrap;
|
programs.bash.loginShellInit = lib.getExe bootstrap;
|
||||||
|
|
||||||
isoImage = {
|
isoImage = {
|
||||||
compressImage = false;
|
compressImage = false;
|
||||||
|
|
@ -55,4 +55,10 @@ let
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
(nixpkgs.lib.nixosSystem { modules = [ installer ]; }).config.system.build.isoImage
|
(import "${nixpkgs}/nixos/lib/eval-config.nix" {
|
||||||
|
modules = [ installer ];
|
||||||
|
# Allow system to be set modularly in nixpkgs.system.
|
||||||
|
# We set it to null, to remove the "legacy" entrypoint's
|
||||||
|
# non-hermetic default.
|
||||||
|
system = null;
|
||||||
|
}).config.system.build.isoImage
|
||||||
|
|
|
||||||
|
|
@ -223,9 +223,9 @@ build_iso () {
|
||||||
nix build \
|
nix build \
|
||||||
--impure --expr "
|
--impure --expr "
|
||||||
let flake = builtins.getFlake (builtins.toString ./.); in
|
let flake = builtins.getFlake (builtins.toString ./.); in
|
||||||
import ./makeInstallerIso.nix {
|
import ./infra/makeInstallerIso.nix {
|
||||||
nixosConfiguration = flake.nixosConfigurations.$vm_name;
|
nixosConfiguration = flake.nixosConfigurations.$vm_name;
|
||||||
nixpkgs = flake.inputs.nixpkgs;
|
# nixpkgs = flake.inputs.nixpkgs;
|
||||||
$nix_host_keys
|
$nix_host_keys
|
||||||
}
|
}
|
||||||
" \
|
" \
|
||||||
|
|
@ -239,7 +239,7 @@ Check the Nix logs and fix things. Possibly there just is no NixOS configuration
|
||||||
"$vm_name"
|
"$vm_name"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ln -sf "$tmpdir/installer-$vm_name/iso/installer.iso" "$tmpdir/installer-$vm_name.iso"
|
ln -sf "$(ls "$tmpdir/installer-$vm_name"/iso/nixos-*.iso)" "$tmpdir/installer-$vm_name.iso"
|
||||||
|
|
||||||
printf 'done building ISO for VM %s.\n' "$vm_name"
|
printf 'done building ISO for VM %s.\n' "$vm_name"
|
||||||
release_lock build
|
release_lock build
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue