From a19b0a7345a7a2c985a79697d4e89611e251c7fc Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Sun, 22 Sep 2024 16:34:16 -0400 Subject: [PATCH] darwin.shell_cmds: convert to Meson and use mkAppleDerivation --- .../darwin/apple-source-releases/default.nix | 2 +- .../shell_cmds/default.nix | 50 --- .../shell_cmds/meson.build.in | 417 ++++++++++++++++++ .../shell_cmds/package.nix | 77 ++++ .../apple-source-releases/versions.json | 4 + 5 files changed, 499 insertions(+), 51 deletions(-) delete mode 100644 pkgs/os-specific/darwin/apple-source-releases/shell_cmds/default.nix create mode 100644 pkgs/os-specific/darwin/apple-source-releases/shell_cmds/meson.build.in create mode 100644 pkgs/os-specific/darwin/apple-source-releases/shell_cmds/package.nix diff --git a/pkgs/os-specific/darwin/apple-source-releases/default.nix b/pkgs/os-specific/darwin/apple-source-releases/default.nix index e996e6e5e584..7377e9ace53f 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/default.nix +++ b/pkgs/os-specific/darwin/apple-source-releases/default.nix @@ -313,7 +313,7 @@ developerToolsPackages_11_3_1 // macosPackages_11_0_1 // { diskdev_cmds = callPackage ./diskdev_cmds/package.nix { }; network_cmds = callPackage ./network_cmds/package.nix { }; file_cmds = callPackage ./file_cmds/package.nix { }; - shell_cmds = applePackage "shell_cmds" "osx-10.11.6" "sha256-kmEOprkiJGMVcl7yHkGX8ymk/5KjE99gWuF8j2hK5hY=" {}; + shell_cmds = callPackage ./shell_cmds/package.nix { }; system_cmds = applePackage "system_cmds" "macos-14.3" "sha256-qFp9nkzsq9uQ7zoyfvO+3gvDlc7kaPvn6luvmO/Io30=" {}; text_cmds = applePackage "text_cmds" "osx-10.11.6" "sha256-KSebU7ZyUsPeqn51nzuGNaNxs9pvmlIQQdkWXIVzDxw=" {}; top = applePackage "top" "osx-10.11.6" "sha256-jbz64ODogtpNyLpXGSZj1jCBdFPVXcVcBkL1vc7g5qQ=" {}; diff --git a/pkgs/os-specific/darwin/apple-source-releases/shell_cmds/default.nix b/pkgs/os-specific/darwin/apple-source-releases/shell_cmds/default.nix deleted file mode 100644 index a8352285c78e..000000000000 --- a/pkgs/os-specific/darwin/apple-source-releases/shell_cmds/default.nix +++ /dev/null @@ -1,50 +0,0 @@ -{ lib, appleDerivation, xcbuildHook, launchd }: - -appleDerivation { - nativeBuildInputs = [ xcbuildHook launchd ]; - - patchPhase = '' - # NOTE: these hashes must be recalculated for each version change - - # disables: - # - su ('security/pam_appl.h' file not found) - # - find (Undefined symbol '_get_date') - # - w (Undefined symbol '_res_9_init') - # - expr - substituteInPlace shell_cmds.xcodeproj/project.pbxproj \ - --replace "FCBA168714A146D000AA698B /* PBXTargetDependency */," "" \ - --replace "FCBA165914A146D000AA698B /* PBXTargetDependency */," "" \ - --replace "FCBA169514A146D000AA698B /* PBXTargetDependency */," "" \ - --replace "FCBA165514A146D000AA698B /* PBXTargetDependency */," "" - - # disable w, test install - # get rid of permission stuff - substituteInPlace xcodescripts/install-files.sh \ - --replace 'ln -f "$BINDIR/w" "$BINDIR/uptime"' "" \ - --replace 'ln -f "$DSTROOT/bin/test" "$DSTROOT/bin/["' "" \ - --replace "-o root -g wheel -m 0755" "" \ - --replace "-o root -g wheel -m 0644" "" - ''; - - # temporary install phase until xcodebuild has "install" support - installPhase = '' - for f in Products/Release/*; do - if [ -f $f ]; then - install -D $f $out/usr/bin/$(basename $f) - fi - done - - export DSTROOT=$out - export SRCROOT=$PWD - . xcodescripts/install-files.sh - - mv $out/usr/* $out - mv $out/private/etc $out - rmdir $out/usr $out/private - ''; - - meta = { - platforms = lib.platforms.darwin; - maintainers = with lib.maintainers; [ matthewbauer ]; - }; -} diff --git a/pkgs/os-specific/darwin/apple-source-releases/shell_cmds/meson.build.in b/pkgs/os-specific/darwin/apple-source-releases/shell_cmds/meson.build.in new file mode 100644 index 000000000000..d2bc7cf19324 --- /dev/null +++ b/pkgs/os-specific/darwin/apple-source-releases/shell_cmds/meson.build.in @@ -0,0 +1,417 @@ +# Build settings based on the upstream Xcode project. +# See: https://github.com/apple-oss-distributions/shell_cmds/blob/main/shell_cmds.xcodeproj/project.pbxproj + +# Project settings +project('shell_cmds', 'c', 'cpp', version : '@version@') +add_global_arguments('-D__FBSDID=__RCSID', language : 'c') + +fs = import('fs') + +# Dependencies +build_cc = meson.get_compiler('c', native : true) + +host_cc = meson.get_compiler('c') +host_cxx = meson.get_compiler('cpp') + + +# pam = cc.find_library('pam') +libedit = dependency('libedit') +libresolv = host_cc.find_library('resolv') +libsbuf = host_cc.find_library('sbuf') +libutil = host_cc.find_library('util') +libxo = dependency('libxo') + +xargs_deps = [ ] +# Versions of macOS prior to 11.0 do not support `strtonum` or `rpmatch` +if not host_cc.has_function('strtonum', prefix : '#include ') + xargs_deps += [ dependency('libbsd-overlay') ] +endif + + +# Generators +bison = generator( + find_program('bison', required : true), + arguments : ['@INPUT@', '--header=@OUTPUT0@', '--output=@OUTPUT1@'], + output : [ '@BASENAME@.tab.h', '@BASENAME@.tab.c'], +) + + +# Binaries + +## These commands all are single files with a man page. + +single_file_cmds = [ + 'basename', + 'chroot', + 'dirname', + 'echo', + 'false', + 'getopt', + 'hostname', + 'jot', + 'kill', + 'killall', + 'lastcomm', + 'lockf', + 'logname', + 'mktemp', + 'nice', + 'nohup', # needs vproc_priv.h + 'path_helper', + 'printenv', + 'printf', + 'pwd', + 'realpath', + 'renice', + 'script', + 'seq', + 'shlock', + 'sleep', + 'systime', + 'tee', + 'time', + 'true', + 'uname', + 'what', + 'whereis', + 'which', + 'yes', +] + +foreach cmd : single_file_cmds + executable( + cmd, + install : true, + sources : [ f'@cmd@/@cmd@.c' ], + ) + foreach section : [ 1, 2, 3, 4, 5, 6, 7, 8 ] + if fs.exists(f'@cmd@/@cmd@.@section@') + install_man(f'@cmd@/@cmd@.@section@') + endif + endforeach +endforeach + +install_data( + 'alias/generic.sh', + install_dir : get_option('bindir'), + install_mode : 'r-xr-xr-x', + rename : 'alias', +) +install_man( + 'alias/alias.1', + 'alias/builtin.1', +) +foreach alias : run_command('cat', 'xcodescripts/builtins.txt', check : true).stdout().strip().split('\n') + install_symlink( + alias, + install_dir : get_option('bindir'), + pointing_to : 'alias', + ) +endforeach + +executable( + 'apply', + dependencies : libsbuf, + install : true, + sources : [ 'apply/apply.c' ], +) +install_man('apply/apply.1') + +executable( + 'date', + include_directories : 'date', + install : true, + sources : [ + 'date/date.c', + 'date/vary.c', + ], +) +install_man('date/date.1') + +executable( + 'env', + include_directories : 'env', + install : true, + sources : [ + 'env/env.c', + 'env/envopts.c', + ], +) +install_man('env/env.1') + +executable( + 'expr', + install : true, + sources : [ + bison.process('expr/expr.y') + ], +) +install_man('expr/expr.1') + +executable( + 'find', + c_args : [ '-D_DARWIN_USE_64_BIT_INODE' ], + include_directories : 'find', + install : true, + sources : [ + 'find/find.c', + 'find/function.c', + 'find/ls.c', + 'find/main.c', + 'find/misc.c', + 'find/operator.c', + 'find/option.c', + bison.process('find/getdate.y'), + ], +) +install_man('find/find.1') + +executable( + 'hexdump', + include_directories : 'hexdump', + install : true, + sources : [ + 'hexdump/conv.c', + 'hexdump/display.c', + 'hexdump/hexdump.c', + 'hexdump/hexsyntax.c', + 'hexdump/odsyntax.c', + 'hexdump/parse.c', + ], +) +install_man( + 'hexdump/hexdump.1', + 'hexdump/od.1', +) +install_symlink( + 'od', + install_dir : get_option('bindir'), + pointing_to : 'hexdump', +) + +executable( + 'id', + c_args : [ '-DUSE_BSM_AUDIT' ], + include_directories : 'id', + install : true, + sources : [ + 'id/id.c', + # 'id/open_directory.c', # Not actually used and doesn’t compile anyway. + ], +) +install_man( + 'id/groups.1', + 'id/id.1', + 'id/whoami.1', +) +foreach cmd : [ 'groups', 'whoami' ] + install_symlink( + cmd, + install_dir : get_option('bindir'), + pointing_to : 'id', + ) +endforeach + +executable( + 'locate', + include_directories : 'locate/locate', + install : true, + sources : [ + 'locate/locate/locate.c', + 'locate/locate/util.c', + ], +) +executable( + 'locate.bigram', + include_directories : 'locate/locate', + install : true, + sources : [ 'locate/bigram/locate.bigram.c', ], +) +executable( + 'locate.code', + include_directories : 'locate/locate', + install : true, + sources : [ 'locate/code/locate.code.c', ], +) +install_data( + 'locate/locate/locate.rc', + install_dir : get_option('sysconfdir'), +) +install_data( + 'locate/locate/concatdb.sh', + 'locate/locate/updatedb.sh', + 'locate/locate/mklocatedb.sh', + install_dir : get_option('libexecdir'), + install_mode : 'r-xr-xr-x', + rename : [ + 'locate.concatdb', + 'locate.updatedb', + 'locate.mklocatedb', + ], +) +install_man( + 'locate/locate/locate.1', + 'locate/locate/locate.updatedb.8', + 'locate/bigram/locate.bigram.8', + 'locate/code/locate.code.8', +) +foreach manpage : [ 'concatdb', 'mklocatedb' ] + install_symlink( + f'locate.@manpage@.8', + install_dir : get_option('mandir') + '/man8', + pointing_to : 'locate.updatedb.8', + ) +endforeach + +# Building `sh` requires several custom targets to generate files it needs. + +bash_bin = find_program('bash') +mknodes = executable('mknodes', sources : 'sh/mknodes.c', native : true) +mksyntax = executable('mksyntax', sources : 'sh/mksyntax.c', native : true) + +builtins = custom_target( + command : [ bash_bin, '@SOURCE_ROOT@/sh/mkbuiltins', '@SOURCE_ROOT@/sh'], + output : [ 'builtins.c', 'builtins.h' ], +) + +nodes = custom_target( + command : [ mknodes, '@SOURCE_ROOT@/sh/nodetypes', '@SOURCE_ROOT@/sh/nodes.c.pat' ], + output : [ 'nodes.c', 'nodes.h' ], +) + +syntax = custom_target( + command : [ mksyntax ], + output : [ 'syntax.c', 'syntax.h' ], +) + +tokens = custom_target( + command : [ bash_bin, '@SOURCE_ROOT@/sh/mktokens' ], + output : 'token.h', +) + +executable( + 'sh', + c_args : [ '-DSHELL' ], + dependencies : [ libedit ], + include_directories : [ 'sh', 'sh/bltin' ], + install : true, + sources : [ + 'kill/kill.c', + 'printf/printf.c', + 'sh/alias.c', + 'sh/arith_yacc.c', + 'sh/arith_yylex.c', + 'sh/bltin/echo.c', + 'sh/cd.c', + 'sh/error.c', + 'sh/eval.c', + 'sh/exec.c', + 'sh/expand.c', + 'sh/histedit.c', + 'sh/input.c', + 'sh/jobs.c', + 'sh/mail.c', + 'sh/main.c', + 'sh/memalloc.c', + 'sh/miscbltin.c', + 'sh/mystring.c', + 'sh/options.c', + 'sh/output.c', + 'sh/parser.c', + 'sh/redir.c', + 'sh/show.c', + 'sh/trap.c', + 'sh/var.c', + 'test/test.c', + builtins, + nodes, + syntax, + tokens, + ], +) +install_man('sh/sh.1') + +# Requires entitlements +# executable( +# 'su', +# dependencies : pam, +# sources : [ 'su/su.c' ], +# ) +# install_data( +# 'su/su.pam', +# install_dir : get_option('sysconfdir') + 'pam.d', +# rename : 'su' +# ) +# install_man('su/su.1') + +executable( + '[', + install : true, + sources : [ 'test/test.c' ], +) +install_man( + 'test/[.1', + 'test/test.1', +) +install_symlink( + 'test', + install_dir : get_option('bindir'), + pointing_to : '[', +) + + +executable( + 'users', + install : true, + sources : [ 'users/users.cc' ], +) +install_man('users/users.1') + +executable( + 'w', + c_args : [ + '-DHAVE_KVM=0', + '-DHAVE_UTMPX=1', + ], + dependencies : [ libresolv, libsbuf, libutil, libxo ], + include_directories : 'w', + install : true, + sources : [ + 'w/fmt.c', + 'w/pr_time.c', + 'w/proc_compare.c', + 'w/w.c', + ], +) +install_man( + 'w/uptime.1', + 'w/w.1', +) +install_symlink( + 'uptime', + install_dir : get_option('bindir'), + pointing_to : 'w', +) + +executable( + 'who', + c_args : [ + '-D_UTMPX_COMPAT', + '-DSUPPORT_UTMPX', + ], + install : true, + sources : [ 'who/who.c' ], +) +install_man('who/who.1') + +executable( + 'xargs', + dependencies : xargs_deps, + include_directories : 'xargs', + install : true, + sources : [ + 'xargs/strnsubst.c', + 'xargs/xargs.c', + ], +) +install_man('xargs/xargs.1') diff --git a/pkgs/os-specific/darwin/apple-source-releases/shell_cmds/package.nix b/pkgs/os-specific/darwin/apple-source-releases/shell_cmds/package.nix new file mode 100644 index 000000000000..88fbbf9fb66c --- /dev/null +++ b/pkgs/os-specific/darwin/apple-source-releases/shell_cmds/package.nix @@ -0,0 +1,77 @@ +{ + lib, + apple-sdk, + bison, + buildPackages, + clang, + libbsd, + libedit, + libresolv, + libsbuf, + libutil, + libxo, + pkg-config, + mkAppleDerivation, +}: + +let + # nohup requires vproc_priv.h from launchd + launchd = apple-sdk.sourceRelease "launchd"; +in +mkAppleDerivation { + releaseName = "shell_cmds"; + + outputs = [ + "out" + "man" + ]; + + xcodeHash = "sha256-JXK5hIsNDjCh7n39IWvHK8O0A3ItBttDlnN1YmAn6y8="; + + postPatch = + '' + # Fix `mktemp` templates + substituteInPlace sh/mkbuiltins \ + --replace-fail '-t ka' '-t ka.XXXXXX' + substituteInPlace sh/mktokens \ + --replace-fail '-t ka' '-t ka.XXXXXX' + + # Update `/etc/locate.rc` paths to point to the store. + for path in locate/locate/locate.updatedb.8 locate/locate/locate.rc locate/locate/updatedb.sh; do + substituteInPlace $path --replace-fail '/etc/locate.rc' "$out/etc/locate.rc" + done + ''; + + env.NIX_CFLAGS_COMPILE = "-I${launchd}/liblaunch"; + + depsBuildBuild = [ clang ]; + + nativeBuildInputs = [ + bison + pkg-config + ]; + + buildInputs = + [ + libedit + libresolv + libsbuf + libutil + libxo + ] + # xargs needs `strtonum`, which was added in 11.0. + ++ lib.optionals (lib.versionOlder (lib.getVersion apple-sdk) "11.0") [ libbsd ]; + + postInstall = '' + # Patch the shebangs to use `sh` from shell_cmds. + HOST_PATH="$out/bin" patchShebangs --host "$out/bin" "$out/libexec" + ''; + + meta = { + description = "Darwin shell commands and the Almquist shell"; + license = [ + lib.licenses.bsd2 + lib.licenses.bsd3 + ]; + }; +} diff --git a/pkgs/os-specific/darwin/apple-source-releases/versions.json b/pkgs/os-specific/darwin/apple-source-releases/versions.json index e1597744be46..b15516803c7b 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/versions.json +++ b/pkgs/os-specific/darwin/apple-source-releases/versions.json @@ -62,5 +62,9 @@ "removefile": { "hash": "sha256-UpNk27kGXnZss1ZXWVJU9jLz/NW63ZAZEDLhyCYoi9M=", "version": "45" + }, + "shell_cmds": { + "hash": "sha256-kmEOprkiJGMVcl7yHkGX8ymk/5KjE99gWuF8j2hK5hY=", + "version": "187" } }