about summary refs log tree commit diff
path: root/nixpkgs/pkgs/by-name/rc/rc/package.nix
blob: 1e1e968e733306d6d8c2b23d11834631b136ffe8 (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
{ lib
, stdenv
, fetchFromGitHub
, pkgsStatic
, byacc
, ed
, ncurses
, readline
, installShellFiles
, historySupport ? true
, readlineSupport ? true
, lineEditingLibrary ? if (stdenv.hostPlatform.isDarwin
                           || stdenv.hostPlatform.isStatic)
                       then "null"
                       else "readline"
}:

assert lib.elem lineEditingLibrary [ "null" "edit" "editline" "readline" "vrl" ];
assert !(lib.elem lineEditingLibrary [ "edit" "editline" "vrl" ]); # broken
assert (lineEditingLibrary == "readline") -> readlineSupport;
stdenv.mkDerivation (finalAttrs: {
  pname = "rc";
  version = "unstable-2023-06-14";

  src = fetchFromGitHub {
    owner = "rakitzis";
    repo = "rc";
    rev = "4aaba1a9cb9fdbb8660696a87850836ffdb09599";
    hash = "sha256-Yql3mt7hTO2W7wTfPje+X2zBGTHiNXGGXYORJewJIM8=";
  };

  outputs = [ "out" "man" ];

  # TODO: think on a less ugly fixup
  postPatch = ''
    ed -v -s Makefile << EOS
    # - remove reference to now-inexistent git index file
    /version.h:/ s| .git/index||
    # - manually insert the git revision string
    /v=/ c
    ${"\t"}v=${builtins.substring 0 7 finalAttrs.src.rev}
    .
    /\.git\/index:/ d
    w
    q
    EOS
  '';

  nativeBuildInputs = [
    byacc
    ed
    installShellFiles
  ];

  buildInputs = [
    ncurses
  ]
  ++ lib.optionals readlineSupport [
    readline
  ];

  strictDeps = true;

  makeFlags  = [
    "CC=${stdenv.cc.targetPrefix}cc"
    "PREFIX=${placeholder "out"}"
    "MANPREFIX=${placeholder "man"}/share/man"
    "CPPFLAGS=\"-DSIGCLD=SIGCHLD\""
    "EDIT=${lineEditingLibrary}"
  ];

  buildFlags = [
    "all"
  ] ++ lib.optionals historySupport [
    "history"
  ];

  postInstall = lib.optionalString historySupport ''
    installManPage history.1
  '';

  passthru = {
    shellPath = "/bin/rc";
    tests.static = pkgsStatic.rc;
  };

  meta = {
    homepage = "https://github.com/rakitzis/rc";
    description = "The Plan 9 shell";
    license = [ lib.licenses.zlib ];
    mainProgram = "rc";
    maintainers = with lib.maintainers; [ ramkromberg AndersonTorres ];
    platforms = lib.platforms.unix;
  };
})