From 3a353e863b98790cbcdbc41a43834628a89b455d Mon Sep 17 00:00:00 2001 From: Sean Buckley Date: Fri, 7 Oct 2022 00:58:13 -0400 Subject: [PATCH] levi: init --- hosts/default.nix | 1 + hosts/levi/default.nix | 54 ++++++++++++++++++++++++++ hosts/levi/optimus.nix | 88 ++++++++++++++++++++++++++++++++++++++++++ modules/sean.nix | 1 + 4 files changed, 144 insertions(+) create mode 100644 hosts/levi/default.nix create mode 100644 hosts/levi/optimus.nix diff --git a/hosts/default.nix b/hosts/default.nix index b44e0ef..5076ad3 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -15,4 +15,5 @@ builtins.mapAttrs cube = "x86_64-linux"; hp = "x86_64-linux"; lenny = "x86_64-linux"; + levi = "x86_64-linux"; } diff --git a/hosts/levi/default.nix b/hosts/levi/default.nix new file mode 100644 index 0000000..7193a45 --- /dev/null +++ b/hosts/levi/default.nix @@ -0,0 +1,54 @@ +{ config, pkgs, ... }: +let + persist = "/var/lib/persist-${config.networking.hostName}"; +in +{ + imports = [ + ./optimus.nix + ]; + + environment.etc = { + "machine-id".source = "${persist}/machine-id"; + "NetworkManager/system-connections".source = + "${persist}/network-connections"; + }; + + systemd.tmpfiles.rules = [ "d ${persist}/network-connections 0700" ]; + + services.openssh.hostKeys = [ + { type = "ed25519"; path = "${persist}/ssh_host_ed25519_key"; } + ]; + + sconfig = { + gnome = true; + profile = "desktop"; + gaming.enable = true; + horizon.enable = true; + wg-home.enable = true; + }; + + boot = { + loader.systemd-boot.enable = true; + loader.efi.canTouchEfiVariables = true; + initrd.availableKernelModules = [ "xhci_pci" "vmd" "nvme" "sd_mod" ]; + }; + + fileSystems = { + "/" = { device = "tmpfs"; fsType = "tmpfs"; options = [ "mode=755" ]; }; + "/boot" = { fsType = "vfat"; device = "/dev/nvme0n1p1"; }; + "/nix" = { device = "levi/nix"; fsType = "zfs"; }; + "/home" = { device = "levi/home"; fsType = "zfs"; }; + "/var/lib" = { device = "levi/lib"; fsType = "zfs"; }; + "/var/log" = { device = "levi/log"; fsType = "zfs"; }; + }; + + users.mutableUsers = false; + users.users.sean.passwordFile = "${persist}/shadow_sean"; + users.users.root.passwordFile = "${persist}/shadow_sean"; + + services.openssh.enable = true; + hardware.video.hidpi.enable = true; + hardware.cpu.intel.updateMicrocode = true; + hardware.enableRedistributableFirmware = true; + system.stateVersion = "22.05"; +} diff --git a/hosts/levi/optimus.nix b/hosts/levi/optimus.nix new file mode 100644 index 0000000..e1383c8 --- /dev/null +++ b/hosts/levi/optimus.nix @@ -0,0 +1,88 @@ +{ lib, pkgs, ... }: +let + current-mode = "nvidia-mux"; + + constants = { + hardware.nvidia.prime.intelBusId = "PCI:0:2:0"; + hardware.nvidia.prime.nvidiaBusId = "PCI:1:0:0"; + boot.kernelPackages = pkgs.linuxPackages_latest; + }; + + available-modes = { + + nvidia = { + ### "sync mode" + # + # good: + # max performance on external displays + # no BIOS settings change needed + # + # bad: + # graphics performance overhead on internal display + # internal display capped at 60hz + # + hardware.nvidia.prime.sync.enable = true; + hardware.nvidia.modesetting.enable = true; + services.xserver.displayManager.gdm.wayland = false; + services.xserver.videoDrivers = [ "nvidia" ]; + # xrandr workaround for laptop panel not showing up with GDM. Reference: + # https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/hardware/video/nvidia.nix + services.xserver.displayManager.sessionCommands = '' + ${pkgs.xorg.xrandr}/bin/xrandr --setprovideroutputsource modesetting NVIDIA-0 + ''; + }; + + nvidia-mux = { + ### optimus disabled in BIOS with MUX switch. + # + # good: + # simple, always works. + # max performance everywhere. + # + # bad: + # cant change laptop brightness. + # requires BIOS setting changes, which is annoying. + # + boot.kernelParams = [ "module_blacklist=i915" ]; + services.xserver.videoDrivers = [ "nvidia" ]; + }; + + intel = { + ### nvidia drivers disabled + # + # Not well tested. Possibly Incomplete. + # + # Shutting off Nvidia GPU would theoretically save power. + # + boot.kernelParams = [ "module_blacklist=nouveau" ]; + }; + + hybrid = { + ### hybrid graphics + # + # Not well tested. Possibly Incomplete. + # Won't allow external displays connected to nvidia GPU. + # + # Everything would use intel by default, + # but specific apps would run on the nvidia GPU under the script. + # + hardware.nvidia.prime.offload.enable = true; + services.xserver.videoDrivers = [ "nvidia" ]; + environment.systemPackages = [ + (pkgs.writeShellScriptBin "nv" '' + 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 "$@" + '') + ]; + }; + + }; + +in +lib.mkMerge [ + (constants) + (available-modes.${current-mode}) +] diff --git a/modules/sean.nix b/modules/sean.nix index 53a18ff..a3877a6 100644 --- a/modules/sean.nix +++ b/modules/sean.nix @@ -4,6 +4,7 @@ let "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIqWHzIXaF88Y8+64gBlLbZ5ZZcLl08kTHG1clHd7gaq desktop" "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJlMPWSVyDNAvXYtpXCI/geCeUEMbL9Nthm9B0zg1sIy sean@hp" "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDuuBHq3x28cdQ0JWAZ0R+2rVlRoPnA+MOvpdF5rraGp sean@lenny" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIE59uvHtxmdjqMaKyPiKLdiwfu0i59iFczrbGY0t6Oed sean@levi" ]; in {