all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob 3d57993921dc57900e40ae051cabf556f205c193 5750 bytes (raw)
name: gnu/packages/patches/vagrant-Support-system-installed-plugins.patch 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
 
From: Hartmut Goebel <h.goebel@crazy-compilers.com>
Date: Mon, 07 Aug 2023 18:09:09 +0200
Subject: Support system-installed plugins

Plugins must be installed as regular Ruby libraries, and they must
contain share/vagrant-plugins/plugins.d/$PLUGINNAME.json with the
following content:

{
  "${PLUGINNAME}": {
    "ruby_version":"$(ruby -e 'puts RUBY_VERSION')",
    "vagrant_version":"$(cat /usr/share/vagrant/version.txt)",
    "gem_version":"",
    "require":"",
    "sources":[]
  }
}

This patch was based on the respective patch from Debian, anyhow heavily
adjusted to Guix and to support GUIX_VAGRANT_PLUGINS_PATH.

Orignal-Author: Antonio Terceiro <terceiro@debian.org>
Co-authored-by: Antonio Terceiro <terceiro@debian.org>
---
 bin/vagrant                      | 15 +++++++++++++++
 lib/vagrant/bundler.rb           |  2 +-
 lib/vagrant/plugin/manager.rb    |  4 ++--
 lib/vagrant/plugin/state_file.rb | 30 ++++++++++++++++++++++++++++--
 lib/vagrant/shared_helpers.rb    |  8 ++++++++
 5 files changed, 54 insertions(+), 5 deletions(-)

diff --git a/bin/vagrant b/bin/vagrant
index d3f4ea6..cc00efa 100755
--- a/bin/vagrant
+++ b/bin/vagrant
@@ -86,6 +86,21 @@ $stderr.sync = true
 # so we can provide correct resolutions later
 builtin_specs = []
 
+# Add the gem paths of vagrant plugins to the Gem search path
+# TODO: find a better way to add paths to the Gem search path
+gempath = []
+if ENV['GEM_PATH']
+  gempath.append(ENV['GEM_PATH'])
+end
+ENV['GUIX_VAGRANT_PLUGINS_PATH'].split(File::PATH_SEPARATOR).each do |pluginsdir|
+  gemdir = File.absolute_path(File.join(pluginsdir, "../../lib/ruby/vendor_ruby"))
+  gempath.append(gemdir)
+end
+ENV['GEM_PATH'] = gempath.join(':')
+gemdir = nil
+gempath = nil
+Gem.clear_paths()  # make GEM_PATH be reevaluated
+
 vagrant_spec = Gem::Specification.find_all_by_name("vagrant").detect do |spec|
   spec.version == Gem::Version.new(Vagrant::VERSION)
 end
diff --git a/lib/vagrant/bundler.rb b/lib/vagrant/bundler.rb
index 46ef69f..27979b9 100644
--- a/lib/vagrant/bundler.rb
+++ b/lib/vagrant/bundler.rb
@@ -665,7 +665,7 @@ module Vagrant
         spec_dir = Gem::Specification.default_specifications_dir
       end
       directories = [spec_dir]
-      if Vagrant.in_bundler?
+      if Vagrant.in_bundler? || Vagrant.in_guix_package?
         Gem::Specification.find_all{true}.each do |spec|
           list[spec.full_name] = spec
         end
diff --git a/lib/vagrant/plugin/manager.rb b/lib/vagrant/plugin/manager.rb
index b73f07f..94cd609 100644
--- a/lib/vagrant/plugin/manager.rb
+++ b/lib/vagrant/plugin/manager.rb
@@ -18,7 +18,7 @@ module Vagrant
 
       # Returns the path to the [StateFile] for system plugins.
       def self.system_plugins_file
-        dir = Vagrant.installer_embedded_dir
+        dir = nil
         return nil if !dir
         Pathname.new(dir).join("plugins.json")
       end
@@ -38,7 +38,7 @@ module Vagrant
 
         system_path  = self.class.system_plugins_file
         @system_file = nil
