ruby: new bundler infrastructure
This improves our Bundler integration (i.e. `bundlerEnv`).
Before describing the implementation differences, I'd like to point a
breaking change: buildRubyGem now expects `gemName` and `version` as
arguments, rather than a `name` attribute in the form of
"<gem-name>-<version>".
Now for the differences in implementation.
The previous implementation installed all gems at once in a single
derivation. This was made possible by using a set of monkey-patches to
prevent Bundler from downloading gems impurely, and to help Bundler
find and activate all required gems prior to installation. This had
several downsides:
* The patches were really hard to understand, and required subtle
interaction with the rest of the build environment.
* A single install failure would cause the entire derivation to fail.
The new implementation takes a different approach: we install gems into
separate derivations, and then present Bundler with a symlink forest
thereof. This has a couple benefits over the existing approach:
* Fewer patches are required, with less interplay with the rest of the
build environment.
* Changes to one gem no longer cause a rebuild of the entire dependency
graph.
* Builds take 20% less time (using gitlab as a reference).
It's unfortunate that we still have to muck with Bundler's internals,
though it's unavoidable with the way that Bundler is currently designed.
There are a number improvements that could be made in Bundler that would
simplify our packaging story:
* Bundler requires all installed gems reside within the same prefix
(GEM_HOME), unlike RubyGems which allows for multiple prefixes to
be specified through GEM_PATH. It would be ideal if Bundler allowed
for packages to be installed and sourced from multiple prefixes.
* Bundler installs git sources very differently from how RubyGems
installs gem packages, and, unlike RubyGems, it doesn't provide a
public interface (CLI or programmatic) to guide the installation of a
single gem. We are presented with the options of either
reimplementing a considerable portion Bundler, or patch and use parts
of its internals; I choose the latter. Ideally, there would be a way
to install gems from git sources in a manner similar to how we drive
`gem` to install gem packages.
* When a bundled program is executed (via `bundle exec` or a
binstub that does `require 'bundler/setup'`), the setup process reads
the Gemfile.lock, activates the dependencies, re-serializes the lock
file it read earlier, and then attempts to overwrite the Gemfile.lock
if the contents aren't bit-identical. I think the reasoning is that
by merely running an application with a newer version of Bundler, you'll
automatically keep the Gemfile.lock up-to-date with any changes in the
format. Unfortunately, that doesn't play well with any form of
packaging, because bundler will immediately cause the application to
abort when it attempts to write to the read-only Gemfile.lock in the
store. We work around this by normalizing the Gemfile.lock with the
version of Bundler that we'll use at runtime before we copy it into
the store. This feels fragile, but it's the best we can do without
changes upstream, or resorting to more delicate hacks.
With all of the challenges in using Bundler, one might wonder why we
can't just cut Bundler out of the picture and use RubyGems. After all,
Nix provides most of the isolation that Bundler is used for anyway.
The problem, however, is that almost every Rails application calls
`Bundler::require` at startup (by way of the default project templates).
Because bundler will then, by default, `require` each gem listed in the
Gemfile, Rails applications are almost always written such that none of
the source files explicitly require their dependencies. That leaves us
with two options: support and use Bundler, or maintain massive patches
for every Rails application that we package.
Closes #8612
2015-11-15 03:17:29 +01:00
|
|
|
{ stdenv, fetchgit, fetchurl, makeWrapper, bundlerEnv, bundler
|
|
|
|
, ruby, openssl, sqlite, dataDir ? "/var/lib/panamax-ui"}@args:
|
2014-12-08 10:02:57 +01:00
|
|
|
|
2015-01-07 02:40:55 +01:00
|
|
|
with stdenv.lib;
|
2014-12-08 10:02:57 +01:00
|
|
|
|
2015-03-18 14:12:13 +01:00
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
name = "panamax-ui-${version}";
|
|
|
|
version = "0.2.14";
|
|
|
|
|
2015-02-07 15:26:16 +01:00
|
|
|
env = bundlerEnv {
|
2015-03-18 14:12:13 +01:00
|
|
|
name = "panamax-ui-gems-${version}";
|
2015-02-07 15:26:16 +01:00
|
|
|
inherit ruby;
|
2017-01-18 00:23:36 +01:00
|
|
|
gemdir = ./.;
|
2015-02-07 15:26:16 +01:00
|
|
|
};
|
2015-03-18 14:12:13 +01:00
|
|
|
|
ruby: new bundler infrastructure
This improves our Bundler integration (i.e. `bundlerEnv`).
Before describing the implementation differences, I'd like to point a
breaking change: buildRubyGem now expects `gemName` and `version` as
arguments, rather than a `name` attribute in the form of
"<gem-name>-<version>".
Now for the differences in implementation.
The previous implementation installed all gems at once in a single
derivation. This was made possible by using a set of monkey-patches to
prevent Bundler from downloading gems impurely, and to help Bundler
find and activate all required gems prior to installation. This had
several downsides:
* The patches were really hard to understand, and required subtle
interaction with the rest of the build environment.
* A single install failure would cause the entire derivation to fail.
The new implementation takes a different approach: we install gems into
separate derivations, and then present Bundler with a symlink forest
thereof. This has a couple benefits over the existing approach:
* Fewer patches are required, with less interplay with the rest of the
build environment.
* Changes to one gem no longer cause a rebuild of the entire dependency
graph.
* Builds take 20% less time (using gitlab as a reference).
It's unfortunate that we still have to muck with Bundler's internals,
though it's unavoidable with the way that Bundler is currently designed.
There are a number improvements that could be made in Bundler that would
simplify our packaging story:
* Bundler requires all installed gems reside within the same prefix
(GEM_HOME), unlike RubyGems which allows for multiple prefixes to
be specified through GEM_PATH. It would be ideal if Bundler allowed
for packages to be installed and sourced from multiple prefixes.
* Bundler installs git sources very differently from how RubyGems
installs gem packages, and, unlike RubyGems, it doesn't provide a
public interface (CLI or programmatic) to guide the installation of a
single gem. We are presented with the options of either
reimplementing a considerable portion Bundler, or patch and use parts
of its internals; I choose the latter. Ideally, there would be a way
to install gems from git sources in a manner similar to how we drive
`gem` to install gem packages.
* When a bundled program is executed (via `bundle exec` or a
binstub that does `require 'bundler/setup'`), the setup process reads
the Gemfile.lock, activates the dependencies, re-serializes the lock
file it read earlier, and then attempts to overwrite the Gemfile.lock
if the contents aren't bit-identical. I think the reasoning is that
by merely running an application with a newer version of Bundler, you'll
automatically keep the Gemfile.lock up-to-date with any changes in the
format. Unfortunately, that doesn't play well with any form of
packaging, because bundler will immediately cause the application to
abort when it attempts to write to the read-only Gemfile.lock in the
store. We work around this by normalizing the Gemfile.lock with the
version of Bundler that we'll use at runtime before we copy it into
the store. This feels fragile, but it's the best we can do without
changes upstream, or resorting to more delicate hacks.
With all of the challenges in using Bundler, one might wonder why we
can't just cut Bundler out of the picture and use RubyGems. After all,
Nix provides most of the isolation that Bundler is used for anyway.
The problem, however, is that almost every Rails application calls
`Bundler::require` at startup (by way of the default project templates).
Because bundler will then, by default, `require` each gem listed in the
Gemfile, Rails applications are almost always written such that none of
the source files explicitly require their dependencies. That leaves us
with two options: support and use Bundler, or maintain massive patches
for every Rails application that we package.
Closes #8612
2015-11-15 03:17:29 +01:00
|
|
|
bundler = args.bundler.override { inherit ruby; };
|
2014-12-08 10:02:57 +01:00
|
|
|
|
2015-01-07 02:40:55 +01:00
|
|
|
src = fetchgit {
|
|
|
|
rev = "refs/tags/v${version}";
|
|
|
|
url = "git://github.com/CenturyLinkLabs/panamax-ui";
|
2016-06-02 13:26:44 +02:00
|
|
|
sha256 = "01k0h0rjqp5arvwxm2xpfxjsag5qw0qqlg7hx4v8f6jsyc4wmjfl";
|
2015-01-07 02:40:55 +01:00
|
|
|
};
|
2014-12-08 10:02:57 +01:00
|
|
|
|
2015-09-21 07:05:22 +02:00
|
|
|
buildInputs = [ makeWrapper env.ruby openssl sqlite bundler ];
|
2014-12-08 10:02:57 +01:00
|
|
|
|
2015-01-07 02:40:55 +01:00
|
|
|
setSourceRoot = ''
|
|
|
|
mkdir -p $out/share
|
2015-02-07 15:26:16 +01:00
|
|
|
cp -R panamax-ui $out/share/panamax-ui
|
2015-01-07 02:40:55 +01:00
|
|
|
export sourceRoot="$out/share/panamax-ui"
|
|
|
|
'';
|
2014-12-08 10:02:57 +01:00
|
|
|
|
2015-01-07 02:40:55 +01:00
|
|
|
postPatch = ''
|
|
|
|
find . -type f -iname "*.haml" -exec sed -e 's|CoreOS Journal|NixOS Journal|g' -i "{}" \;
|
|
|
|
find . -type f -iname "*.haml" -exec sed -e 's|CoreOS Local|NixOS Local|g' -i "{}" \;
|
|
|
|
find . -type f -iname "*.haml" -exec sed -e 's|CoreOS Host|NixOS Host|g' -i "{}" \;
|
|
|
|
sed -e 's|CoreOS Local|NixOS Local|g' -i "spec/features/manage_application_spec.rb"
|
2015-09-03 10:30:11 +02:00
|
|
|
# fix libv8 dependency
|
|
|
|
substituteInPlace Gemfile.lock --replace "3.16.14.7" "3.16.14.11"
|
2014-12-08 10:02:57 +01:00
|
|
|
'';
|
|
|
|
|
2015-01-07 02:40:55 +01:00
|
|
|
configurePhase = ''
|
|
|
|
export HOME=$PWD
|
2015-02-07 15:26:16 +01:00
|
|
|
export GEM_HOME=${env}/${env.ruby.gemPath}
|
2015-01-07 02:40:55 +01:00
|
|
|
'';
|
2014-12-08 10:02:57 +01:00
|
|
|
|
2015-01-07 02:40:55 +01:00
|
|
|
buildPhase = ''
|
|
|
|
rm -f ./bin/*
|
2015-02-07 15:26:16 +01:00
|
|
|
bundle exec rake rails:update:bin
|
2015-01-07 02:40:55 +01:00
|
|
|
'';
|
2014-12-08 10:02:57 +01:00
|
|
|
|
2015-01-07 02:40:55 +01:00
|
|
|
installPhase = ''
|
|
|
|
rm -rf log tmp db
|
|
|
|
ln -sf ${dataDir}/{db,state/log,state/tmp} .
|
|
|
|
|
|
|
|
mkdir -p $out/bin
|
|
|
|
makeWrapper bin/bundle "$out/bin/bundle" \
|
|
|
|
--run "cd $out/share/panamax-ui" \
|
2015-02-07 15:26:16 +01:00
|
|
|
--prefix "PATH" : "$out/share/panamax-ui/bin:${env.ruby}/bin:$PATH" \
|
2015-01-07 02:40:55 +01:00
|
|
|
--prefix "HOME" : "$out/share/panamax-ui" \
|
2015-02-07 15:26:16 +01:00
|
|
|
--prefix "GEM_HOME" : "${env}/${env.ruby.gemPath}" \
|
|
|
|
--prefix "GEM_PATH" : "$out/share/panamax-ui:${bundler}/${env.ruby.gemPath}"
|
2015-01-07 02:40:55 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
meta = with stdenv.lib; {
|
|
|
|
homepage = https://github.com/CenturyLinkLabs/panamax-ui;
|
|
|
|
description = "The Web GUI for Panamax";
|
|
|
|
license = licenses.asl20;
|
|
|
|
maintainers = with maintainers; [ matejc offline ];
|
|
|
|
platforms = platforms.linux;
|
|
|
|
};
|
|
|
|
}
|