···11+{ lib, runCommandLocal }:
22+33+# On darwin, there are some commands neither opensource nor able to build in nixpkgs.
44+# We have no choice but to use those system-shipped impure ones.
55+66+let
77+ commands = {
88+ ditto = "/usr/bin/ditto"; # ditto is not opensource
99+ sudo = "/usr/bin/sudo"; # sudo must be owned by uid 0 and have the setuid bit set
1010+ };
1111+1212+ mkImpureDrv = name: path:
1313+ runCommandLocal "${name}-impure-darwin" {
1414+ __impureHostDeps = [ path ];
1515+1616+ meta = {
1717+ platforms = lib.platforms.darwin;
1818+ };
1919+ } ''
2020+ if ! [ -x ${path} ]; then
2121+ echo Cannot find command ${path}
2222+ exit 1
2323+ fi
2424+2525+ mkdir -p $out/bin
2626+ ln -s ${path} $out/bin
2727+2828+ manpage="/usr/share/man/man1/${name}.1"
2929+ if [ -f $manpage ]; then
3030+ mkdir -p $out/share/man/man1
3131+ ln -s $manpage $out/share/man/man1
3232+ fi
3333+ '';
3434+in lib.mapAttrs mkImpureDrv commands