Error running rails new with default Nix ruby, anyone has manager using ruby on rails on NixOS?

Hello,

I’ve tried so many things, I just can’t seem to be able to run rails new.

I’m getting this error:

Installing psych 5.1.1.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /home/asdf/.local/share/gem/ruby/3.1.0/gems/psych-5.1.1.1/ext/psych
/nix/store/2kw126cy93rix4pmh9lcl120njnb6r7r-ruby-3.1.4/bin/ruby extconf.rb
checking for yaml.h... no
yaml.h not found
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

I’m using the following systemPackages with 23.11:

ruby
gnumake
gcc
libyaml # I've tried with and without this one
package configuration for yaml-0.1 is not found
find_header: checking for yaml.h... -------------------- no

LD_LIBRARY_PATH=.:/nix/store/2kw126cy93rix4pmh9lcl120njnb6r7r-ruby-3.1.4/lib "gcc -o conftest -I/nix/store/2kw126cy93rix4pmh9lcl120njnb6r7r-ruby-3.1.4/include/ruby-3.1.0/x86_64-linux -I/nix/store/2kw126cy93rix4pmh9lcl120njnb6r7r-ruby-3.1.4/include/ruby-3.1.0/ruby/backward -I/nix/store/2kw126cy93rix4pmh9lcl120njnb6r7r-ruby-3.1.4/include/ruby-3.1.0 -I.    -O3 -fPIC conftest.c  -L. -L/nix/store/2kw126cy93rix4pmh9lcl120njnb6r7r-ruby-3.1.4/lib -Wl,-rpath,/nix/store/2kw126cy93rix4pmh9lcl120njnb6r7r-ruby-3.1.4/lib -L. -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,--no-as-needed     -Wl,-rpath,/nix/store/2kw126cy93rix4pmh9lcl120njnb6r7r-ruby-3.1.4/lib -L/nix/store/2kw126cy93rix4pmh9lcl120njnb6r7r-ruby-3.1.4/lib -lruby-3.1.4  -lm  -lc"
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return !!argv[argc];
6: }
/* end */

LD_LIBRARY_PATH=.:/nix/store/2kw126cy93rix4pmh9lcl120njnb6r7r-ruby-3.1.4/lib "gcc -I/nix/store/2kw126cy93rix4pmh9lcl120njnb6r7r-ruby-3.1.4/include/ruby-3.1.0/x86_64-linux -I/nix/store/2kw126cy93rix4pmh9lcl120njnb6r7r-ruby-3.1.4/include/ruby-3.1.0/ruby/backward -I/nix/store/2kw126cy93rix4pmh9lcl120njnb6r7r-ruby-3.1.4/include/ruby-3.1.0 -I.    -O3 -fPIC   -c conftest.c"
conftest.c:3:10: fatal error: yaml.h: No such file or directory
    3 | #include <yaml.h>
      |          ^~~~~~~~
compilation terminated.
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <yaml.h>
/* end */

--------------------

Thank you for any help!

The NixOS environment.systemPackages doesn’t install development headers. Use a nix-shell for this kind of thing:

# shell.nix
{ pkgs ? import <nixpkgs> }:
pkgs.mkShell {
  packages = with pkgs; [
    libyaml
  ];
}

Thank you so much!!! :slight_smile:

hmm, I created the shell.nix

but there’s an error

            1| { pkgs ? import <nixpkgs> }:
            2| pkgs.mkShell {
             | ^
            3|   packages = with pkgs; [

       error: value is a function while a set was expected

do you have any why? sorry for being a noob :confused:

I’m running

$ nix-shell

By the way I’m using flakes in my system, does it play a role here?

Thank you

Oh, whoops, sorry, I wrote that entirely off memory without testing, forgot to call the function:

# shell.nix
{ pkgs ? import <nixpkgs> { } }:
pkgs.mkShell {
  packages = with pkgs; [
    libyaml
  ];
}

nix-shell should still work fine even if your system config uses a flake. You can alternatively use a flake with a devShell.${system}.default and use the nix develop command, which will behave similarly, while having all the advantages of flakes.