diff --git a/deployment/flake-part.nix b/deployment/flake-part.nix index 5a2ea7f6..79052860 100644 --- a/deployment/flake-part.nix +++ b/deployment/flake-part.nix @@ -2,7 +2,7 @@ let allVmIds = builtins.genList (x: 100 + x) 156; # 100 -- 255 - makeInstaller = import ./makeInstaller.nix; + makeInstaller = import ../infra/makeInstaller.nix; in { @@ -31,9 +31,10 @@ in inherit (builtins) mapAttrs; in mapAttrs ( - vmname: + vmname: nixosConfiguration: makeInstaller { inherit (inputs) nixpkgs; + inherit nixosConfiguration; hostKeys = { ed25519 = { private = ./hostKeys/${vmname}/ssh_host_ed25519_key; @@ -52,9 +53,11 @@ in makeProcolixVmResource = vmid: vmconfig: { type = providers.local.exec; imports = [ inputs.nixops4-nixos.modules.nixops4Resource.nixos ]; - ssh.opts = ""; - ssh.host = "95.215.187.${toString vmid}"; - ssh.hostPublicKey = readFile ./hostKeys/fedi${toString vmid}/ssh_host_ed25519_key.pub; + + ssh = { + host = "95.215.187.${toString vmid}"; + hostPublicKey = readFile ./hostKeys/fedi${toString vmid}/ssh_host_ed25519_key.pub; + }; nixpkgs = inputs.nixpkgs; nixos.module = { @@ -62,7 +65,7 @@ in vmconfig { procolix.vmid = vmid; } ./procolixVm.nix - inputs.snf.nixosModules.fediversity + self.nixosModules.fediversity inputs.disko.nixosModules.default ]; }; @@ -70,11 +73,9 @@ in in { - providers.local = inputs.nixops4-nixos.modules.nixops4Provider.local; + providers = { inherit (inputs.nixops4.modules.nixops4Provider) local; }; resources = { - fedi100 = makeProcolixVmResource 100 { }; - fedi101 = makeProcolixVmResource 101 { fediversity = { enable = true; @@ -107,14 +108,6 @@ in }; } ); - - fedi120 = makeProcolixVmResource 120 { - fediversity = { - enable = true; - domain = "fedi120.abundos.eu"; - pixelfed.enable = true; - }; - }; }; }; } diff --git a/deployment/proxmox/provision.sh b/deployment/proxmox/provision.sh index dba60b37..74b92717 100755 --- a/deployment/proxmox/provision.sh +++ b/deployment/proxmox/provision.sh @@ -28,24 +28,27 @@ debug=false help () { cat <<EOF -Usage: $0 [OPTION...] [ID...] +Usage: $0 [OPTION...] ID [ID...] -Authentication options: - --username STR Username, with provider (eg. niols@pve) - --password STR Password +Options: + --username STR Username, with provider (eg. niols@pve; required) + --password STR Password (required) - If not provided via the command line, username and password will be looked for - in a '.proxmox' file in the current working directory, the username on the - first line, and the password on the second. - -Other options: - --sockets INT Number of sockets (default: $sockets) --cores INT Number of cores (default: $cores) --memory INT Memory (default: $memory) - --debug Run this script in debug mode + --sockets INT Number of sockets (default: $sockets) -Others: + --debug Run this script in debug mode (default: $debug) -h|-?|--help Show this help and exit + +Options can also be provided by adding assignments to a '.proxmox' file in the +current working directory. For instance, it could contain: + + cores=7 + username=mireille@pve + debug=true + +Command line options take precedence over options found in the '.proxmox' file. EOF } @@ -57,6 +60,10 @@ die_with_help () { printf '\033[31m'; printf "$@"; printf '\033[0m\n'; help; exi # shellcheck disable=SC2059 debug () { if $debug; then printf >&2 '\033[37m'; printf >&2 "$@"; printf >&2 '\033[0m\n'; fi } +if [ -f .proxmox ]; then + . "$PWD"/.proxmox +fi + while [ $# -gt 0 ]; do argument=$1 shift @@ -78,12 +85,12 @@ while [ $# -gt 0 ]; do esac done +if [ -z "$vm_ids" ]; then + die_with_help "Required: at least one VM id.\n" +fi + if [ -z "$username" ] || [ -z "$password" ]; then - if [ -f .proxmox ]; then - { read -r username; read -r password; } < .proxmox - else - die_with_help "Required: '--username' and '--password'.\n" - fi + die_with_help "Required: '--username' and '--password'.\n" fi readonly sockets diff --git a/deployment/proxmox/remove.sh b/deployment/proxmox/remove.sh index b84323cf..9555380b 100755 --- a/deployment/proxmox/remove.sh +++ b/deployment/proxmox/remove.sh @@ -11,7 +11,7 @@ readonly api_url=https://192.168.51.81:8006/api2/json ## now, let us just use `node051` everywhere. readonly node=node051 -readonly tmpdir=/tmp/proxmox-provision-$RANDOM +readonly tmpdir=/tmp/proxmox-remove-$RANDOM mkdir $tmpdir ################################################################################ @@ -23,18 +23,22 @@ vm_ids= help () { cat <<EOF -Usage: $0 [OPTION...] [ID...] +Usage: $0 [OPTION...] ID [ID...] -Authentication options: +Options: --username STR Username, with provider (eg. niols@pve) --password STR Password - If not provided via the command line, username and password will be looked for - in a '.proxmox' file in the current working directory, the username on the - first line, and the password on the second. - -Others: -h|-?|--help Show this help and exit + +Options can also be provided by adding assignments to a '.proxmox' file in the +current working directory. For instance, it could contain: + + cores=7 + username=mireille@pve + debug=true + +Command line options take precedence over options found in the '.proxmox' file. EOF } @@ -43,6 +47,10 @@ die () { printf '\033[31m'; printf "$@"; printf '\033[0m\n'; exit 2; } # shellcheck disable=SC2059 die_with_help () { printf '\033[31m'; printf "$@"; printf '\033[0m\n'; help; exit 2; } +if [ -f .proxmox ]; then + . "$PWD"/.proxmox +fi + while [ $# -gt 0 ]; do argument=$1 shift @@ -58,12 +66,12 @@ while [ $# -gt 0 ]; do esac done +if [ -z "$vm_ids" ]; then + die_with_help "Required: at least one VM id.\n" +fi + if [ -z "$username" ] || [ -z "$password" ]; then - if [ -f .proxmox ]; then - { read -r username; read -r password; } < .proxmox - else - die_with_help "Required: '--username' and '--password'.\n" - fi + die_with_help "Required: '--username' and '--password'.\n" fi ################################################################################ diff --git a/infra/flake-part.nix b/infra/flake-part.nix index 0896479a..b6208ee3 100644 --- a/infra/flake-part.nix +++ b/infra/flake-part.nix @@ -31,6 +31,8 @@ let in { + flake.lib.makeInstaller = import ./makeInstaller.nix; + nixops4Deployments = makeDeployments (addDefaultDeployment { git = [ "vm02116" diff --git a/deployment/makeInstaller.nix b/infra/makeInstaller.nix similarity index 91% rename from deployment/makeInstaller.nix rename to infra/makeInstaller.nix index a5f787ef..a6155ce3 100644 --- a/deployment/makeInstaller.nix +++ b/infra/makeInstaller.nix @@ -7,8 +7,8 @@ { nixpkgs, hostKeys ? { }, + nixosConfiguration, }: -machine: let inherit (builtins) concatStringsSep attrValues mapAttrs; @@ -25,8 +25,8 @@ let name = "bootstrap"; runtimeInputs = with pkgs; [ nixos-install-tools ]; text = '' - ${machine.config.system.build.diskoScript} - nixos-install --no-root-password --no-channel-copy --system ${machine.config.system.build.toplevel} + ${nixosConfiguration.config.system.build.diskoScript} + nixos-install --no-root-password --no-channel-copy --system ${nixosConfiguration.config.system.build.toplevel} ${concatStringsSep "\n" ( attrValues ( mapAttrs (kind: keys: ''