-
Notifications
You must be signed in to change notification settings - Fork 21
suggest: large suggestion to flake.nix #2136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: lloeki/nix
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 { | ||
| 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); | ||
| } | ||
| ); | ||
| } | ||
| 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"] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because we never use the stable rustfmt anyway, also we need I feel like the only impact it could've had is CI failing because it could not find |
||
| profile = "minimal" | ||
There was a problem hiding this comment.
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
mkShellin the previous PR, but justmkDerivation. This is the way to go indeed 👍