-        @system_file = StateFile.new(system_path) if system_path && system_path.file?
+        @system_file = StateFile.new(system_path, true) #if system_path && system_path.file?
 
         @local_file = nil
         @globalized = @localized = false
diff --git a/lib/vagrant/plugin/state_file.rb b/lib/vagrant/plugin/state_file.rb
index c6872d4..b927fd8 100644
--- a/lib/vagrant/plugin/state_file.rb
+++ b/lib/vagrant/plugin/state_file.rb
@@ -11,11 +11,17 @@ module Vagrant
       # @return [Pathname] path to file
       attr_reader :path
 
-      def initialize(path)
+      def initialize(path, system = false)
         @path = path
+        @system = system
 
         @data = {}
-        if @path.exist?
+        if system
+          if  ENV.has_key?('GUIX_VAGRANT_PLUGINS_PATH')
+            @data["installed"] = {}
+            load_system_plugins
+          end
+        elsif @path.exist?
           begin
             @data = JSON.parse(@path.read)
           rescue JSON::ParserError => e
@@ -30,6 +36,22 @@ module Vagrant
         @data["installed"] ||= {}
       end
 
+      def load_system_plugins
+        ENV['GUIX_VAGRANT_PLUGINS_PATH'].split(File::PATH_SEPARATOR).each do |pluginsdir|
+          extra_plugins = Dir.glob(File.join(pluginsdir, 'plugins.d', '*.json'))
+          extra_plugins.each do |filename|
+            json = File.read(filename)
+            begin
+              plugin_data = JSON.parse(json)
+              @data["installed"].merge!(plugin_data)
+            rescue JSON::ParserError => e
+              raise Vagrant::Errors::PluginStateFileParseError,
+                path: filename, message: e.message
+            end
+          end
+        end
+      end
+
       # Add a plugin that is installed to the state file.
       #
       # @param [String] name The name of the plugin
@@ -107,6 +129,10 @@ module Vagrant
           f.close
           FileUtils.mv(f.path, @path)
         end
+      rescue Errno::EACCES
+        # Ignore permission denied against system-installed plugins; regular
+        # users are not supposed to write there.
+        raise unless @system
       end
 
       protected
diff --git a/lib/vagrant/shared_helpers.rb b/lib/vagrant/shared_helpers.rb
index 7b0b87c..eb9a21e 100644
--- a/lib/vagrant/shared_helpers.rb
+++ b/lib/vagrant/shared_helpers.rb
@@ -43,6 +43,14 @@ module Vagrant
       !defined?(::Bundler).nil?
   end
 
+  # This returns a true/false if we are running from a Guix package
+  #
+  # @return [Boolean]
+  def self.in_guix_package?
+    # FIXME write a proper check if this ever goes upstream
+    true
+  end
+
   # Returns the path to the embedded directory of the Vagrant installer,
   # if there is one (if we're running in an installer).
   #
-- 
2.30.9


debug log:

solving 3d57993921 ...
found 3d57993921 in https://yhetil.org/guix/ce5dd68ceec0db51cd2dcf06b6f4b0db9e801b92.1691432343.git.h.goebel@crazy-compilers.com/

applying [1/1] https://yhetil.org/guix/ce5dd68ceec0db51cd2dcf06b6f4b0db9e801b92.1691432343.git.h.goebel@crazy-compilers.com/
diff --git a/gnu/packages/patches/vagrant-Support-system-installed-plugins.patch b/gnu/packages/patches/vagrant-Support-system-installed-plugins.patch
new file mode 100644
index 0000000000..3d57993921

1:45: trailing whitespace.
 
1:82: trailing whitespace.
 
1:91: trailing whitespace.
 
1:96: trailing whitespace.
 
1:106: trailing whitespace.
 
Checking patch gnu/packages/patches/vagrant-Support-system-installed-plugins.patch...
Applied patch gnu/packages/patches/vagrant-Support-system-installed-plugins.patch cleanly.
warning: squelched 6 whitespace errors
warning: 11 lines add whitespace errors.

index at:
100644 3d57993921dc57900e40ae051cabf556f205c193	gnu/packages/patches/vagrant-Support-system-installed-plugins.patch

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.