Skip to content

Commit bc7be27

Browse files
committed
Migrate to Nix Flake
1 parent 9a012ec commit bc7be27

File tree

6 files changed

+160
-45
lines changed

6 files changed

+160
-45
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ ext/**/skipped_reason.txt
3838
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
3939
.rvmrc
4040
# Ignore local variables
41-
.envrc
41+
/.envrc
42+
/.direnv
4243

4344
# lock files
4445
Gemfile.lock

default.nix

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# flake-compat shim for usage without flakes
2+
(import
3+
(
4+
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
5+
fetchTarball {
6+
url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
7+
sha256 = lock.nodes.flake-compat.locked.narHash;
8+
}
9+
)
10+
{ src = ./.; }
11+
).defaultNix

flake.lock

+76
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
inputs = {
3+
nixpkgs.url = "github:nixos/nixpkgs/master";
4+
5+
# cross-platform convenience
6+
flake-utils.url = "github:numtide/flake-utils";
7+
8+
# backwards compatibility with nix-build and nix-shell
9+
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
10+
};
11+
12+
outputs = { self, nixpkgs, flake-utils, flake-compat }:
13+
# resolve for all platforms in turn
14+
flake-utils.lib.eachDefaultSystem (system:
15+
let
16+
# packages for this system platform
17+
pkgs = nixpkgs.legacyPackages.${system};
18+
19+
# control versions
20+
ruby = pkgs.ruby_3_3;
21+
llvm = pkgs.llvmPackages_16;
22+
gcc = pkgs.gcc13;
23+
in {
24+
devShell = pkgs.llvm.stdenv.mkDerivation {
25+
name = "devshell";
26+
27+
buildInputs = with pkgs; [
28+
ruby
29+
libyaml.dev
30+
31+
# TODO: some gems insist on using `gcc` on Linux, satisfy them for now:
32+
# - json
33+
# - protobuf
34+
# - ruby-prof
35+
gcc
36+
];
37+
38+
shellHook = ''
39+
# get major.minor.0 ruby version
40+
export RUBY_VERSION="$(ruby -e 'puts RUBY_VERSION.gsub(/\d+$/, "0")')"
41+
42+
# make gem install work in-project, compatibly with bundler
43+
export GEM_HOME="$(pwd)/vendor/bundle/ruby/$RUBY_VERSION"
44+
45+
# make bundle work in-project
46+
export BUNDLE_PATH="$(pwd)/vendor/bundle"
47+
48+
# enable calling gem scripts without bundle exec
49+
export PATH="$GEM_HOME/bin:$PATH"
50+
51+
# enable implicitly resolving gems to bundled version
52+
export RUBYGEMS_GEMDEPS="$(pwd)/Gemfile"
53+
'';
54+
};
55+
}
56+
);
57+
}

shell.nix

+11-44
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,11 @@
1-
{
2-
# use the environment channel
3-
pkgs ? import <nixpkgs> {},
4-
5-
# use a pinned package state
6-
pinned ? import(fetchTarball("https://github.com/NixOS/nixpkgs/archive/25865a40d14b.tar.gz")) {},
7-
}:
8-
let
9-
# specify ruby version to use
10-
ruby = pinned.ruby_3_3;
11-
12-
# control llvm/clang version (e.g for packages built from source)
13-
llvm = pinned.llvmPackages_16;
14-
15-
# control gcc version (e.g for packages built from source)
16-
gcc = pinned.gcc13;
17-
in llvm.stdenv.mkDerivation {
18-
# unique project name for this environment derivation
19-
name = "dd-trace-rb.devshell";
20-
21-
buildInputs = [
22-
ruby
23-
24-
# TODO: some gems insist on using `gcc` on Linux, satisfy them for now:
25-
# - json
26-
# - protobuf
27-
# - ruby-prof
28-
gcc
29-
];
30-
31-
shellHook = ''
32-
# get major.minor.0 ruby version
33-
export RUBY_VERSION="$(ruby -e 'puts RUBY_VERSION.gsub(/\d+$/, "0")')"
34-
35-
# make gem install work in-project, compatibly with bundler
36-
export GEM_HOME="$(pwd)/vendor/bundle/ruby/$RUBY_VERSION"
37-
38-
# make bundle work in-project
39-
export BUNDLE_PATH="$(pwd)/vendor/bundle"
40-
41-
# enable calling gem scripts without bundle exec
42-
export PATH="$GEM_HOME/bin:$PATH"
43-
'';
44-
}
1+
# flake-compat shim for usage without flakes
2+
(import
3+
(
4+
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
5+
fetchTarball {
6+
url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
7+
sha256 = lock.nodes.flake-compat.locked.narHash;
8+
}
9+
)
10+
{ src = ./.; }
11+
).shellNix

spec/datadog/release_gem_spec.rb

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
|datadog\.gemspec
3636
|docker-compose\.yml
3737
|shell\.nix
38+
|default\.nix
39+
|flake\.nix
40+
|flake\.lock
3841
|static-analysis\.datadog\.yml
3942
|\.standard\.yml
4043
|\.standard_todo\.yml

0 commit comments

Comments
 (0)