From 82bb3c29fc5bba80be988d9c3ad2a59813be2d93 Mon Sep 17 00:00:00 2001 From: Michael van Straten Date: Thu, 3 Oct 2024 13:43:22 +0200 Subject: [PATCH] Add host configuration for strato server --- flake.lock | 21 ++++++++++ flake.nix | 7 +++- nixosConfigurations/default.nix | 36 +++++++++--------- .../hosts/h2946065/configuration.nix | 38 +++++++++++++++++++ .../hosts/h2946065/virtual-disk-MBR.nix | 37 ++++++++++++++++++ .../modules/hardware/libvirtd.nix | 20 ++++++++++ 6 files changed, 139 insertions(+), 20 deletions(-) create mode 100644 nixosConfigurations/hosts/h2946065/configuration.nix create mode 100644 nixosConfigurations/hosts/h2946065/virtual-disk-MBR.nix create mode 100644 nixosConfigurations/modules/hardware/libvirtd.nix diff --git a/flake.lock b/flake.lock index 9a5ba86..f35a2f0 100644 --- a/flake.lock +++ b/flake.lock @@ -16,6 +16,26 @@ "type": "github" } }, + "disko": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1728109432, + "narHash": "sha256-wmbErh8FG7dRKOtMMpHUqDtFjeqt9Zjx4zssSeTalwU=", + "owner": "nix-community", + "repo": "disko", + "rev": "48ebb577855fb2398653f033b3b2208a9249203d", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "disko", + "type": "github" + } + }, "flake-compat": { "flake": false, "locked": { @@ -389,6 +409,7 @@ "root": { "inputs": { "cyberdream-theme": "cyberdream-theme", + "disko": "disko", "flake-utils": "flake-utils", "home-manager": "home-manager", "neovim-nightly-overlay": "neovim-nightly-overlay", diff --git a/flake.nix b/flake.nix index affcd10..f30a11a 100644 --- a/flake.nix +++ b/flake.nix @@ -28,6 +28,11 @@ url = "github:bandithedoge/nixpkgs-firefox-darwin"; inputs.nixpkgs.follows = "nixpkgs"; }; + + disko = { + url = "github:nix-community/disko"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = @@ -43,7 +48,7 @@ { darwinConfigurations = import ./darwinConfigurations { inherit inputs nix-darwin home-manager; }; - nixosConfigurations = import ./nixosConfigurations { inherit nixpkgs; }; + nixosConfigurations = import ./nixosConfigurations { inherit inputs nixpkgs; }; } // flake-utils.lib.eachDefaultSystem ( system: diff --git a/nixosConfigurations/default.nix b/nixosConfigurations/default.nix index b356155..9950e15 100644 --- a/nixosConfigurations/default.nix +++ b/nixosConfigurations/default.nix @@ -1,21 +1,19 @@ -{ nixpkgs, ... }: +{ inputs, nixpkgs, ... }: let - lib = nixpkgs.lib; - hostConfigurations = lib.filesystem.listFilesRecursive ./hosts; + inherit (nixpkgs.lib) nixosSystem; + + defaultArgs = { + specialArgs = { + make-disk-image = import "${nixpkgs}/nixos/lib/make-disk-image.nix"; + inherit inputs; + }; + }; + in -lib.mergeAttrsList ( - builtins.map ( - hostConfiguration: - let - nixosConfiguration = nixpkgs.lib.nixosSystem { - modules = [ hostConfiguration ]; - specialArgs = { - make-disk-image = import "${nixpkgs}/nixos/lib/make-disk-image.nix"; - }; - }; - in - { - ${nixosConfiguration.config.networking.hostName} = nixosConfiguration; - } - ) hostConfigurations -) +{ + h2946065 = nixosSystem (defaultArgs // { modules = [ ./hosts/h2946065/configuration.nix ]; }); + + rack-01-k8s-master-nuc-01 = nixosSystem ( + defaultArgs // { modules = [ ./hosts/rack-01/k8s-master-nuc-01.nix ]; } + ); +} diff --git a/nixosConfigurations/hosts/h2946065/configuration.nix b/nixosConfigurations/hosts/h2946065/configuration.nix new file mode 100644 index 0000000..c44ce91 --- /dev/null +++ b/nixosConfigurations/hosts/h2946065/configuration.nix @@ -0,0 +1,38 @@ +{ pkgs, ... }: +{ + imports = [ + ../../modules + ../../modules/hardware/libvirtd.nix + ./virtual-disk-MBR.nix + ]; + + networking.hostName = "h2946065"; + + nixpkgs.hostPlatform = "x86_64-linux"; + + services.openssh = { + enable = true; + ports = [ 22 ]; + settings = { + PasswordAuthentication = false; + PermitRootLogin = "no"; + }; + }; + + boot.kernel.sysctl = { + "net.ipv4.ip_unprivileged_port_start" = 80; + + }; + + users.users.michael.extraGroups = [ "docker" ]; + + virtualisation.docker.enable = true; + + networking.firewall.enable = false; + + environment.systemPackages = [ pkgs.docker-compose ]; + + time.timeZone = "Europe/Berlin"; + + system.stateVersion = "25.11"; +} diff --git a/nixosConfigurations/hosts/h2946065/virtual-disk-MBR.nix b/nixosConfigurations/hosts/h2946065/virtual-disk-MBR.nix new file mode 100644 index 0000000..cbf20c7 --- /dev/null +++ b/nixosConfigurations/hosts/h2946065/virtual-disk-MBR.nix @@ -0,0 +1,37 @@ +{ inputs, ... }: +{ + imports = [ inputs.disko.nixosModules.disko ]; + + disko.devices = { + disk = { + main = { + device = "/dev/vda"; + type = "disk"; + content = { + type = "gpt"; + partitions = { + boot = { + size = "1M"; + type = "EF02"; # for grub MBR + # content = { + # mountpoint = "/boot"; + # }; + }; + root = { + size = "100%"; + content = { + type = "btrfs"; + extraArgs = [ "-f" ]; # Override existing partition + mountpoint = "/"; + mountOptions = [ + "compress=zstd" + "noatime" + ]; + }; + }; + }; + }; + }; + }; + }; +} diff --git a/nixosConfigurations/modules/hardware/libvirtd.nix b/nixosConfigurations/modules/hardware/libvirtd.nix new file mode 100644 index 0000000..a68d50f --- /dev/null +++ b/nixosConfigurations/modules/hardware/libvirtd.nix @@ -0,0 +1,20 @@ +{ modulesPath, ... }: +{ + imports = [ (modulesPath + "/profiles/qemu-guest.nix") ]; + + boot.initrd.availableKernelModules = [ + "ata_piix" + "uhci_hcd" + "virtio_pci" + "sr_mod" + "virtio_blk" + ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-intel" ]; + boot.extraModulePackages = [ ]; + + boot.kernelParams = [ + "console=tty1" + "console=ttyS0,115200" + ]; +}