From f6381b14b0b53c2f29f97f047e6a2d59313bf1f0 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 4 Nov 2021 15:55:33 +0100 Subject: [PATCH] pkgs: add change-backlight --- pkgs/change-backlight/change-backlight | 15 +++++++++ pkgs/change-backlight/default.nix | 44 ++++++++++++++++++++++++++ pkgs/default.nix | 2 ++ 3 files changed, 61 insertions(+) create mode 100755 pkgs/change-backlight/change-backlight create mode 100644 pkgs/change-backlight/default.nix diff --git a/pkgs/change-backlight/change-backlight b/pkgs/change-backlight/change-backlight new file mode 100755 index 0000000..e178151 --- /dev/null +++ b/pkgs/change-backlight/change-backlight @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +set -euo pipefail + +if [ "$1" = "up" ]; then + upDown="+$2%" +else + upDown="$2%-" +fi + +newBrightness="$(brightnessctl -m set "$upDown" | cut -d, -f4)" +notify-send -u low \ + -h string:x-canonical-private-synchronous:change-backlight \ + -h "int:value:${newBrightness/\%/}" \ + -- "Set brightness to $newBrightness" diff --git a/pkgs/change-backlight/default.nix b/pkgs/change-backlight/default.nix new file mode 100644 index 0000000..799c814 --- /dev/null +++ b/pkgs/change-backlight/default.nix @@ -0,0 +1,44 @@ +{ lib, brightnessctl, libnotify, makeWrapper, shellcheck, stdenvNoCC }: +stdenvNoCC.mkDerivation rec { + pname = "change-backlight"; + version = "0.1.0"; + + src = ./change-backlight; + + buildInputs = [ + makeWrapper + shellcheck + ]; + + dontUnpack = true; + + buildPhase = '' + shellcheck $src + ''; + + installPhase = '' + mkdir -p $out/bin + cp $src $out/bin/change-backlight + chmod a+x $out/bin/change-backlight + ''; + + wrapperPath = lib.makeBinPath [ + brightnessctl + libnotify + ]; + + fixupPhase = '' + patchShebangs $out/bin/change-backlight + wrapProgram $out/bin/change-backlight --prefix PATH : "${wrapperPath}" + ''; + + meta = with lib; { + description = '' + A script to change a screen's brightness and notify about it + ''; + homepage = "https://gitea.belanyi.fr/ambroisie/nix-config"; + license = with licenses; [ mit ]; + platforms = platforms.linux; + maintainers = with maintainers; [ ambroisie ]; + }; +} diff --git a/pkgs/default.nix b/pkgs/default.nix index 46fa4ab..3f7b1df 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -2,6 +2,8 @@ pkgs.lib.makeScope pkgs.newScope (pkgs: { bw-pass = pkgs.callPackage ./bw-pass { }; + change-backlight = pkgs.callPackage ./change-backlight { }; + comma = pkgs.callPackage ./comma { }; diff-flake = pkgs.callPackage ./diff-flake { };