-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathflake.nix
134 lines (121 loc) · 4.23 KB
/
flake.nix
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
{
description = "Theos development environment";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
};
outputs = {
self,
nixpkgs,
}: let
allSystems = [
"x86_64-linux" # 64bit AMD/Intel x86
];
forAllSystems = fn:
nixpkgs.lib.genAttrs allSystems
(system: fn {pkgs = import nixpkgs {inherit system;};});
in {
devShells = forAllSystems ({pkgs}: {
default = let
rev = "82af6911de5f8d8bafe98945ed1ae3d4f4537218";
llvm-swift = builtins.fetchurl {
url = "https://github.com/CRKatri/llvm-project/releases/download/swift-5.3.2-RELEASE/swift-5.3.2-RELEASE-ubuntu18.04.tar.zst";
sha256 = "1mhr91n6p0sahqdmlpz4fr539g9rwrwq0k9mx9ikg6gcl4ddjzfk";
};
theos-src = pkgs.fetchgit {
url = "https://github.com/theos/theos";
rev = rev;
sha256 = "sha256-T6k8XFnSGFrdy1S2JNXZHZGHJ/NpG09uW20G7bdPIv0=";
leaveDotGit = true;
fetchSubmodules = true;
};
theos-sdks = pkgs.fetchFromGitHub {
owner = "theos";
repo = "sdks";
rev = "bb425abf3acae8eac328b828628b82df544d2774";
sha256 = "sha256-cZfCEWI+Nuon/cbZLBNpqwGNIbiPg184a0NjblrkaQ4=";
};
rpath = pkgs.lib.makeLibraryPath [
pkgs.gcc-unwrapped.lib
pkgs.glibc
pkgs.libedit
pkgs.ncurses5
pkgs.swift
pkgs.util-linux
pkgs.zlib
];
theos = pkgs.stdenv.mkDerivation {
name = "theos";
version = rev;
srcs = [llvm-swift theos-src theos-sdks];
nativeBuildInputs = [pkgs.autoPatchelfHook];
buildInputs = [pkgs.patchelf pkgs.zstd];
phases = ["installPhase"];
installPhase = ''
mkdir -p $out/share
THEOS=$out/share/theos
# install theos
cp -r --no-preserve=mode,ownership ${theos-src} $THEOS
# install llvm-swift
tar -xf ${llvm-swift} -C $TMPDIR
mkdir -p $THEOS/toolchain/linux/iphone $THEOS/toolchain/swift
mv $TMPDIR/swift-5.3.2-RELEASE-ubuntu18.04/* $THEOS/toolchain/linux/iphone/
ln -s $THEOS/toolchain/linux/iphone $THEOS/toolchain/swift
# install 14.5 sdk
cp -r --no-preserve=mode,ownership ${theos-sdks}/iPhoneOS14.5.sdk $THEOS/sdks
# mutate perl scripts so they use `/usr/bin/env perl` as a shebang
find $THEOS -type f -name '*.pl' -exec sed -i 's|#!/usr/bin/perl|#!/usr/bin/env perl|g' {} \;
chmod +x $(find $THEOS -type f -name '*.pl')
# mutate bin/bash scripts so they use `/usr/bin/env bash` as a shebang
find $THEOS/bin -type f -exec sed -i 's|#!/bin/bash|#!/usr/bin/env bash|g' {} \;
chmod +x $THEOS/bin/*
# install nic.pl
mkdir -p $out/bin
cat <<EOF >$out/bin/theos-nic
#!/usr/bin/env bash
perl $THEOS/bin/nic.pl
EOF
chmod +x $out/bin/theos-nic
# patchELF all executables
find $THEOS -type f -executable -exec patchelf --replace-needed libedit.so.2 libedit.so.0 {} \;
find $THEOS -type f -executable -exec patchelf --set-rpath ${rpath} --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) {} \;
# manual fix for an annoying bug
cat <<EOF >$THEOS/toolchain/linux/iphone/bin/ld
#!/bin/sh
LD_LIBRARY_PATH="\$(dirname "\$0")"/../lib:${rpath} "\$(dirname "\$0")"/ld64 "\$@"
EOF
'';
};
# modeled after: https://archlinux.org/groups/x86_64/base-devel/
base-devel = with pkgs; [
autoconf
automake
binutils
bison
fakeroot
file
findutils
flex
gawk
gcc
gettext
gnumake
groff
gzip
libtool
m4
patch
pkgconf
texinfo
which
zstd
];
in
pkgs.mkShell {
buildInputs = with pkgs; base-devel ++ [git perl unzip ncurses5 theos go];
shellHook = ''
export THEOS=${theos}/share/theos
'';
};
});
};
}