From c153851ba4ed40fcef2d346a97191d697a6dac93 Mon Sep 17 00:00:00 2001 From: System administrator Date: Tue, 13 May 2025 11:09:08 +0000 Subject: [PATCH] Initial commit --- configuration.nix | 31 ++++++++++++++++++ disk-config.nix | 57 +++++++++++++++++++++++++++++++++ flake.nix | 81 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 169 insertions(+) create mode 100644 configuration.nix create mode 100644 disk-config.nix create mode 100644 flake.nix diff --git a/configuration.nix b/configuration.nix new file mode 100644 index 0000000..386fb0c --- /dev/null +++ b/configuration.nix @@ -0,0 +1,31 @@ +{ + modulesPath, + lib, + pkgs, + ... +}: +{ + imports = [ + (modulesPath + "/installer/scan/not-detected.nix") + (modulesPath + "/profiles/qemu-guest.nix") + ./disk-config.nix + ]; + boot.loader.grub = { + # no need to set devices, disko will add all devices that have a EF02 partition to the list already + # devices = [ ]; + efiSupport = true; + efiInstallAsRemovable = true; + }; + services.openssh.enable = true; + + environment.systemPackages = map lib.lowPrio [ + pkgs.curl + pkgs.gitMinimal + ]; + + users.users.root.openssh.authorizedKeys.keys = [ + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHDuOIycRP7Ney136ro/doWj1kttJUqmbGz6OC2nia09 michael.huebner@ptspaper.de" + ]; + + system.stateVersion = "24.05"; +} diff --git a/disk-config.nix b/disk-config.nix new file mode 100644 index 0000000..f2b3408 --- /dev/null +++ b/disk-config.nix @@ -0,0 +1,57 @@ +# Example to create a bios compatible gpt partition +{ lib, ... }: +{ + disko.devices = { + disk.disk1 = { + device = lib.mkDefault "/dev/nvme0n1"; + type = "disk"; + content = { + type = "gpt"; + partitions = { + boot = { + name = "boot"; + size = "1M"; + type = "EF02"; + }; + esp = { + name = "ESP"; + size = "1G"; + type = "EF00"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + }; + }; + root = { + name = "root"; + size = "100%"; + content = { + type = "lvm_pv"; + vg = "pool"; + }; + }; + }; + }; + }; + lvm_vg = { + pool = { + type = "lvm_vg"; + lvs = { + root = { + size = "100%FREE"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + mountOptions = [ + "defaults" + ]; + }; + }; + }; + }; + }; + }; +} + diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..93cd82b --- /dev/null +++ b/flake.nix @@ -0,0 +1,81 @@ +{ + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + inputs.disko.url = "github:nix-community/disko"; + inputs.disko.inputs.nixpkgs.follows = "nixpkgs"; + inputs.nixos-facter-modules.url = "github:numtide/nixos-facter-modules"; + + outputs = + { + nixpkgs, + disko, + nixos-facter-modules, + ... + }: + { + nixosConfigurations.hetzner-cloud = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + disko.nixosModules.disko + ./configuration.nix + ]; + }; + # tested with 2GB/2CPU droplet, 1GB droplets do not have enough RAM for kexec + nixosConfigurations.digitalocean = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + disko.nixosModules.disko + { disko.devices.disk.disk1.device = "/dev/vda"; } + { + # do not use DHCP, as DigitalOcean provisions IPs using cloud-init + networking.useDHCP = nixpkgs.lib.mkForce false; + + services.cloud-init = { + enable = true; + network.enable = true; + settings = { + datasource_list = [ "ConfigDrive" ]; + datasource.ConfigDrive = { }; + }; + }; + } + ./configuration.nix + ]; + }; + nixosConfigurations.hetzner-cloud-aarch64 = nixpkgs.lib.nixosSystem { + system = "aarch64-linux"; + modules = [ + disko.nixosModules.disko + ./configuration.nix + ]; + }; + + # Use this for all other targets + # nixos-anywhere --flake .#generic --generate-hardware-config nixos-generate-config ./hardware-configuration.nix + nixosConfigurations.generic = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + disko.nixosModules.disko + ./configuration.nix + ./hardware-configuration.nix + ]; + }; + + # Slightly experimental: Like generic, but with nixos-facter (https://github.com/numtide/nixos-facter) + # nixos-anywhere --flake .#generic-nixos-facter --generate-hardware-config nixos-facter facter.json + nixosConfigurations.generic-nixos-facter = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + disko.nixosModules.disko + ./configuration.nix + nixos-facter-modules.nixosModules.facter + { + config.facter.reportPath = + if builtins.pathExists ./facter.json then + ./facter.json + else + throw "Have you forgotten to run nixos-anywhere with `--generate-hardware-config nixos-facter ./facter.json`?"; + } + ]; + }; + }; +}