private: Yes


{ pkgs ? (import /home/lukas/src/nix/nixpkgs {}) }:
let
  lib = pkgs.lib;
  nolicense =
    lib.filterAttrs
      (name: v:
        let
          val = builtins.tryEval v;
        in val.success && (lib.hasAttrByPath [ "meta" "license" ] val.value))
    pkgs;
  nolicense-names = builtins.attrNames nolicense;
  licensee-out = name: pkg:
  let pkgSrc = pkg.overrideAttrs (oldAttrs: {
    name = "${if oldAttrs ? name then oldAttrs.name else "anonymous"}-src";
    phases = [ "unpackPhase" "installPhase" ];
    installPhase = ''
      cp -R . $out
      mkdir -p $out
    '';
    outputs = [ "out" ];
  });
  in pkgs.runCommandLocal
       "licensee-${name}.txt" {}
       ''
         mkdir lol
         (env HOME=lol ${pkgs.licensee}/bin/licensee detect --json ${pkgSrc} || true) > $out
       '';
  licensee = name: src:
    let licenses = map (x: x.key) (builtins.fromJSON (builtins.readFile (licensee-out name src))).licenses;
    in if builtins.length licenses == 0
       then "no license"
       else lib.concatStringsSep ", " licenses;
in
  pkgs.writeText
    "licenses.txt"
    (lib.concatStringsSep "\n"
      (map
        (name:
        let
          licenseStr = licensee name pkgs."${name}";
        in "${name}, ${licenseStr}")
        nolicense-names))