| 1 | From: Hartmut Goebel <[email protected]>
|
| 2 | Date: Mon, 07 Aug 2023 18:09:09 +0200
|
| 3 | Subject: Support system-installed plugins
|
| 4 |
|
| 5 | Plugins must be installed as regular Ruby libraries, and they must
|
| 6 | contain share/vagrant-plugins/plugins.d/$PLUGINNAME.json with the
|
| 7 | following content:
|
| 8 |
|
| 9 | {
|
| 10 | "${PLUGINNAME}": {
|
| 11 | "ruby_version":"$(ruby -e 'puts RUBY_VERSION')",
|
| 12 | "vagrant_version":"$(cat /usr/share/vagrant/version.txt)",
|
| 13 | "gem_version":"",
|
| 14 | "require":"",
|
| 15 | "sources":[]
|
| 16 | }
|
| 17 | }
|
| 18 |
|
| 19 | This patch was based on the respective patch from Debian, anyhow heavily
|
| 20 | adjusted to Guix and to support GUIX_VAGRANT_PLUGINS_PATH.
|
| 21 |
|
| 22 | Orignal-Author: Antonio Terceiro <[email protected]>
|
| 23 | Co-authored-by: Antonio Terceiro <[email protected]>
|
| 24 | ---
|
| 25 | bin/vagrant | 15 +++++++++++++++
|
| 26 | lib/vagrant/bundler.rb | 2 +-
|
| 27 | lib/vagrant/plugin/manager.rb | 4 ++--
|
| 28 | lib/vagrant/plugin/state_file.rb | 30 ++++++++++++++++++++++++++++--
|
| 29 | lib/vagrant/shared_helpers.rb | 8 ++++++++
|
| 30 | 5 files changed, 54 insertions(+), 5 deletions(-)
|
| 31 |
|
| 32 | diff --git a/bin/vagrant b/bin/vagrant
|
| 33 | index d3f4ea6..cc00efa 100755
|
| 34 | |
| 35 | |
| 36 | @@ -86,6 +86,21 @@ $stderr.sync = true
|
| 37 | # so we can provide correct resolutions later
|
| 38 | builtin_specs = []
|
| 39 |
|
| 40 | +# Add the gem paths of vagrant plugins to the Gem search path
|
| 41 | +# TODO: find a better way to add paths to the Gem search path
|
| 42 | +gempath = []
|
| 43 | +if ENV['GEM_PATH']
|
| 44 | + gempath.append(ENV['GEM_PATH'])
|
| 45 | +end
|
| 46 | +ENV['GUIX_VAGRANT_PLUGINS_PATH'].split(File::PATH_SEPARATOR).each do |pluginsdir|
|
| 47 | + gemdir = File.absolute_path(File.join(pluginsdir, "../../lib/ruby/vendor_ruby"))
|
| 48 | + gempath.append(gemdir)
|
| 49 | +end
|
| 50 | +ENV['GEM_PATH'] = gempath.join(':')
|
| 51 | +gemdir = nil
|
| 52 | +gempath = nil
|
| 53 | +Gem.clear_paths() # make GEM_PATH be reevaluated
|
| 54 | +
|
| 55 | vagrant_spec = Gem::Specification.find_all_by_name("vagrant").detect do |spec|
|
| 56 | spec.version == Gem::Version.new(Vagrant::VERSION)
|
| 57 | end
|
| 58 | diff --git a/lib/vagrant/bundler.rb b/lib/vagrant/bundler.rb
|
| 59 | index 46ef69f..27979b9 100644
|
| 60 | |
| 61 | |
| 62 | @@ -665,7 +665,7 @@ module Vagrant
|
| 63 | spec_dir = Gem::Specification.default_specifications_dir
|
| 64 | end
|
| 65 | directories = [spec_dir]
|
| 66 | - if Vagrant.in_bundler?
|
| 67 | + if Vagrant.in_bundler? || Vagrant.in_guix_package?
|
| 68 | Gem::Specification.find_all{true}.each do |spec|
|
| 69 | list[spec.full_name] = spec
|
| 70 | end
|
| 71 | diff --git a/lib/vagrant/plugin/manager.rb b/lib/vagrant/plugin/manager.rb
|
| 72 | index b73f07f..94cd609 100644
|
| 73 | |
| 74 | |
| 75 | @@ -18,7 +18,7 @@ module Vagrant
|
| 76 |
|
| 77 | # Returns the path to the [StateFile] for system plugins.
|
| 78 | def self.system_plugins_file
|
| 79 | - dir = Vagrant.installer_embedded_dir
|
| 80 | + dir = nil
|
| 81 | return nil if !dir
|
| 82 | Pathname.new(dir).join("plugins.json")
|
| 83 | end
|
| 84 | @@ -38,7 +38,7 @@ module Vagrant
|
| 85 |
|
| 86 | system_path = self.class.system_plugins_file
|
| 87 | @system_file = nil
|
| 88 | - @system_file = StateFile.new(system_path) if system_path && system_path.file?
|
| 89 | + @system_file = StateFile.new(system_path, true) #if system_path && system_path.file?
|
| 90 |
|
| 91 | @local_file = nil
|
| 92 | @globalized = @localized = false
|
| 93 | diff --git a/lib/vagrant/plugin/state_file.rb b/lib/vagrant/plugin/state_file.rb
|
| 94 | index c6872d4..b927fd8 100644
|
| 95 | |
| 96 | |
| 97 | @@ -11,11 +11,17 @@ module Vagrant
|
| 98 | # @return [Pathname] path to file
|
| 99 | attr_reader :path
|
| 100 |
|
| 101 | - def initialize(path)
|
| 102 | + def initialize(path, system = false)
|
| 103 | @path = path
|
| 104 | + @system = system
|
| 105 |
|
| 106 | @data = {}
|
| 107 | - if @path.exist?
|
| 108 | + if system
|
| 109 | + if ENV.has_key?('GUIX_VAGRANT_PLUGINS_PATH')
|
| 110 | + @data["installed"] = {}
|
| 111 | + load_system_plugins
|
| 112 | + end
|
| 113 | + elsif @path.exist?
|
| 114 | begin
|
| 115 | @data = JSON.parse(@path.read)
|
| 116 | rescue JSON::ParserError => e
|
| 117 | @@ -30,6 +36,22 @@ module Vagrant
|
| 118 | @data["installed"] ||= {}
|
| 119 | end
|
| 120 |
|
| 121 | + def load_system_plugins
|
| 122 | + ENV['GUIX_VAGRANT_PLUGINS_PATH'].split(File::PATH_SEPARATOR).each do |pluginsdir|
|
| 123 | + extra_plugins = Dir.glob(File.join(pluginsdir, 'plugins.d', '*.json'))
|
| 124 | + extra_plugins.each do |filename|
|
| 125 | + json = File.read(filename)
|
| 126 | + begin
|
| 127 | + plugin_data = JSON.parse(json)
|
| 128 | + @data["installed"].merge!(plugin_data)
|
| 129 | + rescue JSON::ParserError => e
|
| 130 | + raise Vagrant::Errors::PluginStateFileParseError,
|
| 131 | + path: filename, message: e.message
|
| 132 | + end
|
| 133 | + end
|
| 134 | + end
|
| 135 | + end
|
| 136 | +
|
| 137 | # Add a plugin that is installed to the state file.
|
| 138 | #
|
| 139 | # @param [String] name The name of the plugin
|
| 140 | @@ -107,6 +129,10 @@ module Vagrant
|
| 141 | f.close
|
| 142 | FileUtils.mv(f.path, @path)
|
| 143 | end
|
| 144 | + rescue Errno::EACCES
|
| 145 | + # Ignore permission denied against system-installed plugins; regular
|
| 146 | + # users are not supposed to write there.
|
| 147 | + raise unless @system
|
| 148 | end
|
| 149 |
|
| 150 | protected
|
| 151 | diff --git a/lib/vagrant/shared_helpers.rb b/lib/vagrant/shared_helpers.rb
|
| 152 | index 7b0b87c..eb9a21e 100644
|
| 153 | |
| 154 | |
| 155 | @@ -43,6 +43,14 @@ module Vagrant
|
| 156 | !defined?(::Bundler).nil?
|
| 157 | end
|
| 158 |
|
| 159 | + # This returns a true/false if we are running from a Guix package
|
| 160 | + #
|
| 161 | + # @return [Boolean]
|
| 162 | + def self.in_guix_package?
|
| 163 | + # FIXME write a proper check if this ever goes upstream
|
| 164 | + true
|
| 165 | + end
|
| 166 | +
|
| 167 | # Returns the path to the embedded directory of the Vagrant installer,
|
| 168 | # if there is one (if we're running in an installer).
|
| 169 | #
|
| 170 | --
|
| 171 | 2.30.9
|
| 172 |
|