From 52c7cf2a77e81c580360c9cffb460ac8abe8826a Mon Sep 17 00:00:00 2001 From: albert Date: Thu, 2 Jan 2025 20:34:15 +0100 Subject: [PATCH] Add Framework 16 components --- README.md | 1 + flake.nix | 2 + .../framework16/desktops/gnome/default.nix | 3 + .../framework16/desktops/hyprland/default.nix | 63 +++++++++++++ .../framework16/desktops/plasma6/default.nix | 11 +++ nixos/hosts/framework16/default.nix | 91 +++++++++++++++++++ nixos/hosts/framework16/disks.nix | 87 ++++++++++++++++++ nixos/hosts/framework16/hibernate.nix | 46 ++++++++++ 8 files changed, 304 insertions(+) create mode 100644 home-manager/hosts/framework16/desktops/gnome/default.nix create mode 100644 home-manager/hosts/framework16/desktops/hyprland/default.nix create mode 100644 home-manager/hosts/framework16/desktops/plasma6/default.nix create mode 100644 nixos/hosts/framework16/default.nix create mode 100644 nixos/hosts/framework16/disks.nix create mode 100644 nixos/hosts/framework16/hibernate.nix diff --git a/README.md b/README.md index db5cfe3b..57916e35 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ nix develop -c /etc/nixos/git/docs/setup.sh | nuc-server | Server | Server at my brothers house | ✔️ | ✔️ | | nixos-desktop | Personal | My main desktop | ✔️ | ❌ | | nixos-framework | Personal | My AMD Framework 13 laptop | ✔️ | ❌ | +| framework16 | Personal | My AMD Framework 16 laptop | ✔️ | ❌ | | steamdeck | Personal | Valve Steam Deck gaming console | ✔️ | ✔️ | | piaware-rpi4 | Raspberry Pi | Raspberry Pi for FlightAware flight tracking software | ✔️ | ✔️ | | backups-rpi4 | Raspberry Pi | Raspberry Pi for rsync backups | ✔️ | ✔️ | diff --git a/flake.nix b/flake.nix index 9368d042..fb145ffd 100644 --- a/flake.nix +++ b/flake.nix @@ -64,6 +64,7 @@ # User Machines nixos-desktop = libx.mkHost { hostname = "nixos-desktop"; unfree = true; desktop = "plasma6"; }; nixos-framework = libx.mkHost { hostname = "nixos-framework"; unfree = true; desktop = "plasma6"; }; + framework16 = libx.mkHost { hostname = "framework16"; unfree = true; desktop = "plasma6"; }; steamdeck = libx.mkDeck { hostname = "steamdeck"; desktop = "plasma6"; }; # Raspberry Pi's @@ -86,6 +87,7 @@ # User Machines "albert@nixos-desktop" = libx.mkHome { hostname = "nixos-desktop"; desktop = "plasma6"; theme = "gruvbox"; }; "albert@nixos-framework" = libx.mkHome { hostname = "nixos-framework"; desktop = "plasma6"; }; + "albert@framework16" = libx.mkHome { hostname = "framework16"; desktop = "plasma6"; }; "albert@steamdeck" = libx.mkHome { hostname = "steamdeck"; desktop = "plasma6"; }; # Raspberry Pi's diff --git a/home-manager/hosts/framework16/desktops/gnome/default.nix b/home-manager/hosts/framework16/desktops/gnome/default.nix new file mode 100644 index 00000000..077404aa --- /dev/null +++ b/home-manager/hosts/framework16/desktops/gnome/default.nix @@ -0,0 +1,3 @@ +{ + +} \ No newline at end of file diff --git a/home-manager/hosts/framework16/desktops/hyprland/default.nix b/home-manager/hosts/framework16/desktops/hyprland/default.nix new file mode 100644 index 00000000..2b78186b --- /dev/null +++ b/home-manager/hosts/framework16/desktops/hyprland/default.nix @@ -0,0 +1,63 @@ +{ theme, ... }: { + wayland.windowManager.hyprland = { + settings = { + monitor = ",highrr,auto,1.175"; + bind = [ + '', XF86AudioMute, exec, swayosd --output-volume=mute-toggle'' + '', XF86AudioPrev, exec, playerctl previous'' + '', XF86AudioNext, exec, playerctl next'' + ]; + binde = [ + '', XF86AudioPlay, exec, playerctl play-pause'' + '', XF86AudioNext, exec, playerctl next'' + '', XF86MonBrightnessDown, exec, swayosd-client --brightness=lower'' + '', XF86MonBrightnessUp, exec, swayosd-client --brightness=raise'' + '', XF86AudioMute, exec, swayosd-client --output-volume=mute-toggle'' + '', XF86AudioLowerVolume, exec, swayosd-client --output-volume=lower'' + '', XF86AudioRaiseVolume, exec, swayosd-client --output-volume=raise'' + ]; + bindl = [ + '',switch:on:1241ec0,exec,hyprctl keyword monitor "eDP-1, 2560x1600, 0x0, 1"'' + '',switch:off:1241ec0,exec,hyprctl keyword monitor "eDP-1, disable"'' + ]; + }; + }; + + home.file = { + # Set the custom launcher script + ".config/hypr/start.sh" = { + enable = true; + executable = true; + text = '' + #!/usr/bin/env bash + # https://wiki.hyprland.org/FAQ/#some-of-my-apps-take-a-really-long-time-to-open + dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP & + + # Set the wallpaper + swww init + + # Waybar + waybar & + + # Set up the idle management daemon + swayidle -w \ + timeout 120 'swaylock -f && playerctl pause' \ + timeout 180 'hyprctl dispatch dpms off' \ + timeout 300 'systemctl suspend-then-hibernate' \ + resume 'hyprctl dispatch dpms on' \ + before-sleep 'swaylock -f' \ + before-sleep 'playerctl pause' & + + # Automatic device mounting + udiskie & + + DIR=/etc/nixos/git/wallpapers/${theme} + IMG=`ls $DIR | shuf -n 1` + swww img $DIR/$IMG -t random & + + # Notification listener + mako + ''; + }; + }; +} diff --git a/home-manager/hosts/framework16/desktops/plasma6/default.nix b/home-manager/hosts/framework16/desktops/plasma6/default.nix new file mode 100644 index 00000000..100ec1ba --- /dev/null +++ b/home-manager/hosts/framework16/desktops/plasma6/default.nix @@ -0,0 +1,11 @@ +{ ... }: { + programs.plasma = { + configFile = { + # TODO May need to fix this for the new laptop + "kcminputrc"."Libinput/2362/628/PIXA3854:00 093A:0274 Touchpad" = { + "NaturalScroll" = true; + "TapDragLock" = true; + }; + }; + }; +} diff --git a/nixos/hosts/framework16/default.nix b/nixos/hosts/framework16/default.nix new file mode 100644 index 00000000..2df58153 --- /dev/null +++ b/nixos/hosts/framework16/default.nix @@ -0,0 +1,91 @@ +{ inputs, config, lib, pkgs, modulesPath, ... }: { + imports = [ + inputs.nixos-hardware.nixosModules.framework-16-7040-amd + (modulesPath + "/installer/scan/not-detected.nix") + ./disks.nix + ../../common/services/tailscale-autoconnect.nix + # ../../common/modules/secureboot.nix + ../../common/modules/boot.nix + ../../common/modules/udev-rules.nix + # ../../common/modules/yubikey-auth.nix + ../../common/modules/builder.nix + ../../common/services/podman.nix + ../../common/services/geoclue.nix + ../../common/services/syncthing.nix + ../../common/services/ollama.nix + ]; + + services.ollama.acceleration = "rocm"; + services.ollama.package = pkgs.ollama-rocm; + + hardware.bluetooth.enable = true; # enables support for Bluetooth + hardware.bluetooth.powerOnBoot = true; # powers up the default Bluetooth controller on boot + + services.fwupd.enable = true; + # we need fwupd 1.9.7 to downgrade the fingerprint sensor firmware + services.fwupd.package = (import (builtins.fetchTarball { + url = "https://github.com/NixOS/nixpkgs/archive/bb2009ca185d97813e75736c2b8d1d8bb81bde05.tar.gz"; + sha256 = "sha256:003qcrsq5g5lggfrpq31gcvj82lb065xvr7bpfa8ddsw8x4dnysk"; + }) { inherit (pkgs) system;}).fwupd; + + boot.initrd.availableKernelModules = [ "nvme" "xhci_pci" "thunderbolt" "usb_storage" "uas" "sd_mod" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-amd" ]; + boot.extraModulePackages = [ ]; + # boot.kernelPackages = pkgs.linuxPackages_latest; + boot.kernelParams = [ "boot.shell_on_fail" ]; + # boot.extraModulePackages = with config.boot.kernelPackages; [ acpi_call ]; + boot.kernelPackages = pkgs.linuxPackages_latest; + + networking.useDHCP = lib.mkDefault true; + powerManagement.cpuFreqGovernor = lib.mkDefault "ondemand"; + hardware.keyboard.zsa.enable = true; + hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; + # Set your time zone. + # time.timeZone = "Europe/Warsaw"; + + + # Set the networking hostname: + networking.hostName = "framework16"; + hardware = { + graphics.enable = true; + amdgpu.opencl.enable = true; + }; + + + programs.gamemode = { + enable = true; + enableRenice = true; + settings = { + general = { + renice = 10; + }; + # Warning: GPU optimisations have the potential to damage hardware + gpu = { + # apply_gpu_optimisations = "accept-responsibility"; + gpu_device = 0; + amd_performance_level = "high"; + }; + custom = { + start = "${pkgs.libnotify}/bin/notify-send 'GameMode started'"; + end = "${pkgs.libnotify}/bin/notify-send 'GameMode ended'"; + }; + }; + }; + + environment.systemPackages = with pkgs; [ + # Game related things + gamemode + # WINE + wineWowPackages.stable + winetricks + wineWowPackages.waylandFull + nvtopPackages.amd + # RGB stuff + openrgb-with-all-plugins + rivalcfg + + # Other + distrobox + ]; +} diff --git a/nixos/hosts/framework16/disks.nix b/nixos/hosts/framework16/disks.nix new file mode 100644 index 00000000..265a0503 --- /dev/null +++ b/nixos/hosts/framework16/disks.nix @@ -0,0 +1,87 @@ +{ + imports = [ ../../common/services/snapper.nix ]; + + services.cron = { + systemCronJobs = [ + "0 17 * * * root sudo btrfs-backup root" + "0 17 * * * root sudo btrfs-backup nix" + # "0 17 * * * root sudo btrfs-backup home" + ]; + }; + + services.btrfs.autoScrub.enable = true; + services.btrfs.autoScrub.interval = "weekly"; + + boot.resumeDevice = "/dev/mapper/ROOT"; + # https://sawyershepherd.org/post/hibernating-to-an-encrypted-swapfile-on-btrfs-with-nixos/ + boot.kernelParams = [ "resume_offset=533760" ]; + + disko.devices.disk.nvme0n1 = { + type = "disk"; + device = "/dev/nvme0n1"; + content = { + type = "gpt"; + partitions = { + BOOT = { + priority = 1; + name = "BOOT"; + start = "0%"; + end = "550MiB"; + type = "EF00"; + content = { + type = "filesystem"; + format = "vfat"; + # https://github.com/nix-community/disko/issues/527 + mountOptions = [ "umask=0077" ]; + mountpoint = "/boot"; + }; + }; # partition 1 (ESP) + LUKS-ROOT = { + start = "550MiB"; + end = "100%"; + content = { + type = "luks"; + name = "ROOT"; + extraOpenArgs = [ "--allow-discards" ]; + content = { + type = "btrfs"; + extraArgs = [ "-f" ]; + subvolumes = { + "/root" = { + mountpoint = "/"; + mountOptions = [ "compress=zstd" "noatime" ]; + }; # root + "/home" = { + mountpoint = "/home"; + mountOptions = [ "compress=zstd" "noatime" ]; + }; # home + "/nix" = { + mountpoint = "/nix"; + mountOptions = [ "compress=zstd" "noatime" ]; + }; # nix + # SNAPSHOT SUBVOLS + "/root/.snapshots" = { + mountpoint = "/.snapshots"; + mountOptions = [ "compress=zstd" "noatime" ]; + }; # root + "/home/.snapshots" = { + mountpoint = "/home/.snapshots"; + mountOptions = [ "compress=zstd" "noatime" ]; + }; # home + "/nix/.snapshots" = { + mountpoint = "/nix/.snapshots"; + mountOptions = [ "compress=zstd" "noatime" ]; + }; # nix + # Swap partition + "/swap" = { + mountpoint = "/swap"; + swap.swapfile.size = "64G"; + }; # swap + }; # subvolumes + }; # content.content + }; # content + }; # partition 2 (/ BTRFS) + }; # partitions + }; # content + }; # disko.devices.disk.nvme0 +} # nix diff --git a/nixos/hosts/framework16/hibernate.nix b/nixos/hosts/framework16/hibernate.nix new file mode 100644 index 00000000..2875a022 --- /dev/null +++ b/nixos/hosts/framework16/hibernate.nix @@ -0,0 +1,46 @@ +{ config, pkgs, ... }: + +let + hibernateEnvironment = { + HIBERNATE_SECONDS = "10"; + HIBERNATE_LOCK = "/var/run/autohibernate.lock"; + }; +in { + + systemd.services."awake-after-suspend-for-a-time" = { + description = "Sets up the suspend so that it'll wake for hibernation only if not on AC power"; + wantedBy = [ "suspend.target" ]; + before = [ "systemd-suspend.service" ]; + environment = hibernateEnvironment; + script = '' + if [ $(cat /sys/class/power_supply/ACAD/online) -eq 0 ]; then + curtime=$(date +%s) + echo "$curtime $1" >> /tmp/autohibernate.log + echo "$curtime" > $HIBERNATE_LOCK + ${pkgs.utillinux}/bin/rtcwake -m no -s $HIBERNATE_SECONDS + else + echo "System is on AC power, skipping wake-up scheduling for hibernation." >> /tmp/autohibernate.log + fi + ''; + serviceConfig.Type = "simple"; + }; + + systemd.services."hibernate-after-recovery" = { + description = "Hibernates after a suspend recovery due to timeout"; + wantedBy = [ "suspend.target" ]; + after = [ "systemd-suspend.service" ]; + environment = hibernateEnvironment; + script = '' + curtime=$(date +%s) + sustime=$(cat $HIBERNATE_LOCK) + rm $HIBERNATE_LOCK + if [ $(($curtime - $sustime)) -ge $HIBERNATE_SECONDS ] ; then + systemctl hibernate + else + ${pkgs.utillinux}/bin/rtcwake -m no -s 1 + fi + ''; + serviceConfig.Type = "simple"; + }; + +} \ No newline at end of file