Compare commits

...

4 commits

Author SHA1 Message Date
ecfbf9a557
fixup power config 2024-05-02 15:04:38 +02:00
388a6da603
Merge branch 'power' 2024-05-02 14:26:08 +02:00
5159f69f76
fix cpu detection 2024-05-02 14:25:50 +02:00
caf81af676
experimental 2024-05-02 14:02:35 +02:00
14 changed files with 183 additions and 85 deletions

View file

@ -10,7 +10,7 @@ let
local = mkOption {
type = types.nonEmptyStr;
default = "$HOME/" + (lib.strings.concatStrings (builtins.match "/*(.+)" config.remote));
default = "$HOME/" + (concatStrings (builtins.match "/*(.+)" config.remote));
description = "local path to sync";
};
};

View file

@ -4,7 +4,7 @@ let
screen = with lib; types.submodule {
options = {
fps = mkOption {
type = types.int;
type = types.either types.int (types.nonEmptyListOf types.int);
default = 60;
description = "max framerate of screen";
};

View file

@ -15,6 +15,12 @@ let
description = "set of commands to be run at sway startup";
};
execAlways = mkOption {
type = types.listOf (types.either types.nonEmptyStr types.package);
default = [ ];
description = "set of commands to be run at sway reload";
};
extraConfig = mkOption {
type = types.str;
default = "";
@ -34,6 +40,35 @@ let
};
};
});
build_screen_def = fps_func: with lib; let
output_def = mapAttrsToList
(name: value:
"output ${value.id} mode ${value.mode}@${toString (fps_func value.fps)}Hz"
+ (optionalString (value.pos != null) " position ${value.pos}")
)
cfg.screens;
in
''
for pid in $(${pkgs.procps}/bin/pgrep sway -x)
do
uid=$(id -u $(${pkgs.procps}/bin/ps -o user= -p $pid))
export SWAYSOCK="/run/user/$uid/sway-ipc.$uid.$pid.sock"
if [[ -e "$SWAYSOCK" ]] ; then
echo "sock is $SWAYSOCK"
${config.programs.sway.package}/bin/swaymsg '${concatMapStrings (s: s + " ; ") output_def}'
fi
done
'';
inherit (lib) getExe;
fps_min = fps: with lib; if isInt fps then fps else (foldl' min 2147483647 fps);
fps_max = fps: with lib; if isInt fps then fps else (foldl' max 0 fps);
init_screens_min_fps = with lib; pkgs.writeShellScriptBin "init-screens-min"
(build_screen_def fps_min);
init_screens_max_fps = with lib; pkgs.writeShellScriptBin "init-screens-max"
(build_screen_def fps_max);
init_screens_auto = pkgs.writeShellScriptBin "init-screens-auto" "which run-on-ac && which run-on-bat && run-on-ac ${getExe init_screens_max_fps} && run-on-bat ${getExe init_screens_min_fps} || ${getExe init_screens_max_fps}";
in
{
config =
@ -46,7 +81,7 @@ in
bar_config = ''
bar {
swaybar_command ${lib.getExe waybar_full}
swaybar_command ${getExe waybar_full}
}
'';
@ -60,15 +95,16 @@ in
let
build_definition_lines = mapAttrsToList (name: value: "set \$${name} ${value}");
build_keybind_lines = mapAttrsToList (key: value: "bindsym ${key} ${value}");
build_exec_lines = map (item: "exec " + (if isString item then item else (getExe item)));
build_exec_lines = e: map (item: "${e} " + (if isString item then item else (getExe item)));
build_mode_lines = mapAttrsToList (name: value: ''
mode "${name}" {
${strings.concatLines (map (item: " " + item ) (build_conf value))}}'');
${concatLines (map (item: " " + item ) (build_conf value))}}'');
in
([ ]
++ (build_definition_lines sway_conf.definitions)
++ (build_keybind_lines sway_conf.keybinds)
++ (build_exec_lines sway_conf.autolaunch)
++ (build_exec_lines "exec" sway_conf.autolaunch)
++ (build_exec_lines "exec_always" sway_conf.execAlways)
++ (build_mode_lines sway_conf.modes)
++ optional (sway_conf.extraConfig != "") sway_conf.extraConfig
);
@ -78,7 +114,7 @@ in
++ lib.optional cfg.sway.bar.enable bar_config
++ (lib.mapAttrsToList
(name: value:
"output ${value.id} mode ${value.mode}@${toString value.fps}Hz"
"output ${value.id} mode ${value.mode}"
+ (lib.optionalString (value.pos != null) " position ${value.pos}")
)
cfg.screens)
@ -89,11 +125,17 @@ in
with cfg; lib.mkIf (enable && sway.enable) {
environment.etc."${conf_path}".text = sway_conf;
grimmShared.sway.config.autolaunch = lib.singleton dbus-sway-environment;
grimmShared.sway.config.execAlways = [
dbus-sway-environment
init_screens_auto
];
environment.systemPackages = [
waybar_full
dbus-sway-environment
init_screens_min_fps
init_screens_max_fps
init_screens_auto
] ++ (with pkgs; [
procps
slurp

View file

@ -11,6 +11,8 @@ in
usbutils
opentabletdriver
ddcutil
python312Packages.py-cpuinfo
(writeShellScriptBin "lsiommu" ./lsiommu)
] ++ lib.optionals graphical [
ddcui
];
@ -44,14 +46,15 @@ in
boot = {
kernelParams = [
"splash"
"quiet"
"intel_iommu=on"
"iommu=force"
"pcie_acs_override=downstream"
"mmio_stale_data=full,nosmt"
"pcie_aspm=off"
# "splash"
# "quiet"
# "intel_iommu=on"
# "iommu=force"
# "pcie_acs_override=downstream"
# "mmio_stale_data=full,nosmt"
# "pcie_aspm=off"
]; # "vfio-pci.ids=10de:1aeb,10de:2191,10de:1aed,10de:1aec" ];
loader.efi.canTouchEfiVariables = true;
initrd.availableKernelModules = [
"xhci_pci"
"ahci"
@ -73,10 +76,10 @@ in
}))
];
kernelModules = [
"kvm-intel"
"vfio_pci"
"vfio_iommu_type1"
"vfio"
# "kvm-intel"
# "vfio_pci"
# "vfio_iommu_type1"
# "vfio"
"ddcci_backlight"
"i2c-dev"
];

View file

@ -1,23 +1,57 @@
{ pkgs, config, lib, system, ... }:
let
cfg = config.grimmShared;
perf_policy = lib.optional (lib.systems.elaborate system).isx86 config.boot.kernelPackages.x86_energy_perf_policy;
inherit (lib) optionals optional optionalString concatLines getExe;
inherit (config.boot.kernelPackages) x86_energy_perf_policy cpupower;
enable_perf_policy = (lib.elem system x86_energy_perf_policy.meta.platforms);
powersave = with pkgs; writeShellScriptBin "powersave-mode" (concatLines ([
"${getExe cpupower} frequency-set -g powersave -u 2000000" # clock speed
"${getExe pkgs.brightnessctl} s 20%" # display brightness
] ++ optionals enable_perf_policy [
"${getExe x86_energy_perf_policy} 15" # power save preference
"${getExe x86_energy_perf_policy} --turbo-enable 0" # disable turbo
] ++ optional cfg.sway.enable "init-screens-min"));
performance = pkgs.writeShellScriptBin "performance-mode" (concatLines ([
"${getExe cpupower} frequency-set frequency-set -g performance -u 5000000" # clock speed
"${getExe pkgs.brightnessctl} s 100%" # display brightness
] ++ optionals enable_perf_policy [
"${getExe x86_energy_perf_policy} 0" # performance preference
"${getExe x86_energy_perf_policy} --turbo-enable 1" # enable turbo
] ++ optional cfg.sway.enable "init-screens-max"));
auto = let inherit (pkgs) tlp; in pkgs.writeShellScriptBin "auto-mode" ''
${tlp}/bin/run-on-ac ${getExe performance}
${tlp}/bin/run-on-bat ${getExe powersave}
'';
in
{
config = with cfg; lib.mkIf (enable && laptop_hardware.enable) {
environment.systemPackages = with pkgs; [
acpi
powertop
] ++ lib.optionals graphical [
brightnessctl
cpupower
powersave
performance
auto
] ++ optionals graphical [
tlpui
] ++ perf_policy;
] ++ optional enable_perf_policy x86_energy_perf_policy;
services.acpid = {
enable = true;
acEventCommands = getExe auto;
};
powerManagement.scsiLinkPolicy = lib.mkIf (!config.services.tlp.enable) "min_power";
powerManagement.cpuFreqGovernor = lib.mkDefault "normal";
services.power-profiles-daemon.enable = false;
services.upower.enable = true;
boot.extraModulePackages = perf_policy;
#boot.extraModulePackages = [
# cpupower
#] ++ optional enable_perf_policy x86_energy_perf_policy;
services.tlp = {
enable = true;

View file

@ -13,7 +13,6 @@ in
config = with cfg; lib.mkIf (enable && tooling.enable) {
environment.systemPackages = with pkgs; [
(writeShellScriptBin "systemd-owner" "systemctl show -pUser,UID $@")
(writeShellScriptBin "lsiommu" ./lsiommu)
(writeShellScriptBin "tree" "${lib.getExe pkgs.eza} -T --git -lh --no-permissions --no-user --no-filesize --no-time")
urlencode
pstree
@ -30,7 +29,7 @@ in
fbcat
gomuks
gotop
btop
ranger
wget
file

View file

@ -36,7 +36,7 @@ in
{
config = with cfg; lib.mkIf (enable && portals && graphical) {
environment.systemPackages = with pkgs; [
(callPackage ../../custom/deskwhich/package.nix {})
(callPackage ../../custom/deskwhich/package.nix { })
zathura
imhex
@ -99,7 +99,7 @@ in
"ranger.desktop"
"dolphin.desktop"
];
"x-scheme-handler/mailto"="thunderbird.desktop";
"x-scheme-handler/mailto" = "thunderbird.desktop";
"application/vnd.oasis.opendocument.chart" = "calc.desktop";
"application/vnd.oasis.opendocument.chart-template" = "calc.desktop";

View file

@ -17,12 +17,12 @@ in
];
wlr.enable = true;
wlr.settings = lib.mapAttrs'
(name: value: lib.nameValuePair ("screencast_" + name) {
wlr.settings = with lib; mapAttrs'
(name: value: nameValuePair ("screencast_" + name) {
output_name = value.id;
max_fps = value.fps;
max_fps = if isInt value.fps then value.fps else (foldl' min 2147483647 value.fps);
chooser_type = "simple";
chooser_cmd = "${lib.getExe pkgs.slurp} -f %o -or";
chooser_cmd = "${getExe pkgs.slurp} -f %o -or";
})
cfg.screens;
};

View file

@ -78,11 +78,11 @@
"yafas": "yafas"
},
"locked": {
"lastModified": 1714482312,
"narHash": "sha256-qs41DgEGR2d6Hh+FnfL/6NagoCtRXDXC7yaGD398EXE=",
"lastModified": 1714566321,
"narHash": "sha256-cTWwPbwYtE8r6MuR+0ybG4CFeE8Sid5XHbFJq4itO+A=",
"owner": "chaotic-cx",
"repo": "nyx",
"rev": "8cfa2aa1528faa6319e2e5ab664ff463ba57708c",
"rev": "5939d3fb76b25a48a8c0db716ebb6fe28eab3719",
"type": "github"
},
"original": {
@ -186,7 +186,7 @@
},
"original": {
"type": "tarball",
"url": "https://flakehub.com/f/ipetkov/crane/%2A.tar.gz"
"url": "https://flakehub.com/f/ipetkov/crane/%3D0.16.1.tar.gz"
}
},
"darwin": {
@ -220,12 +220,12 @@
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1711952616,
"narHash": "sha256-WJvDdOph001fA1Ap3AyaQtz/afJAe7meSG5uJAdSE+A=",
"rev": "209048d7c545905c470f6f8c05c5061f391031a8",
"revCount": 1822,
"lastModified": 1714544767,
"narHash": "sha256-kF1bX+YFMedf1g0PAJYwGUkzh22JmULtj8Rm4IXAQKs=",
"rev": "73124e1356bde9411b163d636b39fe4804b7ca45",
"revCount": 1852,
"type": "tarball",
"url": "https://api.flakehub.com/f/pinned/nix-community/fenix/0.1.1822%2Brev-209048d7c545905c470f6f8c05c5061f391031a8/018e98ba-d842-7dad-9d6a-0d0ee173b6b1/source.tar.gz"
"url": "https://api.flakehub.com/f/pinned/nix-community/fenix/0.1.1852%2Brev-73124e1356bde9411b163d636b39fe4804b7ca45/018f333a-c195-795f-9e07-b43b47d5391f/source.tar.gz"
},
"original": {
"type": "tarball",
@ -382,11 +382,11 @@
]
},
"locked": {
"lastModified": 1714430505,
"narHash": "sha256-SSJQ/KOy8uISnoZgqDoRha7g7PFLSFP/BtMWm0wUz8Q=",
"lastModified": 1714515075,
"narHash": "sha256-azMK7aWH0eUc3IqU4Fg5rwZdB9WZBvimOGG3piqvtsY=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "f8e6694edabe4aaa7a85aac47b43ea5d978b116d",
"rev": "6d3b6dc9222c12b951169becdf4b0592ee9576ef",
"type": "github"
},
"original": {
@ -430,11 +430,11 @@
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1714411325,
"narHash": "sha256-td58oD5JOlL8LPglrk+c7rP+nJSJmK7zu0kFGF16XPI=",
"lastModified": 1714532637,
"narHash": "sha256-2oWMEjkJKYzxLXy3OZ/M41VdbZgZLWmwttry551lUE4=",
"owner": "martinvonz",
"repo": "jj",
"rev": "e54e83b0f5c4a5b7d80894c713ae402a5bb280d0",
"rev": "7093d5d359fb3649be0d12a975f26d5607ad8f61",
"type": "github"
},
"original": {
@ -467,11 +467,11 @@
]
},
"locked": {
"lastModified": 1714468768,
"narHash": "sha256-lxbNfjtTOcY18E9ODj3ZwJiF8UWr58CH+/9V3eHdtoQ=",
"lastModified": 1714551038,
"narHash": "sha256-/b4HT/RYfNkKUUpIzIwsHThLLAuKA70O8W/32sh2N0M=",
"owner": "YaLTeR",
"repo": "niri",
"rev": "68ff36f6834beecf74b30a724ae3ef31874a3518",
"rev": "af9caa1d9b176fe3606323a8c05c0c741c1f6c0a",
"type": "github"
},
"original": {
@ -657,11 +657,11 @@
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1711885694,
"narHash": "sha256-dyezzeSbWMpflma+E9USmvSxuLgGcNGcGw3cOnX36ko=",
"lastModified": 1714501997,
"narHash": "sha256-g31zfxwUFzkPgX0Q8sZLcrqGmOxwjEZ/iqJjNx4fEGo=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "e4a405f877efd820bef9c0e77a02494e47c17512",
"rev": "49e502b277a8126a9ad10c802d1aaa3ef1a280ef",
"type": "github"
},
"original": {

View file

@ -42,6 +42,10 @@
url = "https://patch-diff.githubusercontent.com/raw/NixOS/nixpkgs/pull/307541.patch";
hash = "sha256-cyxiWCxBOKrET710C8o9Cwksy64HRez6mB1qF+anHMI=";
}
{
url = "https://patch-diff.githubusercontent.com/raw/NixOS/nixpkgs/pull/308476.patch";
hash = "sha256-J/Bvz4RUn9lP7H4s/c6bZEX9dfWsxfG/dpXYF99U3Vs=";
}
];
customNixosSystem = system: definitions:

View file

@ -8,10 +8,6 @@
networking.hostName = "grimmauld-nixos";
environment.sessionVariables = {
OMP_NUM_THREADS = "12";
};
system.stateVersion = "23.05";
grimmShared.gaming = true;

View file

@ -2,7 +2,9 @@
# and may be overwritten by future invocations. Please make changes
# to /etc/nixos/configuration.nix instead.
{ config, lib, pkgs, modulesPath, ... }:
let
cpus = "12";
in
{
imports =
[
@ -12,6 +14,7 @@
boot.initrd.kernelModules = [ ];
boot.extraModulePackages = [ ];
boot.kernelParams = [ "possible_cpus=${cpus}" ];
fileSystems."/" =
{
@ -32,16 +35,20 @@
size = 48 * 1024;
}];
environment.sessionVariables = {
OMP_NUM_THREADS = cpus;
};
grimmShared = {
screens = {
external = {
id = "HDMI-A-1";
pos = "0,0";
pos = "0 0";
};
internal = {
id = "eDP-1";
fps = 144;
fps = [ 144 60 ];
};
};
laptop_hardware.enable = true;

View file

@ -1,12 +1,12 @@
{ inputs, system, pkgs, config, lib, ... }:
let
{ inputs, system, pkgs, config, lib, ... }:
let
searchclip = pkgs.writeShellScriptBin "searchclip" ''
xdg-open https://www.google.com/search?q=$(wl-paste -p | urlencode)
browser=$(xdg-settings get default-web-browser | sed "s/\.desktop//")
swaymsg [app_id="$browser" urgent="newest"] focus
'';
xdg-open https://www.google.com/search?q=$(wl-paste -p | urlencode)
browser=$(xdg-settings get default-web-browser | sed "s/\.desktop//")
swaymsg [app_id="$browser" urgent="newest"] focus
'';
in
{
{
environment.systemPackages = with pkgs; [
alacritty
rmenu
@ -18,6 +18,7 @@ in
qt6ct
swaynotificationcenter
searchclip
ydotool
];
grimmShared.sway = {
@ -29,9 +30,10 @@ in
style = ./bar/style.css;
};
config = with pkgs; let
config = with pkgs; let
inherit (lib) getExe;
in {
in
{
definitions = {
mod = "Mod4";
left = "h";
@ -152,23 +154,34 @@ in
XF86MonBrightnessDown = "exec ${getExe brightnessctl} s 10-%";
XF86Explorer = "exec $term --command ${getExe ranger}";
XF86Search = "exec ${getExe searchclip}";
XF86HomePage = let open = pkgs.writeShellScriptBin "open_or_switch_browser" ''
browser=$(xdg-settings get default-web-browser | sed "s/\.desktop//")
swaymsg [app_id="$browser"] focus || deskwhich $browser | xargs gio launch
''; in "exec ${getExe open}";
XF86Tools = let open = pkgs.writeShellScriptBin "open_or_switch_spotify" ''
# FIXME: spotify is being weird
while IFS= read -r pid; do
swaymsg [pid=$pid] focus && exit 0
done <<< $(pgrep spotify -u "$(whoami)")
deskwhich spotify | xargs gio launch
''; in "exec ${getExe open}"; # for some reason tools = audio media on my keyboard??
XF86Mail = let open = pkgs.writeShellScriptBin "open_or_switch_mail" ''
desk=$(xdg-settings get default-url-scheme-handler mailto | sed "s/\.desktop//")
swaymsg [app_id="$desk"] focus || deskwhich $desk | xargs gio launch
'';
in "exec ${getExe open}";
XF86HomePage =
let
open = pkgs.writeShellScriptBin "open_or_switch_browser" ''
browser=$(xdg-settings get default-web-browser | sed "s/\.desktop//")
swaymsg [app_id="$browser"] focus || deskwhich $browser | xargs gio launch
'';
in
"exec ${getExe open}";
XF86Tools =
let
open = pkgs.writeShellScriptBin "open_or_switch_spotify" ''
# FIXME: spotify is being weird
while IFS= read -r pid; do
swaymsg [pid=$pid] focus && exit 0
done <<< $(pgrep spotify -u "$(whoami)")
deskwhich spotify | xargs gio launch
'';
in
"exec ${getExe open}"; # for some reason tools = audio media on my keyboard??
XF86Mail =
let
open = pkgs.writeShellScriptBin "open_or_switch_mail" ''
desk=$(xdg-settings get default-url-scheme-handler mailto | sed "s/\.desktop//")
swaymsg [app_id="$desk"] focus || deskwhich $desk | xargs gio launch
'';
in
"exec ${getExe open}";
# XF86Bluetooth = "exec blueman-manager";
};
autolaunch = with pkgs; [
# fixme: absolute paths