Unverified Commit b35afb8c authored by kirillrdy's avatar kirillrdy Committed by GitHub
Browse files

xbattbar: fix build with gcc 14, refactor (#388567)

parents 58895630 d1b07b46
Loading
Loading
Loading
Loading
+24 −18
Original line number Diff line number Diff line
@@ -4,10 +4,9 @@
  fetchgit,
  libX11,
  perl,
  ...
}:

stdenv.mkDerivation rec {
stdenv.mkDerivation (finalAttrs: {
  pname = "xbattbar";
  version = "1.4.9";

@@ -15,40 +14,47 @@ stdenv.mkDerivation rec {
  # repository.
  src = fetchgit {
    url = "https://salsa.debian.org/debian/xbattbar.git";
    rev = "upstream/${version}";
    sha256 = "10w7gs0l4hzhdn38yqyr3az7n4ncmfnd6hhhly6lk5dg7k441ck6";
    tag = "upstream/${finalAttrs.version}";
    hash = "sha256-ZrJAyDyvlUmNpxBC06yrzBJ7vhrZY4+GbfBDQoF+h4M=";
  };

  buildInputs = [ libX11 ];

  # The following patches are applied:
  # - sys-by-default: remove the APM checker binary, make the sys checker
  # remove the APM checker binary, make the sys checker
  # script the default. Rationale: checking battery status by /proc/apm is
  # extremely oldschool and does not work on NixOS, while the sysfs script
  # does.
  patches = [ ./sys-by-default.patch ];
  # - perl shebang patches for acpi/sys scripts
  # - unhardcode path to checker scripts
  patchPhase = ''
    patch -p1 < ${./sys-by-default.patch}
  # - add missing return type in main function
  postPatch = ''
    substituteInPlace xbattbar.c \
      --replace-fail "main(int argc" "int main(int argc"

    sed -i -e "s,/usr/lib/xbattbar/,$out/libexec/," xbattbar.c
    sed -i -e "s,/usr/bin/perl,${perl}/bin/perl," xbattbar-check-acpi
    sed -i -e "s,/usr/bin/perl,${perl}/bin/perl," xbattbar-check-sys
  '';

  installPhase = ''
    mkdir -p $out/bin
    mkdir -p $out/libexec
    runHook preInstall

    mkdir -p $out/{bin,libexec}

    install -m 0755 xbattbar $out/bin/
    install -m 0755 xbattbar-check-acpi $out/libexec/
    install -m 0755 xbattbar-check-sys $out/libexec/

    runHook postInstall
  '';

  meta = with lib; {
  meta = {
    description = "Display battery status in X11";
    homepage = "https://salsa.debian.org/debian/xbattbar";
    license = licenses.gpl2Plus;
    platforms = platforms.linux;
    maintainers = [ maintainers.q3k ];
    license = with lib; licenses.gpl2Plus;
    platforms = lib.platforms.linux;
    maintainers = with lib.maintainers; [ q3k ];
    mainProgram = "xbattbar";
  };
}
})