Packaging/Ruby: Difference between revisions

imported>Makefu
Created page with "Ruby projects are generally packaged with [https://github.com/manveru/bundix bundix]. This guide will show how to package a ruby project == Building '''BeEF''' == <syntaxHigh..."
 
F0x (talk | contribs)
Add example for setting gemConfig for bundlerEnv, extending from defaultGemConfig.
 
(13 intermediate revisions by 10 users not shown)
Line 1: Line 1:
See [https://nixos.org/manual/nixpkgs/stable/#packaging-applications Packaging Ruby programs] in the nixpkgs manual
Ruby projects are generally packaged with [https://github.com/manveru/bundix bundix]. This guide will show how to package a ruby project
Ruby projects are generally packaged with [https://github.com/manveru/bundix bundix]. This guide will show how to package a ruby project
See


== Building '''BeEF''' ==
== Building '''BeEF''' ==
Line 20: Line 26:
     libxml2
     libxml2
     libxslt
     libxslt
     pkgconfig
     pkg-config
     bundix
     bundix
    gnumake
   ];
   ];
}
}
Line 29: Line 36:
<syntaxHighlight lang=console>
<syntaxHighlight lang=console>
$ nix-shell
$ nix-shell
# generate Gemfile.lock
$ bundle lock      # generates Gemfile.lock
$ bundle install
$ bundix              # generates gemset.nix
# generate gemset.nix
$ bundix
</syntaxHighlight>
</syntaxHighlight>


Line 57: Line 62:
     cat > $bin <<EOF
     cat > $bin <<EOF
#!/bin/sh -e
#!/bin/sh -e
exec ${gems}/bin/bundle exec ${ruby}/bin/ruby $i "\$@"
exec ${gems}/bin/bundle exec ${ruby}/bin/ruby $out/share/beef/beef "\$@"
EOF
EOF
     chmod +x $bin
     chmod +x $bin
Line 87: Line 92:
}
}
</syntaxHighlight>
</syntaxHighlight>
=== Override gemConfig locally ===
<syntaxhighlight lang="nix">
gems = bundlerEnv {
    name = "beef-env";
    inherit ruby;
    gemdir  = ./.;
    gemConfig = pkgs.defaultGemConfig // {
        do_sqlite3 = attrs: {
            buildInputs = [ sqlite ];
        };
    };
};
</syntaxhighlight>




After this change we build the package again.
After this change we build the package again.


=== set the local gemConfig ===
=== Defining groups ===
'''TODO''': also merge with the <code>defaultGemConfig</code> somehow
 
Sophisticated applications use groups to organize their gems like <code>development</code>, <code>test</code> and
<code>production</code>.
<code>bundlerEnv</code> only makes the <code>default</code> group available in the environment, that is all gems which are '''not''' in a group.
To make other groups available, they need to be provided as an array. Don't forget to include the <code>default</code> group.
 
Example:
 
<syntaxHighlight lang=nix>
  gems = pkgs.bundlerEnv {
    name = "exampleApp";
    inherit ruby;
    gemfile = ./Gemfile;
    lockfile = ./Gemfile.lock;
    gemset = ./gemset.nix;
    groups = [ "default" "production" "development" "test" ];
  };
</syntaxHighlight>
 
== Using Bundler 2 ==
 
Bundler 2 comes included with Ruby, so instead of importing <code>ruby.devEnv</code> import Ruby and Bundix separately.
 
 
[[Category:Development]]
[[Category:Ruby]]