lol
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #25980 from nyarly/bundlerenv_usecases

BundlerEnv, now with groups and paths

authored by

Charles Strahan and committed by
GitHub
2b57cb91 e8d8633f

+830 -126
+23 -2
doc/languages-frameworks/ruby.xml
··· 41 41 <para>Please check in the <filename>Gemfile</filename>, <filename>Gemfile.lock</filename> and the <filename>gemset.nix</filename> so future updates can be run easily. 42 42 </para> 43 43 44 - <para>Resulting derivations also have two helpful items, <literal>env</literal> and <literal>wrapper</literal>. The first one allows one to quickly drop into 44 + <para>For tools written in Ruby - i.e. where the desire is to install a package and then execute e.g. <command>rake</command> at the command line, there is an alternative builder called <literal>bundlerApp</literal>. Set up the <filename>gemset.nix</filename> the same way, and then, for example: 45 + </para> 46 + 47 + <screen> 48 + <![CDATA[{ lib, bundlerApp }: 49 + 50 + bundlerApp { 51 + pname = "corundum"; 52 + gemdir = ./.; 53 + exes = [ "corundum-skel" ]; 54 + 55 + meta = with lib; { 56 + description = "Tool and libraries for maintaining Ruby gems."; 57 + homepage = https://github.com/nyarly/corundum; 58 + license = licenses.mit; 59 + maintainers = [ maintainers.nyarly ]; 60 + platforms = platforms.unix; 61 + }; 62 + }]]> 63 + 64 + <para>The chief advantage of <literal>bundlerApp</literal> over <literal>bundlerEnv</literal> is the executables introduced in the environment are precisely those selected in the <literal>exes</literal> list, as opposed to <literal>bundlerEnv</literal> which adds all the executables made available by gems in the gemset, which can mean e.g. <command>rspec</command> or <command>rake</command> in unpredictable versions available from various packages. 65 + 66 + <para>Resulting derivations for both builders also have two helpful attributes, <literal>env</literal> and <literal>wrapper</literal>. The first one allows one to quickly drop into 45 67 <command>nix-shell</command> with the specified environment present. E.g. <command>nix-shell -A sensu.env</command> would give you an environment with Ruby preset 46 68 so it has all the libraries necessary for <literal>sensu</literal> in its paths. The second one can be used to make derivations from custom Ruby scripts which have 47 69 <filename>Gemfile</filename>s with their dependencies specified. It is a derivation with <command>ruby</command> wrapped so it can find all the needed dependencies. ··· 74 96 </programlisting> 75 97 76 98 </section> 77 -
+1
lib/maintainers.nix
··· 407 407 np = "Nicolas Pouillard <np.nix@nicolaspouillard.fr>"; 408 408 nslqqq = "Nikita Mikhailov <nslqqq@gmail.com>"; 409 409 nthorne = "Niklas Thörne <notrupertthorne@gmail.com>"; 410 + nyarly = "Judson Lester <nyarly@gmail.com>"; 410 411 obadz = "obadz <obadz-nixos@obadz.com>"; 411 412 ocharles = "Oliver Charles <ollie@ocharles.org.uk>"; 412 413 odi = "Oliver Dunkl <oliver.dunkl@gmail.com>";
+156
pkgs/development/ruby-modules/bundled-common/default.nix
··· 1 + { stdenv, runCommand, ruby, lib 2 + , defaultGemConfig, buildRubyGem, buildEnv 3 + , makeWrapper 4 + , bundler 5 + }@defs: 6 + 7 + { 8 + name ? null 9 + , pname ? null 10 + , mainGemName ? null 11 + , gemdir ? null 12 + , gemfile ? null 13 + , lockfile ? null 14 + , gemset ? null 15 + , ruby ? defs.ruby 16 + , gemConfig ? defaultGemConfig 17 + , postBuild ? null 18 + , document ? [] 19 + , meta ? {} 20 + , groups ? ["default"] 21 + , ignoreCollisions ? false 22 + , ... 23 + }@args: 24 + 25 + assert name == null -> pname != null; 26 + 27 + with import ./functions.nix { inherit lib gemConfig; }; 28 + 29 + let 30 + gemFiles = bundlerFiles args; 31 + 32 + importedGemset = import gemFiles.gemset; 33 + 34 + filteredGemset = filterGemset { inherit ruby groups; } importedGemset; 35 + 36 + configuredGemset = lib.flip lib.mapAttrs filteredGemset (name: attrs: 37 + applyGemConfigs (attrs // { inherit ruby; gemName = name; }) 38 + ); 39 + 40 + hasBundler = builtins.hasAttr "bundler" filteredGemset; 41 + 42 + bundler = 43 + if hasBundler then gems.bundler 44 + else defs.bundler.override (attrs: { inherit ruby; }); 45 + 46 + gems = lib.flip lib.mapAttrs configuredGemset (name: attrs: buildGem name attrs); 47 + 48 + name' = if name != null then 49 + name 50 + else 51 + let 52 + gem = gems."${pname}"; 53 + version = gem.version; 54 + in 55 + "${pname}-${version}"; 56 + 57 + pname' = if pname != null then 58 + pname 59 + else 60 + name; 61 + 62 + copyIfBundledByPath = { bundledByPath ? false, ...}@main: 63 + (if bundledByPath then 64 + assert gemFiles.gemdir != null; "cp -a ${gemFiles.gemdir}/* $out/" 65 + else "" 66 + ); 67 + 68 + maybeCopyAll = pkgname: if pkgname == null then "" else 69 + let 70 + mainGem = gems."${pkgname}" or (throw "bundlerEnv: gem ${pkgname} not found"); 71 + in 72 + copyIfBundledByPath mainGem; 73 + 74 + # We have to normalize the Gemfile.lock, otherwise bundler tries to be 75 + # helpful by doing so at run time, causing executables to immediately bail 76 + # out. Yes, I'm serious. 77 + confFiles = runCommand "gemfile-and-lockfile" {} '' 78 + mkdir -p $out 79 + ${maybeCopyAll mainGemName} 80 + cp ${gemFiles.gemfile} $out/Gemfile || ls -l $out/Gemfile 81 + cp ${gemFiles.lockfile} $out/Gemfile.lock || ls -l $out/Gemfile.lock 82 + ''; 83 + 84 + buildGem = name: attrs: ( 85 + let 86 + gemAttrs = composeGemAttrs ruby gems name attrs; 87 + in 88 + if gemAttrs.type == "path" then 89 + pathDerivation gemAttrs 90 + else 91 + buildRubyGem gemAttrs 92 + ); 93 + 94 + envPaths = lib.attrValues gems ++ lib.optional (!hasBundler) bundler; 95 + 96 + basicEnv = buildEnv { 97 + inherit ignoreCollisions; 98 + 99 + name = name'; 100 + 101 + paths = envPaths; 102 + pathsToLink = [ "/lib" ]; 103 + 104 + postBuild = genStubsScript (defs // args // { 105 + inherit confFiles bundler groups; 106 + binPaths = envPaths; 107 + }) + lib.optionalString (postBuild != null) postBuild; 108 + 109 + meta = { platforms = ruby.meta.platforms; } // meta; 110 + 111 + passthru = rec { 112 + inherit ruby bundler gems mainGem confFiles envPaths; 113 + 114 + wrappedRuby = 115 + stdenv.mkDerivation { 116 + name = "wrapped-ruby-${pname}"; 117 + nativeBuildInputs = [ makeWrapper ]; 118 + buildCommand = '' 119 + mkdir -p $out/bin 120 + for i in ${ruby}/bin/*; do 121 + makeWrapper "$i" $out/bin/$(basename "$i") \ 122 + --set BUNDLE_GEMFILE ${confFiles}/Gemfile \ 123 + --set BUNDLE_PATH ${basicEnv}/${ruby.gemPath} \ 124 + --set BUNDLE_FROZEN 1 \ 125 + --set GEM_HOME ${basicEnv}/${ruby.gemPath} \ 126 + --set GEM_PATH ${basicEnv}/${ruby.gemPath} 127 + done 128 + ''; 129 + }; 130 + 131 + env = let 132 + irbrc = builtins.toFile "irbrc" '' 133 + if !(ENV["OLD_IRBRC"].nil? || ENV["OLD_IRBRC"].empty?) 134 + require ENV["OLD_IRBRC"] 135 + end 136 + require 'rubygems' 137 + require 'bundler/setup' 138 + ''; 139 + in stdenv.mkDerivation { 140 + name = "${pname}-interactive-environment"; 141 + nativeBuildInputs = [ wrappedRuby basicEnv ]; 142 + shellHook = '' 143 + export OLD_IRBRC=$IRBRC 144 + export IRBRC=${irbrc} 145 + ''; 146 + buildCommand = '' 147 + echo >&2 "" 148 + echo >&2 "*** Ruby 'env' attributes are intended for interactive nix-shell sessions, not for building! ***" 149 + echo >&2 "" 150 + exit 1 151 + ''; 152 + }; 153 + }; 154 + }; 155 + in 156 + basicEnv
+75
pkgs/development/ruby-modules/bundled-common/functions.nix
··· 1 + { lib, gemConfig, ... }: 2 + rec { 3 + bundlerFiles = { 4 + gemfile ? null 5 + , lockfile ? null 6 + , gemset ? null 7 + , gemdir ? null 8 + , ... 9 + }: { 10 + inherit gemdir; 11 + 12 + gemfile = 13 + if gemfile == null then assert gemdir != null; gemdir + "/Gemfile" 14 + else gemfile; 15 + 16 + lockfile = 17 + if lockfile == null then assert gemdir != null; gemdir + "/Gemfile.lock" 18 + else lockfile; 19 + 20 + gemset = 21 + if gemset == null then assert gemdir != null; gemdir + "/gemset.nix" 22 + else gemset; 23 + }; 24 + 25 + filterGemset = {ruby, groups,...}@env: gemset: lib.filterAttrs (name: attrs: platformMatches ruby attrs && groupMatches groups attrs) gemset; 26 + 27 + platformMatches = {rubyEngine, version, ...}@ruby: attrs: ( 28 + !(attrs ? "platforms") || 29 + builtins.length attrs.platforms == 0 || 30 + builtins.any (platform: 31 + platform.engine == rubyEngine && 32 + (!(platform ? "version") || platform.version == version.majMin) 33 + ) attrs.platforms 34 + ); 35 + 36 + groupMatches = groups: attrs: ( 37 + !(attrs ? "groups") || 38 + builtins.any (gemGroup: builtins.any (group: group == gemGroup) groups) attrs.groups 39 + ); 40 + 41 + applyGemConfigs = attrs: 42 + (if gemConfig ? "${attrs.gemName}" 43 + then attrs // gemConfig."${attrs.gemName}" attrs 44 + else attrs); 45 + 46 + genStubsScript = { lib, ruby, confFiles, bundler, groups, binPaths, ... }: '' 47 + ${ruby}/bin/ruby ${./gen-bin-stubs.rb} \ 48 + "${ruby}/bin/ruby" \ 49 + "${confFiles}/Gemfile" \ 50 + "$out/${ruby.gemPath}" \ 51 + "${bundler}/${ruby.gemPath}" \ 52 + ${lib.escapeShellArg binPaths} \ 53 + ${lib.escapeShellArg groups} 54 + ''; 55 + 56 + pathDerivation = { gemName, version, path, ... }: 57 + let 58 + res = { 59 + type = "derivation"; 60 + bundledByPath = true; 61 + name = gemName; 62 + version = version; 63 + outPath = path; 64 + outputs = [ "out" ]; 65 + out = res; 66 + outputName = "out"; 67 + }; 68 + in res; 69 + 70 + composeGemAttrs = ruby: gems: name: attrs: ((removeAttrs attrs ["source" "platforms"]) // attrs.source // { 71 + inherit ruby; 72 + gemName = name; 73 + gemPath = map (gemName: gems."${gemName}") (attrs.dependencies or []); 74 + }); 75 + }
+50
pkgs/development/ruby-modules/bundled-common/test.nix
··· 1 + { stdenv, writeText, lib, ruby, defaultGemConfig, callPackage, test, stubs, should }@defs: 2 + let 3 + testConfigs = { 4 + inherit lib; 5 + gemConfig = defaultGemConfig; 6 + }; 7 + functions = (import ./functions.nix testConfigs); 8 + in 9 + builtins.concatLists [ 10 + ( test.run "All set, no gemdir" (functions.bundlerFiles { 11 + gemfile = test/Gemfile; 12 + lockfile = test/Gemfile.lock; 13 + gemset = test/gemset.nix; 14 + }) { 15 + gemfile = should.equal test/Gemfile; 16 + lockfile = should.equal test/Gemfile.lock; 17 + gemset = should.equal test/gemset.nix; 18 + }) 19 + 20 + ( test.run "Just gemdir" (functions.bundlerFiles { 21 + gemdir = test/.; 22 + }) { 23 + gemfile = should.equal test/Gemfile; 24 + lockfile = should.equal test/Gemfile.lock; 25 + gemset = should.equal test/gemset.nix; 26 + }) 27 + 28 + ( test.run "Gemset and dir" (functions.bundlerFiles { 29 + gemdir = test/.; 30 + gemset = test/extraGemset.nix; 31 + }) { 32 + gemfile = should.equal test/Gemfile; 33 + lockfile = should.equal test/Gemfile.lock; 34 + gemset = should.equal test/extraGemset.nix; 35 + }) 36 + 37 + ( test.run "Filter empty gemset" {} (set: functions.filterGemset {inherit ruby; groups = ["default"]; } set == {})) 38 + ( let gemSet = { test = { groups = ["x" "y"]; }; }; 39 + in 40 + test.run "Filter matches a group" gemSet (set: functions.filterGemset {inherit ruby; groups = ["y" "z"];} set == gemSet)) 41 + ( let gemSet = { test = { platforms = []; }; }; 42 + in 43 + test.run "Filter matches empty platforms list" gemSet (set: functions.filterGemset {inherit ruby; groups = [];} set == gemSet)) 44 + ( let gemSet = { test = { platforms = [{engine = ruby.rubyEngine; version = ruby.version.majMin;}]; }; }; 45 + in 46 + test.run "Filter matches on platform" gemSet (set: functions.filterGemset {inherit ruby; groups = [];} set == gemSet)) 47 + ( let gemSet = { test = { groups = ["x" "y"]; }; }; 48 + in 49 + test.run "Filter excludes based on groups" gemSet (set: functions.filterGemset {inherit ruby; groups = ["a" "b"];} set == {})) 50 + ]
+48
pkgs/development/ruby-modules/bundler-app/default.nix
··· 1 + { lib, stdenv, callPackage, runCommand, ruby }@defs: 2 + 3 + # Use for simple installation of Ruby tools shipped in a Gem. 4 + # Start with a Gemfile that includes `gem <toolgem>` 5 + # > nix-shell -p bundler bundix 6 + # (shell)> bundle lock 7 + # (shell)> bundix 8 + # Then use rubyTool in the default.nix: 9 + 10 + # rubyTool { pname = "gemifiedTool"; gemdir = ./.; exes = ["gemified-tool"]; } 11 + # The 'exes' parameter ensures that a copy of e.g. rake doesn't polute the system. 12 + { 13 + # use the name of the name in question; its version will be picked up from the gemset 14 + pname 15 + # gemdir is the location of the Gemfile{,.lock} and gemset.nix; usually ./. 16 + , gemdir 17 + # Exes is the list of executables provided by the gems in the Gemfile 18 + , exes ? [] 19 + # Scripts are ruby programs depend on gems in the Gemfile (e.g. scripts/rails) 20 + , scripts ? [] 21 + , ruby ? defs.ruby 22 + , gemfile ? null 23 + , lockfile ? null 24 + , gemset ? null 25 + , preferLocalBuild ? false 26 + , allowSubstitutes ? false 27 + , meta ? {} 28 + , postBuild ? "" 29 + }@args: 30 + 31 + let 32 + basicEnv = (callPackage ../bundled-common {}) args; 33 + 34 + cmdArgs = removeAttrs args [ "pname" "postBuild" ] 35 + // { inherit preferLocalBuild allowSubstitutes; }; # pass the defaults 36 + in 37 + runCommand basicEnv.name cmdArgs '' 38 + mkdir -p $out/bin; 39 + ${(lib.concatMapStrings (x: "ln -s '${basicEnv}/bin/${x}' $out/bin/${x};\n") exes)} 40 + ${(lib.concatMapStrings (s: "makeWrapper $out/bin/$(basename ${s}) $srcdir/${s} " + 41 + "--set BUNDLE_GEMFILE ${basicEnv.confFiles}/Gemfile "+ 42 + "--set BUNDLE_PATH ${basicEnv}/${ruby.gemPath} "+ 43 + "--set BUNDLE_FROZEN 1 "+ 44 + "--set GEM_HOME ${basicEnv}/${ruby.gemPath} "+ 45 + "--set GEM_PATH ${basicEnv}/${ruby.gemPath} "+ 46 + "--run \"cd $srcdir\";\n") scripts)} 47 + ${postBuild} 48 + ''
+32 -124
pkgs/development/ruby-modules/bundler-env/default.nix
··· 1 1 { stdenv, runCommand, writeText, writeScript, writeScriptBin, ruby, lib 2 2 , callPackage, defaultGemConfig, fetchurl, fetchgit, buildRubyGem, buildEnv 3 - , git 4 - , makeWrapper 5 - , bundler 6 - , tree 3 + , linkFarm, git, makeWrapper, bundler, tree 7 4 }@defs: 8 5 9 6 { name ? null ··· 12 9 , gemfile ? null 13 10 , lockfile ? null 14 11 , gemset ? null 12 + , groups ? ["default"] 15 13 , ruby ? defs.ruby 16 14 , gemConfig ? defaultGemConfig 17 15 , postBuild ? null 18 16 , document ? [] 19 17 , meta ? {} 20 - , groups ? ["default"] 21 18 , ignoreCollisions ? false 22 19 , ... 23 20 }@args: 24 21 25 22 let 26 - drvName = 27 - if name != null then name 28 - else if pname != null then "${toString pname}-${mainGem.version}" 29 - else throw "bundlerEnv: either pname or name must be set"; 30 - 31 - mainGem = 32 - if pname == null then null 33 - else gems."${pname}" or (throw "bundlerEnv: gem ${pname} not found"); 34 - 35 - gemfile' = 36 - if gemfile == null then gemdir + "/Gemfile" 37 - else gemfile; 38 - 39 - lockfile' = 40 - if lockfile == null then gemdir + "/Gemfile.lock" 41 - else lockfile; 42 - 43 - gemset' = 44 - if gemset == null then gemdir + "/gemset.nix" 45 - else gemset; 46 - 47 - importedGemset = import gemset'; 48 - 49 - filteredGemset = (lib.filterAttrs (name: attrs: 50 - if (builtins.hasAttr "groups" attrs) 51 - then (builtins.any (gemGroup: builtins.any (group: group == gemGroup) groups) attrs.groups) 52 - else true 53 - ) importedGemset); 54 - 55 - applyGemConfigs = attrs: 56 - (if gemConfig ? "${attrs.gemName}" 57 - then attrs // gemConfig."${attrs.gemName}" attrs 58 - else attrs); 59 - 60 - configuredGemset = lib.flip lib.mapAttrs filteredGemset (name: attrs: 61 - applyGemConfigs (attrs // { inherit ruby; gemName = name; }) 62 - ); 23 + inherit (import ../bundled-common/functions.nix {inherit lib ruby gemConfig groups; }) genStubsScript; 63 24 64 - hasBundler = builtins.hasAttr "bundler" filteredGemset; 25 + basicEnv = (callPackage ../bundled-common {}) (args // { inherit pname name; mainGemName = pname; }); 65 26 66 - bundler = 67 - if hasBundler then gems.bundler 68 - else defs.bundler.override (attrs: { inherit ruby; }); 27 + inherit (basicEnv) envPaths; 28 + # Idea here is a mkDerivation that gen-bin-stubs new stubs "as specified" - 29 + # either specific executables or the bin/ for certain gem(s), but 30 + # incorporates the basicEnv as a requirement so that its $out is in our path. 69 31 70 - gems = lib.flip lib.mapAttrs configuredGemset (name: attrs: 71 - buildRubyGem ((removeAttrs attrs ["source"]) // attrs.source // { 72 - inherit ruby; 73 - gemName = name; 74 - gemPath = map (gemName: gems."${gemName}") (attrs.dependencies or []); 75 - })); 76 - 77 - # We have to normalize the Gemfile.lock, otherwise bundler tries to be 78 - # helpful by doing so at run time, causing executables to immediately bail 79 - # out. Yes, I'm serious. 80 - confFiles = runCommand "gemfile-and-lockfile" {} '' 81 - mkdir -p $out 82 - cp ${gemfile'} $out/Gemfile 83 - cp ${lockfile'} $out/Gemfile.lock 84 - ''; 85 - 86 - envPaths = lib.attrValues gems ++ lib.optional (!hasBundler) bundler; 87 - 88 - binPaths = if mainGem != null then [ mainGem ] else envPaths; 89 - 90 - bundlerEnv = buildEnv { 91 - inherit ignoreCollisions; 32 + # When stubbing the bins for a gem, we should use the gem expression 33 + # directly, which means that basicEnv should somehow make it available. 92 34 93 - name = drvName; 35 + # Different use cases should use different variations on this file, rather 36 + # than the expression trying to deduce a use case. 94 37 95 - paths = envPaths; 96 - pathsToLink = [ "/lib" ]; 38 + # The basicEnv should be put into passthru so that e.g. nix-shell can use it. 39 + in 40 + if pname == null then 41 + basicEnv // { inherit name basicEnv; } 42 + else 43 + (buildEnv { 44 + inherit ignoreCollisions; 97 45 98 - postBuild = '' 99 - ${ruby}/bin/ruby ${./gen-bin-stubs.rb} \ 100 - "${ruby}/bin/ruby" \ 101 - "${confFiles}/Gemfile" \ 102 - "$out/${ruby.gemPath}" \ 103 - "${bundler}/${ruby.gemPath}" \ 104 - ${lib.escapeShellArg binPaths} \ 105 - ${lib.escapeShellArg groups} 106 - '' + lib.optionalString (postBuild != null) postBuild; 46 + name = basicEnv.name; 107 47 108 - meta = { platforms = ruby.meta.platforms; } // meta; 48 + paths = envPaths; 49 + pathsToLink = [ "/lib" ]; 109 50 110 - passthru = rec { 111 - inherit ruby bundler gems; 51 + postBuild = genStubsScript { 52 + inherit lib ruby bundler groups; 53 + confFiles = basicEnv.confFiles; 54 + binPaths = [ basicEnv.gems."${pname}" ]; 55 + } + lib.optionalString (postBuild != null) postBuild; 112 56 113 - wrappedRuby = stdenv.mkDerivation { 114 - name = "wrapped-ruby-${drvName}"; 115 - nativeBuildInputs = [ makeWrapper ]; 116 - buildCommand = '' 117 - mkdir -p $out/bin 118 - for i in ${ruby}/bin/*; do 119 - makeWrapper "$i" $out/bin/$(basename "$i") \ 120 - --set BUNDLE_GEMFILE ${confFiles}/Gemfile \ 121 - --set BUNDLE_PATH ${bundlerEnv}/${ruby.gemPath} \ 122 - --set BUNDLE_FROZEN 1 \ 123 - --set GEM_HOME ${bundlerEnv}/${ruby.gemPath} \ 124 - --set GEM_PATH ${bundlerEnv}/${ruby.gemPath} 125 - done 126 - ''; 57 + meta = { platforms = ruby.meta.platforms; } // meta; 58 + passthru = basicEnv.passthru // { 59 + inherit basicEnv; 60 + inherit (basicEnv) env; 127 61 }; 128 - 129 - env = let 130 - irbrc = builtins.toFile "irbrc" '' 131 - if !(ENV["OLD_IRBRC"].nil? || ENV["OLD_IRBRC"].empty?) 132 - require ENV["OLD_IRBRC"] 133 - end 134 - require 'rubygems' 135 - require 'bundler/setup' 136 - ''; 137 - in stdenv.mkDerivation { 138 - name = "interactive-${drvName}-environment"; 139 - nativeBuildInputs = [ wrappedRuby bundlerEnv ]; 140 - shellHook = '' 141 - export OLD_IRBRC="$IRBRC" 142 - export IRBRC=${irbrc} 143 - ''; 144 - buildCommand = '' 145 - echo >&2 "" 146 - echo >&2 "*** Ruby 'env' attributes are intended for interactive nix-shell sessions, not for building! ***" 147 - echo >&2 "" 148 - exit 1 149 - ''; 150 - }; 151 - }; 152 - }; 153 - in 154 - bundlerEnv 62 + })
pkgs/development/ruby-modules/bundler-env/gen-bin-stubs.rb pkgs/development/ruby-modules/bundled-common/gen-bin-stubs.rb
+33
pkgs/development/ruby-modules/bundler-env/test.nix
··· 1 + { stdenv, writeText, lib, ruby, defaultGemConfig, callPackage, test, stubs, should}@defs: 2 + let 3 + bundlerEnv = callPackage ./default.nix stubs // { 4 + basicEnv = callPackage ../bundled-common stubs; 5 + }; 6 + 7 + justName = bundlerEnv { 8 + name = "test-0.1.2"; 9 + gemset = ./test/gemset.nix; 10 + }; 11 + 12 + pnamed = bundlerEnv { 13 + pname = "test"; 14 + gemdir = ./test; 15 + gemset = ./test/gemset.nix; 16 + gemfile = ./test/Gemfile; 17 + lockfile = ./test/Gemfile.lock; 18 + }; 19 + in 20 + builtins.concatLists [ 21 + (test.run "bundlerEnv { name }" justName { 22 + name = should.equal "test-0.1.2"; 23 + }) 24 + (test.run "bundlerEnv { pname }" pnamed 25 + [ 26 + (should.haveKeys [ "name" "env" "postBuild" ]) 27 + { 28 + name = should.equal "test-0.1.2"; 29 + env = should.beASet; 30 + postBuild = should.havePrefix "/nix/store"; 31 + } 32 + ]) 33 + ]
pkgs/development/ruby-modules/bundler-env/test/Gemfile

This is a binary file and will not be displayed.

pkgs/development/ruby-modules/bundler-env/test/Gemfile.lock

This is a binary file and will not be displayed.

+10
pkgs/development/ruby-modules/bundler-env/test/gemset.nix
··· 1 + { 2 + test = { 3 + source = { 4 + remotes = ["https://rubygems.org"]; 5 + sha256 = "1j5r0anj8m4qlf2psnldip4b8ha2bsscv11lpdgnfh4nnchzjnxw"; 6 + type = "gem"; 7 + }; 8 + version = "0.1.2"; 9 + }; 10 + }
+1
pkgs/development/ruby-modules/gem/default.nix
··· 87 87 ++ lib.optional stdenv.isDarwin darwin.libobjc 88 88 ++ buildInputs; 89 89 90 + #name = builtins.trace (attrs.name or "no attr.name" ) "${namePrefix}${gemName}-${version}"; 90 91 name = attrs.name or "${namePrefix}${gemName}-${version}"; 91 92 92 93 inherit src;
+6
pkgs/development/ruby-modules/runtests.sh
··· 1 + #!/usr/bin/env bash 2 + set -o xtrace 3 + cd $(dirname $0) 4 + find . -name text.nix 5 + testfiles=$(find . -name test.nix) 6 + nix-build -E "with import <nixpkgs> {}; callPackage testing/driver.nix { testFiles = [ $testfiles ]; }" --show-trace && cat result
+28
pkgs/development/ruby-modules/testing/assertions.nix
··· 1 + { test, lib, ...}: 2 + { 3 + equal = expected: actual: 4 + if actual == expected then 5 + (test.passed "= ${toString expected}") else 6 + (test.failed ( 7 + "expected '${toString expected}'(${builtins.typeOf expected})" 8 + + " != "+ 9 + "actual '${toString actual}'(${builtins.typeOf actual})" 10 + )); 11 + 12 + beASet = actual: 13 + if builtins.isAttrs actual then 14 + (test.passed "is a set") else 15 + (test.failed "is not a set, was ${builtins.typeOf actual}: ${toString actual}"); 16 + 17 + haveKeys = expected: actual: 18 + if builtins.all 19 + (ex: builtins.any (ac: ex == ac) (builtins.attrNames actual)) 20 + expected then 21 + (test.passed "has expected keys") else 22 + (test.failed "keys differ: expected: [${lib.concatStringsSep ";" expected}] actual: [${lib.concatStringsSep ";" (builtins.attrNames actual)}]"); 23 + 24 + havePrefix = expected: actual: 25 + if lib.hasPrefix expected actual then 26 + (test.passed "has prefix '${expected}'") else 27 + (test.failed "prefix '${expected}' not found in '${actual}'"); 28 + }
+20
pkgs/development/ruby-modules/testing/driver.nix
··· 1 + /* 2 + Run with: 3 + nix-build -E 'with import <nixpkgs> { }; callPackage ./test.nix {}' --show-trace; and cat result 4 + 5 + Confusingly, the ideal result ends with something like: 6 + error: build of ‘/nix/store/3245f3dcl2wxjs4rci7n069zjlz8qg85-test-results.tap.drv’ failed 7 + */ 8 + { writeText, lib, callPackage, testFiles, stdenv, ruby }@defs: 9 + let 10 + testTools = rec { 11 + test = import ./testing.nix; 12 + stubs = import ./stubs.nix defs; 13 + should = import ./assertions.nix { inherit test lib; }; 14 + }; 15 + 16 + tap = import ./tap-support.nix; 17 + 18 + results = builtins.concatLists (map (file: callPackage file testTools) testFiles); 19 + in 20 + writeText "test-results.tap" (tap.output results)
+33
pkgs/development/ruby-modules/testing/stubs.nix
··· 1 + { stdenv, lib, ruby, callPackage, ... }: 2 + let 3 + real = { 4 + inherit (stdenv) mkDerivation; 5 + }; 6 + mkDerivation = {name, ...}@argSet: 7 + derivation { 8 + inherit name; 9 + text = (builtins.toJSON (lib.filterAttrs ( n: v: builtins.any (x: x == n) ["name" "system"]) argSet)); 10 + builder = stdenv.shell; 11 + args = [ "-c" "echo $(<$textPath) > $out"]; 12 + system = stdenv.system; 13 + passAsFile = ["text"]; 14 + }; 15 + fetchurl = {url?"", urls ? [],...}: "fetchurl:${if urls == [] then url else builtins.head urls}"; 16 + 17 + stdenv' = stdenv // { 18 + inherit mkDerivation; 19 + stubbed = true; 20 + }; 21 + ruby' = ruby // { 22 + stdenv = stdenv'; 23 + stubbed = true; 24 + }; 25 + in 26 + { 27 + ruby = ruby'; 28 + buildRubyGem = callPackage ../gem { 29 + inherit fetchurl; 30 + ruby = ruby'; 31 + }; 32 + stdenv = stdenv'; 33 + }
+21
pkgs/development/ruby-modules/testing/tap-support.nix
··· 1 + with builtins; 2 + let 3 + withIndexes = list: genList (idx: (elemAt list idx) // {index = idx;}) (length list); 4 + 5 + testLine = report: "${okStr report} ${toString (report.index + 1)} ${report.description}" + testDirective report + testYaml report; 6 + 7 + # These are part of the TAP spec, not yet implemented. 8 + #c.f. https://github.com/NixOS/nixpkgs/issues/27071 9 + testDirective = report: ""; 10 + testYaml = report: ""; 11 + 12 + okStr = { result, ...}: if result == "pass" then "ok" else "not ok"; 13 + in 14 + { 15 + output = reports: '' 16 + TAP version 13 17 + 1..${toString (length reports)}'' + (foldl' (l: r: l + "\n" + r) "" (map testLine (withIndexes reports))) + '' 18 + 19 + # Finished at ${toString currentTime} 20 + ''; 21 + }
+62
pkgs/development/ruby-modules/testing/testing.nix
··· 1 + with builtins; 2 + let 3 + /* 4 + underTest = { 5 + x = { 6 + a = 1; 7 + b = "2"; 8 + }; 9 + }; 10 + 11 + tests = [ 12 + (root: false) 13 + { 14 + x = [ 15 + (set: true) 16 + { 17 + a = (a: a > 1); 18 + b = (b: b == "3"); 19 + } 20 + ]; 21 + } 22 + ]; 23 + 24 + results = run "Examples" underTest tests; 25 + */ 26 + 27 + passed = desc: { 28 + result = "pass"; 29 + description = desc; 30 + }; 31 + 32 + failed = desc: { 33 + result = "failed"; 34 + description = desc; 35 + }; 36 + 37 + prefixName = name: res: { 38 + inherit (res) result; 39 + description = "${name}: ${res.description}"; 40 + }; 41 + 42 + run = name: under: tests: if isList tests then 43 + (concatLists (map (run name under) tests)) 44 + else if isAttrs tests then 45 + (concatLists (map ( 46 + subName: run (name + "." + subName) (if hasAttr subName under then getAttr subName under else "<MISSING!>") (getAttr subName tests) 47 + ) (attrNames tests))) 48 + else if isFunction tests then 49 + let 50 + res = tests under; 51 + in 52 + if isBool res then 53 + [ 54 + (prefixName name (if tests under then passed "passed" else failed "failed")) 55 + ] 56 + else 57 + [ (prefixName name res) ] 58 + else [ 59 + failed (name ": not a function, list or set") 60 + ]; 61 + in 62 + { inherit run passed failed; }
+3
pkgs/development/tools/corundum/Gemfile
··· 1 + source "https://rubygems.org" 2 + 3 + gem "corundum", "=0.6.2"
+56
pkgs/development/tools/corundum/Gemfile.lock
··· 1 + GEM 2 + remote: https://rubygems.org/ 3 + specs: 4 + calibrate (0.0.1) 5 + caliph (0.3.1) 6 + corundum (0.6.2) 7 + bundler (~> 1.10) 8 + caliph (~> 0.3) 9 + mattock (~> 0.9) 10 + paint (~> 0.8) 11 + rspec (>= 2.0, < 4) 12 + simplecov (>= 0.5) 13 + simplecov-json (~> 0.2) 14 + diff-lcs (1.3) 15 + docile (1.1.5) 16 + json (2.1.0) 17 + mattock (0.10.1) 18 + calibrate (~> 0.0.1) 19 + caliph (~> 0.3) 20 + rake (~> 10.0) 21 + tilt (> 0) 22 + valise (~> 1.1) 23 + paint (0.9.0) 24 + rake (10.5.0) 25 + rspec (3.6.0) 26 + rspec-core (~> 3.6.0) 27 + rspec-expectations (~> 3.6.0) 28 + rspec-mocks (~> 3.6.0) 29 + rspec-core (3.6.0) 30 + rspec-support (~> 3.6.0) 31 + rspec-expectations (3.6.0) 32 + diff-lcs (>= 1.2.0, < 2.0) 33 + rspec-support (~> 3.6.0) 34 + rspec-mocks (3.6.0) 35 + diff-lcs (>= 1.2.0, < 2.0) 36 + rspec-support (~> 3.6.0) 37 + rspec-support (3.6.0) 38 + simplecov (0.14.1) 39 + docile (~> 1.1.0) 40 + json (>= 1.8, < 3) 41 + simplecov-html (~> 0.10.0) 42 + simplecov-html (0.10.1) 43 + simplecov-json (0.2) 44 + json 45 + simplecov 46 + tilt (2.0.7) 47 + valise (1.2.1) 48 + 49 + PLATFORMS 50 + ruby 51 + 52 + DEPENDENCIES 53 + corundum (= 0.6.2) 54 + 55 + BUNDLED WITH 56 + 1.14.4
+15
pkgs/development/tools/corundum/default.nix
··· 1 + { lib, bundlerApp }: 2 + 3 + bundlerApp { 4 + pname = "corundum"; 5 + gemdir = ./.; 6 + exes = [ "corundum-skel" ]; 7 + 8 + meta = with lib; { 9 + description = "Tool and libraries for maintaining Ruby gems."; 10 + homepage = https://github.com/nyarly/corundum; 11 + license = licenses.mit; 12 + maintainers = [ maintainers.nyarly ]; 13 + platforms = platforms.unix; 14 + }; 15 + }
+154
pkgs/development/tools/corundum/gemset.nix
··· 1 + { 2 + calibrate = { 3 + source = { 4 + remotes = ["https://rubygems.org"]; 5 + sha256 = "17kmlss7db70pjwdbbhag7mnixh8wasdq6n1v8663x50z9c7n2ng"; 6 + type = "gem"; 7 + }; 8 + version = "0.0.1"; 9 + }; 10 + caliph = { 11 + source = { 12 + remotes = ["https://rubygems.org"]; 13 + sha256 = "08d07n4m4yh1h9icq6n9dkw4jwgdmgd638f15mxr2pvqp4wycsnr"; 14 + type = "gem"; 15 + }; 16 + version = "0.3.1"; 17 + }; 18 + corundum = { 19 + source = { 20 + remotes = ["https://rubygems.org"]; 21 + sha256 = "1y6shjrqaqyh14a1r4ic660g6jnq4abdrx9imglyalzyrlrwbsxq"; 22 + type = "gem"; 23 + }; 24 + version = "0.6.2"; 25 + }; 26 + diff-lcs = { 27 + source = { 28 + remotes = ["https://rubygems.org"]; 29 + sha256 = "18w22bjz424gzafv6nzv98h0aqkwz3d9xhm7cbr1wfbyas8zayza"; 30 + type = "gem"; 31 + }; 32 + version = "1.3"; 33 + }; 34 + docile = { 35 + source = { 36 + remotes = ["https://rubygems.org"]; 37 + sha256 = "0m8j31whq7bm5ljgmsrlfkiqvacrw6iz9wq10r3gwrv5785y8gjx"; 38 + type = "gem"; 39 + }; 40 + version = "1.1.5"; 41 + }; 42 + json = { 43 + source = { 44 + remotes = ["https://rubygems.org"]; 45 + sha256 = "01v6jjpvh3gnq6sgllpfqahlgxzj50ailwhj9b3cd20hi2dx0vxp"; 46 + type = "gem"; 47 + }; 48 + version = "2.1.0"; 49 + }; 50 + mattock = { 51 + source = { 52 + remotes = ["https://rubygems.org"]; 53 + sha256 = "02d6igwr4sfj4jnky8d5h0rm2cc665k1bqz7sj4khzvr18nk3ai6"; 54 + type = "gem"; 55 + }; 56 + version = "0.10.1"; 57 + }; 58 + paint = { 59 + source = { 60 + remotes = ["https://rubygems.org"]; 61 + sha256 = "1fcn7cfrhbl4nl95fmcd67q33h7bl3iafsafs6w9yj4nqzagz1yc"; 62 + type = "gem"; 63 + }; 64 + version = "0.9.0"; 65 + }; 66 + rake = { 67 + source = { 68 + remotes = ["https://rubygems.org"]; 69 + sha256 = "0jcabbgnjc788chx31sihc5pgbqnlc1c75wakmqlbjdm8jns2m9b"; 70 + type = "gem"; 71 + }; 72 + version = "10.5.0"; 73 + }; 74 + rspec = { 75 + source = { 76 + remotes = ["https://rubygems.org"]; 77 + sha256 = "1nd50hycab2a2vdah9lxi585g8f63jxjvmzmxqyln51grxwx9hzb"; 78 + type = "gem"; 79 + }; 80 + version = "3.6.0"; 81 + }; 82 + rspec-core = { 83 + source = { 84 + remotes = ["https://rubygems.org"]; 85 + sha256 = "18np8wyw2g79waclpaacba6nd7x60ixg07ncya0j0qj1z9b37grd"; 86 + type = "gem"; 87 + }; 88 + version = "3.6.0"; 89 + }; 90 + rspec-expectations = { 91 + source = { 92 + remotes = ["https://rubygems.org"]; 93 + sha256 = "028ifzf9mqp3kxx40q1nbwj40g72g9zk0wr78l146phblkv96w0a"; 94 + type = "gem"; 95 + }; 96 + version = "3.6.0"; 97 + }; 98 + rspec-mocks = { 99 + source = { 100 + remotes = ["https://rubygems.org"]; 101 + sha256 = "0nv6jkxy24sag1i9w9wi3850k6skk2fm6yhcrgnmlz6vmwxvizp8"; 102 + type = "gem"; 103 + }; 104 + version = "3.6.0"; 105 + }; 106 + rspec-support = { 107 + source = { 108 + remotes = ["https://rubygems.org"]; 109 + sha256 = "050paqqpsml8w88nf4a15zbbj3vvm471zpv73sjfdnz7w21wnypb"; 110 + type = "gem"; 111 + }; 112 + version = "3.6.0"; 113 + }; 114 + simplecov = { 115 + source = { 116 + remotes = ["https://rubygems.org"]; 117 + sha256 = "1r9fnsnsqj432cmrpafryn8nif3x0qg9mdnvrcf0wr01prkdlnww"; 118 + type = "gem"; 119 + }; 120 + version = "0.14.1"; 121 + }; 122 + simplecov-html = { 123 + source = { 124 + remotes = ["https://rubygems.org"]; 125 + sha256 = "0f3psphismgp6jp1fxxz09zbswh7m2xxxr6gqlzdh7sgv415clvm"; 126 + type = "gem"; 127 + }; 128 + version = "0.10.1"; 129 + }; 130 + simplecov-json = { 131 + source = { 132 + remotes = ["https://rubygems.org"]; 133 + sha256 = "0x9hr08pkj5d14nfzsn5h8b7ayl6q0xir45dcx5rv2a7g10kzlpp"; 134 + type = "gem"; 135 + }; 136 + version = "0.2"; 137 + }; 138 + tilt = { 139 + source = { 140 + remotes = ["https://rubygems.org"]; 141 + sha256 = "1is1ayw5049z8pd7slsk870bddyy5g2imp4z78lnvl8qsl8l0s7b"; 142 + type = "gem"; 143 + }; 144 + version = "2.0.7"; 145 + }; 146 + valise = { 147 + source = { 148 + remotes = ["https://rubygems.org"]; 149 + sha256 = "1arsbmk2gifrhv244qrld7s3202xrnxy6vlc5gqklg70dpsinbn5"; 150 + type = "gem"; 151 + }; 152 + version = "1.2.1"; 153 + }; 154 + }
+3
pkgs/top-level/all-packages.nix
··· 6412 6412 bundix = callPackage ../development/ruby-modules/bundix { }; 6413 6413 bundler = callPackage ../development/ruby-modules/bundler { }; 6414 6414 bundlerEnv = callPackage ../development/ruby-modules/bundler-env { }; 6415 + bundlerApp = callPackage ../development/ruby-modules/bundler-app { }; 6415 6416 6416 6417 inherit (callPackage ../development/interpreters/ruby {}) 6417 6418 ruby_2_0_0 ··· 6726 6727 conan = callPackage ../development/tools/build-managers/conan { }; 6727 6728 6728 6729 cookiecutter = pythonPackages.cookiecutter; 6730 + 6731 + corundum = callPackage ../development/tools/corundum { }; 6729 6732 6730 6733 ctags = callPackage ../development/tools/misc/ctags { }; 6731 6734