diff --git a/configuration.nix b/configuration.nix index 419dc1a..4861416 100644 --- a/configuration.nix +++ b/configuration.nix @@ -1,30 +1,27 @@ -# Edit this configuration file to define what should be installed on -# your system. Help is available in the configuration.nix(5) man page, on -# https://search.nixos.org/options and in the NixOS manual (`nixos-help`). - -{ config, lib, pkgs, user, allowed, secrets, rice, ... }: - +{ config, lib, pkgs, user, allowed, secrets, rice, nvidia, ... }: +let +in { - imports = - [ # Include the results of the hardware scan. - ./system-modules/hardware-configuration.nix - ./system-modules/users.nix - ./system-modules/sound.nix - ./system-modules/ollama.nix - ./system-modules/grub.nix - ./system-modules/dm.nix + imports = [ + ./system-modules/hardware-configuration.nix + ./system-modules/nvidia.nix # only does stuff if nvidia.enabled + ./system-modules/users.nix + ./system-modules/sound.nix + ./system-modules/grub.nix + ./system-modules/dm.nix - ./system-modules/hsmw.nix - ./system-modules/health_reminder.nix - ./system-modules/davmail.nix - ./system-modules/docker.nix + ./system-modules/hsmw.nix + ./system-modules/docker.nix + ./system-modules/health_reminder.nix + ./system-modules/davmail.nix + ./system-modules/ollama.nix ]; - networking.hostName = "NxXPS"; + networking.hostName = "NxXPS"; networking.networkmanager = { enable = true; - }; + }; @@ -48,13 +45,13 @@ services.printing.enable = true; # rtkit is optional but recommended - security.rtkit.enable = true; + security.rtkit.enable = true; # Enable touchpad support (enabled default in most desktopManager). services.xserver.libinput.enable = true; hardware.uinput.enable = true; - # log into this machine + # log into this machine services.openssh.enable = false; @@ -62,6 +59,9 @@ hardware.bluetooth.powerOnBoot = true; # services.blueman.enable = true; + nixpkgs.config.allowUnfree = true; + # nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) allowed.unfree-packages; + # List packages installed in system profile. To search, run: # $ nix search wget @@ -81,6 +81,7 @@ direnv openssl blueman + dmidecode ]; fonts.packages = with pkgs; [ @@ -90,7 +91,7 @@ ] ++ [ rice.font.base.package rice.font.code.package - ] + ]; programs.gnupg.agent = { enable = true; @@ -98,9 +99,10 @@ }; - programs.hyprland = { # config is done with home-manager + programs.hyprland = { + # config is done with home-manager enable = true; - xwayland.enable = true; + xwayland.enable = true; }; system.stateVersion = "23.11"; diff --git a/flake.lock b/flake.lock index f4d586e..235caa1 100644 --- a/flake.lock +++ b/flake.lock @@ -23,11 +23,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1711668574, - "narHash": "sha256-u1dfs0ASQIEr1icTVrsKwg2xToIpn7ZXxW3RHfHxshg=", + "lastModified": 1712168706, + "narHash": "sha256-XP24tOobf6GGElMd0ux90FEBalUtw6NkBSVh/RlA6ik=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "219951b495fc2eac67b1456824cc1ec1fd2ee659", + "rev": "1487bdea619e4a7a53a4590c475deabb5a9d1bfb", "type": "github" }, "original": { @@ -38,11 +38,11 @@ }, "nixpkgs-unstable": { "locked": { - "lastModified": 1711703276, - "narHash": "sha256-iMUFArF0WCatKK6RzfUJknjem0H9m4KgorO/p3Dopkk=", + "lastModified": 1712163089, + "narHash": "sha256-Um+8kTIrC19vD4/lUCN9/cU9kcOsD1O1m+axJqQPyMM=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "d8fe5e6c92d0d190646fb9f1056741a229980089", + "rev": "fd281bd6b7d3e32ddfa399853946f782553163b5", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index ab97f8f..3ee5ec5 100644 --- a/flake.nix +++ b/flake.nix @@ -1,77 +1,95 @@ { description = "A Flake lol"; - + inputs = { nixpkgs.url = "nixpkgs/nixos-23.11"; nixpkgs-unstable.url = "nixpkgs/nixos-unstable"; home-manager.url = "github:nix-community/home-manager/release-23.11"; home-manager.inputs.nixpkgs.follows = "nixpkgs"; }; - + outputs = { self, nixpkgs, nixpkgs-unstable, home-manager, ... }: - let - system = "x86_64-linux"; - pkgs = nixpkgs.legacyPackages.${system}; - user = "nx2"; - pkgs-unstable = nixpkgs-unstable.legacyPackages.${system}; - allowed = { - unfree-packages = [ - "spotify" - "discord" - "obsidian" - "zoom-us" - "zoom" - "vscode-extension-ms-vscode-remote-remote-ssh" - "vscode-extension-MS-python-vscode-pylance" - ]; - inecure-packages = [ - "electron-25.9.0" - ]; - }; - secrets = import ./secrets/passwords-and-certificates.nix; - rice = { - transparency = "0.8"; - colors = { - main-fg = "#ffffff"; - main-bg = "#000000"; - bubble-fg = "#ffffff"; - bubble-bg = "#222222"; - bubble-border = "#bbbbbb"; - secondary-fg = "#ffffff"; - secondary-bg = "#222255"; - lines = "#bbbbbb"; - accent = "#ff00ff"; + let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + pkgs-unstable = nixpkgs-unstable.legacyPackages.${system}; + user = "nx2"; + + nvidia = rec { + enable = true; + prime = true; + # unfree = if enable then [ + unfree = [ + "nvidia-x11" + "nvidia-settings" + "nvidia-persistenced" + "cudatoolkit" + "cudatoolkit-11.8.0" + "cudatoolkit-12.2.2" + ]; + # ] else []; }; - font = { - code = { - name = "CascadiaCove-NF"; - package = (pkgs.nerdfonts.override { fonts = [ "CascadiaCode" ]; }); - }; - base = { - name = "Atkinson Hyperlegible"; - package = pkgs.atkinson-hyperlegible; + allowed = { + unfree-packages = [ + "spotify" + "cudatoolkit-12.2.2" + "discord" + "obsidian" + "zoom-us" + "zoom" + "vscode-extension-MS-python-vscode-pylance" + ] ++ nvidia.unfree ; + + inecure-packages = [ + "electron-25.9.0" + ]; + }; + + secrets = import ./secrets/passwords-and-certificates.nix; + + rice = { + transparency = "0.9"; + colors = rec { + main-fg = "#ffffff"; + main-bg = "#000000"; + bubble-fg = main-fg; + bubble-bg = "#222222"; + bubble-border = "#bbbbbb"; + secondary-fg = main-fg; + secondary-bg = "#222255"; + lines = "#bbbbbb"; + accent = "#ff00ff"; + }; + font = { + code = { + name = "CascadiaCove-NF"; + package = (pkgs.nerdfonts.override { fonts = [ "CascadiaCode" ]; }); + }; + base = { + name = "Atkinson Hyperlegible"; + package = pkgs.atkinson-hyperlegible; + }; }; }; - }; - in - { - nixosConfigurations = { - NxXPS = nixpkgs.lib.nixosSystem { - inherit system; - modules = [ - ./configuration.nix - ]; - specialArgs = {inherit user allowed secrets rice;}; + in + { + nixosConfigurations = { + NxXPS = nixpkgs.lib.nixosSystem { + inherit system; + modules = [ + ./configuration.nix + ]; + specialArgs = { inherit user pkgs-unstable allowed secrets rice nvidia; }; + }; }; - }; - homeConfigurations = { - nx2 = home-manager.lib.homeManagerConfiguration { - inherit pkgs; - modules = [ ./home.nix ]; - extraSpecialArgs = {inherit system user allowed secrets pkgs-unstable rice;}; + homeConfigurations = { + nx2 = home-manager.lib.homeManagerConfiguration { + inherit pkgs; + modules = [ ./home.nix ]; + extraSpecialArgs = { inherit system user allowed secrets pkgs-unstable rice nvidia; }; + }; }; - }; - }; + }; } diff --git a/system-modules/hardware-configuration.nix b/system-modules/hardware-configuration.nix index fa56b66..2e2583a 100644 --- a/system-modules/hardware-configuration.nix +++ b/system-modules/hardware-configuration.nix @@ -1,51 +1,54 @@ -# 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, user, pkgs, modulesPath, ... }: { - imports = - [ - (modulesPath + "/installer/scan/not-detected.nix") - ]; + imports = [ + (modulesPath + "/installer/scan/not-detected.nix") + ]; boot.initrd.availableKernelModules = [ "xhci_pci" "thunderbolt" "vmd" "nvme" "usb_storage" "sd_mod" "rtsx_pci_sdmmc" ]; - boot.initrd.kernelModules = [ ]; + # boot.initrd.kernelModules = [ ]; boot.kernelModules = [ "kvm-intel" ]; boot.extraModulePackages = [ ]; - fileSystems."/" = - # { device = "/dev/disk/by-uuid/9770465e-6b0e-40ec-944a-953fe71cf47a"; - { - device = "/dev/disk/by-label/nixos"; - fsType = "ext4"; - }; + fileSystems."/" = { + device = "/dev/disk/by-label/nixos"; + fsType = "ext4"; + }; - fileSystems."/boot" = - { - device = "/dev/disk/by-label/EFI"; - fsType = "vfat"; - }; - fileSystems."/home/${user}/shared" = - { - device = "/dev/disk/by-label/shared"; - fsType = "ntfs"; - }; + fileSystems."/boot" = { + device = "/dev/disk/by-label/EFI"; + fsType = "vfat"; + }; + fileSystems."/home/${user}/shared" = { + device = "/dev/disk/by-label/shared"; + fsType = "ntfs"; + }; swapDevices = [ - { - device = "/dev/disk/by-label/swap"; - # size = 16 * 1024; - } + { device = "/dev/disk/by-label/swap"; } ]; - # 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.wlp0s20f3.useDHCP = lib.mkDefault true; nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; + + # from nixos-hardware + services.thermald.enable = lib.mkDefault true; + boot.extraModprobeConfig = '' + options iwlwifi 11n_disable=8 + ''; + boot.initrd.kernelModules = [ "i915" ]; + + environment.variables = { + VDPAU_DRIVER = lib.mkIf config.hardware.opengl.enable (lib.mkDefault "va_gl"); + }; + + hardware.opengl.extraPackages = with pkgs; [ + (if (lib.versionOlder (lib.versions.majorMinor lib.version) "23.11") then vaapiIntel else intel-vaapi-driver) + libvdpau-va-gl + intel-media-driver + ]; + + } diff --git a/system-modules/nvidia.nix b/system-modules/nvidia.nix new file mode 100644 index 0000000..d5e122f --- /dev/null +++ b/system-modules/nvidia.nix @@ -0,0 +1,72 @@ +{ config, pkgs, pkgs-unstable, lib, nvidia, ... }: +let +in +{ + config = lib.mkIf nvidia.enable { + environment.systemPackages = with pkgs; [ + lshw + nvtop + glxinfo + (pkgs.writeShellScriptBin "nvidia-offload" '' + export __NV_PRIME_RENDER_OFFLOAD=1 + export __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0 + export __GLX_VENDOR_LIBRARY_NAME=nvidia + export __VK_LAYER_NV_optimus=NVIDIA_only + exec "$@" + '') + ] ++ [ + # pkgs-unstable.nvtopPackages.intel + # pkgs-unstable.nvtopPackages.nvidia + ]; + + # Load nvidia driver for Xorg and Wayland + services.xserver.videoDrivers = [ "nvidia" ]; + + hardware = { + nvidia = { + prime = lib.mkIf nvidia.prime { + intelBusId = "PCI:0:2:0"; + nvidiaBusId = "PCI:1:0:0"; + offload = { + enable = true; + enableOffloadCmd = true; + }; + }; + modesetting.enable = true; + + # Modesetting is required. + + # 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; + + # Fine-grained power management. Turns off GPU when not in use. + # Experimental and only works on modern Nvidia GPUs (Turing or newer). + powerManagement.finegrained = true; + + # 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 = false; + + # 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; + }; + opengl = { + enable = true; + driSupport = true; + driSupport32Bit = true; + }; + }; + }; +}