<commit_before>{ stdenv, fetchurl, makeWrapper
, perl, libassuan, libgcrypt
, perlPackages, lockfileProgs, gnupg
# For the tests:
, bash, openssh, which, socat, cpio, hexdump
}:

stdenv.mkDerivation rec {
  name = "monkeysphere-${version}";
  version = "0.42";

  src = fetchurl {
    url = "http://archive.monkeysphere.info/debian/pool/monkeysphere/m/monkeysphere/monkeysphere_${version}.orig.tar.gz";
    sha256 = "1haqgjxm8v2xnhc652lx79p2cqggb9gxgaf19w9l9akar2qmdjf1";
  };

  patches = [ ./monkeysphere.patch ];

  nativeBuildInputs = [ makeWrapper ];
  buildInputs = [ perl libassuan libgcrypt ]
    ++ stdenv.lib.optional doCheck
      ([ gnupg openssh which socat cpio hexdump ] ++
      (with perlPackages; [ CryptOpenSSLRSA CryptOpenSSLBignum ]));

  makeFlags = ''
    PREFIX=/
    DESTDIR=$(out)
  '';

  # Not all checks pass yet (NixOS specific problems) and the tests "drain"
  # entropy (apparently GnuPG still uses /dev/random).
  doCheck = false;
  preCheck = ''
    patchShebangs tests/keytrans
    patchShebangs src/share/keytrans
    patchShebangs src/share/checkperms
    sed -i "s,/usr/bin/env\ bash,${bash}/bin/bash," tests/basic
    sed -i "s,/usr/sbin/sshd,${openssh}/bin/sshd," tests/basic
    sed -i "s/<(hd/<(hexdump/" tests/keytrans
  '';

  postFixup =
    let wrapperArgs = runtimeDeps:
          "--prefix PERL5LIB : "
          + (with perlPackages; stdenv.lib.makePerlPath [
              CryptOpenSSLRSA
              CryptOpenSSLBignum
            ])
          + stdenv.lib.optionalString
              (builtins.length runtimeDeps > 0)
              " --prefix PATH : ${stdenv.lib.makeBinPath runtimeDeps}";
        wrapMonkeysphere = runtimeDeps: program:
          "wrapProgram $out/bin/${program} ${wrapperArgs runtimeDeps}\n";
        wrapPrograms = runtimeDeps: programs: stdenv.lib.concatMapStrings
          (wrapMonkeysphere runtimeDeps)
          programs;
    in wrapPrograms [ gnupg ] [ "monkeysphere-authentication" "monkeysphere-host" ]
      + wrapPrograms [ lockfileProgs ] [ "monkeysphere" ]
      + ''
        # These 4 programs depend on the program name ($0):
        for program in openpgp2pem openpgp2spki openpgp2ssh pem2openpgp; do
          rm $out/bin/$program
          ln -sf keytrans $out/share/monkeysphere/$program
          makeWrapper $out/share/monkeysphere/$program $out/bin/$program \
            ${wrapperArgs [ ]}
        done
      '';<commit_msg>monkeysphere: Replace a hardcoded path and fix more tests<commit_after>{ stdenv, fetchurl, makeWrapper
, perl, libassuan, libgcrypt
, perlPackages, lockfileProgs, gnupg, coreutils
# For the tests:
, bash, openssh, which, socat, cpio, hexdump
}:

stdenv.mkDerivation rec {
  name = "monkeysphere-${version}";
  version = "0.42";

  src = fetchurl {
    url = "http://archive.monkeysphere.info/debian/pool/monkeysphere/m/monkeysphere/monkeysphere_${version}.orig.tar.gz";
    sha256 = "1haqgjxm8v2xnhc652lx79p2cqggb9gxgaf19w9l9akar2qmdjf1";
  };

  patches = [ ./monkeysphere.patch ];

  postPatch = ''
    sed -i "s,/usr/bin/env,${coreutils}/bin/env," src/share/ma/update_users
  '';

  nativeBuildInputs = [ makeWrapper ];
  buildInputs = [ perl libassuan libgcrypt ]
    ++ stdenv.lib.optional doCheck
      ([ gnupg openssh which socat cpio hexdump lockfileProgs ] ++
      (with perlPackages; [ CryptOpenSSLRSA CryptOpenSSLBignum ]));

  makeFlags = ''
    PREFIX=/
    DESTDIR=$(out)
  '';

  # Not all checks pass yet (NixOS specific problems) and the tests "drain"
  # entropy (apparently GnuPG still uses /dev/random).
  doCheck = false;
  preCheck = ''
    patchShebangs tests/
    patchShebangs src/
    sed -i "s,/usr/sbin/sshd,${openssh}/bin/sshd," tests/basic
    sed -i "s/<(hd/<(hexdump/" tests/keytrans
  '';

  postFixup =
    let wrapperArgs = runtimeDeps:
          "--prefix PERL5LIB : "
          + (with perlPackages; stdenv.lib.makePerlPath [
              CryptOpenSSLRSA
              CryptOpenSSLBignum
            ])
          + stdenv.lib.optionalString
              (builtins.length runtimeDeps > 0)
              " --prefix PATH : ${stdenv.lib.makeBinPath runtimeDeps}";
        wrapMonkeysphere = runtimeDeps: program:
          "wrapProgram $out/bin/${program} ${wrapperArgs runtimeDeps}\n";
        wrapPrograms = runtimeDeps: programs: stdenv.lib.concatMapStrings
          (wrapMonkeysphere runtimeDeps)
          programs;
    in wrapPrograms [ gnupg ] [ "monkeysphere-authentication" "monkeysphere-host" ]
      + wrapPrograms [ lockfileProgs ] [ "monkeysphere" ]
      + ''
        # These 4 programs depend on the program name ($0):
        for program in openpgp2pem openpgp2spki openpgp2ssh pem2openpgp; do
          rm $out/bin/$program
          ln -sf keytrans $out/share/monkeysphere/$program
          makeWrapper $out/share/monkeysphere/$program $out/bin/$program \
            ${wrapperArgs [ ]}
        done
      '';
{'fraction_non_alphanumeric': 0.11824877250409166, 'fraction_numerical': 0.012274959083469721, 'mean_word_length': 2.804669260700389, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4545288', 'n_tokens_mistral': 1725, 'n_tokens_neox': 1688, 'n_words': 334}