summaryrefslogtreecommitdiffstats
path: root/flake.nix
blob: 7629d56f715e3f2b89759eb20a0eceffed6555a7 (about) (plain) (blame)
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
{
  inputs = {
    nixpkgs.url = "nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, flake-utils, ... }@inputs:
    flake-utils.lib.eachDefaultSystem
      (system:
        let
          pkgs = import nixpkgs { inherit system; };

          llvmVersion = 22;
          gccVersion = 16;
          boostVersion = 191;

          llvmPackages = pkgs."llvmPackages_${toString llvmVersion}";
          libstdcxxGcc = pkgs."gcc${toString gccVersion}".cc;  # the unwrapped version!
          stdenv = pkgs.stdenvAdapters.overrideCC llvmPackages.stdenv (llvmPackages.clang.override {
            gccForLibs = libstdcxxGcc;
          });
          boost = pkgs."boost${toString boostVersion}";

          routemon-server = stdenv.mkDerivation {
            name = "routemon-server";
            src = ./server;

            buildInputs = with pkgs; [ boost pugixml expat icu openssl sqlite ];
            nativeBuildInputs = with pkgs; [
              llvmPackages.clang-tools boost  # not from pkgs
              cmake ninja gettext
            ];

            hardeningDisable = [
              # Disable here because this breaks C++ modules (I suspect because it sets -D_FORTIFY_SOURCE=3)
              # We set plenty of hardening options in CMakeLists.txt anyway.
              "all"
            ];

            env.NIX_CFLAGS_COMPILE = toString [
              "-DLOCALEDIR=${builtins.placeholder "out"}/share/locale"
              "-Wno-reserved-module-identifier"
              "-isystem ${libstdcxxGcc}/include/c++/${libstdcxxGcc.version}/backward"
            ];

            cmakeFlags = [
              "--preset=nix-derivation"
              "-DCMAKE_CXX_STDLIB_MODULES_JSON=${libstdcxxGcc}/lib/libstdc++.modules.json"
            ];
          };

          routemon-web = pkgs.stdenvNoCC.mkDerivation {
            name = "routemon-web";

            src = ./web;

            installPhase = ''
              runHook preInstall

              mkdir -p $out/usr/lib/routemon-web/htdocs
              cp -rv index.html index.js style.css $out/usr/lib/routemon-web/htdocs

              runHook postInstall
            '';
          };
        in
        {
          packages.routemon-server = routemon-server;
          packages.routemon-web = routemon-web;

          devShells.default = pkgs.mkShell.override { inherit stdenv; } {
            buildInputs = [ pkgs.nix-index pkgs.nix-tree ];
            inputsFrom = [ routemon-server ];
          };

          formatter = pkgs.nixpkgs-fmt;
        });
}