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