From dd86c6d25a0d06ea9234850fce7dafff34c987ec Mon Sep 17 00:00:00 2001 From: Judson Date: Sat, 10 Jun 2017 17:11:37 -0700 Subject: Adding Corundum as demo of rubyTool --- pkgs/development/tools/corundum/default.nix | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 pkgs/development/tools/corundum/default.nix (limited to 'pkgs/development/tools/corundum/default.nix') diff --git a/pkgs/development/tools/corundum/default.nix b/pkgs/development/tools/corundum/default.nix new file mode 100644 index 000000000000..36f5bb06c349 --- /dev/null +++ b/pkgs/development/tools/corundum/default.nix @@ -0,0 +1,13 @@ +{ rubyTool }: + +rubyTool { + name = "corundum-0.6.2"; + gemdir = ./.; + meta = { + description = "Tool and libraries for maintaining Ruby gems."; + homepage = http://sass-lang.com/; + license = licenses.mit; + maintainers = [ maintainers.nyarly ]; + platforms = platforms.unix; + }; +} -- cgit 1.4.1 From fc302bc07fd7a771751a6b94760730f1032e1f76 Mon Sep 17 00:00:00 2001 From: Judson Date: Sat, 10 Jun 2017 17:38:49 -0700 Subject: Not quite done - something fishy about the name attr --- pkgs/development/ruby-modules/tool/default.nix | 13 +++++++------ pkgs/development/tools/corundum/default.nix | 6 ++++-- 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'pkgs/development/tools/corundum/default.nix') diff --git a/pkgs/development/ruby-modules/tool/default.nix b/pkgs/development/ruby-modules/tool/default.nix index 5a11218fdeab..9b8848592b2c 100644 --- a/pkgs/development/ruby-modules/tool/default.nix +++ b/pkgs/development/ruby-modules/tool/default.nix @@ -1,4 +1,4 @@ -{ stdenv }@defs: +{ lib, stdenv, callPackage, runCommand, ruby }@defs: { name @@ -8,25 +8,26 @@ , exes ? [] # Scripts are ruby programs depend on gems in the Gemfile (e.g. scripts/rails) , scripts ? [] +, ruby ? defs.ruby , gemfile ? null , lockfile ? null , gemset ? null , preferLocalBuild ? false , allowSubstitutes ? false , meta ? {} -, postBuild +, postBuild ? "" }@args: let basicEnv = (callPackage ../bundled-common {}) args; - args = removeAttrs args_ [ "name" "postBuild" ] + cmdArgs = removeAttrs args [ "name" "postBuild" ] // { inherit preferLocalBuild allowSubstitutes; }; # pass the defaults in - runCommand name args '' - mkdir -p ${out}/bin; cd $out; + runCommand name cmdArgs '' + mkdir -p $out/bin; cd $out; ${(lib.concatMapStrings (x: "ln -s '${basicEnv}/bin/${x}' '${x}';\n") exes)} - ${(lib.concatMapStrings (s: "makeWrapper ${out}/bin/$(basename ${s}) $srcdir/${s} " + + ${(lib.concatMapStrings (s: "makeWrapper $out/bin/$(basename ${s}) $srcdir/${s} " + "--set BUNDLE_GEMFILE ${basicEnv.confFiles}/Gemfile "+ "--set BUNDLE_PATH ${basicEnv}/${ruby.gemPath} "+ "--set BUNDLE_FROZEN 1 "+ diff --git a/pkgs/development/tools/corundum/default.nix b/pkgs/development/tools/corundum/default.nix index 36f5bb06c349..53cb8e8f3b76 100644 --- a/pkgs/development/tools/corundum/default.nix +++ b/pkgs/development/tools/corundum/default.nix @@ -1,9 +1,11 @@ -{ rubyTool }: +{ lib, rubyTool }: rubyTool { name = "corundum-0.6.2"; gemdir = ./.; - meta = { + exes = [ "corundum-skel" ]; + + meta = with lib; { description = "Tool and libraries for maintaining Ruby gems."; homepage = http://sass-lang.com/; license = licenses.mit; -- cgit 1.4.1 From 70e7e543c5493761cf065dc96ec8c8cbafe40aba Mon Sep 17 00:00:00 2001 From: Judson Date: Tue, 27 Jun 2017 10:56:36 -0700 Subject: A few cleanups and renames. One feature remains... --- .../ruby-modules/bundled-common/default.nix | 2 - .../ruby-modules/bundler-app/default.nix | 47 ++++++++++++++++++++++ pkgs/development/ruby-modules/tool/default.nix | 47 ---------------------- pkgs/development/tools/corundum/default.nix | 4 +- pkgs/top-level/all-packages.nix | 2 +- 5 files changed, 50 insertions(+), 52 deletions(-) create mode 100644 pkgs/development/ruby-modules/bundler-app/default.nix delete mode 100644 pkgs/development/ruby-modules/tool/default.nix (limited to 'pkgs/development/tools/corundum/default.nix') diff --git a/pkgs/development/ruby-modules/bundled-common/default.nix b/pkgs/development/ruby-modules/bundled-common/default.nix index 354353ffab11..6e7bd7a898bd 100644 --- a/pkgs/development/ruby-modules/bundled-common/default.nix +++ b/pkgs/development/ruby-modules/bundled-common/default.nix @@ -82,8 +82,6 @@ let name = if name == null then pname else name; - #name = pname; - paths = envPaths; pathsToLink = [ "/lib" ]; diff --git a/pkgs/development/ruby-modules/bundler-app/default.nix b/pkgs/development/ruby-modules/bundler-app/default.nix new file mode 100644 index 000000000000..a5308b79ff3d --- /dev/null +++ b/pkgs/development/ruby-modules/bundler-app/default.nix @@ -0,0 +1,47 @@ +{ lib, stdenv, callPackage, runCommand, ruby }@defs: + +# Use for simple installation of Ruby tools shipped in a Gem. +# Start with a Gemfile that includes `gem ` +# > nix-shell -p bundler bundix +# (shell)> bundle lock +# (shell)> bundix +# Then use rubyTool in the default.nix: + +# rubyTool { name = "gemifiedTool"; gemdir = ./.; exes = ["gemified-tool"]; } +# The 'exes' parameter ensures that a copy of e.g. rake doesn't polute the system. +{ + name + # gemdir is the location of the Gemfile{,.lock} and gemset.nix; usually ./. +, gemdir + # Exes is the list of executables provided by the gems in the Gemfile +, exes ? [] + # Scripts are ruby programs depend on gems in the Gemfile (e.g. scripts/rails) +, scripts ? [] +, ruby ? defs.ruby +, gemfile ? null +, lockfile ? null +, gemset ? null +, preferLocalBuild ? false +, allowSubstitutes ? false +, meta ? {} +, postBuild ? "" +}@args: + +let + basicEnv = (callPackage ../bundled-common {}) args; + + cmdArgs = removeAttrs args [ "name" "postBuild" ] + // { inherit preferLocalBuild allowSubstitutes; }; # pass the defaults +in + runCommand name cmdArgs '' + mkdir -p $out/bin; + ${(lib.concatMapStrings (x: "ln -s '${basicEnv}/bin/${x}' $out/bin/${x};\n") exes)} + ${(lib.concatMapStrings (s: "makeWrapper $out/bin/$(basename ${s}) $srcdir/${s} " + + "--set BUNDLE_GEMFILE ${basicEnv.confFiles}/Gemfile "+ + "--set BUNDLE_PATH ${basicEnv}/${ruby.gemPath} "+ + "--set BUNDLE_FROZEN 1 "+ + "--set GEM_HOME ${basicEnv}/${ruby.gemPath} "+ + "--set GEM_PATH ${basicEnv}/${ruby.gemPath} "+ + "--run \"cd $srcdir\";\n") scripts)} + ${postBuild} + '' diff --git a/pkgs/development/ruby-modules/tool/default.nix b/pkgs/development/ruby-modules/tool/default.nix deleted file mode 100644 index a5308b79ff3d..000000000000 --- a/pkgs/development/ruby-modules/tool/default.nix +++ /dev/null @@ -1,47 +0,0 @@ -{ lib, stdenv, callPackage, runCommand, ruby }@defs: - -# Use for simple installation of Ruby tools shipped in a Gem. -# Start with a Gemfile that includes `gem ` -# > nix-shell -p bundler bundix -# (shell)> bundle lock -# (shell)> bundix -# Then use rubyTool in the default.nix: - -# rubyTool { name = "gemifiedTool"; gemdir = ./.; exes = ["gemified-tool"]; } -# The 'exes' parameter ensures that a copy of e.g. rake doesn't polute the system. -{ - name - # gemdir is the location of the Gemfile{,.lock} and gemset.nix; usually ./. -, gemdir - # Exes is the list of executables provided by the gems in the Gemfile -, exes ? [] - # Scripts are ruby programs depend on gems in the Gemfile (e.g. scripts/rails) -, scripts ? [] -, ruby ? defs.ruby -, gemfile ? null -, lockfile ? null -, gemset ? null -, preferLocalBuild ? false -, allowSubstitutes ? false -, meta ? {} -, postBuild ? "" -}@args: - -let - basicEnv = (callPackage ../bundled-common {}) args; - - cmdArgs = removeAttrs args [ "name" "postBuild" ] - // { inherit preferLocalBuild allowSubstitutes; }; # pass the defaults -in - runCommand name cmdArgs '' - mkdir -p $out/bin; - ${(lib.concatMapStrings (x: "ln -s '${basicEnv}/bin/${x}' $out/bin/${x};\n") exes)} - ${(lib.concatMapStrings (s: "makeWrapper $out/bin/$(basename ${s}) $srcdir/${s} " + - "--set BUNDLE_GEMFILE ${basicEnv.confFiles}/Gemfile "+ - "--set BUNDLE_PATH ${basicEnv}/${ruby.gemPath} "+ - "--set BUNDLE_FROZEN 1 "+ - "--set GEM_HOME ${basicEnv}/${ruby.gemPath} "+ - "--set GEM_PATH ${basicEnv}/${ruby.gemPath} "+ - "--run \"cd $srcdir\";\n") scripts)} - ${postBuild} - '' diff --git a/pkgs/development/tools/corundum/default.nix b/pkgs/development/tools/corundum/default.nix index 53cb8e8f3b76..b7c0006a7b51 100644 --- a/pkgs/development/tools/corundum/default.nix +++ b/pkgs/development/tools/corundum/default.nix @@ -1,7 +1,7 @@ { lib, rubyTool }: -rubyTool { - name = "corundum-0.6.2"; +bundlerApp { + pname = "corundum"; gemdir = ./.; exes = [ "corundum-skel" ]; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 0686adaea5f1..e6c1d9e23301 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -6161,7 +6161,7 @@ with pkgs; bundix = callPackage ../development/ruby-modules/bundix { }; bundler = callPackage ../development/ruby-modules/bundler { }; bundlerEnv = callPackage ../development/ruby-modules/bundler-env { }; - rubyTool = callPackage ../development/ruby-modules/tool { }; + bundlerApp = callPackage ../development/ruby-modules/bundler-app { }; inherit (callPackage ../development/interpreters/ruby {}) ruby_2_0_0 -- cgit 1.4.1 From e149f0234451e6ac714492076e5796546a2b035b Mon Sep 17 00:00:00 2001 From: Judson Date: Tue, 27 Jun 2017 22:33:18 -0700 Subject: Using pname and fetching versions --- .../ruby-modules/bundled-common/default.nix | 24 ++++++++++++++++++---- .../ruby-modules/bundler-app/default.nix | 9 ++++---- .../ruby-modules/bundler-env/default.nix | 7 +------ pkgs/development/tools/corundum/default.nix | 2 +- 4 files changed, 27 insertions(+), 15 deletions(-) (limited to 'pkgs/development/tools/corundum/default.nix') diff --git a/pkgs/development/ruby-modules/bundled-common/default.nix b/pkgs/development/ruby-modules/bundled-common/default.nix index 6e7bd7a898bd..09eb36a247a4 100644 --- a/pkgs/development/ruby-modules/bundled-common/default.nix +++ b/pkgs/development/ruby-modules/bundled-common/default.nix @@ -5,8 +5,8 @@ }@defs: { - name -, pname ? name + name ? null +, pname ? null , mainGemName ? null , gemdir ? null , gemfile ? null @@ -22,6 +22,8 @@ , ... }@args: +assert name == null -> pname != null; + with import ./functions.nix { inherit lib gemConfig; }; let @@ -43,6 +45,20 @@ let gems = lib.flip lib.mapAttrs configuredGemset (name: attrs: buildGem name attrs); + name' = if name != null then + name + else + let + gem = gems."${pname}"; + version = gem.version; + in + "${pname}-${version}"; + + pname' = if pname != null then + pname + else + name; + copyIfBundledByPath = { bundledByPath ? false, ...}@main: (if bundledByPath then assert gemFiles.gemdir != null; "cp -a ${gemFiles.gemdir}/* $out/" @@ -78,9 +94,9 @@ let envPaths = lib.attrValues gems ++ lib.optional (!hasBundler) bundler; basicEnv = buildEnv { - inherit ignoreCollisions; + inherit ignoreCollisions; - name = if name == null then pname else name; + name = name'; paths = envPaths; pathsToLink = [ "/lib" ]; diff --git a/pkgs/development/ruby-modules/bundler-app/default.nix b/pkgs/development/ruby-modules/bundler-app/default.nix index a5308b79ff3d..99d1dd64dc4f 100644 --- a/pkgs/development/ruby-modules/bundler-app/default.nix +++ b/pkgs/development/ruby-modules/bundler-app/default.nix @@ -7,10 +7,11 @@ # (shell)> bundix # Then use rubyTool in the default.nix: -# rubyTool { name = "gemifiedTool"; gemdir = ./.; exes = ["gemified-tool"]; } +# rubyTool { pname = "gemifiedTool"; gemdir = ./.; exes = ["gemified-tool"]; } # The 'exes' parameter ensures that a copy of e.g. rake doesn't polute the system. { - name + # use the name of the name in question; its version will be picked up from the gemset + pname # gemdir is the location of the Gemfile{,.lock} and gemset.nix; usually ./. , gemdir # Exes is the list of executables provided by the gems in the Gemfile @@ -30,10 +31,10 @@ let basicEnv = (callPackage ../bundled-common {}) args; - cmdArgs = removeAttrs args [ "name" "postBuild" ] + cmdArgs = removeAttrs args [ "pname" "postBuild" ] // { inherit preferLocalBuild allowSubstitutes; }; # pass the defaults in - runCommand name cmdArgs '' + runCommand basicEnv.name cmdArgs '' mkdir -p $out/bin; ${(lib.concatMapStrings (x: "ln -s '${basicEnv}/bin/${x}' $out/bin/${x};\n") exes)} ${(lib.concatMapStrings (s: "makeWrapper $out/bin/$(basename ${s}) $srcdir/${s} " + diff --git a/pkgs/development/ruby-modules/bundler-env/default.nix b/pkgs/development/ruby-modules/bundler-env/default.nix index 7d175cfeccb7..2e2653621a76 100644 --- a/pkgs/development/ruby-modules/bundler-env/default.nix +++ b/pkgs/development/ruby-modules/bundler-env/default.nix @@ -22,11 +22,6 @@ let inherit (import ../bundled-common/functions.nix {inherit lib ruby gemConfig groups; }) genStubsScript; - drvName = - if name != null then lib.traceVal name - else if pname != null then "${toString pname}-${basicEnv.gems."${pname}".version}" - else throw "bundlerEnv: either pname or name must be set"; - basicEnv = (callPackage ../bundled-common {}) (args // { inherit pname name; mainGemName = pname; }); inherit (basicEnv) envPaths; @@ -48,7 +43,7 @@ in (buildEnv { inherit ignoreCollisions; - name = drvName; + name = basicEnv.name; paths = envPaths; pathsToLink = [ "/lib" ]; diff --git a/pkgs/development/tools/corundum/default.nix b/pkgs/development/tools/corundum/default.nix index b7c0006a7b51..e149a25859ad 100644 --- a/pkgs/development/tools/corundum/default.nix +++ b/pkgs/development/tools/corundum/default.nix @@ -1,4 +1,4 @@ -{ lib, rubyTool }: +{ lib, bundlerApp }: bundlerApp { pname = "corundum"; -- cgit 1.4.1 From 728bb987ec4c3bcf7e43cb7b98db229ec52b93ed Mon Sep 17 00:00:00 2001 From: Judson Date: Sun, 2 Jul 2017 17:55:41 -0700 Subject: Adding docs for bundlerApp. --- doc/languages-frameworks/ruby.xml | 27 ++++++++++++++++++++++++--- pkgs/development/tools/corundum/default.nix | 2 +- 2 files changed, 25 insertions(+), 4 deletions(-) (limited to 'pkgs/development/tools/corundum/default.nix') diff --git a/doc/languages-frameworks/ruby.xml b/doc/languages-frameworks/ruby.xml index 3c6e4f5e01a4..6a14854b5c56 100644 --- a/doc/languages-frameworks/ruby.xml +++ b/doc/languages-frameworks/ruby.xml @@ -41,12 +41,34 @@ bundlerEnv rec { Please check in the Gemfile, Gemfile.lock and the gemset.nix so future updates can be run easily. -Resulting derivations also have two helpful items, env and wrapper. The first one allows one to quickly drop into +For tools written in Ruby - i.e. where the desire is to install a package and then execute e.g. rake at the command line, there is an alternative builder called bundlerApp. Set up the gemset.nix the same way, and then, for example: + + + + + +The chief advantage of bundlerApp over bundlerEnv is the the executables introduced in the environment are precisely those selected in the exes list, as opposed to bundlerEnv which adds all the executables made available by gems in the gemset, which can mean e.g. rspec or rake in unpredicable versions available from various packages. + +Resulting derivations for both builders also have two helpful items, env and wrapper. The first one allows one to quickly drop into nix-shell with the specified environment present. E.g. nix-shell -A sensu.env would give you an environment with Ruby preset so it has all the libraries necessary for sensu in its paths. The second one can be used to make derivations from custom Ruby scripts which have Gemfiles with their dependencies specified. It is a derivation with ruby wrapped so it can find all the needed dependencies. For example, to make a derivation my-script for a my-script.rb (which should be placed in bin) you should -run bundix as specified above and then use bundlerEnv lile this: +run bundix as specified above and then use bundlerEnv like this: - diff --git a/pkgs/development/tools/corundum/default.nix b/pkgs/development/tools/corundum/default.nix index e149a25859ad..22d7b236ffa4 100644 --- a/pkgs/development/tools/corundum/default.nix +++ b/pkgs/development/tools/corundum/default.nix @@ -7,7 +7,7 @@ bundlerApp { meta = with lib; { description = "Tool and libraries for maintaining Ruby gems."; - homepage = http://sass-lang.com/; + homepage = https://github.com/nyarly/corundum; license = licenses.mit; maintainers = [ maintainers.nyarly ]; platforms = platforms.unix; -- cgit 1.4.1