Skip to content

Commit

Permalink
[nix flake] make dev shell moldy (#6096)
Browse files Browse the repository at this point in the history
This commit switches the dev shell provided by the Nix flake to use
`mold` as the linker, rather than `ld`. This results in substantially
faster build times (at least on my build machine, where building Nexus
with `ld` results in memory bottlenecks and swaps to disk a bunch).

To use `mold` in the Nix dev shell, we override the Nix `stdenv` to use
Mold as the system linker, as well as overriding `clang` as the C
compiler (which we did previously).

Additionally, I've made a couple very minor style tweaks to the Nix
flake.

@sunshowers, I'd be interested to know whether the Nix dev shell is now
usable on your system, as I know we had problems previously due to your
system-wide non-Nix use of `mold`...
  • Loading branch information
hawkw authored Jul 16, 2024
1 parent 4cde53b commit ed4fe2f
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
};
};

outputs = { self, nixpkgs, rust-overlay, ... }:
outputs = { nixpkgs, rust-overlay, ... }:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
Expand Down Expand Up @@ -381,11 +381,16 @@
};
};

devShells.x86_64-linux.default =
pkgs.mkShell.override
devShells.x86_64-linux.default = with pkgs;
mkShell.override
{
# use Clang as the C compiler for all C libraries
stdenv = pkgs.clangStdenv;
stdenv =
# use Mold as the linker rather than ld, for faster builds. Mold
# to require substantially less memory to link Nexus and its
# avoiding swapping on memory-constrained dev systems.
stdenvAdapters.useMoldLinker
# use Clang as the C compiler for all C libraries.
clangStdenv;
}
{
inherit buildInputs;
Expand All @@ -398,10 +403,10 @@
];

name = "omicron";
DEP_PQ_LIBDIRS = "${pkgs.postgresql.lib}/lib";
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
OPENSSL_DIR = "${pkgs.openssl.dev}";
OPENSSL_LIB_DIR = "${pkgs.openssl.out}/lib";
DEP_PQ_LIBDIRS = "${postgresql.lib}/lib";
LIBCLANG_PATH = "${libclang.lib}/lib";
OPENSSL_DIR = "${openssl.dev}";
OPENSSL_LIB_DIR = "${openssl.out}/lib";

MG_OPENAPI_PATH = mgOpenAPI;
DDM_OPENAPI_PATH = ddmOpenAPI;
Expand Down

0 comments on commit ed4fe2f

Please sign in to comment.