From aec06c4b37c5448e3d5794c22a9baa2c1032dd34 Mon Sep 17 00:00:00 2001 From: Nikolaos Karaolidis Date: Tue, 18 Jun 2024 16:05:20 +0300 Subject: [PATCH] Add base eirene config Signed-off-by: Nikolaos Karaolidis --- README.md | 4 + flake.nix | 16 +++- hosts/common/default.nix | 1 + hosts/eirene/base/default.nix | 59 ++++++++++++++ hosts/eirene/base/hardware-configuration.nix | 14 ++++ hosts/eirene/vm/hardware-configuration.nix | 11 +-- users/common/default.nix | 81 ++++++++++---------- 7 files changed, 135 insertions(+), 51 deletions(-) create mode 100644 hosts/eirene/base/default.nix create mode 100644 hosts/eirene/base/hardware-configuration.nix diff --git a/README.md b/README.md index 8214bea..ac7c31f 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,10 @@ The below installation example is for a fresh `eirene-vm` virtual machine. mkdir -p /mnt/persist/etc/ssh ssh-keygen -t ed25519 -f /mnt/persist/etc/ssh/ssh_host_ed25519_key cp /mnt/persist/etc/ssh/ssh_host_ed25519_key /host/hosts/eirene/secrets/ssh_host_ed25519_key + + # Optional - Copy user keys + mkdir -p /mnt/persist/home/nick/.local/share/sops-nix + cp /host/users/nick/secrets/key.txt /mnt/persist/home/nick/.local/share/sops-nix/key.txt ``` 4. Update `sops` Configuration diff --git a/flake.nix b/flake.nix index 76e9b6c..aa30e85 100644 --- a/flake.nix +++ b/flake.nix @@ -27,10 +27,18 @@ }; outputs = { self, nixpkgs, ... } @ inputs: { - nixosConfigurations.eirene-vm = nixpkgs.lib.nixosSystem { - specialArgs = { inherit inputs; }; - system = "x86_64-linux"; - modules = [ ./hosts/eirene/vm ]; + nixosConfigurations = { + eirene-vm = nixpkgs.lib.nixosSystem { + specialArgs = { inherit inputs; }; + system = "x86_64-linux"; + modules = [ ./hosts/eirene/vm ]; + }; + + eirene = nixpkgs.lib.nixosSystem { + specialArgs = { inherit inputs; }; + system = "x86_64-linux"; + modules = [ ./hosts/eirene/base ]; + }; }; }; } diff --git a/hosts/common/default.nix b/hosts/common/default.nix index 6375ae6..ef78de8 100644 --- a/hosts/common/default.nix +++ b/hosts/common/default.nix @@ -98,4 +98,5 @@ }; nix.settings.experimental-features = [ "nix-command" "flakes" ]; + nixpkgs.config.allowUnfree = true; } diff --git a/hosts/eirene/base/default.nix b/hosts/eirene/base/default.nix new file mode 100644 index 0000000..a365b7a --- /dev/null +++ b/hosts/eirene/base/default.nix @@ -0,0 +1,59 @@ +{ config, inputs, lib, pkgs, ... }: + +{ + imports = [ + inputs.disko.nixosModules.disko + (import ../format.nix { device = "/dev/disk/by-id/nvme-SAMSUNG_MZVL22T0HBLB-00BL2_S64RNE0R602762"; }) + ./hardware-configuration.nix + ../. + ]; + + networking.hostName = "eirene"; + + # https://github.com/NixOS/nixos-hardware/tree/master/lenovo/legion/16achg6 + + hardware = { + cpu.amd = { + updateMicrocode = true; + }; + + nvidia = { + modesetting.enable = true; + powerManagement.enable = true; + open = false; + + prime = { + offload = { + enable = true; + enableOffloadCmd = true; + }; + nvidiaBusId = "PCI:1:0:0"; + amdgpuBusId = "PCI:6:0:0"; + }; + }; + + opengl = { + driSupport = true; + driSupport32Bit = true; + extraPackages = with pkgs; [ + amdvlk + driversi686Linux.amdvlk + rocmPackages.clr + rocmPackages.clr.icd + ]; + }; + }; + + services = { + xserver.videoDrivers = [ "nvidia" ]; + tlp.enable = true; + fstrim.enable = true; + }; + + boot = { + kernelParams = [ "amd_pstate=active" "video=eDP:2560x1600@165" ]; + initrd.kernelModules = [ "amdgpu" ]; + }; + + home-manager.sharedModules = lib.mkIf config.programs.hyprland.enable [{ wayland.windowManager.hyprland.settings.monitor = "eDP, 2560x1600@165, 0x0, 1"; }]; +} diff --git a/hosts/eirene/base/hardware-configuration.nix b/hosts/eirene/base/hardware-configuration.nix new file mode 100644 index 0000000..f25d193 --- /dev/null +++ b/hosts/eirene/base/hardware-configuration.nix @@ -0,0 +1,14 @@ +{ config, lib, modulesPath, ... }: + +{ + imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; + + boot = { + initrd.availableKernelModules = [ "nvme" "ahci" "usbhid" ]; + kernelModules = [ "kvm-amd" ]; + }; + + networking.useDHCP = lib.mkDefault true; + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; + hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; +} diff --git a/hosts/eirene/vm/hardware-configuration.nix b/hosts/eirene/vm/hardware-configuration.nix index 04a8b02..0709eb7 100644 --- a/hosts/eirene/vm/hardware-configuration.nix +++ b/hosts/eirene/vm/hardware-configuration.nix @@ -1,18 +1,13 @@ { lib, modulesPath, ... }: { - imports = [ - (modulesPath + "/profiles/qemu-guest.nix") - ]; + imports = [ (modulesPath + "/profiles/qemu-guest.nix") ]; boot = { - initrd.availableKernelModules = ["ahci" "xhci_pci" "virtio_pci" "virtio_scsi" "sr_mod" "virtio_blk"]; - initrd.kernelModules = []; - kernelModules = ["kvm-amd"]; - extraModulePackages = []; + initrd.availableKernelModules = [ "ahci" "xhci_pci" "virtio_pci" "virtio_scsi" "sr_mod" "virtio_blk" ]; + kernelModules = [ "kvm-amd" ]; }; networking.useDHCP = lib.mkDefault true; - nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; } diff --git a/users/common/default.nix b/users/common/default.nix index d146f84..7d3d1c9 100644 --- a/users/common/default.nix +++ b/users/common/default.nix @@ -15,9 +15,12 @@ in dconf.enable = true; }; + environment.sessionVariables.NIXOS_OZONE_WL = "1"; + home-manager = { extraSpecialArgs = { inherit inputs; }; backupFileExtension = "bak"; + sharedModules = [{ imports = [ inputs.impermanence.nixosModules.home-manager.impermanence @@ -43,50 +46,50 @@ in }]; users = lib.attrsets.mapAttrs' (user: config: lib.attrsets.nameValuePair - (user) - (let - init = pkgs.pkgs.writeShellScriptBin "hyprland-init" '' - ${pkgs.swww}/bin/swww-daemon &> /tmp/swww.log & + (user) + (let + init = pkgs.pkgs.writeShellScriptBin "hyprland-init" '' + ${pkgs.swww}/bin/swww-daemon &> /tmp/swww.log & - while ! swww query &> /dev/null; do - sleep 0.1 - done + while ! swww query &> /dev/null; do + sleep 0.1 + done - ${pkgs.swww}/bin/swww img ${config.wallpaper} - ''; - in - { - home.persistence."/persist${config.home}" = { - directories = [ - "Documents" - "Downloads" - "Music" - "Pictures" - "Videos" - "Templates" - "VMs" - "git" - ".mozilla" - ".local/share/zsh" - ]; - files = [ - ".local/share/sops-nix/key.txt" - ]; - allowOther = true; - }; + ${pkgs.swww}/bin/swww img ${config.wallpaper} + ''; + in + { + home.persistence."/persist${config.home}" = { + directories = [ + "Documents" + "Downloads" + "Music" + "Pictures" + "Videos" + "Templates" + "VMs" + "git" + ".mozilla" + ".local/share/zsh" + ]; + files = [ + ".local/share/sops-nix/key.txt" + ]; + allowOther = true; + }; - programs.git = { - userName = config.fullName; - userEmail = config.email; - }; + programs.git = { + userName = config.fullName; + userEmail = config.email; + }; - stylix = { - image = config.wallpaper; - base16Scheme = config.base16Scheme; - }; + stylix = { + image = config.wallpaper; + base16Scheme = config.base16Scheme; + }; - wayland.windowManager.hyprland.settings.exec-once = "${init}/bin/hyprland-init"; - }) + wayland.windowManager.hyprland.settings.exec-once = "${init}/bin/hyprland-init"; + }) ) normalUsers; };