<commit_before>{ lib
, stdenv
, alsa-lib
, at-spi2-atk
, at-spi2-core
, atk
, autoPatchelfHook
, cairo
, cups
, dbus
, dpkg
, expat
, fetchurl
, gdk-pixbuf
, glib
, gtk3
, libdrm
, libxkbcommon
, makeWrapper
, mesa
, nixosTests
, nspr
, nss
, pango
, pciutils
, systemd
, undmg
, writeShellScriptBin
, xorg
}:

let
  inherit (stdenv.hostPlatform) system;

  version = "3.1.0";

  # At first start, the program checks for supported operating systems by calling `lsb_release -a`
  # and only runs when it finds Debian/Ubuntu. So we present us as Debian an make it happy.
  fake-lsb-release = writeShellScriptBin "lsb_release" ''
    echo "Distributor ID: Debian"
    echo "Description:    Debian GNU/Linux 10 (buster)"
    echo "Release:        10"
    echo "Codename:       buster"
  '';

  binPath = lib.makeBinPath [
    fake-lsb-release
  ];

  systemArgs = rec {
    x86_64-linux = rec {
      src = fetchurl {
        url = "https://download.breitbandmessung.de/bbm/Breitbandmessung-${version}-linux.deb";
        sha256 = "sha256-jSP+H9ej9Wd+swBZSy9uMi2ExSTZ191FGZhqaocTl7w=";
      };

      dontUnpack = true;

      nativeBuildInputs = [
        autoPatchelfHook
        dpkg
        makeWrapper
      ];

      buildInputs = runtimeDependencies;

      runtimeDependencies = [
        alsa-lib
        at-spi2-atk
        at-spi2-core
        atk
        cairo
        cups
        dbus
        expat
        gdk-pixbuf
        glib
        gtk3
        libdrm
        libxkbcommon
        mesa
        nspr
        nss
        pango
        pciutils
        systemd
        xorg.libX11
        xorg.libXcomposite
        xorg.libXdamage
        xorg.libXext
        xorg.libXfixes
        xorg.libXrandr
        xorg.libxcb
        xorg.libxshmfence
      ];

      installPhase = ''
        dpkg-deb -x $src $out
        mkdir -p $out/bin

        chmod -R g-w $out

        addAutoPatchelfSearchPath --no-recurse $out/opt/Breitbandmessung
        autoPatchelfFile $out/opt/Breitbandmessung/breitbandmessung

        makeWrapper $out/opt/Breitbandmessung/breitbandmessung $out/bin/breitbandmessung \
          --prefix PATH : ${binPath}

        mv $out/usr/share $out/share
        rmdir $out/usr

        # Fix the desktop link
        substituteInPlace $out/share/applications/breitbandmessung.desktop \
          --replace /opt/Breitbandmessung $out/bin
      '';

      dontAutoPatchelf = true;
      dontPatchELF = true;
    };

    x86_64-darwin = {
      src = fetchurl {
        url = "https://download.breitbandmessung.de/bbm/Breitbandmessung-${version}-mac.dmg";
        sha256 = "sha256-2c8mDKJuHDSw7p52EKnJO5vr2kNTLU6r9pmGPANjE20=";<commit_msg>breitbandmessung: don't use bundled electron<commit_after>{ lib
, stdenv
, fetchurl
, dpkg
, electron_16
, makeWrapper
, nixosTests
, nodePackages
, undmg
}:

let
  inherit (stdenv.hostPlatform) system;

  version = "3.1.0";

  systemArgs = rec {
    x86_64-linux = rec {
      src = fetchurl {
        url = "https://download.breitbandmessung.de/bbm/Breitbandmessung-${version}-linux.deb";
        sha256 = "sha256-jSP+H9ej9Wd+swBZSy9uMi2ExSTZ191FGZhqaocTl7w=";
      };

      nativeBuildInputs = [
        dpkg
        makeWrapper
        nodePackages.asar
      ];

      unpackPhase = "dpkg-deb -x $src .";

      installPhase = ''
        mkdir -p $out/bin
        mv usr/share $out/share
        mkdir -p $out/share/breitbandmessung/resources

        asar e opt/Breitbandmessung/resources/app.asar $out/share/breitbandmessung/resources

        # At first start, the program checks for supported operating systems by using the `bizzby-lsb-release`
        # module and only runs when it finds Debian/Ubuntu. So we present us as Debian and make it happy.
        cat <<EOF > $out/share/breitbandmessung/resources/node_modules/bizzby-lsb-release/lib/lsb-release.js
        module.exports = function release() {
          return {
            distributorID: "Debian",
            description: "Debian GNU/Linux 10 (buster)",
            release: "10",
            codename: "buster"
          }
        }
        EOF

        makeWrapper ${electron_16}/bin/electron $out/bin/breitbandmessung \
          --add-flags $out/share/breitbandmessung/resources/build/electron.js

        # Fix the desktop link
        substituteInPlace $out/share/applications/breitbandmessung.desktop \
          --replace /opt/Breitbandmessung $out/bin
      '';
    };

    x86_64-darwin = {
      src = fetchurl {
        url = "https://download.breitbandmessung.de/bbm/Breitbandmessung-${version}-mac.dmg";
        sha256 = "sha256-2c8mDKJuHDSw7p52EKnJO5vr2kNTLU6r9pmGPANjE20=";
{'fraction_non_alphanumeric': 0.09842434707532915, 'fraction_numerical': 0.022447658104899633, 'mean_word_length': 2.1805078929306796, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1886729', 'n_tokens_mistral': 1745, 'n_tokens_neox': 1601, 'n_words': 306}