From d832db0455d1e7c3f622682c6531184cba66fb12 Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Thu, 2 Jul 2026 23:42:59 +0200 Subject: [PATCH] Add a machines directory to replace local.nix + detect if my device is a laptop --- .gitignore | 1 + configuration.nix | 14 ++++++- home/doggo/hyprland-config.nix | 65 +++++++++++++++++++++++++++------ local.nix | 67 ---------------------------------- machines/desktop/local.nix | 42 +++++++++++++++++++++ machines/laptop/local.nix | 23 ++++++++++++ modules/filesystems.nix | 8 ++-- modules/kernel.nix | 6 +++ 8 files changed, 142 insertions(+), 84 deletions(-) delete mode 100644 local.nix create mode 100644 machines/desktop/local.nix create mode 100644 machines/laptop/local.nix diff --git a/.gitignore b/.gitignore index 8ed425a..eae5166 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /hardware-configuration.nix +tamal/.silo \ No newline at end of file diff --git a/configuration.nix b/configuration.nix index 17be201..b902923 100644 --- a/configuration.nix +++ b/configuration.nix @@ -48,15 +48,21 @@ let localPackagesOverlay ]; }; + + isLaptop = + let + powerSupplyDir = /sys/class/power_supply; + in + builtins.pathExists powerSupplyDir && lib.any (name: lib.hasPrefix "BAT" name) (builtins.attrNames (builtins.readDir powerSupplyDir)); in { nixpkgs.pkgs = pkgs; # Uses the nixtamal nixpkgs _module.args.nixtamal = nixtamal; + _module.args.isLaptop = isLaptop; imports = [ ./workarounds.nix - ./local.nix ./hardware-configuration.nix # Results of the hardware scan ("nixos-generate-config" command) ./modules/filesystems.nix "${nixtamal.home-manager}/nixos" @@ -75,6 +81,10 @@ in ./common/ollama-config.nix + ./machines/${ + if isLaptop then "laptop" else "desktop" + }/local.nix + # ISO installer building stuff: ./ISO/iso.nix ]; @@ -126,7 +136,7 @@ in }; home-manager.extraSpecialArgs = { - inherit nixtamal localPackagesOverlay; + inherit nixtamal localPackagesOverlay isLaptop; }; home-manager.users.doggo = import ./home/doggo/doggo.nix; diff --git a/home/doggo/hyprland-config.nix b/home/doggo/hyprland-config.nix index 28d1da7..5cceb2f 100644 --- a/home/doggo/hyprland-config.nix +++ b/home/doggo/hyprland-config.nix @@ -12,8 +12,43 @@ let mocha = { peach = "rgb(fab387)"; }; + + find_monitor = id: "$(hyprctl monitors -j | jq -r '.[] | select(.id==${builtins.toString id}) | .name')"; + + backgrounds_commands = [ + "swaybg -i '${./backgrounds/ubuntu_budgie_wallpaper1.jpg}' -o ${find_monitor 0}" + "murale '/disk2/MemoryRebootHatsune&Shrek.avi' -o ${find_monitor 1} --mpv-options '${mpv_options}'" # TODO: Make nixtamal download it with yt-dlp + ]; + + # Start(/stop) my backgrounds on (un)plug + watch-ac-plug = pkgs.writeShellApplication { + name = "watch-ac-plug"; + runtimeInputs = [ pkgs.dbus pkgs.gawk ]; + text = '' + dbus-monitor --system "type='signal',interface='org.freedesktop.DBus.Properties',path='/org/freedesktop/UPower'" | + while read -r line; do + if echo "$line" | grep -q "OnBattery"; then + read -r _ state + if echo "$state" | grep -q "true"; then + ${builtins.concatStringsSep " && " (builtins.map (cmd: "pkill -f '.*${cmd}'") backgrounds_commands)} + else + ${builtins.concatStringsSep " && " (builtins.map (cmd: "${uwsm} ${cmd}") backgrounds_commands)} + fi + fi + done + ''; + }; in { + systemd.user.services.watch-ac-plug = lib.mkIf isLaptop { + Unit.Description = "Start/stop my backgrounds on AC plug/unplug"; + Install.WantedBy = [ "graphical-session.target" ]; + Service = { + ExecStart = "${watch-ac-plug}/bin/watch-ac-plug"; + Restart = "always"; + }; + }; + wayland.windowManager.hyprland = { enable = true; systemd = { @@ -24,30 +59,36 @@ in ]; settings = { - monitor = if !isLaptop then [ - { output = "DP-3"; mode = "2560x1440@144"; position = "0x0"; scale = 1; vrr = 2; } - { output = "HDMI-A-4"; mode = "1920x1080@77"; position = "-1920x128"; scale = 1; } - ] else [ - { - output = "eDP-1"; mode = "2880x1800@120"; position = "0x0"; scale = 1.5; + monitor = [ + ({ + # Desktop settings + output = "DP-3"; + mode = "highres@highrr"; + position = "0x0"; scale = 1; vrr = 2; + } // lib.optionalAttrs isLaptop { + # Laptop settings + output = "eDP-1"; + scale = 1.5; cm = "hdredid"; bitdepth = 10; min_luminance = 0.0; max_luminance = 2000; sdr_min_luminance = 0.005; sdr_max_luminance = 350; # 106? sdrsaturation = 1.0; # 1.175? 0.975? #sdrbrightness = 1.1; # 1.2625? 0.975? - } + }) + { output = ""; mode = "highres@highrr"; position = if isLaptop then "auto-right" else "auto-left"; scale = 1; } ]; - + # AUTOSTART # on = { _args = [ "hyprland.start" (lib.generators.mkLuaInline '' function() - ${if isLaptop then "-- " else ""}hl.exec_cmd("${uwsm} murale '/disk2/MemoryRebootHatsune&Shrek.avi' -o HDMI-A-4 --mpv-options '${mpv_options}'") - hl.exec_cmd("${uwsm} swaybg ${ - if isLaptop then "-c 000000 -o '*'" else "-i '${./backgrounds/ubuntu_budgie_wallpaper1.jpg}' -o DP-3" - }") + hl.exec_cmd("${uwsm} swaybg -c 000000 -o '*'") + ${builtins.concatStringsSep "\n " (builtins.map (cmd: + "hl.exec_cmd(\"${if isLaptop then "[ \"$(busctl get-property org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower OnBattery | awk '{print $2}')\" = \"true\" ] && " else ""}" + + "${uwsm} ${cmd}\")") backgrounds_commands) + } hl.exec_cmd("${uwsm} ironbar") hl.exec_cmd("${uwsm} wl-paste --type text --watch cliphist store") hl.exec_cmd("${uwsm} wl-paste --type image --watch cliphist store") diff --git a/local.nix b/local.nix deleted file mode 100644 index 5bad748..0000000 --- a/local.nix +++ /dev/null @@ -1,67 +0,0 @@ -{ config, lib, pkgs, functions, ...}: - -let - isLaptop = false; -in -{ - _module.args.isLaptop = isLaptop; - home-manager.extraSpecialArgs = { inherit isLaptop; }; - - boot.extraModulePackages = with config.boot.kernelPackages; [ - # Common modules - ] ++ (if !isLaptop then [ - # Desktop modules - (functions.mkPatchedAuto nct6687d) - r8125 - ] else [ - # Laptop modules - ]); - - boot.kernelModules = [ - # Common modules - ] ++ (if !isLaptop then [ - # Desktop modules - "nct6687" # d disappears in actual module name - "r8125" # replaces r8169 - ] else [ - # Laptop modules - ]); - - boot.blacklistedKernelModules = [] ++ (if !isLaptop then [ - "r8169" - ] else []); - - # CRU screen overclocking - hardware.firmware = lib.mkIf (!isLaptop) [ - (pkgs.runCommandLocal "PHL-edid-77hz" {} '' - mkdir -p $out/lib/firmware/edid - cp ${/disk2/Bunker/CRU/PHL_243V5_OC_77MHZ.bin} $out/lib/firmware/edid/PHL_243V5_OC_77MHZ.bin - '') - ]; - - boot.kernelParams = lib.mkIf (!isLaptop) [ - "drm.edid_firmware=HDMI-A-4:edid/PHL_243V5_OC_77MHZ.bin" - ]; - - programs.coolercontrol.enable = !isLaptop; - - boot.loader.limine.extraEntries = lib.mkIf (!isLaptop) '' - /Windows - protocol: efi - path: label(windows_efi):/EFI/Microsoft/Boot/bootmgfw.efi - ''; - - powerManagement.cpuFreqGovernor = if !isLaptop then "performance" else "schedutil"; - - services.auto-cpufreq = { - enable = isLaptop; - settings = { - charger.turbo = "auto"; - battery.turbo = "never"; - }; - }; - - fileSystems."/".options = [ "noatime" ]; - - networking.hostName = if !isLaptop then "lizard" else "lizard-portable"; -} diff --git a/machines/desktop/local.nix b/machines/desktop/local.nix new file mode 100644 index 0000000..9eaf3ef --- /dev/null +++ b/machines/desktop/local.nix @@ -0,0 +1,42 @@ +{ config, lib, pkgs, functions, ...}: + +{ + + boot.extraModulePackages = with config.boot.kernelPackages; [ + (functions.mkPatchedAuto nct6687d) + r8125 + ]; + + boot.kernelModules = [ + "nct6687" # d disappears in actual module name + "r8125" # replaces r8169 + ]; + + boot.blacklistedKernelModules = [ + "r8169" + ]; + + # CRU screen overclocking + hardware.firmware = [ + (pkgs.runCommandLocal "PHL-edid-77hz" {} '' + mkdir -p $out/lib/firmware/edid + cp ${/disk2/Bunker/CRU/PHL_243V5_OC_77MHZ.bin} $out/lib/firmware/edid/PHL_243V5_OC_77MHZ.bin + '') + ]; + + boot.kernelParams = [ + "drm.edid_firmware=HDMI-A-4:edid/PHL_243V5_OC_77MHZ.bin" + ]; + + programs.coolercontrol.enable = true; + + boot.loader.limine.extraEntries = '' + /Windows + protocol: efi + path: label(windows_efi):/EFI/Microsoft/Boot/bootmgfw.efi + ''; + + powerManagement.cpuFreqGovernor = "performance"; + + networking.hostName = "lizard"; +} diff --git a/machines/laptop/local.nix b/machines/laptop/local.nix new file mode 100644 index 0000000..f104189 --- /dev/null +++ b/machines/laptop/local.nix @@ -0,0 +1,23 @@ +{ config, ...}: + +{ + boot.extraModulePackages = with config.boot.kernelPackages; []; + + boot.kernelModules = []; + + boot.blacklistedKernelModules = []; + + powerManagement.cpuFreqGovernor = "schedutil"; + + services.auto-cpufreq = { + enable = true; + settings = { + charger.turbo = "auto"; + battery.turbo = "never"; + }; + }; + + services.upower.enable = true; + + networking.hostName = "lizard-portable"; +} diff --git a/modules/filesystems.nix b/modules/filesystems.nix index 482c6ee..3b36fcb 100644 --- a/modules/filesystems.nix +++ b/modules/filesystems.nix @@ -2,8 +2,9 @@ { # Note: for f2fs, create it with "sudo mkfs.f2fs -l root -i -O extra_attr,flexible_inline_xattr,inode_checksum,sb_checksum,compression,lost_found /dev/sdxY" - fileSystems."/".options = lib.mkIf (config.fileSystems."/".fsType == "f2fs") - (lib.mkAfter [ + fileSystems."/".options = lib.mkMerge [ + [ "noatime" ] + (lib.mkIf (config.fileSystems."/".fsType == "f2fs") (lib.mkAfter [ "discard" # Better (on f2fs) than fstrim "X-fstrim.notrim" # To avoid fstrim "compress_algorithm=lzo-rle" @@ -16,7 +17,8 @@ "checkpoint_merge" "fsync_mode=posix" "nat_bits" - ]); + ])) + ]; services.fstrim.enable = true; diff --git a/modules/kernel.nix b/modules/kernel.nix index 16bcd32..abacdbf 100644 --- a/modules/kernel.nix +++ b/modules/kernel.nix @@ -51,6 +51,12 @@ boot.kernelPatches = [ ]; + boot.extraModulePackages = []; + + boot.kernelModules = []; + + boot.blacklistedKernelModules = []; + services.scx = { # https://wiki.cachyos.org/configuration/sched-ext/#general-recommendations enable = true; scheduler = "scx_lavd";