nixos/pkgs/writeXrandrScriptBin/default.nix

28 lines
794 B
Nix
Raw Normal View History

2024-08-17 23:37:08 -07:00
{ lib, writeShellScriptBin, xrandr }:
2024-08-17 03:43:22 -07:00
let
inherit (builtins) getAttr hasAttr isAttrs concatStringsSep;
2024-08-17 23:37:08 -07:00
inherit (lib) assertMsg lists escapeShellArgs getExe;
2024-08-17 03:43:22 -07:00
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 [
2024-08-17 08:15:35 -07:00
(toGNUCommandLine { } { inherit output; })
2024-08-17 03:43:22 -07:00
(lists.optional (isPrimary config) "--primary")
(toGNUCommandLine { } config)
]));
args = mapAttrsToList getArgList config;
in
2024-08-17 00:14:46 -07:00
writeShellScriptBin name ''
2024-08-17 23:37:08 -07:00
${getExe xrandr} \
2024-08-17 03:43:22 -07:00
${concatStringsSep " \\\n " args}
2024-08-16 23:46:33 -07:00
''