~ehmry/sigil

ref: post-mortem sigil/overlay/default.nix -rw-r--r-- 7.4 KiB
2b1c9d71Emery Hemingway Link the write-up (or write-off) of the project 11 months ago
                                                                                
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
{ flake }:
final: prev:
with prev;

let
  # Helper functions to override package dependant
  # on whether the host or target system is Genode.

  overrideHost = attrs: drv:
    if hostPlatform.isGenode then drv.override attrs else drv;

  overrideTarget = attrs: drv:
    if targetPlatform.isGenode then drv.override attrs else drv;

  overrideAttrsHost = f: drv:
    if hostPlatform.isGenode then drv.overrideAttrs f else drv;

  overrideAttrsTarget = f: drv:
    if targetPlatform.isGenode then drv.overrideAttrs f else drv;

  addPatches' = patches: attrs: { patches = attrs.patches or [ ] ++ patches; };

  addPatchesHost = ps: overrideAttrsHost (addPatches' ps);

  addPatchesTarget = ps: overrideAttrsTarget (addPatches' ps);

  autoreconfHost = overrideAttrsHost
    (attrs: { nativeBuildInputs = [ final.autoreconfHook ]; });

  nullPkgs =
    # Nullify these packages to find problems early.
    if hostPlatform.isGenode then
      builtins.listToAttrs (map (name: {
        inherit name;
        value = null;
      }) [ "iproute2" ])
    else
      { };

in nullPkgs // {

  bash = overrideAttrsTarget (attrs: {
    configureFlags = attrs.configureFlags
      ++ [ "--without-bash-malloc" ]; # no sbrk please
    postPatch = "sed '/check_dev_tty/d' shell.c";
  }) bash;

  binutils-unwrapped = overrideAttrsTarget (attrs: {
    patches = attrs.patches ++ [
      ./binutils/support-genode.patch
      # Upstreamed, remove at next release.
    ];
    nativeBuildInputs = attrs.nativeBuildInputs
      ++ [ final.updateAutotoolsGnuConfigScriptsHook ];
  }) binutils-unwrapped;

  cmake =
    # TODO: upstream
    overrideAttrsTarget (attrs: {
      postInstall = with stdenv; ''
        local MODULE="$out/share/cmake-${
          lib.versions.majorMinor attrs.version
        }/Modules/Platform/Genode.cmake"
        if [ -e "$MODULE" ]; then
            echo "Upstream provides $MODULE!"
            exit 1
        fi
        cp ${./cmake/Genode.cmake} $MODULE
      '';
    }) cmake;

  coreutils = overrideHost {
    gmp = null;
    libiconv = null;
  } (overrideAttrsHost (attrs: {
    configureFlags = [
      "--disable-acl"
      "--disable-largefile"
      "--disable-xattr"
      "--disable-libcap"
      "--disable-nls"
    ];
    LDFLAGS = [ "-Wl,--no-as-needed" ];
    # keep libposix NEEDED
  }) coreutils);

  erisPatchHook = final.callPackage ./eris-patch-hook {
    patchelf = prev.patchelf.overrideAttrs (attrs: {
      patches = attrs.patched or [ ] ++ [
        ./patchelf/dynstr.patch
        ./patchelf/shiftFile.patch
        ./patchelf/disable-assert.patch
      ];
    });
  };

  gdb = addPatchesTarget [
    ./gdb/genode.patch
    # Upstreamed, remove at next release.
  ] gdb;

  genodeLibcCross = callPackage ./libc { };

  genodePackages =
    # The Genode-only packages.
    import ../packages {
      inherit flake;
      pkgs = final;
    };

  grub2 =
    # No need for a Genode build of GRUB.
    if stdenv.targetPlatform.isGenode then
      prev.buildPackages.grub2
    else
      prev.grub2;

  libcCrossChooser = name:
    if stdenv.targetPlatform.isGenode then
      targetPackages.genodeLibcCross
    else
      prev.libcCrossChooser name;

  libsodium = overrideAttrsHost (attrs: {
    patches = (attrs.patches or [ ]) ++ [
      ./libsodium/genode.patch
      # https://github.com/jedisct1/libsodium/pull/1006
    ];
  }) libsodium;

  libkrb5 =
    # Do not want.
    autoreconfHost libkrb5;

  libtool =
    # Autotools related nonesense. Better to compile
    # everything static than to deal with this one.
    overrideAttrsTarget (attrs: {
      nativeBuildInputs = with final;
        attrs.nativeBuildInputs ++ [ autoconf automake115x ];
      patches = ./libtool/genode.patch;
    }) libtool;

  libtoxcore = overrideHost {
    libopus = null;
    libvpx = null;
  } libtoxcore;

  linuxPackages =
    # Dummy package.
    if hostPlatform.isGenode then {
      extend = _: final.linuxPackages;
      features = { };
      kernel.config = {
        isEnabled = _: false;
        isYes = _: false;
      };
    } else
      linuxPackages;

  llvmPackages_11 = if targetPlatform.isGenode then
  # A copy of the LLVM expressions from Nixpkgs.
  # Nothing here is upstreamed.
    callPackage ./llvm-11 ({
      inherit (stdenvAdapters) overrideCC;
      buildLlvmTools = buildPackages.llvmPackages_11.tools;
      targetLlvmLibraries = targetPackages.llvmPackages_11.libraries;
    } // lib.optionalAttrs
      (stdenv.hostPlatform.isi686 && buildPackages.stdenv.cc.isGNU) {
        stdenv = gcc7Stdenv;
      })
  else
    prev.llvmPackages_11;

  ncurses =
    # https://invisible-island.net/autoconf/
    # Stay clear of upstream on this one.
    addPatchesHost [ ./ncurses/genode.patch ] ncurses;

  nim-unwrapped =
    # Fixes to the compiler and standard libary.
    prev.nim-unwrapped.overrideAttrs
    (attrs: { patches = attrs.patches ++ [ ./nim/genode.patch ]; });

  nimblePackages =
    # Packages from the Nimble flake with adjustments.
    let pkgs' = flake.inputs.nimble.overlay (final // pkgs') final;
    in pkgs'.nimblePackages.extend (final: prev: {

      genode = prev.genode.overrideAttrs (attrs: rec {
        version = "20.11.1";
        src = fetchgit {
          inherit (attrs.src) url;
          rev = "v${version}";
          sha256 = "0i78idsrgph0g2yir6niar7v827y6qnmd058s6mpvp091sllvlv8";
        };
      });

    });

  openssl =
    overrideHost { static = true; } # shared library comes out stupid big
    (overrideAttrsHost (attrs: {
      outputs = [ "out" ]
        ++ builtins.filter (x: x != "bin" && x != "out") attrs.outputs;
      patches = attrs.patches or [ ] ++ [ ./openssl/genode.patch ];
      configureScript = {
        x86_64-genode = "./Configure Genode-x86_64";
      }.${stdenv.hostPlatform.system} or (throw
        "Not sure what configuration to use for ${stdenv.hostPlatform.config}");
      configureFlags = attrs.configureFlags ++ [ "no-devcryptoeng" ];
      postInstall =
        "rm $out/bin/c_rehash"; # eliminate the perl runtime dependency
    }) openssl);

  patchelf = addPatchesTarget [
    ./patchelf/dynstr.patch
    # Patch to fix a bug in rewriting the .dynstr section.
  ] prev.patchelf;

  rsync = overrideHost {
    enableACLs = false;
    popt = null;
  } (overrideAttrsHost (attrs: { outputs = [ "out" "man" ]; }) rsync);

  solo5-tools = callPackage ./solo5-tools { };

  stdenv = overrideHost (old: {
    extraNativeBuildInputs = old.extraNativeBuildInputs
      ++ [ final.buildPackages.erisPatchHook ];
  }) prev.stdenv;

  tor = overrideAttrsHost (attrs: {
    configureFlags = attrs.configureFlags or [ ]
      ++ [ "--disable-tool-name-check" ];
    patches = attrs.patches or [ ] ++ [
      ./tor/genode.patch
      # We don't do users and groups here.
    ];
    postPatch = null; # Avoid torsocks patching
  }) tor;

  zlib = overrideAttrsHost (attrs: {
    postInstall = attrs.postInstall or "" + ''
      pushd ''${!outputLib}/lib
      find . -type l -delete
      mv libz.so.* libz.so
      popd
    '';
  }) zlib;

  zstd = let
    static = true;
    legacySupport = false;
  in overrideAttrsHost (attrs: rec {
    cmakeFlags = lib.attrsets.mapAttrsToList
      (name: value: "-DZSTD_${name}:BOOL=${if value then "ON" else "OFF"}") {
        BUILD_SHARED = !static;
        BUILD_STATIC = static;
        PROGRAMS_LINK_SHARED = !static;
        LEGACY_SUPPORT = legacySupport;
        BUILD_TESTS = doCheck;
      };
    doCheck = stdenv.hostPlatform == stdenv.buildPlatform;
  }) prev.zstd;

}