Allow all ids between 100 and 255
This commit is contained in:
parent
d719a974c2
commit
e275808313
35
flake.nix
35
flake.nix
|
@ -44,18 +44,23 @@
|
|||
devShells.default = pkgs.mkShell { packages = [ inputs'.nixops4.packages.default ]; };
|
||||
};
|
||||
|
||||
flake.allVmIds = [
|
||||
"101"
|
||||
"102"
|
||||
"103"
|
||||
"104"
|
||||
"105"
|
||||
"106"
|
||||
"107"
|
||||
"108"
|
||||
"109"
|
||||
"110"
|
||||
];
|
||||
flake.vmIdTo03d =
|
||||
id:
|
||||
let
|
||||
sid = toString id;
|
||||
in
|
||||
if id >= 0 && id <= 9 then
|
||||
"00${sid}"
|
||||
else if id >= 10 && id <= 99 then
|
||||
"0${sid}"
|
||||
else
|
||||
sid;
|
||||
|
||||
flake.allVmIds = # 100 -- 255
|
||||
let
|
||||
allVmIdsFrom = x: if x > 255 then [ ] else [ x ] ++ allVmIdsFrom (x + 1);
|
||||
in
|
||||
allVmIdsFrom 100;
|
||||
|
||||
flake.nixosConfigurations.provisioning =
|
||||
let
|
||||
|
@ -72,7 +77,7 @@
|
|||
in
|
||||
listToAttrs (
|
||||
map (vmid: {
|
||||
name = "fedi${vmid}";
|
||||
name = "fedi${self.vmIdTo03d vmid}";
|
||||
value = makeProvisioningConfiguration vmid;
|
||||
}) self.allVmIds
|
||||
);
|
||||
|
@ -108,8 +113,8 @@
|
|||
type = providers.local.exec;
|
||||
imports = [ inputs.nixops4-nixos.modules.nixops4Resource.nixos ];
|
||||
ssh.opts = "";
|
||||
ssh.host = "95.215.187.${vmid}";
|
||||
ssh.hostPublicKey = readFile ./hostKeys/fedi${vmid}/ssh_host_ed25519_key.pub;
|
||||
ssh.host = "95.215.187.${self.vmIdTo03d vmid}";
|
||||
ssh.hostPublicKey = readFile ./hostKeys/fedi${self.vmIdTo03d vmid}/ssh_host_ed25519_key.pub;
|
||||
|
||||
nixpkgs = inputs.nixpkgs;
|
||||
nixos.module =
|
||||
|
|
|
@ -9,17 +9,28 @@ let
|
|||
inherit (lib) mkOption;
|
||||
inherit (lib.types) types;
|
||||
|
||||
vmIdTo03d =
|
||||
id:
|
||||
let
|
||||
sid = toString id;
|
||||
in
|
||||
if id >= 0 && id <= 9 then
|
||||
"00${sid}"
|
||||
else if id >= 10 && id <= 99 then
|
||||
"0${sid}"
|
||||
else
|
||||
sid;
|
||||
in
|
||||
|
||||
{
|
||||
imports = [ (modulesPath + "/profiles/qemu-guest.nix") ];
|
||||
|
||||
options = {
|
||||
procolix = {
|
||||
vmid = mkOption {
|
||||
type = types.str;
|
||||
type = types.int;
|
||||
description = ''
|
||||
Identifier of the machine. This is a number between 10 and 255, padded
|
||||
with zeroes to always be three characters.
|
||||
Identifier of the machine. This is a number between 10 and 255.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
@ -32,7 +43,7 @@ in
|
|||
services.openssh.enable = true;
|
||||
|
||||
networking = {
|
||||
hostName = "fedi${config.procolix.vmid}";
|
||||
hostName = "fedi${vmIdTo03d config.procolix.vmid}";
|
||||
domain = "procolix.com";
|
||||
|
||||
interfaces = {
|
||||
|
@ -40,7 +51,7 @@ in
|
|||
ipv4 = {
|
||||
addresses = [
|
||||
{
|
||||
address = "95.215.187.${config.procolix.vmid}";
|
||||
address = "95.215.187.${vmIdTo03d config.procolix.vmid}";
|
||||
prefixLength = 24;
|
||||
}
|
||||
];
|
||||
|
@ -48,7 +59,7 @@ in
|
|||
ipv6 = {
|
||||
addresses = [
|
||||
{
|
||||
address = "2a00:51c0:13:1305::${config.procolix.vmid}";
|
||||
address = "2a00:51c0:13:1305::${vmIdTo03d config.procolix.vmid}";
|
||||
prefixLength = 64;
|
||||
}
|
||||
];
|
||||
|
|
|
@ -162,7 +162,7 @@ printf 'Creating VM...'
|
|||
http_ --form POST $apiurl/nodes/$node/qemu \
|
||||
\
|
||||
vmid==$vmid \
|
||||
name==fedi$vmid \
|
||||
name==$(printf 'fedi%03d' $vmid) \
|
||||
pool==Fediversity \
|
||||
\
|
||||
ide2=="local:iso/$isoname,media=cdrom" \
|
||||
|
|
Reference in a new issue