From 0f750d4c41bf553363590a3c074f784de4a66389 Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Mon, 3 Apr 2023 16:19:16 +0200 Subject: [PATCH] Add a basic `shell.nix` file This is entirely optional to use but for nixpkgs users this is a really easy way to get things up and running. With just: ``` nix-shell ``` All needed dependencies get automatically pulled in, dropping the user in a ready-to-use shell. Then as usual: ``` bundle install ``` Puts everything in a `vendor/bundle` directory, which behaves as usual regarding `gem install` and `bundle` in general. Should it need to be cleaned up, e.g to start form scratch, a simple `rm -rf vendor/bundle` is sufficient. Also, gem commands can typically be run with or without `bundle exec`. It also pins to a specific commit for the channel, so that tool versions are always consistent across platforms (incl. CPU arches and OSes). --- .gitignore | 1 - shell.nix | 44 ++++++++++++++++++++++++++++++++ spec/ddtrace/release_gem_spec.rb | 1 + 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 shell.nix diff --git a/.gitignore b/.gitignore index 2b197195ee5..155130d6ac1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ *.gem *.rbc *.swp -*.nix *.vim /.config /coverage/ diff --git a/shell.nix b/shell.nix new file mode 100644 index 00000000000..bd3f6566f9f --- /dev/null +++ b/shell.nix @@ -0,0 +1,44 @@ +{ + # use the environment channel + pkgs ? import {}, + + # use a pinned package state + pinned ? import(fetchTarball("https://github.com/NixOS/nixpkgs/archive/14d9b465c71.tar.gz")) {}, +}: +let + # specify ruby version to use + ruby = pinned.ruby_3_1; + + # control llvm/clang version (e.g for packages built from source) + llvm = pinned.llvmPackages_12; + + # control gcc version (e.g for packages built from source) + gcc = pinned.gcc12; +in llvm.stdenv.mkDerivation { + # unique project name for this environment derivation + name = "dd-trace-rb.devshell"; + + buildInputs = [ + ruby + + # TODO: some gems insist on using `gcc` on Linux, satisfy them for now: + # - json + # - protobuf + # - ruby-prof + gcc + ]; + + shellHook = '' + # get major.minor.0 ruby version + export RUBY_VERSION="$(ruby -e 'puts RUBY_VERSION.gsub(/\d+$/, "0")')" + + # make gem install work in-project, compatibly with bundler + export GEM_HOME="$(pwd)/vendor/bundle/ruby/$RUBY_VERSION" + + # make bundle work in-project + export BUNDLE_PATH="$(pwd)/vendor/bundle" + + # enable calling gem scripts without bundle exec + export PATH="$GEM_HOME/bin:$PATH" + ''; +} diff --git a/spec/ddtrace/release_gem_spec.rb b/spec/ddtrace/release_gem_spec.rb index 09577ee616d..8ad27b99e48 100644 --- a/spec/ddtrace/release_gem_spec.rb +++ b/spec/ddtrace/release_gem_spec.rb @@ -30,6 +30,7 @@ |Steepfile |ddtrace\.gemspec |docker-compose\.yml + |shell\.nix ) $ /x