Updating submodules
[hiphop-php.git] / flake.nix
blob673bdb0b59d5dbc81546fcd9bb9095a770937b18
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           devShellForPackage = hhvm:
29             pkgs.mkShell.override
30               { stdenv = hhvm.stdenv; }
31               {
32                 inputsFrom = [
33                   hhvm
34                 ];
35                 packages = [
36                   pkgs.rnix-lsp
37                   pkgs.fpm
38                   pkgs.rpm
39                 ];
40                 inherit (hhvm)
41                   NIX_CFLAGS_COMPILE
42                   CMAKE_TOOLCHAIN_FILE;
43               };
44         in
45         rec {
46           packages.hhvm = pkgs.callPackage ./hhvm.nix {
47             lastModifiedDate = self.lastModifiedDate;
48           };
49           packages.hhvm_clang = packages.hhvm.override {
50             stdenv = pkgs.llvmPackages_14.stdenv;
51           };
52           packages.default = packages.hhvm;
54           devShells.clang = devShellForPackage packages.hhvm_clang;
55           devShells.default = devShellForPackage packages.hhvm;
57           ${if pkgs.hostPlatform.isLinux then "bundlers" else null} =
58             let
59               fpmScript =
60                 outputType: pkg:
61                 ''
62                   # Copy to a temporary directory as a workaround to https://github.com/jordansissel/fpm/issues/807
63                   while read LINE
64                   do
65                     mkdir -p "$(dirname "./$LINE")"
66                     cp -r "/$LINE" "./$LINE"
67                     chmod --recursive u+w "./$LINE"
68                     FPM_INPUTS+=("./$LINE")
69                   done < ${pkgs.lib.strings.escapeShellArg (pkgs.referencesByPopularity pkg)}
71                   ${pkgs.lib.strings.escapeShellArg pkgs.fpm}/bin/fpm \
72                     --verbose \
73                     --package "$out" \
74                     --input-type dir \
75                     --output-type ${outputType} \
76                     --name ${pkgs.lib.strings.escapeShellArg pkg.pname} \
77                     --version ${
78                       pkgs.lib.strings.escapeShellArg
79                         (builtins.replaceStrings ["-"] ["~"] pkg.version)
80                     } \
81                     --description ${pkgs.lib.strings.escapeShellArg pkg.meta.description} \
82                     --url ${pkgs.lib.strings.escapeShellArg pkg.meta.homepage} \
83                     --maintainer ${pkgs.lib.strings.escapeShellArg (pkgs.lib.strings.concatStringsSep ", " (map ({name, email, ...}: "\"${name}\" <${email}>") pkg.meta.maintainers))} \
84                     --license ${pkgs.lib.strings.escapeShellArg (pkgs.lib.strings.concatStringsSep " AND " (map ({spdxId, ...}: spdxId) (pkgs.lib.lists.toList pkg.meta.license)))} \
85                     --after-install ${
86                       pkgs.writeScript "after-install.sh" ''
87                         for EXECUTABLE in ${pkgs.lib.strings.escapeShellArg pkg}/bin/*
88                         do
89                           NAME=$(basename "$EXECUTABLE")
90                           update-alternatives --install "/usr/bin/$NAME" "$NAME" "$EXECUTABLE" 1
91                         done
92                       ''
93                     } \
94                     --before-remove ${
95                       pkgs.writeScript "before-remove.sh" ''
96                         for EXECUTABLE in ${pkgs.lib.strings.escapeShellArg pkg}/bin/*
97                         do
98                           NAME=$(basename "$EXECUTABLE")
99                           update-alternatives --remove "$NAME" "$EXECUTABLE"
100                         done
101                       ''
102                     } \
103                     -- \
104                     "''${FPM_INPUTS[@]}"
105                 '';
106             in
107             {
108               rpm = pkg: pkgs.runCommand
109                 "bundle.rpm"
110                 { nativeBuildInputs = [ pkgs.rpm ]; }
111                 (fpmScript "rpm" pkg);
112               deb = pkg: pkgs.runCommand
113                 "bundle.deb"
114                 { nativeBuildInputs = [ pkg.stdenv.cc ]; }
115                 (fpmScript "deb" pkg);
116             };
118         }
119       );