Skip to content

Commit

Permalink
Add a basic shell.nix file
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
lloeki committed Apr 5, 2023
1 parent fd50833 commit 0f750d4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
*.gem
*.rbc
*.swp
*.nix
*.vim
/.config
/coverage/
Expand Down
44 changes: 44 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
# use the environment channel
pkgs ? import <nixpkgs> {},

# 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"
'';
}
1 change: 1 addition & 0 deletions spec/ddtrace/release_gem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
|Steepfile
|ddtrace\.gemspec
|docker-compose\.yml
|shell\.nix
)
$
/x
Expand Down

0 comments on commit 0f750d4

Please sign in to comment.