Compare commits

..

5 Commits

Author SHA1 Message Date
Zynh Ludwig c4b536f3cf writeXrandrScriptBin: config input 2024-08-17 06:57:31 -07:00
Zynh Ludwig 9b279a0b3c pkgs: callDefaultPackage alias 2024-08-17 05:46:00 -07:00
Zynh Ludwig a1903be803 pkgs: name passing 2024-08-17 05:45:52 -07:00
Zynh Ludwig b9ee61bc0c pkgs: writeXrandrScriptBin 2024-08-17 05:45:52 -07:00
Zynh Ludwig 353dc4fac3 pkgs: lib binding 2024-08-17 03:08:17 -07:00
3 changed files with 50 additions and 12 deletions

View File

@ -65,17 +65,24 @@ in
systemctl suspend systemctl suspend
'') '')
(writeShellScriptBin "tv-on" '' (writeXrandrScriptBin "tv-on" {
xrandr \ DP-0 = {
--output DP-0 --primary --mode 1920x1080 --pos 1920x1080 --rotate normal \ primary = true;
--output HDMI-0 --mode 1920x1080 --pos 0x1080 --rotate normal \ mode = "1920x1080";
--output HDMI-1 --mode 1920x1080 --pos 1920x0 --rotate normal \ pos = "1920x1080";
--output DP-1 --off \ rotate = "normal";
--output DP-2 --off \ };
--output DP-3 --off \ HDMI-0 = {
--output DP-4 --off \ mode = "1920x1080";
--output DP-5 --off pos = "0x1080";
'') rotate = "normal";
};
HDMI-1 = {
mode = "1920x1080";
pos = "1920x0";
rotate = "normal";
};
})
feh feh
imagemagick imagemagick

View File

@ -1,4 +1,8 @@
final: prev: final: prev:
let
callDefaultPackage = path: prev.callPackage path { };
in
{ {
wrapWine = prev.lib.callPackage ./wrapWine.nix { }; wrapWine = callDefaultPackage ./wrapWine.nix;
writeXrandrScriptBin = callDefaultPackage ./writeXrandrScriptBin.nix;
} }

View File

@ -0,0 +1,27 @@
{ lib, writeShellScriptBin }:
let
inherit (builtins) getAttr hasAttr isAttrs concatStringsSep;
inherit (lib) assertMsg lists escapeShellArgs;
inherit (lib.attrsets) mapAttrsToList;
inherit (lib.cli) toGNUCommandLine;
in
name: config:
assert assertMsg (isAttrs config)
"config should be an attrs, found ${lib.typeOf config}";
let
isPrimary = config:
(hasAttr "primary" config) && (getAttr "primary" config);
getArgList = output: config:
(escapeShellArgs (lists.flatten [
(toGNUCommandLine { } { "--output" = output; })
(lists.optional (isPrimary config) "--primary")
(toGNUCommandLine { } config)
]));
args = mapAttrsToList getArgList config;
in
writeShellScriptBin name ''
xrandr \
${concatStringsSep " \\\n " args}
''