Module: VagrantPlugins::Nixos

Defined in:
lib/vagrant-nixos.rb,
lib/vagrant-nixos/util.rb,
lib/vagrant-nixos/guest.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

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

.rebuild(machine, nix_env = nil) ⇒ 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
62
63
64
65
# File 'lib/vagrant-nixos/util.rb', line 30

def self.rebuild(machine, nix_env=nil)
	# 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
	conf_paths = if @@imports[machine.id].nil?
		[]
	else
		@@imports[machine.id].keys.inject([]) do |paths, filename|
			paths << "./#{filename}"
		end
	end
	conf_paths << "./vagrant-provision.nix"
	# construct the nix module
	conf << %{
		imports = [
			#{conf_paths.join("\n\t\t")}
		];
	}
	# default NIX_PATH
	if nix_env
		conf << %{
			config.environment.shellInit = ''
				export NIX_PATH=#{nix_env}:$NIX_PATH
			'';
		}
	end
	conf << "}"
	# output / build the config
	_write_config(machine, "vagrant.nix", conf)
	rebuild!(machine, nix_env)
end

.rebuild!(machine, nix_env = nil) ⇒ Object

just do nixos-rebuild



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/vagrant-nixos/util.rb', line 68

def self.rebuild!(machine, nix_env=nil)
	# 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 = "NIX_PATH=#{nix_env}:$NIX_PATH #{rebuild_cmd}" if nix_env
	machine.communicate.tap do |comm|
		comm.sudo(rebuild_cmd)
	end
end

.same?(machine, f1, f2) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/vagrant-nixos/util.rb', line 81

def self.same?(machine, f1, f2)
	machine.communicate.test("cmp --silent #{f1} #{f2}")
end

.source_rootObject

This returns the path to the source of this plugin.



13
14
15
# File 'lib/vagrant-nixos.rb', line 13

def self.source_root
	@source_root ||= Pathname.new(File.expand_path("../../../", __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

#importsObject



26
27
# File 'lib/vagrant-nixos/util.rb', line 26

def imports
end