Module: VagrantPlugins::Nixos
- Defined in:
- lib/vagrant-nixos/util.rb,
lib/vagrant-nixos/guest.rb,
lib/vagrant-nixos-plugin.rb,
lib/vagrant-nixos/config.rb,
lib/vagrant-nixos/plugin.rb,
lib/vagrant-nixos/version.rb,
lib/vagrant-nixos/provisioner.rb,
lib/vagrant-nixos/cap/change_host_name.rb,
lib/vagrant-nixos/cap/configure_networks.rb
Defined Under Namespace
Modules: Cap Classes: Config, Guest, NixosConfigError, Plugin, Provisioner
Constant Summary collapse
- VERSION =
"0.0.6"- @@imports =
Not sure if this is legit. But We’ll use this module to store the state of the nix configuration and handle sending it to the machine.
{}
- @@nix_imports =
{}
Class Method Summary collapse
-
.include_config(machine, filename) ⇒ Object
mark a file that should be imported to the main config.
-
.prepare(machine, config) ⇒ Object
rebuild the base vagrant.nix configuration.
-
.rebuild!(machine, config) ⇒ Object
just do nixos-rebuild.
- .same?(machine, f1, f2) ⇒ Boolean
-
.source_root ⇒ Object
This returns the path to the source of this plugin.
-
.write_config(machine, filename, conf) ⇒ Object
Send file to machine and report if it changed See _write_config.
Instance Method Summary collapse
Class Method Details
.include_config(machine, filename) ⇒ Object
mark a file that should be imported to the main config
19 20 21 22 23 24 |
# File 'lib/vagrant-nixos/util.rb', line 19 def self.include_config(machine, filename) if @@imports[machine.id].nil? @@imports[machine.id] = {} end @@imports[machine.id][filename] = true end |
.prepare(machine, config) ⇒ Object
rebuild the base vagrant.nix configuration
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 |
# File 'lib/vagrant-nixos/util.rb', line 30 def self.prepare(machine, config) # build conf = "{ config, pkgs, ... }:\n{" # Add a mock provision file if it is missing as during boot the # provisioning file may not be deployed yet. if !machine.communicate.test("test -f /etc/nixos/vagrant-provision.nix") _write_config(machine, "vagrant-provision.nix", "{ config, pkgs, ... }: {}") end # imports include_config(machine, 'vagrant-provision.nix') conf_paths = @@imports[machine.id].keys.inject([]) do |paths, filename| paths << "./#{filename}" end # construct the nix module conf << %{ imports = [ #{conf_paths.join("\n\t\t")} ]; } # default NIX_PATH if config.NIX_PATH conf << %{ config.environment.shellInit = '' export NIX_PATH=#{config.NIX_PATH}:$NIX_PATH ''; } end conf << "}" # output / build the config _write_config(machine, "vagrant.nix", conf) end |
.rebuild!(machine, config) ⇒ Object
just do nixos-rebuild
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 |
# File 'lib/vagrant-nixos/util.rb', line 64 def self.rebuild!(machine, config) self.prepare(machine, config) # Add a tmp vagreant.nix file if it is missing if !machine.communicate.test("grep 'provision' </etc/nixos/vagrant.nix") _write_config(machine, "vagrant.nix", %{{ config, pkgs, ... }: { imports = [ ./vagrant-provision.nix ];}}) end # rebuild rebuild_cmd = "nixos-rebuild switch" rebuild_cmd = "#{rebuild_cmd} -I nixos-config=/etc/nixos/vagrant.nix" if config.include rebuild_cmd = "NIX_PATH=#{config.NIX_PATH}:$NIX_PATH #{rebuild_cmd}" if config.NIX_PATH machine.communicate.tap do |comm| comm.execute(rebuild_cmd, sudo: true) do |type, data| if [:stderr, :stdout].include?(type) # Output the data with the proper color based on the stream. color = type == :stdout ? :green : :red = { new_line: false, prefix: false, } [:color] = color machine.env.ui.info(data, ) if config.verbose end end end end |
.same?(machine, f1, f2) ⇒ Boolean
93 94 95 |
# File 'lib/vagrant-nixos/util.rb', line 93 def self.same?(machine, f1, f2) machine.communicate.test("cmp --silent #{f1} #{f2}") end |
.source_root ⇒ Object
This returns the path to the source of this plugin.
13 14 15 |
# File 'lib/vagrant-nixos-plugin.rb', line 13 def self.source_root @source_root ||= Pathname.new(File.("../../../", __FILE__)) end |
.write_config(machine, filename, conf) ⇒ Object
Send file to machine and report if it changed See _write_config
13 14 15 16 |
# File 'lib/vagrant-nixos/util.rb', line 13 def self.write_config(machine, filename, conf) include_config(machine, filename) _write_config(machine, filename, conf) end |
Instance Method Details
#imports ⇒ Object
26 27 |
# File 'lib/vagrant-nixos/util.rb', line 26 def imports end |