nixos/pkgs/writeXrandrScriptBin/default.nix

28 lines
794 B
Nix
Raw Normal View History

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