diff --git a/.gitignore b/.gitignore index db504ee..3f83c66 100644 --- a/.gitignore +++ b/.gitignore @@ -34,7 +34,9 @@ override.tf.json .terraformrc terraform.rc - # ENV .env admin.*config + +# Nix +**/result/* diff --git a/proxmox.tjo.cloud/configuration.nix b/proxmox.tjo.cloud/configuration.nix index 73a8890..8beb391 100644 --- a/proxmox.tjo.cloud/configuration.nix +++ b/proxmox.tjo.cloud/configuration.nix @@ -1,8 +1,45 @@ -{ lib, pkgs, ... }: { + config, + lib, + pkgs, + modulesPath, + ... +}: +{ + imports = [ + "${toString modulesPath}/profiles/qemu-guest.nix" + ]; + system.stateVersion = "24.05"; + fileSystems."/" = { + device = "/dev/disk/by-label/nixos"; + autoResize = true; + fsType = "ext4"; + }; + + fileSystems."/boot" = { + device = "/dev/disk/by-label/ESP"; + fsType = "vfat"; + }; + + boot.growPartition = true; + boot.kernelParams = [ "console=ttyS0" ]; boot.loader.systemd-boot.enable = true; + #boot.loader.grub.device = "nodev"; + #boot.loader.grub.efiSupport = true; + #boot.loader.grub.efiInstallAsRemovable = true; + boot.loader.timeout = 0; + + system.build.qcow2 = import "${toString modulesPath}/../lib/make-disk-image.nix" { + inherit lib config pkgs; + name = "nixos"; + diskSize = "auto"; + format = "qcow2-compressed"; + partitionTableType = "efi"; + copyChannel = true; + configFile = pkgs.writeText "configuration.nix" (pkgs.lib.readFile ./configuration.nix); + }; services.qemuGuest.enable = true; diff --git a/proxmox.tjo.cloud/flake.lock b/proxmox.tjo.cloud/flake.lock index a3c6069..3305ce1 100644 --- a/proxmox.tjo.cloud/flake.lock +++ b/proxmox.tjo.cloud/flake.lock @@ -1,56 +1,5 @@ { "nodes": { - "flake-utils": { - "locked": { - "lastModified": 1667395993, - "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "nixlib": { - "locked": { - "lastModified": 1723942470, - "narHash": "sha256-QdSArN0xKESEOTcv+3kE6yu4B4WX9lupZ4+Htx3RXGg=", - "owner": "nix-community", - "repo": "nixpkgs.lib", - "rev": "531a2e8416a6d8200a53eddfbdb8f2c8dc4a1251", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "nixpkgs.lib", - "type": "github" - } - }, - "nixos-generators": { - "inputs": { - "nixlib": "nixlib", - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1724028932, - "narHash": "sha256-U11ZiQPrpIBdv7oS23bNdX9GCxe/hPf/ARr64P2Wj1Y=", - "owner": "nix-community", - "repo": "nixos-generators", - "rev": "5fd22603892e4ec5ac6085058ed658243143aacd", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "nixos-generators", - "type": "github" - } - }, "nixpkgs": { "locked": { "lastModified": 1724316499, @@ -69,30 +18,7 @@ }, "root": { "inputs": { - "nixos-generators": "nixos-generators", - "nixpkgs": "nixpkgs", - "xc": "xc" - } - }, - "xc": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1724081153, - "narHash": "sha256-j2bfrmjBSf87ByVSGUaNzHk3Hh605/rOjar3slWAhjQ=", - "owner": "joerdav", - "repo": "xc", - "rev": "48e28d6f29623b0c2eedce688fcb7d29f0d2976e", - "type": "github" - }, - "original": { - "owner": "joerdav", - "repo": "xc", - "type": "github" + "nixpkgs": "nixpkgs" } } }, diff --git a/proxmox.tjo.cloud/flake.nix b/proxmox.tjo.cloud/flake.nix index 56f33ae..5c35f01 100644 --- a/proxmox.tjo.cloud/flake.nix +++ b/proxmox.tjo.cloud/flake.nix @@ -1,70 +1,18 @@ { + description = "Basic NixOS qcow2 image with CloudInit for Proxmox"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; - nixos-generators = { - url = "github:nix-community/nixos-generators"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - xc = { - url = "github:joerdav/xc"; - inputs.nixpkgs.follows = "nixpkgs"; - }; }; - outputs = + { self, nixpkgs }: { - nixpkgs, - nixos-generators, - xc, - ... - }: - let - pkgsForSystem = - system: - import nixpkgs { - inherit system; - overlays = [ (final: prev: { xc = xc.packages.${system}.xc; }) ]; + nixosConfigurations = { + build-qcow2 = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + ./configuration.nix + ]; }; - allVMs = [ - "x86_64-linux" - "aarch64-linux" - ]; - forAllVMs = - f: - nixpkgs.lib.genAttrs allVMs ( - system: - f { - inherit system; - pkgs = pkgsForSystem system; - } - ); - in - { - packages = forAllVMs ( - { system, pkgs }: - { - vm = nixos-generators.nixosGenerate { - format = "qcow-efi"; - system = system; - - specialArgs = { - pkgs = pkgs; - }; - - modules = [ - # Pin nixpkgs to the flake input, so that the packages installed - # come from the flake inputs.nixpkgs.url. - ( - { ... }: - { - nix.registry.nixpkgs.flake = nixpkgs; - } - ) - # Apply the rest of the config. - ./configuration.nix - ]; - }; - } - ); + }; }; } diff --git a/proxmox.tjo.cloud/justfile b/proxmox.tjo.cloud/justfile index 7563008..555c2de 100644 --- a/proxmox.tjo.cloud/justfile +++ b/proxmox.tjo.cloud/justfile @@ -2,11 +2,11 @@ default: @just --list build: - @nix build .#vm + @nix build .#nixosConfigurations.build-qcow2.config.system.build.qcow2 apply: build #!/usr/bin/env sh - export NIXOS_IMAGE=$(nix path-info --quiet .#vm)/nixos.qcow2 + export NIXOS_IMAGE=$(nix path-info --quiet .#nixosConfigurations.build-qcow2.config.system.build.qcow2)/nixos.qcow2 export TF_VAR_image_path=$NIXOS_IMAGE echo "Deploying $NIXOS_IMAGE"