nixpkgs/pkgs/applications/version-management/gitlab/generate_nix_requirements.rb
Thomas Hunger 59995e168c nixos: Add gitlab and gitlab-shell
I had to make several adjustments to make it work with nixos:

* Replace relative config file lookups with ENV variable.
* Modify gitlab-shell to not clear then environment when running
  pre-receive.
* Modify gitlab-shell to write some environment variables into
  the .authorized_keys file to make sure gitlab-shell reads the
  correct config file.
* Log unicorn output to syslog.
  I tried various ways of adding a syslog package but the bundler would
  not pick them up. Please fix in a better way if possible.
* Gitlab-runner program wrapper.
  This is useful to run e.g. backups etc. with the correct
  environment set up.
2014-12-12 18:01:29 +01:00

57 lines
1.3 KiB
Ruby
Executable File

#!/usr/bin/env ruby
require 'rubygems'
require 'bundler'
require 'fileutils'
require 'net/http'
require 'net/https'
require 'uri'
TMP_DIR = "/tmp/gems"
FileUtils.rm_rf(TMP_DIR) if File.exists?(TMP_DIR)
FileUtils.mkdir TMP_DIR
GEMSERVER = "http://rubygems.org"
# inspect Gemfile.lock
lockfile = Bundler::LockfileParser.new(Bundler.read_file("Gemfile.lock"))
to_mirror = {}
uri = URI(GEMSERVER)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == 'https'
requirements = {}
lockfile.specs.each do |s|
possible_gem_name = "#{s.name}-#{s.version.to_s}.gem"
Dir.chdir TMP_DIR do
filename = `gem fetch #{s.name} -v #{s.version.to_s}`.split()[1]
hash = `sha256sum #{filename}.gem`
url = "#{GEMSERVER}/downloads/#{filename}.gem"
puts url
requirements[s.name] = { :version => s.version.to_s,
:hash => hash.split().first,
:url => url,}
end
end
filename = 'Gemfile.nix'
File.open(filename, 'w') do |file|
file.puts "["
requirements.each do |name, info|
file.puts "{"
file.puts ['name = ', '"', name, '";'].join('')
file.puts ['hash = ', '"', info[:hash], '";'].join('')
file.puts ['url = ', '"', info[:url], '";'].join('')
file.puts ['version = ', '"', info[:version], '";'].join('')
file.puts "}"
end
file.puts "]"
end