1{ lib
2, stdenv
3, python27
4, callPackage
5, fetchFromGitHub
6, makeWrapper
7, # re2c deps
8 autoreconfHook
9, # py-yajl deps
10 git
11, # oil deps
12 cmark
13, file
14, glibcLocales
15, six
16, typing
17}:
18
19rec {
20 re2c = stdenv.mkDerivation rec {
21 pname = "re2c";
22 version = "1.0.3";
23 sourceRoot = "${src.name}/re2c";
24 src = fetchFromGitHub {
25 owner = "skvadrik";
26 repo = "re2c";
27 rev = version;
28 sha256 = "0grx7nl9fwcn880v5ssjljhcb9c5p2a6xpwil7zxpmv0rwnr3yqi";
29 };
30 nativeBuildInputs = [ autoreconfHook ];
31 preCheck = ''
32 patchShebangs run_tests.sh
33 '';
34 };
35
36 py-yajl = python27.pkgs.buildPythonPackage rec {
37 pname = "oil-pyyajl-unstable";
38 version = "2022-09-01";
39 src = fetchFromGitHub {
40 owner = "oilshell";
41 repo = "py-yajl";
42 rev = "72686b0e2e9d13d3ce5fefe47ecd607c540c90a3";
43 hash = "sha256-H3GKN0Pq1VFD5+SWxm8CXUVO7zAyj/ngKVmDaG/aRT4=";
44 fetchSubmodules = true;
45 };
46 # just for submodule IIRC
47 nativeBuildInputs = [ git ];
48 };
49
50 /*
51 Upstream isn't interested in packaging this as a library
52 (or accepting all of the patches we need to do so).
53 This creates one without disturbing upstream too much.
54 */
55 oildev = python27.pkgs.buildPythonPackage rec {
56 pname = "oildev-unstable";
57 version = "2021-07-14";
58
59 src = fetchFromGitHub {
60 owner = "oilshell";
61 repo = "oil";
62 # rev == present HEAD of release/0.14.0
63 rev = "3d0427e222f7e42ae7be90c706d7fde555efca2e";
64 hash = "sha256-XMoNkBEEmD6AwNSu1uSh3OcWLfy4/ADtRckn/Pj2cP4=";
65
66 /*
67 It's not critical to drop most of these; the primary target is
68 the vendored fork of Python-2.7.13, which is ~ 55M and over 3200
69 files, dozens of which get interpreter script patches in fixup.
70
71 Note: -f is necessary to keep it from being a pain to update
72 hash on rev updates. Command will fail w/o and not print hash.
73 */
74 postFetch = ''
75 rm -rf $out/{Python-2.7.13,metrics,py-yajl,rfc,gold,web,testdata,services,demo,devtools}
76 '';
77 };
78
79 # patch to support a python package, pass tests on macOS, drop deps, etc.
80 patchSrc = fetchFromGitHub {
81 owner = "abathur";
82 repo = "nix-py-dev-oil";
83 rev = "v0.14.0.0";
84 hash = "sha256-U6uR8G6yB2xwuDE/fznco23mVFSVdCxPUNdCRYz4Mj8=";
85 };
86 patches = [
87 "${patchSrc}/0001-add_setup_py.patch"
88 "${patchSrc}/0002-add_MANIFEST_in.patch"
89 "${patchSrc}/0004-disable-internal-py-yajl-for-nix-built.patch"
90 "${patchSrc}/0006-disable_failing_libc_tests.patch"
91 "${patchSrc}/0007-namespace_via_init.patch"
92 "${patchSrc}/0009-avoid_nix_arch64_darwin_toolchain_bug.patch"
93 "${patchSrc}/0010-disable-line-input.patch"
94 "${patchSrc}/0011-disable-fanos.patch"
95 "${patchSrc}/0012-disable-doc-cmark.patch"
96 ];
97
98 configureFlags = [
99 "--without-readline"
100 ];
101
102 nativeBuildInputs = [ re2c file makeWrapper ];
103
104 propagatedBuildInputs = [ six typing py-yajl ];
105
106 doCheck = true;
107
108 preBuild = ''
109 build/dev.sh all
110 '';
111
112 postPatch = ''
113 patchShebangs asdl build core doctools frontend pyext oil_lang
114 substituteInPlace pyext/fastlex.c --replace '_gen/frontend' '../_gen/frontend'
115 substituteInPlace core/main_loop.py --replace 'import fanos' '# import fanos'
116 rm cpp/stdlib.h # keep modules from finding the wrong stdlib?
117 # work around hard parse failure documented in oilshell/oil#1468
118 substituteInPlace osh/cmd_parse.py --replace 'elif self.c_id == Id.Op_LParen' 'elif False'
119 '';
120
121 /*
122 We did convince oil to upstream an env for specifying
123 this to support a shell.nix. Would need a patch if they
124 later drop this support. See:
125 https://github.com/oilshell/oil/blob/46900310c7e4a07a6223eb6c08e4f26460aad285/doctools/cmark.py#L30-L34
126 */
127 _NIX_SHELL_LIBCMARK = "${cmark}/lib/libcmark${stdenv.hostPlatform.extensions.sharedLibrary}";
128
129 # See earlier note on glibcLocales TODO: verify needed?
130 LOCALE_ARCHIVE = lib.optionalString (stdenv.buildPlatform.libc == "glibc") "${glibcLocales}/lib/locale/locale-archive";
131
132 # not exhaustive; sample what resholve uses as a sanity check
133 pythonImportsCheck = [
134 "oil"
135 "oil.asdl"
136 "oil.core"
137 "oil.frontend"
138 "oil._devbuild"
139 "oil._devbuild.gen.id_kind_asdl"
140 "oil._devbuild.gen.syntax_asdl"
141 "oil.tools.osh2oil"
142 ];
143
144 meta = {
145 license = with lib.licenses; [
146 psfl # Includes a portion of the python interpreter and standard library
147 asl20 # Licence for Oil itself
148 ];
149 };
150 };
151}