summary refs log tree commit diff
path: root/pkgs/os-specific/darwin/apple-source-releases/system_cmds/default.nix
blob: d42d142ef6ee74d9aa17f5111f73f7b346e144e5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
{ stdenv, appleDerivation, lib
, libutil, Librpcsvc, apple_sdk, pam, CF, openbsm }:

appleDerivation {
  # xcbuild fails with:
  # /nix/store/fc0rz62dh8vr648qi7hnqyik6zi5sqx8-xcbuild-wrapper/nix-support/setup-hook: line 1:  9083 Segmentation fault: 11  xcodebuild OTHER_CFLAGS="$NIX_CFLAGS_COMPILE" OTHER_CPLUSPLUSFLAGS="$NIX_CFLAGS_COMPILE" OTHER_LDFLAGS="$NIX_LDFLAGS" build
  # see issue facebook/xcbuild#188
  # buildInputs = [ xcbuild ];

  buildInputs = [ libutil Librpcsvc apple_sdk.frameworks.OpenDirectory pam CF
                  apple_sdk.frameworks.IOKit openbsm ];
  # NIX_CFLAGS_COMPILE = lib.optionalString hostPlatform.isi686 "-D__i386__"
  #                    + lib.optionalString hostPlatform.isx86_64 "-D__x86_64__"
  #                    + lib.optionalString hostPlatform.isAarch32 "-D__arm__";
  NIX_CFLAGS_COMPILE = [ "-DDAEMON_UID=1"
                         "-DDAEMON_GID=1"
                         "-DDEFAULT_AT_QUEUE='a'"
                         "-DDEFAULT_BATCH_QUEUE='b'"
                         "-DPERM_PATH=\"/usr/lib/cron/\""
                         "-DOPEN_DIRECTORY"
                         "-DNO_DIRECT_RPC"
                         "-DAPPLE_GETCONF_UNDERSCORE"
                         "-DAPPLE_GETCONF_SPEC"
                         "-DUSE_PAM"
                         "-DUSE_BSM_AUDIT"
                         "-D_PW_NAME_LEN=MAXLOGNAME"
                         "-D_PW_YPTOKEN=\"__YP!\""
                         "-DAHZV1=64 "
                         "-DAU_SESSION_FLAG_HAS_TTY=0x4000"
                         "-DAU_SESSION_FLAG_HAS_AUTHENTICATED=0x4000"
                       ] ++ lib.optional (!stdenv.isLinux) " -D__FreeBSD__ ";

  patchPhase = ''
    substituteInPlace login.tproj/login.c \
      --replace bsm/audit_session.h bsm/audit.h
    substituteInPlace login.tproj/login_audit.c \
      --replace bsm/audit_session.h bsm/audit.h
  '' + lib.optionalString stdenv.isAarch64 ''
    substituteInPlace sysctl.tproj/sysctl.c \
      --replace "GPROF_STATE" "0"
    substituteInPlace login.tproj/login.c \
      --replace "defined(__arm__)" "defined(__arm__) || defined(__arm64__)"
  '';

  buildPhase = ''
    for dir in *.tproj; do
      name=$(basename $dir)
      name=''${name%.tproj}

      CFLAGS=""
      case $name in
           arch) CFLAGS="-framework CoreFoundation";;
           atrun) CFLAGS="-Iat.tproj";;
           chkpasswd)
             CFLAGS="-framework OpenDirectory -framework CoreFoundation -lpam";;
           getconf)
               for f in getconf.tproj/*.gperf; do
                   cfile=''${f%.gperf}.c
                   LC_ALL=C awk -f getconf.tproj/fake-gperf.awk $f > $cfile
               done
           ;;
           iostat) CFLAGS="-framework IOKit -framework CoreFoundation";;
           login) CFLAGS="-lbsm -lpam";;
           nvram) CFLAGS="-framework CoreFoundation -framework IOKit";;
           sadc) CFLAGS="-framework IOKit -framework CoreFoundation";;
           sar) CFLAGS="-Isadc.tproj";;
      esac

      echo "Building $name"

      case $name in

           # These are all broken currently.
           arch) continue;;
           chpass) continue;;
           dirhelper) continue;;
           dynamic_pager) continue;;
           fs_usage) continue;;
           latency) continue;;
           pagesize) continue;;
           passwd) continue;;
           reboot) continue;;
           sc_usage) continue;;
           shutdown) continue;;
           trace) continue;;

           *) cc $dir/*.c -I''${dir} $CFLAGS -o $name ;;
      esac
    done
  '';

  installPhase = ''
    for dir in *.tproj; do
      name=$(basename $dir)
      name=''${name%.tproj}
      [ -x $name ] && install -D $name $out/bin/$name
      for n in 1 2 3 4 5 6 7 8 9; do
        for f in $dir/*.$n; do
          install -D $f $out/share/man/man$n/$(basename $f)
        done
      done
    done
  '';

  meta = {
    platforms = lib.platforms.darwin;
    maintainers = with lib.maintainers; [ shlevy matthewbauer ];
  };
}