merge names::NamingTable -> names::Names
[hiphop-php.git] / flake.nix
blob6585a9da1e7d937d97237c3617bd5d4377498b4b
2   inputs = {
3     flake-utils.url = "github:numtide/flake-utils";
4     flake-compat.url = "github:edolstra/flake-compat";
5     flake-compat.flake = false;
6     nixpkgs-mozilla.url = "github:mozilla/nixpkgs-mozilla";
7   };
8   outputs =
9     { self, nixpkgs, flake-utils, flake-compat, nixpkgs-mozilla }:
10     flake-utils.lib.eachSystem [
11       "x86_64-darwin"
12       "x86_64-linux"
13     ]
14       (
15         system:
16         let
17           pkgs = import nixpkgs {
18             inherit system;
19             overlays = [
20               nixpkgs-mozilla.overlays.rust
21             ];
22             config.permittedInsecurePackages = [
23               # It's OK to depend on libdwarf 20210528, because we did not call
24               # the particular vulnerable function in libdwarf
25               "libdwarf-20210528"
26             ];
27           };
28         in
29         rec {
30           packages.hhvm = pkgs.callPackage ./hhvm.nix {
31             lastModifiedDate = self.lastModifiedDate;
32           };
33           packages.default = packages.hhvm;
35           checks.quick = pkgs.runCommand
36             "hhvm-quick-test"
37             {
38               buildInputs = pkgs.lib.optionals pkgs.hostPlatform.isMacOS [
39                 # `system_cmds` provides `sysctl`, which is used in hphp/test/run.php on macOS
40                 pkgs.darwin.system_cmds
41               ];
42             }
43             ''
44               set -ex
45               cd ${./.}
46               HHVM_BIN="${packages.hhvm}/bin/hhvm" "${packages.hhvm}/bin/hhvm" hphp/test/run.php quick
47               mkdir $out
48             '';
50           devShells.default =
51             pkgs.mkShell
52               {
53                 inputsFrom = [
54                   packages.hhvm
55                 ];
56                 packages = [
57                   pkgs.rnix-lsp
58                   pkgs.fpm
59                   pkgs.rpm
60                 ];
61                 inherit (packages.hhvm)
62                   NIX_CFLAGS_COMPILE
63                   CMAKE_INIT_CACHE;
64               };
66           ${if pkgs.hostPlatform.isLinux then "bundlers" else null} =
67             let
68               fpmScript =
69                 outputType: pkg:
70                 ''
71                   # Copy to a temporary directory as a workaround to https://github.com/jordansissel/fpm/issues/807
72                   while read LINE
73                   do
74                     mkdir -p "$(dirname "./$LINE")"
75                     cp -r "/$LINE" "./$LINE"
76                     chmod --recursive u+w "./$LINE"
77                     FPM_INPUTS+=("./$LINE")
78                   done < ${pkgs.lib.strings.escapeShellArg (pkgs.referencesByPopularity pkg)}
80                   # Dangling symlink
81                   rm ./nix/store/*-libgccjit-*/lib/lib
83                   ${pkgs.lib.strings.escapeShellArg pkgs.fpm}/bin/fpm \
84                     --verbose \
85                     --package "$out" \
86                     --input-type dir \
87                     --output-type ${outputType} \
88                     --name ${pkgs.lib.strings.escapeShellArg pkg.pname} \
89                     --version ${
90                       pkgs.lib.strings.escapeShellArg
91                         (builtins.replaceStrings ["-"] ["~"] pkg.version)
92                     } \
93                     --description ${pkgs.lib.strings.escapeShellArg pkg.meta.description} \
94                     --url ${pkgs.lib.strings.escapeShellArg pkg.meta.homepage} \
95                     --maintainer ${pkgs.lib.strings.escapeShellArg (pkgs.lib.strings.concatStringsSep ", " (map ({name, email, ...}: "\"${name}\" <${email}>") pkg.meta.maintainers))} \
96                     --license ${pkgs.lib.strings.escapeShellArg (pkgs.lib.strings.concatStringsSep " AND " (map ({spdxId, ...}: spdxId) (pkgs.lib.lists.toList pkg.meta.license)))} \
97                     --after-install ${
98                       pkgs.writeScript "after-install.sh" ''
99                         for EXECUTABLE in ${pkgs.lib.strings.escapeShellArg pkg}/bin/*
100                         do
101                           NAME=$(basename "$EXECUTABLE")
102                           update-alternatives --install "/usr/bin/$NAME" "$NAME" "$EXECUTABLE" 1
103                         done
104                       ''
105                     } \
106                     --before-remove ${
107                       pkgs.writeScript "before-remove.sh" ''
108                         for EXECUTABLE in ${pkgs.lib.strings.escapeShellArg pkg}/bin/*
109                         do
110                           NAME=$(basename "$EXECUTABLE")
111                           update-alternatives --remove "$NAME" "$EXECUTABLE"
112                         done
113                       ''
114                     } \
115                     -- \
116                     "''${FPM_INPUTS[@]}"
117                 '';
118             in
119             {
120               rpm = pkg: pkgs.runCommand
121                 "bundle.rpm"
122                 { nativeBuildInputs = [ pkgs.rpm ]; }
123                 (fpmScript "rpm" pkg);
124               deb = pkg: pkgs.runCommand
125                 "bundle.deb"
126                 { nativeBuildInputs = [ pkg.stdenv.cc ]; }
127                 (fpmScript "deb" pkg);
128             };
130         }
131       );