Attempt to implement and test setting static ips from instance metadata
This commit is contained in:
parent
dd1cfa79e7
commit
47dbb7cdd3
16 changed files with 258 additions and 59 deletions
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
system,
|
||||
...
|
||||
}:
|
||||
|
@ -10,16 +11,16 @@ in
|
|||
{
|
||||
options.khscodes.hetzner = {
|
||||
enable = lib.mkEnableOption "Enables the machine as a hetzner machine";
|
||||
ipv6-addr = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
description = "IPv6 address of the server, for now detecting this from the server itself is not supported";
|
||||
default = null;
|
||||
};
|
||||
diskName = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "nixos";
|
||||
description = "Name of the root disk device";
|
||||
};
|
||||
metadataApiUri = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
description = "Sets the metadata API url that the server will contact to gather metadata information from. Should probably only be used for testing";
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
|
@ -48,10 +49,29 @@ in
|
|||
networkConfig = {
|
||||
DHCP = "ipv4";
|
||||
};
|
||||
routes = [ { Gateway = "fe80::1"; } ];
|
||||
linkConfig.RequiredForOnline = "routable";
|
||||
address = lib.mkIf (cfg.ipv6-addr != null) [ cfg.ipv6-addr ];
|
||||
};
|
||||
};
|
||||
|
||||
systemd.services.hetzner-static-ip = {
|
||||
enable = true;
|
||||
wants = [ "network-online.target" ];
|
||||
after = [ "network-online.target" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
RemainAfterExit = true;
|
||||
ExecStart = ''
|
||||
${lib.getExe pkgs.khscodes.hetzner-static-ip} configure
|
||||
'';
|
||||
};
|
||||
environment =
|
||||
{
|
||||
PATH = lib.mkForce "";
|
||||
}
|
||||
// lib.attrsets.optionalAttrs (cfg.metadataApiUri != null) {
|
||||
INSTANCE_API_URI = cfg.metadataApiUri;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue