From 2147766e07d11a1465dcddbe46595cb9181f8710 Mon Sep 17 00:00:00 2001 From: Aleksandr Lebedev Date: Wed, 20 Nov 2024 20:33:42 +0100 Subject: [PATCH] Separated some settings --- flake.nix | 23 ++++++++-------- nixos/configuration.nix | 50 +++++----------------------------- nixos/homepc-hardware-conf.nix | 41 ++++++++++++++++++++++++++++ nixos/hyprland/hyprland.nix | 6 ++-- nixos/libvirt.nix | 39 ++++++++++++++++++++++++++ nixos/nvidia.nix | 46 +++++++++++++++++++++++++++++++ 6 files changed, 148 insertions(+), 57 deletions(-) create mode 100644 nixos/homepc-hardware-conf.nix create mode 100644 nixos/libvirt.nix create mode 100644 nixos/nvidia.nix diff --git a/flake.nix b/flake.nix index 2a40ea5..3acc97e 100644 --- a/flake.nix +++ b/flake.nix @@ -20,27 +20,28 @@ }; outputs = { self, nixpkgs, stylix, nix-flatpak, ... }@inputs: - let - system = "x86_64-linux"; - pkgs = import nixpkgs { - inherit system; - config = { - allowUnfree = true; - - }; - }; + let + #system = "x86_64-linux"; + #pkgs = import nixpkgs { + # inherit system; + # config = { + # allowUnfree = true; + # }; + #}; in { nixosConfigurations = { homepc = nixpkgs.lib.nixosSystem { - specialArgs = { inherit system; inherit inputs; }; + specialArgs = { hostname = "nixosbtw"; system = "x86_64-linux"; inherit inputs; }; modules = [ #nur.nixosModules.nur ./nixos/configuration.nix + ./nixos/nvidia.nix + ./nixos/homepc-hardware-conf.nix inputs.home-manager.nixosModules.default stylix.nixosModules.stylix - nix-flatpak.nixosModules.default + #nix-flatpak.nixosModules.default ]; }; }; diff --git a/nixos/configuration.nix b/nixos/configuration.nix index b60cfe9..f626d5f 100644 --- a/nixos/configuration.nix +++ b/nixos/configuration.nix @@ -2,22 +2,22 @@ # your system. Help is available in the configuration.nix(5) man page # and in the NixOS manual (accessible by running ‘nixos-help’). -{ config, pkgs, stylix, inputs, ... }: +{ config, pkgs, stylix, hostname, inputs, ... }: { imports = [ # Include the results of the hardware scan. - ./hardware-configuration.nix inputs.home-manager.nixosModules.default ./firefox.nix + ./libvirt.nix ]; # Bootloader. boot.loader.systemd-boot.enable = true; - boot.loader.efi.canTouchEfiVariables = true; + boot.loader.efi.canTouchEfiVariables = if hostname == "nixosbtw" then true else false; boot.kernelPackages = pkgs.linuxPackages_latest; - networking.hostName = "nixosbtw"; # Define your hostname. + networking.hostName = hostname; # networking.wireless.enable = true; # Enables wireless support via wpa_supplicant. # Configure network proxy if necessary @@ -151,8 +151,8 @@ vscode-fhs # development - clang_18 - dotnetCorePackages.sdk_8_0_3xx + #clang_18 + #dotnetCorePackages.sdk_8_0_3xx ]; programs.kdeconnect.enable = true; programs.kdeconnect.package = pkgs.kdePackages.kdeconnect-kde; @@ -193,45 +193,9 @@ hardware = { graphics = { enable = true; - extraPackages = with pkgs; [ - nvidia-vaapi-driver - ]; }; - nvidia = { - # https://nixos.wiki/wiki/Nvidia - # Modesetting is required. - modesetting.enable = true; - - # Nvidia power management. Experimental, and can cause sleep/suspend to fail. - # Enable this if you have graphical corruption issues or application crashes after waking - # up from sleep. This fixes it by saving the entire VRAM memory to /tmp/ instead - # of just the bare essentials. - powerManagement.enable = true;#false; - - # Fine-grained power management. Turns off GPU when not in use. - # Experimental and only works on modern Nvidia GPUs (Turing or newer). - powerManagement.finegrained = false; - - # Use the NVidia open source kernel module (not to be confused with the - # independent third-party "nouveau" open source driver). - # Support is limited to the Turing and later architectures. Full list of - # supported GPUs is at: - # https://github.com/NVIDIA/open-gpu-kernel-modules#compatible-gpus - # Only available from driver 515.43.04+ - # Currently alpha-quality/buggy, so false is currently the recommended setting. - open = true; - - # Enable the Nvidia settings menu, - # accessible via `nvidia-settings`. - nvidiaSettings = true; - - # Optionally, you may need to select the appropriate driver version for your specific GPU. - package = config.boot.kernelPackages.nvidiaPackages.stable; - }; - logitech.wireless.enable = true; }; - services.xserver.videoDrivers = [ "nvidia" ]; security.polkit.enable = true; @@ -264,7 +228,7 @@ }; home-manager = { - extraSpecialArgs = {inherit pkgs; inherit inputs;}; + extraSpecialArgs = {inherit pkgs; inherit hostname; inherit inputs;}; users = { "kylekrein" = import ./home.nix; }; diff --git a/nixos/homepc-hardware-conf.nix b/nixos/homepc-hardware-conf.nix new file mode 100644 index 0000000..c007890 --- /dev/null +++ b/nixos/homepc-hardware-conf.nix @@ -0,0 +1,41 @@ +# 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, pkgs, modulesPath, ... }: + +{ + imports = + [ (modulesPath + "/installer/scan/not-detected.nix") + ]; + + boot.initrd.availableKernelModules = [ "nvme" "xhci_pci" "ahci" "usb_storage" "usbhid" "sd_mod" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-amd" ]; + boot.extraModulePackages = [ ]; + + fileSystems."/" = + { device = "/dev/disk/by-uuid/10040de2-c5df-42c9-94fa-d6d9d76397f4"; + fsType = "ext4"; + }; + + fileSystems."/boot" = + { device = "/dev/disk/by-uuid/9973-FDA6"; + fsType = "vfat"; + options = [ "fmask=0077" "dmask=0077" ]; + }; + + swapDevices = + [ { device = "/dev/disk/by-uuid/88d26139-5a1c-4ced-bd0f-a0f118d7e773"; } + ]; + + # 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 = lib.mkDefault true; + # networking.interfaces.wlp5s0.useDHCP = lib.mkDefault true; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; + hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; +} diff --git a/nixos/hyprland/hyprland.nix b/nixos/hyprland/hyprland.nix index da2e625..f20d819 100644 --- a/nixos/hyprland/hyprland.nix +++ b/nixos/hyprland/hyprland.nix @@ -1,4 +1,4 @@ -{ pkgs, lib, ... }: +{ pkgs, lib, hostname, ... }: let toggle_monitors = ./toggle_monitors.sh; wallpaper-image = ./wallpaper.jpg; @@ -13,10 +13,10 @@ in enable = true; xwayland.enable = true; settings = { - monitor = [ + monitor = if hostname == "nixosbtw" then [ "DP-1,2560x1440@75,1600x0,1.6" "DP-3,2560x1440@75,0x0,1.6" - ]; + ] else ",auto,auto,1.6"; xwayland = { force_zero_scaling = true; diff --git a/nixos/libvirt.nix b/nixos/libvirt.nix new file mode 100644 index 0000000..22d2fd0 --- /dev/null +++ b/nixos/libvirt.nix @@ -0,0 +1,39 @@ +{ pkgs, ... }: +let + username = "kylekrein"; +in +{ + virtualisation = { + libvirtd = { + enable = true; + qemu = { + package = pkgs.qemu_kvm; + swtpm.enable = true; + ovmf.enable = true; + ovmf.packages = [ pkgs.OVMFFull.fd ]; + }; + }; + spiceUSBRedirection.enable = true; + }; + + users.users.${username}.extraGroups = [ "libvirtd" ]; + + environment.systemPackages = with pkgs; [ + spice + spice-gtk + spice-protocol + virt-viewer + #virtio-win + #win-spice + ]; + programs.virt-manager.enable = true; + + home-manager.users.${username} = { + dconf.settings = { + "org/virt-manager/virt-manager/connections" = { + autoconnect = [ "qemu:///system" ]; + uris = [ "qemu:///system" ]; + }; + }; + }; +} diff --git a/nixos/nvidia.nix b/nixos/nvidia.nix new file mode 100644 index 0000000..b533ef1 --- /dev/null +++ b/nixos/nvidia.nix @@ -0,0 +1,46 @@ +{ config, pkgs, ... }: +{ + hardware = { + graphics = { + enable = true; + extraPackages = with pkgs; [ + nvidia-vaapi-driver + ]; + }; + nvidia = { + # https://nixos.wiki/wiki/Nvidia + # Modesetting is required. + modesetting.enable = true; + + # Nvidia power management. Experimental, and can cause sleep/suspend to fail. + # Enable this if you have graphical corruption issues or application crashes after waking + # up from sleep. This fixes it by saving the entire VRAM memory to /tmp/ instead + # of just the bare essentials. + powerManagement.enable = true;#false; + + # Fine-grained power management. Turns off GPU when not in use. + # Experimental and only works on modern Nvidia GPUs (Turing or newer). + powerManagement.finegrained = false; + + # Use the NVidia open source kernel module (not to be confused with the + # independent third-party "nouveau" open source driver). + # Support is limited to the Turing and later architectures. Full list of + # supported GPUs is at: + # https://github.com/NVIDIA/open-gpu-kernel-modules#compatible-gpus + # Only available from driver 515.43.04+ + # Currently alpha-quality/buggy, so false is currently the recommended setting. + open = true; + + # Enable the Nvidia settings menu, + # accessible via `nvidia-settings`. + nvidiaSettings = true; + + # Optionally, you may need to select the appropriate driver version for your specific GPU. + package = config.boot.kernelPackages.nvidiaPackages.stable; + }; + + logitech.wireless.enable = true; + }; + services.xserver.videoDrivers = [ "nvidia" ]; + +}