Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 46 additions & 36 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,62 +1,72 @@
# Copyright 2026-Present Datadog, Inc. https://www.datadoghq.com/
# SPDX-License-Identifier: Apache-2.0

{
description = "A dev environment with the tools needed to work on libdatadog.";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/release-25.11";

# cross-platform convenience
flake-utils.url = "github:numtide/flake-utils";

# backwards compatibility with nix-build and nix-shell
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";

# pinned, exact upstream Rust toolchains
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};

# backwards compatibility with nix-build and nix-shell
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
};

outputs = { self, nixpkgs, flake-utils, flake-compat, rust-overlay }:
# resolve for all platforms in turn
flake-utils.lib.eachDefaultSystem (system:
let
# packages for this system platform, with the rust-overlay applied
outputs = {
nixpkgs,
flake-utils,
rust-overlay,
...
}:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
overlays = [(import rust-overlay)];
};
mkShell = rust-toolchain:
pkgs.mkShell {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally missed we didn't use mkShell in the previous PR, but just mkDerivation. This is the way to go indeed 👍

name = "libdatadog-devshell";
# The stdenv cc-wrapper injects -D_FORTIFY_SOURCE, which glibc rejects
# when compiling without optimization. Some build scripts (e.g.
# spawn_worker's trampoline.c) compile C at -O0 with -Werror, so the
# resulting fortify #warning becomes a hard error. Disable fortify
# hardening in the shell so those builds succeed.
hardeningDisable = [
"fortify"
"fortify3"
];

# A devshell for a given Rust toolchain (read from a toolchain file via
# rust-overlay), with the rest of the build dependencies.
mkDevShell = rust: pkgs.stdenv.mkDerivation {
name = "libdatadog-devshell";

# The stdenv cc-wrapper injects -D_FORTIFY_SOURCE, which glibc rejects
# when compiling without optimization. Some build scripts (e.g.
# spawn_worker's trampoline.c) compile C at -O0 with -Werror, so the
# resulting fortify #warning becomes a hard error. Disable fortify
# hardening in the shell so those builds succeed.
hardeningDisable = [ "fortify" "fortify3" ];

nativeBuildInputs = [
rust # rustc + cargo + rustfmt + clippy, pinned via toolchain file
pkgs.rust-cbindgen
pkgs.cmake
pkgs.autoconf
pkgs.automake
pkgs.libtool
];
};
packages =
[rust-toolchain]
++ (with pkgs; [
rust-cbindgen
cargo-nextest
cmake
autoconf
automake
libtool
alejandra
]);
env = {
# Required by rust-analyzer
RUST_SRC_PATH = "${rust-toolchain}/lib/rustlib/src/rust/library";
};
};
in {
# Default: the pinned stable toolchain (single source of truth is
# ./rust-toolchain.toml), matching CI and rustup.
devShells.default = mkDevShell (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml);
# Use with `nix develop`
devShells.default = mkShell (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml);

# Nightly toolchain (./nightly-toolchain.toml) for the jobs that
# genuinely need a nightly compiler. Use with `nix develop .#nightly`.
devShells.nightly = mkDevShell (pkgs.rust-bin.fromRustupToolchainFile ./nightly-toolchain.toml);
# genuinely need a nightly compiler.
# Use with `nix develop .#nightly`.
devShells.nightly = mkShell (pkgs.rust-bin.fromRustupToolchainFile ./nightly-toolchain.toml);
}
);
}
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "1.87.0"
components = ["rustfmt", "clippy"]
components = ["clippy", "rust-src"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? Doesn't this impact non Nix-users in some way?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we never use the stable rustfmt anyway, also we need rust-src for rust-analyzer to allow go-to-definition to std functions.

I feel like the only impact it could've had is CI failing because it could not find rustfmt but as said above we don't use the stable rustfmt

profile = "minimal"
Loading