···11+{ lib }:
22+/**
33+ Override unfree licenses to free ones in a derivation.
44+55+ This function takes a derivation and replaces any unfree license with lib.licenses.free.
66+ Note: This only works for simple packages. Complex packages with unfree dependencies
77+ in their build process (like firefox-bin -> firefox-bin-unwrapped) cannot be handled
88+ this way and need other approaches.
99+1010+ # Example
1111+1212+ ```nix
1313+ halalify pkgs.someUnfreePackage
1414+ ```
1515+*/
1616+drv:
1717+if !lib.isDerivation drv then
1818+ drv
1919+else
2020+ let
2121+ # Helper to check if a license is unfree
2222+ isUnfreeLicense = license: lib.isAttrs license && license ? free && !license.free;
2323+2424+ # Helper to make a license free
2525+ makeFreeLicense =
2626+ license:
2727+ if isUnfreeLicense license then
2828+ lib.licenses.free
2929+ else if lib.isList license then
3030+ map makeFreeLicense license
3131+ else
3232+ license;
3333+ in
3434+ drv.overrideAttrs (old: {
3535+ # Override the license
3636+ meta =
3737+ (old.meta or { })
3838+ // lib.optionalAttrs (old.meta ? license) {
3939+ license = makeFreeLicense old.meta.license;
4040+ };
4141+ })