No such file or directory .ruby-version
jcf opened this issue · comments
After building a Ruby environment using the following flake, things like rails server
fail unexpectedly.
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
devenv = {
url = "github:cachix/devenv/9ba9e3b908a12ddc6c43f88c52f2bf3c1d1e82c1";
inputs.nixpkgs.follows = "nixpkgs";
};
nixpkgs-ruby = {
url = "github:bobvanderlinden/nixpkgs-ruby";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = {
self,
flake-utils,
nixpkgs,
devenv,
nixpkgs-ruby,
} @ inputs:
flake-utils.lib.eachDefaultSystem (system: let
rb = nixpkgs-ruby.lib.packageFromRubyVersionFile {
file = ./.ruby-version;
inherit system;
};
overlays = [
(self: super: rec {
ruby = rb;
})
];
pkgs = import nixpkgs {inherit overlays system;};
gems = pkgs.bundlerEnv {
name = "app-gems";
gemdir = ./.;
groups = ["default" "development" "production" "test"];
};
updater = pkgs.writeScriptBin "update-gems" (builtins.readFile
(pkgs.substituteAll {
src = ./nix/update.tmpl.sh;
bundix = "${pkgs.bundix}/bin/bundix";
bundler = "${gems.bundler}/bin/bundler";
}));
in {
devShells.default = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
({pkgs, ...}: {
env.TAILWINDCSS_INSTALL_DIR = "./node_modules/.bin";
packages = with pkgs; [
bash
bundix
gems
(lowPrio gems.wrappedRuby)
git
jq
ldns
nodePackages.pnpm
nodejs-18_x
shellcheck
updater
];
process.implementation = "overmind";
processes.server.exec = "rails server";
processes.tailwind.exec = "rails tailwindcss:watch";
services.postgres = {
enable = true;
initialDatabases = [{name = "app_development";} {name = "app_test";}];
};
})
];
};
});
}
/nix/store/skb0a8xqfwi00cgrak0b24j8zqnqpj5a-bundler-2.5.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler.rb:505:in `initialize': (Bundler::Dsl::DSLError)
[!] There was an error parsing `Gemfile`: No such file or directory @ rb_sysopen - /nix/store/zng0ldq9255k5mgsp981mf400jix9ypv-gemfile-and-lockfile/.ruby-version. Bundler cannot continue.
# from /nix/store/zng0ldq9255k5mgsp981mf400jix9ypv-gemfile-and-lockfile/Gemfile:3
# -------------------------------------------
#
> ruby file: '.ruby-version'
#
# -------------------------------------------
from /nix/store/skb0a8xqfwi00cgrak0b24j8zqnqpj5a-bundler-2.5.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler.rb:505:in `open'
from /nix/store/skb0a8xqfwi00cgrak0b24j8zqnqpj5a-bundler-2.5.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler.rb:505:in `block in read_file'
from /nix/store/skb0a8xqfwi00cgrak0b24j8zqnqpj5a-bundler-2.5.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler/shared_helpers.rb:103:in `filesystem_access'
from /nix/store/skb0a8xqfwi00cgrak0b24j8zqnqpj5a-bundler-2.5.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler.rb:504:in `read_file'
from /nix/store/skb0a8xqfwi00cgrak0b24j8zqnqpj5a-bundler-2.5.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler/ruby_dsl.rb:44:in `normalize_ruby_file'
from /nix/store/skb0a8xqfwi00cgrak0b24j8zqnqpj5a-bundler-2.5.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler/ruby_dsl.rb:19:in `ruby'
from /nix/store/zng0ldq9255k5mgsp981mf400jix9ypv-gemfile-and-lockfile/Gemfile:3:in `eval_gemfile'
from /nix/store/skb0a8xqfwi00cgrak0b24j8zqnqpj5a-bundler-2.5.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler/dsl.rb:49:in `instance_eval'
from /nix/store/skb0a8xqfwi00cgrak0b24j8zqnqpj5a-bundler-2.5.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler/dsl.rb:49:in `eval_gemfile'
from /nix/store/skb0a8xqfwi00cgrak0b24j8zqnqpj5a-bundler-2.5.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler/dsl.rb:12:in `evaluate'
from /nix/store/skb0a8xqfwi00cgrak0b24j8zqnqpj5a-bundler-2.5.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler/definition.rb:38:in `build'
from /nix/store/skb0a8xqfwi00cgrak0b24j8zqnqpj5a-bundler-2.5.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler.rb:208:in `definition'
from /nix/store/skb0a8xqfwi00cgrak0b24j8zqnqpj5a-bundler-2.5.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler.rb:156:in `setup'
from /nix/store/a17cw78xqvql6b0sp9z7x4jwgk5ygrwa-devenv-profile/bin/rails:33:in `<main>'
/nix/store/skb0a8xqfwi00cgrak0b24j8zqnqpj5a-bundler-2.5.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler.rb:505:in `initialize': No such file or directory @ rb_sysopen - /nix/store/zng0ldq9255k5mgsp981mf400jix9ypv-gemfile-and-lockfile/.ruby-version (Errno::ENOENT)
from /nix/store/skb0a8xqfwi00cgrak0b24j8zqnqpj5a-bundler-2.5.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler.rb:505:in `open'
from /nix/store/skb0a8xqfwi00cgrak0b24j8zqnqpj5a-bundler-2.5.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler.rb:505:in `block in read_file'
from /nix/store/skb0a8xqfwi00cgrak0b24j8zqnqpj5a-bundler-2.5.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler/shared_helpers.rb:103:in `filesystem_access'
from /nix/store/skb0a8xqfwi00cgrak0b24j8zqnqpj5a-bundler-2.5.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler.rb:504:in `read_file'
from /nix/store/skb0a8xqfwi00cgrak0b24j8zqnqpj5a-bundler-2.5.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler/ruby_dsl.rb:44:in `normalize_ruby_file'
from /nix/store/skb0a8xqfwi00cgrak0b24j8zqnqpj5a-bundler-2.5.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler/ruby_dsl.rb:19:in `ruby'
from /nix/store/zng0ldq9255k5mgsp981mf400jix9ypv-gemfile-and-lockfile/Gemfile:3:in `eval_gemfile'
from /nix/store/skb0a8xqfwi00cgrak0b24j8zqnqpj5a-bundler-2.5.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler/dsl.rb:49:in `instance_eval'
from /nix/store/skb0a8xqfwi00cgrak0b24j8zqnqpj5a-bundler-2.5.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler/dsl.rb:49:in `eval_gemfile'
from /nix/store/skb0a8xqfwi00cgrak0b24j8zqnqpj5a-bundler-2.5.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler/dsl.rb:12:in `evaluate'
from /nix/store/skb0a8xqfwi00cgrak0b24j8zqnqpj5a-bundler-2.5.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler/definition.rb:38:in `build'
from /nix/store/skb0a8xqfwi00cgrak0b24j8zqnqpj5a-bundler-2.5.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler.rb:208:in `definition'
from /nix/store/skb0a8xqfwi00cgrak0b24j8zqnqpj5a-bundler-2.5.3/lib/ruby/gems/3.2.0/gems/bundler-2.5.3/lib/bundler.rb:156:in `setup'
from /nix/store/a17cw78xqvql6b0sp9z7x4jwgk5ygrwa-devenv-profile/bin/rails:33:in `<main>'
Metadata
$ nix flake metadata
Resolved URL: git+file:///Users/jcf/app
Locked URL: git+file:///Users/jcf/app
Description: app
Path: /nix/store/zyfr1jks5s09s0pick027msyzb8jb3kl-source
Revision: 0300ea5b19ed76f828b9c300fcc859bc40e0075a-dirty
Last modified: 2024-01-24 23:33:54
Inputs:
├───devenv: github:cachix/devenv/9ba9e3b908a12ddc6c43f88c52f2bf3c1d1e82c1
│ ├───flake-compat: github:edolstra/flake-compat/35bb57c0c8d8b62bbfd284272c928ceb64ddbde9
│ ├───nix: github:domenkozar/nix/7c91803598ffbcfe4a55c44ac6d49b2cf07a527f
│ │ ├───lowdown-src: github:kristapsdz/lowdown/d2c2b44ff6c27b936ec27358a2653caaef8f73b8
│ │ ├───nixpkgs follows input 'devenv/nixpkgs'
│ │ └───nixpkgs-regression: github:NixOS/nixpkgs/215d4d0fd80ca5163643b03a33fde804a29cc1e2
│ ├───nixpkgs follows input 'nixpkgs'
│ └───pre-commit-hooks: github:cachix/pre-commit-hooks.nix/5843cf069272d92b60c3ed9e55b7a8989c01d4c7
│ ├───flake-compat follows input 'devenv/flake-compat'
│ ├───flake-utils: github:numtide/flake-utils/a1720a10a6cfe8234c0e93907ffe81be440f4cef
│ │ └───systems: github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e
│ ├───gitignore: github:hercules-ci/gitignore.nix/a20de23b925fd8264fd7fad6454652e142fd7f73
│ │ └───nixpkgs follows input 'devenv/pre-commit-hooks/nixpkgs'
│ ├───nixpkgs follows input 'devenv/nixpkgs'
│ └───nixpkgs-stable: github:NixOS/nixpkgs/c37ca420157f4abc31e26f436c1145f8951ff373
├───flake-utils: github:numtide/flake-utils/1ef2e671c3b0c19053962c07dbda38332dcebf26
│ └───systems: github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e
├───nixpkgs: github:NixOS/nixpkgs/c7a0ce9ef46dd66de970876436ef6ebe4a8ca299
└───nixpkgs-ruby: github:bobvanderlinden/nixpkgs-ruby/a51f1dd843474eae34f764b1bb5c2e2621cf298f
├───flake-compat: github:edolstra/flake-compat/0f9255e01c2351cc7d116c072cb317785dd33b33
├───flake-utils: github:numtide/flake-utils/ff7b65b44d01cf9ba6a71320833626af21126384
│ └───systems: github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e
└───nixpkgs follows input 'nixpkgs'
direnv: loading ~/app/.envrc
direnv: using flake . --impure
The directory referred to contains a Gemfile
and a Gemfile.lock
. Interestingly, this worked before I updated flake inputs earlier today.
Rolling back fixes things. These versions work as expected with the aforementioned flake.nix
.
Path: /nix/store/bhz52jkwmax5m651kmswq18xcanmj2yc-source
Revision: 7900c65e6a4942a81d036705be2d31e0808efcda
Revisions: 242
Last modified: 2024-01-25 00:04:04
Inputs:
├───devenv: github:cachix/devenv/9ba9e3b908a12ddc6c43f88c52f2bf3c1d1e82c1
│ ├───flake-compat: github:edolstra/flake-compat/35bb57c0c8d8b62bbfd284272c928ceb64ddbde9
│ ├───nix: github:domenkozar/nix/7c91803598ffbcfe4a55c44ac6d49b2cf07a527f
│ │ ├───lowdown-src: github:kristapsdz/lowdown/d2c2b44ff6c27b936ec27358a2653caaef8f73b8
│ │ ├───nixpkgs follows input 'devenv/nixpkgs'
│ │ └───nixpkgs-regression: github:NixOS/nixpkgs/215d4d0fd80ca5163643b03a33fde804a29cc1e2
│ ├───nixpkgs: github:NixOS/nixpkgs/126f49a01de5b7e35a43fd43f891ecf6d3a51459
│ └───pre-commit-hooks: github:cachix/pre-commit-hooks.nix/5843cf069272d92b60c3ed9e55b7a8989c01d4c7
│ ├───flake-compat follows input 'devenv/flake-compat'
│ ├───flake-utils: github:numtide/flake-utils/a1720a10a6cfe8234c0e93907ffe81be440f4cef
│ │ └───systems: github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e
│ ├───gitignore: github:hercules-ci/gitignore.nix/a20de23b925fd8264fd7fad6454652e142fd7f73
│ │ └───nixpkgs follows input 'devenv/pre-commit-hooks/nixpkgs'
│ ├───nixpkgs follows input 'devenv/nixpkgs'
│ └───nixpkgs-stable: github:NixOS/nixpkgs/c37ca420157f4abc31e26f436c1145f8951ff373
├───flake-utils: github:numtide/flake-utils/ff7b65b44d01cf9ba6a71320833626af21126384
│ └───systems: github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e
├───nixpkgs: github:NixOS/nixpkgs/1774d07242995050d2d8a91cb4da0855eac2e472
└───nixpkgs-ruby: github:bobvanderlinden/nixpkgs-ruby/1b5bbe0a0c37b5ac1969bdb47e83d2f8aedb5984
├───flake-compat: github:edolstra/flake-compat/35bb57c0c8d8b62bbfd284272c928ceb64ddbde9
├───flake-utils: github:numtide/flake-utils/919d646de7be200f3bf08cb76ae1f09402b6f9b4
│ └───systems: github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e
└───nixpkgs: github:NixOS/nixpkgs/f64b9738da8e86195766147e9752c67fccee006c
Hmm, I'm trying to make bundix work, but it's failing to generate gemset.nix
.
Probably not what you're after, but I could get it to work with devenv.sh
without bundix:
$ devenv init
$ echo 3.3.0 > .ruby-version
devenv.nix
:
{ pkgs, ... }:
{
languages.ruby = {
enable = true;
versionFile = ./.ruby-version;
};
}
devenv.yaml
:
inputs:
nixpkgs:
url: github:NixOS/nixpkgs/nixpkgs-unstable
nixpkgs-ruby:
url: github:bobvanderlinden/nixpkgs-ruby
inputs:
nixpkgs:
follows: nixpkgs
$ bundle init
$ bundle add rails
$ rails new blog
$ cd blog
$ rails server
If bundix is the issue, could you create a gist with all files included, so that I can reproduce the issue?
Apologies for the slow response, Bob, and thank you for your help.
I've pushed a minimal reproduction: https://github.com/jcf/nixpkgs-ruby-111
Edit: Just to explain why I'm jumping through these hoops, the use of plain devenv will make installing Rubygems like pg
and nokogiri
tricky as they depend on C, etc. It's only with an explicit version of Ruby configured via the .ruby-version
file and Bundix that I've been able to reliably install a set of realistic Rails dependencies.
If you rely on a .ruby-version
file in your Gemfile, you have to inform bundlerEnv
via extraConfigPaths
like so:
gems = pkgs.bundlerEnv {
name = "nixpkgs-ruby-111-gems";
gemdir = ./.;
groups = ["default" "development" "production" "test"];
extraConfigPaths = [ "${./.}/.ruby-version" ];
};
With that extraConfigPaths
in place, the Gemfile
in one's Nix store has its .ruby-version
file alongside.
Ah that is new for me. Thanks for the feedback 👍
The documentation of nixpkgs does indeed mention this solution: https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/ruby.section.md#using-an-existing-gemfile-using-an-existing-gemfile
Still a bit surprising it is needed. Hopefully a future reader will be helped with this issue 👍
Still a bit surprising it is needed. Hopefully a future reader will be helped with this issue 👍
My thoughts exactly! Thanks for the assist, Bob.