···1+{ lib, runCommandLocal }:
2+3+# On darwin, there are some commands neither opensource nor able to build in nixpkgs.
4+# We have no choice but to use those system-shipped impure ones.
5+6+let
7+ commands = {
8+ ditto = "/usr/bin/ditto"; # ditto is not opensource
9+ sudo = "/usr/bin/sudo"; # sudo must be owned by uid 0 and have the setuid bit set
10+ };
11+12+ mkImpureDrv = name: path:
13+ runCommandLocal "${name}-impure-darwin" {
14+ __impureHostDeps = [ path ];
15+16+ meta = {
17+ platforms = lib.platforms.darwin;
18+ };
19+ } ''
20+ if ! [ -x ${path} ]; then
21+ echo Cannot find command ${path}
22+ exit 1
23+ fi
24+25+ mkdir -p $out/bin
26+ ln -s ${path} $out/bin
27+28+ manpage="/usr/share/man/man1/${name}.1"
29+ if [ -f $manpage ]; then
30+ mkdir -p $out/share/man/man1
31+ ln -s $manpage $out/share/man/man1
32+ fi
33+ '';
34+in lib.mapAttrs mkImpureDrv commands