summary refs log tree commit diff
path: root/pkgs/tools/system/mac-fdisk/default.nix
blob: 292b77d2d2cf79b090306da172abea1dc44a3b02 (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
110
111
112
{ stdenv
, lib
, fetchzip
, fetchpatch
, installShellFiles
}:

stdenv.mkDerivation rec {
  pname = "mac-fdisk";
  version = "0.1.16";

  src = fetchzip {
    url = "https://deb.debian.org/debian/pool/main/m/mac-fdisk/mac-fdisk_0.1.orig.tar.gz";
    sha256 = "sha256-pYNyhPvRKdIje0Rpay0OzmrkGcl+/JOhMv7r+2LZk/Q=";
  };

  patches = [
    # Debian's changeset, extracted into a patch
    (fetchpatch {
      url = "https://git.adelielinux.org/adelie/packages/-/raw/1b708c8a90e3548c4954c6367a9376f76f3746bd/user/mac-fdisk/mac-fdisk-0.1-debian.patch";
      sha256 = "sha256-a9pGF+UsFeZiXgracmT4anqgpmcGcS/W3jGtFzHZtt4=";
    })
    # Include a lot more headers and remove a bunch of braindead __linux__ checks
    (fetchpatch {
      url = "https://git.adelielinux.org/adelie/packages/-/raw/1fa4c88ee21866eeb0feae8f6b0bf609a04711cc/user/mac-fdisk/mac-fdisk-0.1-headers.patch";
      sha256 = "sha256-FIk9K+lP+3e1pgmNfymTdpdSoTpBDv29kmwYgqYwWQw=";
    })
    # Add support for more architectures
    (fetchpatch {
      url = "https://git.adelielinux.org/adelie/packages/-/raw/1b708c8a90e3548c4954c6367a9376f76f3746bd/user/mac-fdisk/mac-fdisk-0.1-more-arches.patch";
      sha256 = "sha256-HNRmzETUmKfZQFrjg6Y/HPwUnLk0vO5DokfU4umdOm0=";
    })
    # From p16 (source?), adjusts some types & fixes PPC64 support
    (fetchpatch {
      url = "https://git.adelielinux.org/adelie/packages/-/raw/1fa4c88ee21866eeb0feae8f6b0bf609a04711cc/user/mac-fdisk/mac-fdisk-0.1_p16-ppc64.patch";
      sha256 = "sha256-GK0nfga59nOXotkbKI+2ejA9TtyZUwDIxuXWFGGbeFg=";
    })
    # From p16 (source?), makes some inlines static
    (fetchpatch {
      url = "https://git.adelielinux.org/adelie/packages/-/raw/1fa4c88ee21866eeb0feae8f6b0bf609a04711cc/user/mac-fdisk/mac-fdisk-0.1_p16-proper-inline.patch";
      sha256 = "sha256-wr2teKpm0FyqNudKYlTD49pTFDis33Fo+0LULNYIJko=";
    })
    # Adds x86_64 support
    (fetchpatch {
      url = "https://git.adelielinux.org/adelie/packages/-/raw/1b708c8a90e3548c4954c6367a9376f76f3746bd/user/mac-fdisk/mac-fdisk-amd64.patch";
      sha256 = "sha256-iO4/sY5sGKQyymMmAOb/TlCc9id2qgEDw7E8pFZpsHI=";
    })
    # Fix missing header in fdisk.c on musl
    (fetchpatch {
      url = "https://git.adelielinux.org/adelie/packages/-/raw/1fa4c88ee21866eeb0feae8f6b0bf609a04711cc/user/mac-fdisk/mac-fdisk-fdisk-header-musl.patch";
      sha256 = "sha256-mKBVjvLKtxKPADeoPqp17YdJ1QWj2enAYhKKSqTnQ44=";
    })
    # Support disks >550GB
    (fetchpatch {
      url = "https://git.adelielinux.org/adelie/packages/-/raw/1fa4c88ee21866eeb0feae8f6b0bf609a04711cc/user/mac-fdisk/mac-fdisk-large-disk-support.patch";
      sha256 = "sha256-IXZZdozqZKyZEz87ZzB8Jof22GgvHf4GaXBqSKn8su8=";
    })
    # Enable Large File Support (>2GiB)
    (fetchpatch {
      url = "https://git.adelielinux.org/adelie/packages/-/raw/1fa4c88ee21866eeb0feae8f6b0bf609a04711cc/user/mac-fdisk/mac-fdisk-largerthan2gb.patch";
      sha256 = "sha256-ATK7QYXV7BOk8iIFeXY8g+ZHLuuhww9pcrqOMDn/oLM=";
    })
    # Fix compilation on non-glibc
    (fetchpatch {
      url = "https://git.adelielinux.org/adelie/packages/-/raw/1fa4c88ee21866eeb0feae8f6b0bf609a04711cc/user/mac-fdisk/mac-fdisk-non-glibc-support.patch";
      sha256 = "sha256-CBZUKf7dPvvpuG5L+SI1FQ4W7/fDgeKXHUMFkJNu/MY=";
    })
    # Flush stdout after printing prompt for better UX
    (fetchpatch {
      url = "https://git.adelielinux.org/adelie/packages/-/raw/656ae6bf9f8a64aee95c4797b20bfe713627f1f4/user/mac-fdisk/flush-stdout.patch";
      sha256 = "sha256-k7+UPiUf/oCQdDhxDcC+FRwkxS89WSsYzFw6fUB/10I=";
    })
  ];

  nativeBuildInputs = [
    installShellFiles
  ];

  enableParallelBuilding = true;

  NIX_CFLAGS_COMPILE = "-D_GNU_SOURCE";

  hardeningDisable = [ "format" ];

  installPhase = ''
    runHook preInstall

    install -Dm755 pdisk $out/sbin/mac-fdisk
    install -Dm755 fdisk $out/sbin/pmac-fdisk

    for manpage in {,p}mac-fdisk.8; do
      mv "$manpage".in $manpage
      installManPage $manpage
    done

    runHook postInstall
  '';

  meta = with lib; {
    description = "68K and PowerPC Mac disk partitioning utility, Adélie Linux version";
    # http://ftp.mklinux.apple.com:/pub/Other_Tools/ but that one's looong dead, link goes to the patch compilation we're using
    homepage = "https://git.adelielinux.org/adelie/packages/-/tree/master/user/mac-fdisk";
    license = with licenses; [
      hpnd # original license statements seems to match this (in files that are shared with pdisk)
      gpl1Plus # fdisk.c
    ];
    maintainers = with maintainers; [ OPNA2608 ];
    # the toolchain that's being expected for Mac support (SCSI.h from Universal Headers 2.0, SIOUX.h from Metrowerks CoreWarrior) is ancient, unsure about BSDs
    platforms = platforms.linux;
    badPlatforms = platforms.aarch64; # missing some platform definitions
  };
}