From 7a14f3d49f113347175ff75589fc3304bdd2fe1a Mon Sep 17 00:00:00 2001 From: Andre-Philippe Paquet Date: Mon, 23 Dec 2024 12:00:50 -0500 Subject: [PATCH 1/6] servapp: initial move to nixos --- .github/workflows/push-check.yaml | 2 +- .github/workflows/updater.yaml | 6 +- flake.lock | 6 +- flake.nix | 17 +- home-manager/servapp.nix | 2 +- nixos/servapp/configuration.nix | 95 +++++++ nixos/servapp/hardware-configuration.nix | 53 ++++ nixos/servapp/virt/default.nix | 33 +++ nixos/servapp/virt/domains/homeassistant.xml | 250 +++++++++++++++++++ nixos/servapp/virt/domains/pihole.xml | 241 ++++++++++++++++++ nixos/servapp/virt/pools/download.xml | 15 ++ secrets | 2 +- x | 10 +- 13 files changed, 718 insertions(+), 14 deletions(-) create mode 100644 nixos/servapp/configuration.nix create mode 100644 nixos/servapp/hardware-configuration.nix create mode 100644 nixos/servapp/virt/default.nix create mode 100644 nixos/servapp/virt/domains/homeassistant.xml create mode 100644 nixos/servapp/virt/domains/pihole.xml create mode 100644 nixos/servapp/virt/pools/download.xml diff --git a/.github/workflows/push-check.yaml b/.github/workflows/push-check.yaml index 21d3005..88dcf68 100644 --- a/.github/workflows/push-check.yaml +++ b/.github/workflows/push-check.yaml @@ -58,7 +58,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - machine: ["appaquet@deskapp"] + machine: ["appaquet@deskapp", "appaquet@servapp"] steps: - uses: actions/checkout@v4 - uses: DeterminateSystems/nix-installer-action@main diff --git a/.github/workflows/updater.yaml b/.github/workflows/updater.yaml index c88ba2f..f486269 100644 --- a/.github/workflows/updater.yaml +++ b/.github/workflows/updater.yaml @@ -87,7 +87,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - machine: ["appaquet@deskapp"] + machine: ["appaquet@deskapp", "appaquet@servapp"] steps: - uses: actions/checkout@v4 @@ -107,7 +107,7 @@ jobs: - name: Building NixOS baseline run: | set -xe - MACHINE_KEY="appaquet@deskapp" ./x nixos build + MACHINE_KEY="${{ matrix.machine }}" ./x nixos build nix-collect-garbage # free up intermediary, since we're low on disk on gha mv result result-before @@ -119,7 +119,7 @@ jobs: - name: Building NixOS new run: | set -xe - MACHINE_KEY="appaquet@deskapp" ./x nixos build + MACHINE_KEY="${{ matrix.machine }}" ./x nixos build mv result result-after - name: Diffing... diff --git a/flake.lock b/flake.lock index 76c182c..7122db4 100644 --- a/flake.lock +++ b/flake.lock @@ -441,11 +441,11 @@ ] }, "locked": { - "lastModified": 1734116890, - "narHash": "sha256-5QVuAB30qgg07ryz7U5Ch33K5VPhUb3KS9uYasvntLs=", + "lastModified": 1734973134, + "narHash": "sha256-44vUcOsZRHWqV02XfCHfD1HUxAi/ODLRRxBHKtNH79E=", "owner": "appaquet", "repo": "dotfiles-secrets", - "rev": "dcf013a62cbcc9db1cbf62727725a50e441146f5", + "rev": "1f78be17751b4be2dc5e75ceea9aaf7fa5531d79", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 2d6c7b0..384d078 100755 --- a/flake.nix +++ b/flake.nix @@ -135,8 +135,11 @@ extraSpecialArgs.secrets.commonHome ] ++ commonHomeModules; extraSpecialArgs = { - inherit inputs unstablePkgs cfg; + inherit inputs unstablePkgs; secrets = secrets.init "linux"; + cfg = cfg // { + isNixos = true; + }; }; }; @@ -191,6 +194,18 @@ ./nixos/deskapp/configuration.nix ]; }; + + servapp = nixpkgs.lib.nixosSystem { + specialArgs = { + inherit (self) common; + inherit inputs; + secrets = secrets.init "linux"; + }; + modules = [ + nixosOverlaysModule + ./nixos/servapp/configuration.nix + ]; + }; }; }; } diff --git a/home-manager/servapp.nix b/home-manager/servapp.nix index b4025a5..0e0a87f 100644 --- a/home-manager/servapp.nix +++ b/home-manager/servapp.nix @@ -10,5 +10,5 @@ home.username = "appaquet"; home.homeDirectory = "/home/appaquet"; - home.stateVersion = "23.11"; + home.stateVersion = "24.11"; } diff --git a/nixos/servapp/configuration.nix b/nixos/servapp/configuration.nix new file mode 100644 index 0000000..4d22247 --- /dev/null +++ b/nixos/servapp/configuration.nix @@ -0,0 +1,95 @@ +{ pkgs, secrets, ... }: + +{ + imports = [ + ./hardware-configuration.nix + ./virt + ../common.nix + ../dev.nix + ../docker.nix + ../network-bridge.nix + ../ups.nix + ../nasapp.nix + ]; + + boot.loader.systemd-boot.enable = true; + boot.loader.efi.canTouchEfiVariables = true; + boot.kernelPackages = pkgs.linuxPackages_latest; + boot.kernelParams = [ ]; + + networking.hostName = "servapp"; + + # Drives + swapDevices = [ + { + device = "/swapfile"; + size = 16 * 1024; # 16GB + } + ]; + + # Networking + # networking.networkmanager.enable = true; + # networking.myBridge = { + # enable = true; + # interface = "enp1s0"; # TODO: probably wrong + # lanIp = "192.168.0.13"; + # }; + + # NasAPP mounts + nasapp = { + enable = true; + credentials = secrets.servapp.nasappCifs; + uid = "appaquet"; + gid = "users"; + shares = [ + { + share = "backup_servapp"; # TODO: move to backup + mount = "/mnt/backup_servapp"; + } + { + share = "video"; + mount = "/mnt/video"; + } + ]; + }; + + # Display + services.xserver.enable = true; + services.xserver.displayManager.lightdm.enable = true; + services.xserver.desktopManager.xfce.enable = true; + services.xserver = { + xkb.layout = "us"; + xkb.variant = ""; + }; + services.displayManager.autoLogin.enable = true; + services.displayManager.autoLogin.user = "appaquet"; + + # Enable sound with pipewire. + hardware.pulseaudio.enable = false; + security.rtkit.enable = true; + services.pipewire = { + enable = true; + alsa.enable = true; + alsa.support32Bit = true; + pulse.enable = true; + }; + + # Programs & services + programs.firefox.enable = true; + services.printing.enable = false; + services.openssh.enable = true; + + # Open ports in the firewall. + # networking.firewall.allowedTCPPorts = [ ... ]; + # networking.firewall.allowedUDPPorts = [ ... ]; + # Or disable the firewall altogether. + networking.firewall.enable = false; + + # This value determines the NixOS release from which the default + # settings for stateful data, like file locations and database versions + # on your system were taken. It‘s perfectly fine and recommended to leave + # this value at the release version of the first install of this system. + # Before changing this value read the documentation for this option + # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html). + system.stateVersion = "24.11"; +} diff --git a/nixos/servapp/hardware-configuration.nix b/nixos/servapp/hardware-configuration.nix new file mode 100644 index 0000000..db4b963 --- /dev/null +++ b/nixos/servapp/hardware-configuration.nix @@ -0,0 +1,53 @@ +# Do not modify this file! It was generated by ‘nixos-generate-config’ +# and may be overwritten by future invocations. Please make changes +# to /etc/nixos/configuration.nix instead. +{ + config, + lib, + modulesPath, + ... +}: + +{ + imports = [ + (modulesPath + "/installer/scan/not-detected.nix") + ]; + + boot.initrd.availableKernelModules = [ + "nvme" + "xhci_pci" + "ahci" + "usbhid" + "usb_storage" + "sd_mod" + ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-amd" ]; + boot.extraModulePackages = [ ]; + + fileSystems."/" = { + device = "/dev/disk/by-uuid/141971f9-e5ed-4eec-b306-a7b3db3d005d"; + fsType = "ext4"; + }; + + fileSystems."/boot" = { + device = "/dev/disk/by-uuid/8A5E-82A3"; + fsType = "vfat"; + options = [ + "fmask=0022" + "dmask=0022" + ]; + }; + + swapDevices = [ ]; + + # Enables DHCP on each ethernet and wireless interface. In case of scripted networking + # (the default) this is the recommended approach. When using systemd-networkd it's + # still possible to use this option, but it's recommended to use it in conjunction + # with explicit per-interface declarations with `networking.interfaces..useDHCP`. + networking.useDHCP = lib.mkDefault true; + networking.interfaces.eno1.useDHCP = false; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; + hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; +} diff --git a/nixos/servapp/virt/default.nix b/nixos/servapp/virt/default.nix new file mode 100644 index 0000000..6b75aec --- /dev/null +++ b/nixos/servapp/virt/default.nix @@ -0,0 +1,33 @@ +{ + inputs, + ... +}: + +{ + imports = [ + ../../virt.nix + inputs.nixvirt.nixosModules.default + ]; + + virtualisation = { + libvirt.enable = true; + libvirt.connections = { + "qemu:///system" = { + domains = [ + { + definition = ./domains/homeassistant.xml; + } + { + definition = ./domains/pihole.xml; + } + ]; + pools = [ + { + definition = ./pools/download.xml; + active = true; + } + ]; + }; + }; + }; +} diff --git a/nixos/servapp/virt/domains/homeassistant.xml b/nixos/servapp/virt/domains/homeassistant.xml new file mode 100644 index 0000000..60b429e --- /dev/null +++ b/nixos/servapp/virt/domains/homeassistant.xml @@ -0,0 +1,250 @@ + + homeassistant + 594f25c4-862c-448c-8154-4666f6f36718 + + + + + + 4194304 + 4194304 + 4 + + /machine + + + hvm + + + + + /run/libvirt/nix-ovmf/OVMF_CODE.fd + /home/appaquet/homeassistant/OVMF_VARS.fd + + + + + + + + + + + + + + destroy + restart + destroy + + + + + + /run/libvirt/nix-emulators/qemu-system-x86_64 + + + + + + +
+ + + +
+ + + + + + + + +
+ + + + + +
+ + + + + +
+ + + + + +
+ + + + + +
+ + + + + +
+ + + + + +
+ + + + + +
+ + + + + +
+ + + + + +
+ + + + + +
+ + + + + +
+ + + + + +
+ + + + + +
+ + + +
+ + + +
+ + + + + + + + +
+ + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + + + + + + + + + + + +
+ +