diff --git a/pkgs/os-specific/darwin/apple-source-releases/default.nix b/pkgs/os-specific/darwin/apple-source-releases/default.nix index 9593b5bbd86c..675fda696395 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/default.nix +++ b/pkgs/os-specific/darwin/apple-source-releases/default.nix @@ -316,7 +316,7 @@ developerToolsPackages_11_3_1 // macosPackages_11_0_1 // { shell_cmds = callPackage ./shell_cmds/package.nix { }; system_cmds = callPackage ./system_cmds/package.nix { }; text_cmds = callPackage ./text_cmds/package.nix { }; - top = applePackage "top" "osx-10.11.6" "sha256-jbz64ODogtpNyLpXGSZj1jCBdFPVXcVcBkL1vc7g5qQ=" {}; + top = callPackage ./top/package.nix { }; PowerManagement = callPackage ./PowerManagement/package.nix { }; # `configdHeaders` can’t use an override because `pkgs.darwin.configd` on aarch64-darwin will diff --git a/pkgs/os-specific/darwin/apple-source-releases/top/default.nix b/pkgs/os-specific/darwin/apple-source-releases/top/default.nix deleted file mode 100644 index 2a47de021dc6..000000000000 --- a/pkgs/os-specific/darwin/apple-source-releases/top/default.nix +++ /dev/null @@ -1,19 +0,0 @@ -{xcbuildHook, appleDerivation, apple_sdk, ncurses, libutil, lib}: - -appleDerivation { - nativeBuildInputs = [ xcbuildHook ]; - buildInputs = [ apple_sdk.frameworks.IOKit ncurses libutil ]; - # Workaround build failure on -fno-common toolchains: - # duplicate symbol '_tsamp' in: main.o top.o - env.NIX_CFLAGS_COMPILE = "-fcommon"; - NIX_LDFLAGS = "-lutil"; - installPhase = '' - install -D Products/Release/libtop.a $out/lib/libtop.a - install -D Products/Release/libtop.h $out/include/libtop.h - install -D Products/Release/top $out/bin/top - ''; - meta = { - platforms = lib.platforms.darwin; - maintainers = with lib.maintainers; [ matthewbauer ]; - }; -} diff --git a/pkgs/os-specific/darwin/apple-source-releases/top/meson.build.in b/pkgs/os-specific/darwin/apple-source-releases/top/meson.build.in new file mode 100644 index 000000000000..59ce121d7650 --- /dev/null +++ b/pkgs/os-specific/darwin/apple-source-releases/top/meson.build.in @@ -0,0 +1,80 @@ +# Build settings based on the upstream Xcode project. +# See: https://github.com/apple-oss-distributions/top/blob/main/top.xcodeproj/project.pbxproj + +# Project settings +project('top', 'c', version : '@version@') + + +# Dependencies +cc = meson.get_compiler('c') + +libutil = cc.find_library('util', has_headers : 'libutil.h') +ncurses = [ + dependency('ncurses'), + dependency('form'), + dependency('panel'), +] +sdk_frameworks = dependency('appleframeworks', modules : ['CoreFoundation', 'IOKit']) + + +# Libraries +libtop = static_library( + 'top', + sources : [ + 'libtop.c', + ], +) +install_headers( + 'libtop.h', +) + +# Binaries +top = executable( + 'top', + dependencies : [libutil, ncurses, sdk_frameworks], + install : true, + link_with : libtop, + sources : [ + 'command.c', + 'cpu.c', + 'csw.c', + 'faults.c', + 'generic.c', + 'globalstats.c', + 'layout.c', + 'log.c', + 'logging.c', + 'main.c', + 'memstats.c', + 'messages.c', + 'options.c', + 'pgrp.c', + 'pid.c', + 'ports.c', + 'power.c', + 'ppid.c', + 'preferences.c', + 'pstate.c', + 'sig.c', + 'statistic.c', + 'syscalls.c', + 'threads.c', + 'timestat.c', + 'top.c', + 'uid.c', + 'uinteger.c', + 'user.c', + 'userinput.c', + 'userinput_help.c', + 'userinput_mode.c', + 'userinput_order.c', + 'userinput_secondary_order.c', + 'userinput_signal.c', + 'userinput_sleep.c', + 'userinput_user.c', + 'workqueue.c', + ], +) +install_man( + 'top.1', +) diff --git a/pkgs/os-specific/darwin/apple-source-releases/top/package.nix b/pkgs/os-specific/darwin/apple-source-releases/top/package.nix new file mode 100644 index 000000000000..9267fde52223 --- /dev/null +++ b/pkgs/os-specific/darwin/apple-source-releases/top/package.nix @@ -0,0 +1,37 @@ +{ + apple-sdk_11, + fetchpatch2, + libutil, + mkAppleDerivation, + ncurses, + pkg-config, +}: + +let + xnu = apple-sdk_11.sourceRelease "xnu"; +in +mkAppleDerivation { + releaseName = "top"; + + xcodeHash = "sha256-TuBdZztwCpNwPP0er+7h6FoPV9AbdZAXpzGcqBAuD5Y="; + + postPatch = '' + # Fix duplicate symbol error. `tsamp` is unused in `main.c`. + substituteInPlace main.c \ + --replace-fail 'const libtop_tsamp_t *tsamp;' "" + + # Adding the whole sys folder causes header conflicts, so copy only the private headers that are needed. + mkdir sys + cp ${xnu}/bsd/sys/{kern_memorystatus.h,reason.h} sys/ + ''; + + buildInputs = [ + apple-sdk_11 + libutil + ncurses + ]; + + nativeBuildInputs = [ pkg-config ]; + + meta.description = "Display information about processes"; +} diff --git a/pkgs/os-specific/darwin/apple-source-releases/versions.json b/pkgs/os-specific/darwin/apple-source-releases/versions.json index 82426a816292..c2a837d26b53 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/versions.json +++ b/pkgs/os-specific/darwin/apple-source-releases/versions.json @@ -74,5 +74,9 @@ "text_cmds": { "hash": "sha256-KSebU7ZyUsPeqn51nzuGNaNxs9pvmlIQQdkWXIVzDxw=", "version": "99" + }, + "top": { + "hash": "sha256-jbz64ODogtpNyLpXGSZj1jCBdFPVXcVcBkL1vc7g5qQ=", + "version": "108" } }