set hostName and domain in nixos config directly
This commit is contained in:
parent
371b851ca5
commit
bd5dc4b883
5 changed files with 55 additions and 45 deletions
16
flake.nix
16
flake.nix
|
@ -40,18 +40,19 @@
|
|||
pkgs-unstable = nixpkgs-unstable.legacyPackages.${system};
|
||||
machines = import ./nixos/machines;
|
||||
physicalMachines = lib.filterAttrs (n: v: v.type == "physical") machines;
|
||||
# TODO: Maybe use mergeAttrLists
|
||||
# TODO: Use mergeAttrLists
|
||||
mkNixosSystems = systemDef:
|
||||
nixpkgs.lib.foldlAttrs
|
||||
(acc: name: machine:
|
||||
acc // {
|
||||
"${name}" = nixpkgs.lib.nixosSystem (systemDef machine);
|
||||
"${name}" = nixpkgs.lib.nixosSystem (systemDef name machine);
|
||||
})
|
||||
{ }
|
||||
physicalMachines;
|
||||
mkDeployNodes = nodeDef:
|
||||
# TODO: Use mergeAttrLists
|
||||
nixpkgs.lib.foldlAttrs
|
||||
(acc: name: machine: acc // { "${name}" = nodeDef machine; })
|
||||
(acc: name: machine: acc // { "${name}" = nodeDef name machine; })
|
||||
{ }
|
||||
physicalMachines;
|
||||
in
|
||||
|
@ -75,7 +76,7 @@
|
|||
|
||||
formatter.${system} = pkgs.nixfmt;
|
||||
|
||||
nixosConfigurations = mkNixosSystems (machine: {
|
||||
nixosConfigurations = mkNixosSystems (name: machine: {
|
||||
inherit system;
|
||||
specialArgs = { inherit machines machine kubenix dns microvm disko agenix; };
|
||||
modules = [ ./nixos ];
|
||||
|
@ -85,12 +86,11 @@
|
|||
sshUser = "root";
|
||||
user = "root";
|
||||
|
||||
nodes = mkDeployNodes (machine: {
|
||||
# TODO: simply get this from nixos configuration?
|
||||
hostname = "${machine.hostName}.${machine.domain}";
|
||||
nodes = mkDeployNodes (name: machine: {
|
||||
hostname = self.nixosConfigurations.${name}.config.networking.fqdn;
|
||||
profiles.system = {
|
||||
path = deploy-rs.lib.${system}.activate.nixos
|
||||
self.nixosConfigurations.${machine.hostName};
|
||||
self.nixosConfigurations.${name};
|
||||
};
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,35 +1,44 @@
|
|||
{
|
||||
jefke = {
|
||||
# TODO: directly set and read this from nixos config.
|
||||
hostName = "jefke";
|
||||
domain = "hyp";
|
||||
# TODO: model this in a nixos module?
|
||||
type = "physical";
|
||||
|
||||
nixosModule.lab = {
|
||||
terraformDatabase.enable = true;
|
||||
|
||||
storage = {
|
||||
osDisk = "/dev/sda";
|
||||
dataPartition = "/dev/nvme0n1p1";
|
||||
nixosModule = {
|
||||
networking = {
|
||||
hostName = "jefke";
|
||||
# TODO: generate this using type?
|
||||
domain = "hyp";
|
||||
};
|
||||
|
||||
ssh = {
|
||||
useCertificates = true;
|
||||
# TODO: automatically set this?
|
||||
hostCert = builtins.readFile ./jefke_host_ed25519-cert.pub;
|
||||
userCert = builtins.readFile ./jefke_user_ed25519-cert.pub;
|
||||
lab = {
|
||||
terraformDatabase.enable = true;
|
||||
|
||||
storage = {
|
||||
osDisk = "/dev/sda";
|
||||
dataPartition = "/dev/nvme0n1p1";
|
||||
};
|
||||
|
||||
ssh = {
|
||||
useCertificates = true;
|
||||
# TODO: automatically set this?
|
||||
hostCert = builtins.readFile ./jefke_host_ed25519-cert.pub;
|
||||
userCert = builtins.readFile ./jefke_user_ed25519-cert.pub;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
atlas = {
|
||||
hostName = "atlas";
|
||||
domain = "hyp";
|
||||
type = "physical";
|
||||
|
||||
nixosModule = { config, ... }:
|
||||
let inherit (config.lab.networking) dmzServicesIPv4 dmzServicesIPv6; in
|
||||
{
|
||||
networking = {
|
||||
hostName = "atlas";
|
||||
domain = "hyp";
|
||||
};
|
||||
|
||||
lab = {
|
||||
networking = {
|
||||
# TODO: Ideally, we don't have to set this here.
|
||||
|
@ -53,11 +62,14 @@
|
|||
};
|
||||
|
||||
lewis = {
|
||||
hostName = "lewis";
|
||||
domain = "hyp";
|
||||
type = "physical";
|
||||
|
||||
nixosModule = { pkgs, ... }: {
|
||||
networking = {
|
||||
hostName = "lewis";
|
||||
domain = "hyp";
|
||||
};
|
||||
|
||||
lab = {
|
||||
dataHost.enable = true;
|
||||
|
||||
|
@ -76,8 +88,6 @@
|
|||
};
|
||||
|
||||
my-microvm = {
|
||||
hostName = "my-microvm";
|
||||
domain = "dmz";
|
||||
type = "virtual";
|
||||
hypervisorName = "lewis";
|
||||
|
||||
|
@ -86,6 +96,11 @@
|
|||
echo "Hello world from inside a virtual machine!!" | ${pkgs.lolcat}/bin/lolcat
|
||||
'';
|
||||
|
||||
networking = {
|
||||
hostName = "my-microvm";
|
||||
domain = "dmz";
|
||||
};
|
||||
|
||||
lab.vmMacAddress = "BA:DB:EE:F0:00:00";
|
||||
};
|
||||
};
|
||||
|
|
|
@ -89,8 +89,6 @@ in {
|
|||
|
||||
config = {
|
||||
networking = {
|
||||
hostName = machine.hostName;
|
||||
domain = machine.domain;
|
||||
nftables.enable = true;
|
||||
useDHCP = machine.type == "virtual";
|
||||
|
||||
|
|
|
@ -58,23 +58,20 @@
|
|||
|
||||
microvm.vms =
|
||||
let
|
||||
vmsForHypervisor = lib.attrValues (lib.filterAttrs (n: v: v.type == "virtual" && v.hypervisorName == machine.hostName) machines);
|
||||
vmsForHypervisor = lib.filterAttrs (n: v: v.type == "virtual" && v.hypervisorName == config.networking.hostName) machines;
|
||||
in
|
||||
lib.attrsets.mergeAttrsList (map
|
||||
(vm:
|
||||
builtins.mapAttrs
|
||||
(name: vm:
|
||||
{
|
||||
"${vm.hostName}" = {
|
||||
# TODO Simplify?
|
||||
specialArgs = { inherit agenix disko pkgs lib microvm; machine = vm; hypervisorConfig = config; };
|
||||
config = {
|
||||
imports = [
|
||||
./.
|
||||
];
|
||||
};
|
||||
# TODO Simplify?
|
||||
specialArgs = { inherit agenix disko pkgs lib microvm; machine = vm; hypervisorConfig = config; };
|
||||
config = {
|
||||
imports = [
|
||||
./.
|
||||
];
|
||||
};
|
||||
}
|
||||
)
|
||||
vmsForHypervisor
|
||||
);
|
||||
vmsForHypervisor;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{ lib, config, machine, hypervisorConfig, ... }: {
|
||||
{ lib, config, hypervisorConfig, ... }: {
|
||||
options.lab.vmMacAddress = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = ''
|
||||
|
@ -19,7 +19,7 @@
|
|||
|
||||
interfaces = [{
|
||||
type = "tap";
|
||||
id = "vm-${machine.hostName}";
|
||||
id = "vm-${config.networking.hostName}";
|
||||
mac = config.lab.vmMacAddress;
|
||||
}];
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue