darwin.system_cmds: use mkAppleDerivation

This commit is contained in:
Randy Eckenrode 2024-09-22 16:50:07 -04:00
parent a19b0a7345
commit 9ea9221a1e
No known key found for this signature in database
GPG Key ID: 64C1CD4EC2A600D9
6 changed files with 352 additions and 289 deletions

View File

@ -314,7 +314,7 @@ developerToolsPackages_11_3_1 // macosPackages_11_0_1 // {
network_cmds = callPackage ./network_cmds/package.nix { };
file_cmds = callPackage ./file_cmds/package.nix { };
shell_cmds = callPackage ./shell_cmds/package.nix { };
system_cmds = applePackage "system_cmds" "macos-14.3" "sha256-qFp9nkzsq9uQ7zoyfvO+3gvDlc7kaPvn6luvmO/Io30=" {};
system_cmds = callPackage ./system_cmds/package.nix { };
text_cmds = applePackage "text_cmds" "osx-10.11.6" "sha256-KSebU7ZyUsPeqn51nzuGNaNxs9pvmlIQQdkWXIVzDxw=" {};
top = applePackage "top" "osx-10.11.6" "sha256-jbz64ODogtpNyLpXGSZj1jCBdFPVXcVcBkL1vc7g5qQ=" {};
PowerManagement = callPackage ./PowerManagement/package.nix { };

View File

@ -1,161 +0,0 @@
{
lib,
stdenv,
stdenvNoCC,
appleDerivation,
fetchFromGitHub,
runCommand,
gawk,
meson,
ninja,
pkg-config,
libdispatch,
libmalloc,
libplatform,
Librpcsvc,
libutil,
ncurses,
openbsm,
pam,
xnu,
CoreFoundation,
CoreSymbolication,
DirectoryService,
IOKit,
Kernel,
Libc,
OpenDirectory,
WebKit,
}:
let
OpenDirectoryPrivate = stdenvNoCC.mkDerivation (finalAttrs: {
name = "apple-private-framework-OpenDirectory";
version = "146";
src = fetchFromGitHub {
owner = "apple-oss-distributions";
repo = "OpenDirectory";
rev = "OpenDirectory-${finalAttrs.version}";
hash = "sha256-6fSl8PasCZSBfe0ftaePcBuSEO3syb6kK+mfDI6iR7A=";
};
dontConfigure = true;
dontBuild = true;
installPhase = ''
runHook preInstall
mkdir -p "$out/include/CFOpenDirectory" "$out/include/OpenDirectory"
install -t "$out/include/CFOpenDirectory" \
Core/CFOpenDirectoryPriv.h \
Core/CFODTrigger.h
touch "$out/include/CFOpenDirectory/CFOpenDirectoryConstantsPriv.h"
install -t "$out/include/OpenDirectory" \
Framework/OpenDirectoryPriv.h \
Framework/NSOpenDirectoryPriv.h
runHook postInstall
'';
});
libmallocPrivate = stdenvNoCC.mkDerivation {
pname = "libmalloc-private";
version = lib.getVersion libmalloc;
inherit (libmalloc) src;
dontConfigure = true;
dontBuild = true;
installPhase = ''
runHook preInstall
mkdir -p "$out/include"
cp -r private/*.h "$out/include"
runHook postInstall
'';
};
# Private xnu headers that are part of the source tree but not in the xnu derivation.
xnuPrivate = stdenvNoCC.mkDerivation {
pname = "xnu-private";
version = lib.getVersion xnu;
inherit (xnu) src;
dontConfigure = true;
dontBuild = true;
installPhase = ''
runHook preInstall
mkdir -p "$out/include"
cp libsyscall/wrappers/spawn/spawn_private.h "$out/include"
runHook postInstall
'';
};
in
appleDerivation (finalAttrs: {
nativeBuildInputs = [
gawk
meson
ninja
pkg-config
];
buildInputs = [
libdispatch
libplatform
Librpcsvc
libutil
ncurses
openbsm
pam
xnu
CoreFoundation
CoreSymbolication
DirectoryService
IOKit
Kernel
OpenDirectory
];
postPatch = ''
# Replace hard-coded, impure system paths with the output path in the store.
sed -e "s|PATH=[^;]*|PATH='$out/bin'|" -i "pagesize/pagesize.sh"
'';
# A vendored meson.build is used instead of the upstream Xcode project.
# This is done for a few reasons:
# - The upstream project causes `xcbuild` to crash.
# See: https://github.com/facebookarchive/xcbuild/issues/188;
# - Achieving the same flexibility regarding SDK version would require modifying the
# Xcode project, but modifying Xcode projects without using Xcode is painful; and
# - Using Meson allows the derivation to leverage the robust Meson support in nixpkgs,
# and it allows it to use Meson features to simplify the build (e.g., generators).
preConfigure = ''
substitute '${./meson.build}' meson.build \
--subst-var-by kernel '${Kernel}' \
--subst-var-by libc_private '${Libc}' \
--subst-var-by libmalloc_private '${libmallocPrivate}' \
--subst-var-by opendirectory '${OpenDirectory}' \
--subst-var-by opendirectory_private '${OpenDirectoryPrivate}' \
--subst-var-by xnu '${xnu}' \
--subst-var-by xnu_private '${xnuPrivate}' \
--subst-var-by version '${finalAttrs.version}'
cp '${./meson.options}' meson.options
'';
mesonFlags = [ (lib.mesonOption "sdk_version" stdenv.hostPlatform.darwinSdkVersion) ];
meta = {
platforms = lib.platforms.darwin;
maintainers = with lib.maintainers; [
shlevy
matthewbauer
];
};
})

View File

@ -5,10 +5,18 @@
# Project settings
project('system_cmds', 'c', version : '@version@')
if host_machine.system() != 'linux'
add_project_arguments('-D__FreeBSD__', language : 'c')
endif
add_project_arguments(
'-D__FreeBSD__',
# Suppresses suffixing symbols with '$UNIX2003', which causes link failures.
'-D__DARWIN_ONLY_UNIX_CONFORMANCE=1',
# Make sure Darwin is correctly detected as macOS
'-DPLATFORM_MacOSX=1',
# Access private definitions
'-DPRIVATE=1',
# From bsd/sys/private_event.h in xnu
'-Dkqueue_id_t=uint64_t',
language : 'c',
)
sdk_version = get_option('sdk_version')
@ -22,50 +30,23 @@ core_foundation = dependency('appleframeworks', modules : 'CoreFoundation')
core_symbolication = dependency('appleframeworks', modules : 'CoreSymbolication')
directory_service = dependency('appleframeworks', modules : 'DirectoryService')
iokit = dependency('appleframeworks', modules : 'IOKit')
kernel = declare_dependency(include_directories : '@kernel@/Library/Frameworks/Kernel.framework/Headers')
open_directory = dependency('appleframeworks', modules : 'OpenDirectory')
cfopen_directory = dependency('appleframeworks', modules : 'CFOpenDirectory')
## Private Headers
cfopen_directory = declare_dependency(
dependencies : declare_dependency(
compile_args :[ '-iframework', '@opendirectory@/Library/Frameworks/OpenDirectory.framework/Frameworks' ],
),
include_directories : '@opendirectory_private@/include',
)
libc_private = declare_dependency(include_directories : '@libc_private@/include')
libmalloc_private = declare_dependency(include_directories : '@libmalloc_private@/include')
xnu_include_dirs = [
'@xnu@/include/bsd',
'@xnu@/include/libkern',
'@xnu@/include/iokit',
'@xnu@/include/osfmk',
'@xnu_private@/include'
]
if sdk_version.version_compare('>=10.13')
xnu_include_dirs += '@xnu@/include/san'
endif
xnu_private = declare_dependency(
compile_args : [
# Suppresses suffixing symbols with '$UNIX2003', which causes link failures.
'-D__DARWIN_ONLY_UNIX_CONFORMANCE=1',
# Make sure Darwin is correctly detected as macOS
'-DPLATFORM_MacOSX=1',
# Access private definitions
'-DPRIVATE=1'
],
include_directories : xnu_include_dirs
)
## Libraries
dbm = cc.find_library('dbm')
ncurses = dependency('ncurses')
openbsm = cc.find_library('bsm')
pam = cc.find_library('pam')
# Feature Tests
if sdk_version.version_compare('<12')
add_project_arguments('-DkIOMainPortDefault=kIOMasterPortDefault', language : 'c')
add_project_arguments('-DIOMainPort=IOMasterPort', language : 'c')
add_project_arguments(
'-DIOMainPort=IOMasterPort',
'-DkIOMainPortDefault=kIOMasterPortDefault',
language : 'c'
)
endif
@ -74,15 +55,23 @@ pgperf = generator(
fake_gperf,
arguments : [ '-f', meson.source_root() + '/getconf/fake-gperf.awk', '@INPUT@' ],
capture : true,
output : '@BASENAME@.gperf.c'
output : '@BASENAME@.gperf.c',
)
# Binaries
executable('ac', install : true, sources : 'ac/ac.c')
executable(
'ac',
install : true,
sources : 'ac/ac.c',
)
install_man('ac/ac.8')
executable('accton', install : true, sources : 'accton/accton.c')
executable(
'accton',
install : true,
sources : 'accton/accton.c',
)
install_man('accton/accton.8')
executable(
@ -90,12 +79,14 @@ executable(
build_by_default : sdk_version.version_compare('>=11'),
dependencies : [ core_foundation ],
install : sdk_version.version_compare('>=11'),
sources : 'arch/arch.c'
)
install_man(
'arch/arch.1',
'arch/machine.1'
sources : 'arch/arch.c',
)
if sdk_version.version_compare('>=11')
install_man(
'arch/arch.1',
'arch/machine.1',
)
endif
executable(
'at',
@ -111,26 +102,29 @@ executable(
'at/at.c',
'at/panic.c',
'at/parsetime.c',
'at/perm.c'
]
'at/perm.c',
],
)
install_man('at/at.1')
executable(
'atrun',
c_args : [ '-DDAEMON_UID=1', '-DDAEMON_GID=1' ],
c_args : [
'-DDAEMON_UID=1',
'-DDAEMON_GID=1',
],
include_directories : 'at',
install : true,
sources : [
'atrun/atrun.c',
'atrun/gloadavg.c'
'atrun/gloadavg.c',
]
)
install_man('atrun/atrun.8')
executable(
'chkpasswd',
c_args : '-DUSE_PAM',
c_args : [ '-DUSE_PAM' ],
dependencies : [ core_foundation, open_directory, pam ],
install : true,
sources : [
@ -140,13 +134,13 @@ executable(
'chkpasswd/pam_passwd.c',
'chkpasswd/passwd.c',
'chkpasswd/stringops.c'
]
],
)
install_man('chkpasswd/chkpasswd.8')
executable(
'chpass',
dependencies : [ core_foundation, cfopen_directory, directory_service, open_directory ],
dependencies : [ core_foundation, cfopen_directory, open_directory ],
install : true,
sources : [
'chpass/chpass.c',
@ -154,22 +148,30 @@ executable(
'chpass/field.c',
'chpass/open_directory.c',
'chpass/table.c',
'chpass/util.c'
'chpass/util.c',
]
)
install_man('chpass/chpass.1')
executable('cpuctl', install : true, sources : 'cpuctl/cpuctl.c')
executable(
'cpuctl',
install : true,
sources : 'cpuctl/cpuctl.c'
)
install_man('cpuctl/cpuctl.8')
executable('dmesg', install : true, sources : 'dmesg/dmesg.c')
executable(
'dmesg',
install : true,
sources : 'dmesg/dmesg.c',
)
install_man('dmesg/dmesg.8')
executable(
'dynamic_pager',
c_args : '-DNO_DIRECT_RPC',
install : true,
sources : 'dynamic_pager/dynamic_pager.c'
sources : 'dynamic_pager/dynamic_pager.c',
)
install_man('dynamic_pager/dynamic_pager.8')
@ -177,10 +179,15 @@ executable(
'fs_usage',
# Requires 'ktrace/session.h'
build_by_default : false,
c_args : [
'-DTARGET_OS_EXCLAVECORE=0',
'-DTARGET_OS_EXCLAVEKIT=0',
],
# dependencies : [ libutil ],
install : false,
sources : 'fs_usage/fs_usage.c'
sources : 'fs_usage/fs_usage.c',
)
# install_man('fs_usage/fs_usage.1')
install_man('fs_usage/fs_usage.1')
executable(
'gcore',
@ -197,7 +204,7 @@ executable(
'gcore/threads.c',
'gcore/utils.c',
'gcore/vanilla.c',
'gcore/vm.c'
'gcore/vm.c',
]
)
# install_man('gcore/gcore-internal.1', 'gcore/gcore.1')
@ -209,16 +216,17 @@ executable(
install : true,
sources : [
'getconf/getconf.c',
] + pgperf.process(
[
'getconf/confstr.gperf',
'getconf/limits.gperf',
'getconf/unsigned_limits.gperf',
'getconf/progenv.gperf',
'getconf/sysconf.gperf',
'getconf/pathconf.gperf'
]
)
pgperf.process(
[
'getconf/confstr.gperf',
'getconf/limits.gperf',
'getconf/unsigned_limits.gperf',
'getconf/progenv.gperf',
'getconf/sysconf.gperf',
'getconf/pathconf.gperf',
]
),
]
)
install_man('getconf/getconf.1')
@ -229,16 +237,20 @@ executable(
'getty/chat.c',
'getty/init.c',
'getty/main.c',
'getty/subr.c'
'getty/subr.c',
]
)
install_man(
'getty/getty.8',
'getty/gettytab.5',
'getty/ttys.5'
'getty/ttys.5',
)
executable('hostinfo', install : true, sources : 'hostinfo/hostinfo.c')
executable(
'hostinfo',
install : true,
sources : 'hostinfo/hostinfo.c',
)
install_man('hostinfo/hostinfo.8')
executable(
@ -246,7 +258,7 @@ executable(
dependencies : [ core_foundation, iokit ],
include_directories : 'at',
install : true,
sources : 'iosim/iosim.c'
sources : 'iosim/iosim.c',
)
install_man('iosim/iosim.1')
@ -254,24 +266,23 @@ executable(
'iostat',
dependencies : [ core_foundation, iokit ],
install : true,
sources : 'iostat/iostat.c'
sources : 'iostat/iostat.c',
)
install_man('iostat/iostat.8')
executable(
'kpgo',
dependencies : [ xnu_private ],
install : true,
sources : 'kpgo/kpgo.c'
sources : 'kpgo/kpgo.c',
)
# No man pages for `kpgo`
executable(
'latency',
build_by_default : sdk_version.version_compare('>=12'),
dependencies : ncurses,
dependencies : [ ncurses ],
install : sdk_version.version_compare('>=12'),
sources : 'latency/latency.c'
sources : 'latency/latency.c',
)
if sdk_version.version_compare('>=12')
install_man('latency/latency.1')
@ -282,11 +293,11 @@ executable(
# Requires SoftLinking/WeakLinking.h and end-point security entitlements
build_by_default : false,
c_args : '-DUSE_BSM_AUDIT=1',
dependencies : [ openbsm, xnu_private ],
dependencies : [ openbsm ],
install : false,
sources : [
'login/login.c',
'login/login_audit.c'
'login/login_audit.c',
]
)
# install_man('login/login.1')
@ -295,7 +306,7 @@ executable(
'lskq',
build_by_default : sdk_version.version_compare('>=12'),
install : sdk_version.version_compare('>=12'),
sources : 'lskq/lskq.c'
sources : 'lskq/lskq.c',
)
if sdk_version.version_compare('>=12')
install_man('lskq/lskq.1')
@ -318,50 +329,68 @@ endif
executable(
'ltop',
install : true,
sources : 'ltop/ltop.c'
sources : 'ltop/ltop.c',
)
install_man('ltop/ltop.1')
executable('mean', install : true, sources : 'mean/mean.c')
executable(
'mean',
install : true,
sources : 'mean/mean.c',
)
# No man pages for `mean`.
executable(
'memory_pressure',
dependencies : [ xnu_private ],
c_args : ['-include', 'stdint.h'],
install : true,
sources : 'memory_pressure/memory_pressure.c'
sources : 'memory_pressure/memory_pressure.c',
)
install_man('memory_pressure/memory_pressure.1')
executable('mkfile', install : true, sources : 'mkfile/mkfile.c')
executable(
'mkfile',
install : true,
sources : 'mkfile/mkfile.c',
)
install_man('mkfile/mkfile.8')
executable(
'mslutil',
build_by_default : sdk_version.version_compare('>=10.13'),
dependencies : [ libmalloc_private ],
install : sdk_version.version_compare('>=10.13'),
sources : 'mslutil/mslutil.c'
sources : 'mslutil/mslutil.c',
)
if sdk_version.version_compare('>=10.13')
install_man('mslutil/mslutil.1')
endif
executable('newgrp', install : true, sources : 'newgrp/newgrp.c')
executable(
'newgrp',
install : true,
sources : 'newgrp/newgrp.c',
)
install_man('newgrp/newgrp.1')
executable('nologin', install : true, sources : 'nologin/nologin.c')
executable(
'nologin',
install : true,
sources : 'nologin/nologin.c',
)
install_man(
'nologin/nologin.5',
'nologin/nologin.8'
'nologin/nologin.8',
)
executable(
'nvram',
c_args : '-DTARGET_OS_BRIDGE=0',
dependencies : [ core_foundation, iokit, libc_private, xnu_private ],
c_args : [
'-DTARGET_OS_BRIDGE=0',
'-DkIONVRAMDeletePropertyKeyWRet="IONVRAM-DELETEWRET-PROPERTY"',
],
dependencies : [ core_foundation, iokit ],
install : true,
sources : 'nvram/nvram.c'
sources : 'nvram/nvram.c',
)
install_man('nvram/nvram.8')
@ -372,20 +401,20 @@ custom_target(
install_dir : get_option('bindir'),
install_mode : 'r-xr-xr-x',
input : 'pagesize/pagesize.sh',
output : 'pagesize'
output : 'pagesize',
)
install_man('pagesize/pagesize.1')
executable(
'passwd',
dependencies : [ core_foundation, cfopen_directory, directory_service, open_directory, pam ],
dependencies : [ core_foundation, cfopen_directory, open_directory, pam ],
install : true,
sources : [
'passwd/file_passwd.c',
'passwd/nis_passwd.c',
'passwd/od_passwd.c',
'passwd/pam_passwd.c',
'passwd/passwd.c'
'passwd/passwd.c',
]
)
install_man('passwd/passwd.1')
@ -393,20 +422,28 @@ install_man('passwd/passwd.1')
executable(
'proc_uuid_policy',
install : true,
sources : 'proc_uuid_policy/proc_uuid_policy.c'
sources : 'proc_uuid_policy/proc_uuid_policy.c',
)
install_man('proc_uuid_policy/proc_uuid_policy.1')
executable('purge', install : true, sources : 'purge/purge.c')
executable(
'purge',
install : true,
sources : 'purge/purge.c',
)
install_man('purge/purge.8')
executable(
'pwd_mkdb',
c_args : [ '-D_PW_NAME_LEN=MAXLOGNAME', '-D_PW_YPTOKEN="__YP!"' ],
c_args : [
'-D_PW_NAME_LEN=MAXLOGNAME',
'-D_PW_YPTOKEN="__YP!"',
],
dependencies : [ dbm ],
install : true,
sources : [
'pwd_mkdb/pw_scan.c',
'pwd_mkdb/pwd_mkdb.c'
'pwd_mkdb/pwd_mkdb.c',
]
)
install_man('pwd_mkdb/pwd_mkdb.8')
@ -416,19 +453,20 @@ executable(
# Requires IOKitUser kext APIs
build_by_default : false,
install : false,
sources : 'reboot/reboot.c'
sources : 'reboot/reboot.c',
)
# install_man('reboot/reboot.8')
executable(
'sa',
c_args : '-DAHZV1',
dependencies : [ dbm ],
install : true,
sources : [
'sa/db.c',
'sa/main.c',
'sa/pdb.c',
'sa/usrdb.c'
'sa/usrdb.c',
]
)
install_man('sa/sa.8')
@ -438,7 +476,7 @@ executable(
build_by_default : sdk_version.version_compare('>=12'),
dependencies : ncurses,
install : sdk_version.version_compare('>=12'),
sources : 'sc_usage/sc_usage.c'
sources : 'sc_usage/sc_usage.c',
)
if sdk_version.version_compare('>=12')
install_man('sc_usage/sc_usage.1')
@ -448,40 +486,51 @@ executable('shutdown',
# Requires IOKitUser kext APIs
build_by_default : false,
install : false,
sources : 'shutdown/shutdown.c'
sources : 'shutdown/shutdown.c',
)
# install_man('shutdown/shutdown.8')
executable(
'stackshot',
build_by_default : sdk_version.version_compare('>=10.13'),
dependencies : [ xnu_private ],
install : sdk_version.version_compare('>=10.13'),
sources : 'stackshot/stackshot.c'
# Requires private entitlements
build_by_default : false and sdk_version.version_compare('>=10.13'),
install : false and sdk_version.version_compare('>=10.13'),
sources : 'stackshot/stackshot.c',
)
# No man pages for `stackshot`.
executable('sync', install : true, sources : 'sync/sync.c')
executable(
'sync',
install : true,
sources : 'sync/sync.c',
)
# No man pages for `sync`.
executable('sysctl', install : true, sources : 'sysctl/sysctl.c')
executable(
'sysctl',
install : true,
sources : 'sysctl/sysctl.c',
)
install_man(
'sysctl/sysctl.8',
'sysctl/sysctl.conf.5'
'sysctl/sysctl.conf.5',
)
executable(
'taskpolicy',
build_by_default : sdk_version.version_compare('>=11'),
dependencies : [ xnu_private ],
install : sdk_version.version_compare('>=11'),
sources : 'taskpolicy/taskpolicy.c'
sources : 'taskpolicy/taskpolicy.c',
)
if sdk_version.version_compare('>=11')
install_man('taskpolicy/taskpolicy.8')
endif
executable('vifs', install : true, sources : 'vifs/vifs.c')
executable(
'vifs',
install : true,
sources : 'vifs/vifs.c',
)
install_man('vifs/vifs.8')
executable(
@ -489,33 +538,54 @@ executable(
install : true,
sources : [
'vipw/pw_util.c',
'vipw/vipw.c'
]
'vipw/vipw.c',
],
)
install_man('vipw/vipw.8')
executable('vm_purgeable_stat',
build_by_default : sdk_version.version_compare('>=11'),
install : sdk_version.version_compare('>=11'),
sources : 'vm_purgeable_stat/vm_purgeable_stat.c'
sources : 'vm_purgeable_stat/vm_purgeable_stat.c',
)
if sdk_version.version_compare('>=11')
install_man('vm_purgeable_stat/vm_purgeable_stat.1')
endif
executable('vm_stat', install : true, sources : 'vm_stat/vm_stat.c')
executable(
'vm_stat',
install : true,
sources : 'vm_stat/vm_stat.c',
)
install_man('vm_stat/vm_stat.1')
executable('wait4path', install : true, sources : 'wait4path/wait4path.c')
executable(
'wait4path',
install : true,
sources : 'wait4path/wait4path.c',
)
install_man('wait4path/wait4path.1')
executable('wordexp-helper', install : true, sources : 'wordexp-helper/wordexp-helper.c')
executable(
'wordexp-helper',
install : true,
sources : 'wordexp-helper/wordexp-helper.c',
)
# No man pages for `wordexp-helper`.
executable('zdump', include_directories : 'zic', install : true, sources : 'zdump/zdump.c')
executable(
'zdump',
include_directories : 'zic',
install : true,
sources : 'zdump/zdump.c',
)
install_man('zdump/zdump.8')
executable('zic', install : true, sources : 'zic/zic.c')
executable(
'zic',
install : true,
sources : 'zic/zic.c',
)
install_man('zic/zic.8')
executable(
@ -527,7 +597,7 @@ executable(
sources : [
'zlog/SymbolicationHelper.c',
'zlog/zlog.c',
]
],
)
if sdk_version.version_compare('>=11')
install_man('zlog/zlog.1')
@ -537,9 +607,8 @@ executable(
'zprint',
# Requires IOKitUser kext APIs
build_by_default : false,
dependencies: [ kernel ],
install : false,
sources : 'zprint/zprint.c'
sources : 'zprint/zprint.c',
)
# install_man('zprint/zprint.1')

View File

@ -0,0 +1,109 @@
{
lib,
apple-sdk,
apple-sdk_12,
mkAppleDerivation,
ncurses,
openpam,
pkg-config,
stdenv,
stdenvNoCC,
}:
let
libdispatch = apple-sdk.sourceRelease "libdispatch"; # Has to match the version of the SDK
Libc = apple-sdk_12.sourceRelease "Libc";
libmalloc = apple-sdk_12.sourceRelease "libmalloc";
OpenDirectory = apple-sdk_12.sourceRelease "OpenDirectory";
libplatform = apple-sdk_12.sourceRelease "libplatform";
xnu = apple-sdk_12.sourceRelease "xnu";
privateHeaders = stdenvNoCC.mkDerivation {
name = "system_cmds-deps-private-headers";
buildCommand = ''
install -D -t "$out/include/CFOpenDirectory" \
'${OpenDirectory}/Core/CFOpenDirectoryPriv.h' \
'${OpenDirectory}/Core/CFODTrigger.h'
touch "$out/include/CFOpenDirectory/CFOpenDirectoryConstantsPriv.h"
install -D -t "$out/include/IOKit" \
'${xnu}/iokit/IOKit/IOKitKeysPrivate.h'
install -D -t "$out/include/OpenDirectory" \
'${OpenDirectory}/Framework/OpenDirectoryPriv.h' \
'${OpenDirectory}/Framework/NSOpenDirectoryPriv.h'
install -D -t "$out/include/System/sys" \
'${xnu}/bsd/sys/proc.h' \
'${xnu}/bsd/sys/proc_uuid_policy.h'
install -D -t "$out/include" \
'${libmalloc}/private/stack_logging.h' \
'${libplatform}/private/_simple.h' \
'${xnu}/libsyscall/wrappers/spawn/spawn_private.h'
cp -r '${libdispatch}/private' "$out/include/dispatch"
# Work around availability headers compatibility issue when building with an unprocessed SDK.
chmod -R u+w "$out/include/dispatch"
find "$out/include/dispatch" -name '*.h' -exec sed -i {} -e 's/, bridgeos([^)]*)//g' \;
install -D -t "$out/include/kern" \
'${xnu}/osfmk/kern/debug.h'
install -D -t "$out/include/mach" \
'${xnu}/osfmk/mach/coalition.h'
install -D -t "$out/include/os" \
'${Libc}/os/assumes.h' \
'${xnu}/libkern/os/base_private.h'
install -D -t "$out/include/sys" \
'${xnu}/bsd/sys/csr.h' \
'${xnu}/bsd/sys/pgo.h' \
'${xnu}/bsd/sys/kern_memorystatus.h' \
'${xnu}/bsd/sys/reason.h' \
'${xnu}/bsd/sys/resource.h' \
'${xnu}/bsd/sys/spawn_internal.h' \
'${xnu}/bsd/sys/stackshot.h'
# Older source releases depend on CrashReporterClient.h, but its not publicly available.
touch "$out/include/CrashReporterClient.h"
'';
};
in
mkAppleDerivation {
releaseName = "system_cmds";
xcodeHash = "sha256-KYOKLOwJyHwIQmIdCCN+UtiqKSr8NLPJudIOiznbfMw=";
patches = [
# Use availability checks to fall back to older APIs on older macOS versions.
./patches/0001-Add-availability-checks-to-vm_purgeable_stat.patch
];
postPatch = ''
# Replace hard-coded, impure system paths with the output path in the store.
sed -e "s|PATH=[^;]*|PATH='$out/bin'|" -i "pagesize/pagesize.sh"
'';
preConfigure = ''
export NIX_CFLAGS_COMPILE+=" -iframework $SDKROOT/System/Library/Frameworks/OpenDirectory.framework/Frameworks"
'';
env.NIX_CFLAGS_COMPILE = "-I${privateHeaders}/include";
buildInputs = [
apple-sdk.privateFrameworksHook
ncurses
openpam
];
nativeBuildInputs = [ pkg-config ];
mesonFlags = [ (lib.mesonOption "sdk_version" stdenv.hostPlatform.darwinSdkVersion) ];
meta.description = "System commands for Darwin";
}

View File

@ -0,0 +1,42 @@
From 18a676bc44a8bc24374ab35a258a18049b56b6d4 Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Mon, 2 Sep 2024 21:46:34 -0400
Subject: [PATCH] Add availability checks to vm_purgeable_stat
---
vm_purgeable_stat/vm_purgeable_stat.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/vm_purgeable_stat/vm_purgeable_stat.c b/vm_purgeable_stat/vm_purgeable_stat.c
index 330704d..9d9041b 100644
--- a/vm_purgeable_stat/vm_purgeable_stat.c
+++ b/vm_purgeable_stat/vm_purgeable_stat.c
@@ -88,7 +88,11 @@ int get_task_from_pid(int pid, task_t *task)
fprintf(stderr, "%s\n", PRIV_ERR_MSG);
return -1;
}
- kr = task_inspect_for_pid(mach_task_self(), pid, task);
+ if (__builtin_available(macOS 11.3, *)) {
+ kr = task_inspect_for_pid(mach_task_self(), pid, task);
+ } else {
+ kr = task_for_pid(mach_task_self(), pid, task);
+ }
if (kr != KERN_SUCCESS) {
fprintf(stderr, "Failed to get task port for pid: %d\n", pid);
return -1;
@@ -128,7 +132,11 @@ int get_system_tasks(task_array_t *tasks, mach_msg_type_number_t *count)
vm_deallocate(mach_task_self(), (vm_address_t)psets, (vm_size_t)psetCount * sizeof(mach_port_t));
/* convert the processor-set-priv to a list of tasks for the processor set */
- ret = processor_set_tasks_with_flavor(pset_priv, TASK_FLAVOR_INSPECT, tasks, count);
+ if (__builtin_available(macOS 11.0, *)) {
+ ret = processor_set_tasks_with_flavor(pset_priv, TASK_FLAVOR_INSPECT, tasks, count);
+ } else {
+ ret = processor_set_tasks(pset_priv, tasks, count);
+ }
if (ret != KERN_SUCCESS) {
fprintf(stderr, "processor_set_tasks_with_flavor() failed: %s\n", mach_error_string(ret));
return -1;
--
2.44.1

View File

@ -66,5 +66,9 @@
"shell_cmds": {
"hash": "sha256-kmEOprkiJGMVcl7yHkGX8ymk/5KjE99gWuF8j2hK5hY=",
"version": "187"
},
"system_cmds": {
"hash": "sha256-qFp9nkzsq9uQ7zoyfvO+3gvDlc7kaPvn6luvmO/Io30=",
"version": "970.0.4"
}
}