From 3d875fd981291da9860656a1bd5a41e0b247bd51 Mon Sep 17 00:00:00 2001 From: Victor Date: Sat, 7 Jan 2023 12:52:42 +0100 Subject: [PATCH] refactor templates --- flake.nix | 47 ++++++++++++++++++------- nixos/common/generic-vm.nix | 7 +--- nixos/{ => templates}/iso-graphical.nix | 0 nixos/{ => templates}/iso.nix | 0 nixos/{ => templates}/proxmox-lxc.nix | 4 +-- nixos/templates/proxmox-vm.nix | 28 +++++++++++++++ 6 files changed, 65 insertions(+), 21 deletions(-) rename nixos/{ => templates}/iso-graphical.nix (100%) rename nixos/{ => templates}/iso.nix (100%) rename nixos/{ => templates}/proxmox-lxc.nix (82%) create mode 100644 nixos/templates/proxmox-vm.nix diff --git a/flake.nix b/flake.nix index 7d18751..44d8b52 100644 --- a/flake.nix +++ b/flake.nix @@ -49,9 +49,20 @@ nixos-hardware.url = "github:NixOS/nixos-hardware/master"; }; - outputs = { self, nixpkgs, vault-secrets, minecraft-servers, colmena - , home-manager, hyprpaper, hyprland, nixos-generators, nixos-hardware, nur - , ... }@inputs: + outputs = + { self + , nixpkgs + , vault-secrets + , minecraft-servers + , colmena + , home-manager + , hyprpaper + , hyprland + , nixos-generators + , nixos-hardware + , nur + , ... + }@inputs: let inherit (nixpkgs) lib; @@ -90,7 +101,8 @@ source /etc/set-environment nix repl --file "${./.}/repl.nix" $@ ''; - in { + in + { # Make the nixosConfigurations for compat reasons nixosConfigurations = (import (inputs.colmena + "/src/nix/hive/eval.nix") { @@ -102,12 +114,14 @@ }).nodes; # Make the colmena configuration - colmena = lib.foldr (el: acc: acc // util.mkColmenaHost el) { - meta = { - inherit specialArgs; - nixpkgs = pkgs; - }; - } nixHosts; + colmena = lib.foldr (el: acc: acc // util.mkColmenaHost el) + { + meta = { + inherit specialArgs; + nixpkgs = pkgs; + }; + } + nixHosts; packages.${system} = { inherit apply-local; @@ -117,19 +131,26 @@ iso = nixos-generators.nixosGenerate { inherit system pkgs; format = "iso"; - modules = [ (import ./nixos/iso.nix) ]; + modules = [ (import ./nixos/templates/iso.nix) ]; }; iso-graphical = nixos-generators.nixosGenerate { inherit system pkgs; format = "iso"; - modules = [ (import ./nixos/iso-graphical.nix) ]; + modules = [ (import ./nixos/templates/iso-graphical.nix) ]; }; proxmox-lxc = nixos-generators.nixosGenerate { inherit system pkgs; format = "proxmox-lxc"; - modules = [ (import ./nixos/proxmox-lxc.nix) ]; + modules = [ (import ./nixos/templates/proxmox-lxc.nix) ]; + }; + + # Currently broken as it assumes `local-lvm` exists + proxmox-vm = nixos-generators.nixosGenerate { + inherit system pkgs; + format = "proxmox"; + modules = [ (import ./nixos/templates/proxmox-vm.nix) ]; }; }; diff --git a/nixos/common/generic-vm.nix b/nixos/common/generic-vm.nix index dc8aeb8..856a8b3 100644 --- a/nixos/common/generic-vm.nix +++ b/nixos/common/generic-vm.nix @@ -1,10 +1,5 @@ { lib, ... }: { - - # The global useDHCP flag is deprecated, therefore explicitly set to false here. - # Per-interface useDHCP will be mandatory in the future, so this generated config - # replicates the default behaviour. - networking.useDHCP = false; - networking.interfaces.ens18.useDHCP = lib.mkDefault true; + networking.useDHCP = true; # Enable qemu guest agent services.qemuGuest.enable = true; diff --git a/nixos/iso-graphical.nix b/nixos/templates/iso-graphical.nix similarity index 100% rename from nixos/iso-graphical.nix rename to nixos/templates/iso-graphical.nix diff --git a/nixos/iso.nix b/nixos/templates/iso.nix similarity index 100% rename from nixos/iso.nix rename to nixos/templates/iso.nix diff --git a/nixos/proxmox-lxc.nix b/nixos/templates/proxmox-lxc.nix similarity index 82% rename from nixos/proxmox-lxc.nix rename to nixos/templates/proxmox-lxc.nix index 8eac5c5..e748529 100644 --- a/nixos/proxmox-lxc.nix +++ b/nixos/templates/proxmox-lxc.nix @@ -1,5 +1,5 @@ { config, pkgs, lib, ... }: { - imports = [ ./common/common.nix ./common/generic-lxc.nix ]; + imports = [ ../common/common.nix ../common/generic-lxc.nix ]; proxmoxLXC = { manageNetwork = true; @@ -21,7 +21,7 @@ networking.useDHCP = true; - system.stateVersion = "22.11"; + system.stateVersion = "23.05"; users.users.root.initialPassword = "toor"; } diff --git a/nixos/templates/proxmox-vm.nix b/nixos/templates/proxmox-vm.nix new file mode 100644 index 0000000..945cce3 --- /dev/null +++ b/nixos/templates/proxmox-vm.nix @@ -0,0 +1,28 @@ +{ config, pkgs, lib, ... }: { + imports = [ ../common/common.nix ../common/generic-vm.nix ]; + + proxmox.qemuConf = { + virtio0 = "local-zsfs:vm-9999-disk-0"; + cores = 1; + memory = 1024; + bios = "ovmf"; + }; + + # Enable SSH + services.openssh = { + enable = true; + passwordAuthentication = false; + permitRootLogin = "yes"; + openFirewall = true; + }; + + networking.hostName = lib.mkDefault "template"; + + time.timeZone = lib.mkDefault "Europe/Amsterdam"; + + networking.useDHCP = true; + + system.stateVersion = "23.05"; + + users.users.root.initialPassword = "toor"; +}