vagrant-nixos-plugin 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +111 -0
- data/Rakefile +3 -0
- data/lib/vagrant-nixos-plugin.rb +17 -0
- data/lib/vagrant-nixos/cap/change_host_name.rb +30 -0
- data/lib/vagrant-nixos/cap/configure_networks.rb +56 -0
- data/lib/vagrant-nixos/config.rb +51 -0
- data/lib/vagrant-nixos/guest.rb +13 -0
- data/lib/vagrant-nixos/nix.rb +94 -0
- data/lib/vagrant-nixos/plugin.rb +52 -0
- data/lib/vagrant-nixos/provisioner.rb +27 -0
- data/lib/vagrant-nixos/util.rb +122 -0
- data/lib/vagrant-nixos/version.rb +5 -0
- data/vagrant-nixos-plugin.gemspec +24 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c737e0645fac2818dd42a92841b641922710b899
|
4
|
+
data.tar.gz: 4b2af76eac1964a5faddad7e5f375e1d337668b6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7b11d262f33643617ac54812edb26f3be635fdf21f17c6bc782ea9f185a3520ab6541105c0dc0083391525775706a395ac4ae833d3d2cf8f9771be76970f269f
|
7
|
+
data.tar.gz: 435f35e02644364e68a5f95655fe549047d5e2e8845797d173547f58a32bfee174c3f045123955d7280886ece3c0773806e207255ff234807603b7bddd352886
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in vagrant-nixos.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :development do
|
7
|
+
# We depend on Vagrant for development, but we don't add it as a
|
8
|
+
# gem dependency because we expect to be installed within the
|
9
|
+
# Vagrant environment itself using `vagrant plugin`.
|
10
|
+
gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git"
|
11
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Chris Farmiloe
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
# NixOS Vagrant Plugin
|
2
|
+
|
3
|
+
This plugin makes working with [NixOS](http://nixos.org) guests in [Vagrant](http://www.vagrantup.com) a bit nicer:
|
4
|
+
|
5
|
+
* Allow network configurations
|
6
|
+
* Allow hostname setting
|
7
|
+
* Provide nix provisioning
|
8
|
+
|
9
|
+
## Install:
|
10
|
+
|
11
|
+
NOTE: this project is a fork of the `vagrant-nixos` gem. Both can't be
|
12
|
+
installed at the same time.
|
13
|
+
|
14
|
+
```bash
|
15
|
+
$ vagrant plugin install vagrant-nixos-plugin
|
16
|
+
```
|
17
|
+
|
18
|
+
## Example Vagrantfile
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
Vagrant.configure("2") do |config|
|
22
|
+
|
23
|
+
# use a suitable NixOS base
|
24
|
+
# http://github.com/oxdi/nixos
|
25
|
+
config.vm.box = "nixos-14.02-x86_64"
|
26
|
+
config.vm.box_url = "http://s3.amazonaws.com/oxdi/nixos-14.02-x86_64-virtualbox.box"
|
27
|
+
|
28
|
+
# set hostname
|
29
|
+
config.vm.hostname = "nixy"
|
30
|
+
|
31
|
+
# Setup networking
|
32
|
+
config.vm.network "private_network", :ip => "172.16.16.16"
|
33
|
+
|
34
|
+
# Add the htop package
|
35
|
+
config.vm.provision :nixos, :expression => {
|
36
|
+
environment: {
|
37
|
+
systemPackages: [ :htop ]
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
In the above `Vagrantfile` example we provision the box using the `:expression` method, which will perform a simple ruby -> nix conversion. `:expression` provisioning creates a nix module that executes with `pkgs` in scope. It is roughly equivilent to the below version that uses the `:inline` method.
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
config.vm.provision :nixos, :inline => %{
|
48
|
+
{config, pkgs, ...}: with pkgs; {
|
49
|
+
environment.systemPackages = [ htop ];
|
50
|
+
}
|
51
|
+
}, :NIX_PATH => "/custom/path/to/nixpkgs"
|
52
|
+
```
|
53
|
+
|
54
|
+
The above example also shows the optional setting of a custom `NIX_PATH` path.
|
55
|
+
|
56
|
+
You can also use an external nix configuration file:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
config.vm.provision :nixos, :path => “configuration.nix”
|
60
|
+
```
|
61
|
+
|
62
|
+
If you need provisioning to be included explicitly during rebuild use:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
config.vm.provision :nixos,
|
66
|
+
:path => “configuration.nix”,
|
67
|
+
:include => true
|
68
|
+
```
|
69
|
+
|
70
|
+
You can enable verbose provision output during rebuild process with:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
config.vm.provision :nixos,
|
74
|
+
:path => “configuration.nix”,
|
75
|
+
:verbose => true
|
76
|
+
```
|
77
|
+
|
78
|
+
If you need to use functions or access values using dot syntax you can use the `Nix` module:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
config.vm.provision :nixos, :expression => {
|
82
|
+
services: {
|
83
|
+
postgresql: {
|
84
|
+
enable: true,
|
85
|
+
package: Nix.pkgs.postgresql93,
|
86
|
+
enableTCPIP: true,
|
87
|
+
authentication: Nix.lib.mkForce(%{
|
88
|
+
local all all trust
|
89
|
+
host all all 127.0.0.1/32 trust
|
90
|
+
}),
|
91
|
+
initialScript: "/etc/nixos/postgres.sql"
|
92
|
+
}
|
93
|
+
}
|
94
|
+
}
|
95
|
+
```
|
96
|
+
|
97
|
+
|
98
|
+
## How it works
|
99
|
+
|
100
|
+
In nixos we don't mess around with the files in `/etc` instead we write expressions for the system configuration starting in `/etc/nixos/configuration.nix`.
|
101
|
+
|
102
|
+
This plugin sets some ground rules for nixos boxes to keep this configuration clean and provisioning possible.
|
103
|
+
|
104
|
+
Box creators should ensure that their `configuration.nix` file imports an nix module `/etc/nixos/vagrant.nix` which will be overwritten by `vagrant-nixos-plugin` during `vagrant up` or `vagrant provision`.
|
105
|
+
|
106
|
+
See the configuration in our [NixOS packer template](http://github.com/oxdi/nixos) for an example.
|
107
|
+
|
108
|
+
## Issues
|
109
|
+
|
110
|
+
It's a bit slow on the initial boot/provision at the moment as it must run nixos-rebuild several times. This is far from ideal I'm sure I'll find a better place to hook in the rebuild step soon.
|
111
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "vagrant-nixos/version"
|
2
|
+
require "vagrant-nixos/plugin"
|
3
|
+
require "vagrant-nixos/util"
|
4
|
+
require "vagrant-nixos/nix"
|
5
|
+
|
6
|
+
module VagrantPlugins
|
7
|
+
module Nixos
|
8
|
+
lib_path = Pathname.new(File.expand_path("../nixos", __FILE__))
|
9
|
+
autoload :Action, lib_path.join("action")
|
10
|
+
autoload :Errors, lib_path.join("errors")
|
11
|
+
|
12
|
+
# This returns the path to the source of this plugin.
|
13
|
+
def self.source_root
|
14
|
+
@source_root ||= Pathname.new(File.expand_path("../../../", __FILE__))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'set'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module Nixos
|
7
|
+
module Cap
|
8
|
+
class ChangeHostName
|
9
|
+
include Vagrant::Util
|
10
|
+
|
11
|
+
def self.nix_module(name)
|
12
|
+
<<-NIX
|
13
|
+
{ config, pkgs, ... }:
|
14
|
+
{
|
15
|
+
networking.hostName = "#{name}";
|
16
|
+
}
|
17
|
+
NIX
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.change_host_name(machine, name)
|
21
|
+
if Nixos.write_config(machine, "vagrant-hostname.nix", nix_module(name))
|
22
|
+
machine.env[:ui].info "Change host name to #{name}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'set'
|
2
|
+
require 'tempfile'
|
3
|
+
require 'netaddr'
|
4
|
+
|
5
|
+
require "vagrant/util/template_renderer"
|
6
|
+
|
7
|
+
module VagrantPlugins
|
8
|
+
module Nixos
|
9
|
+
module Cap
|
10
|
+
class ConfigureNetworks
|
11
|
+
include Vagrant::Util
|
12
|
+
|
13
|
+
def self.nix_interface_expr(options)
|
14
|
+
addr = NetAddr::CIDR.create("#{options[:ip]} #{options[:netmask]}")
|
15
|
+
prefix_length = addr.netmask[1, addr.netmask.size]
|
16
|
+
<<-NIX
|
17
|
+
{
|
18
|
+
name = "eth#{options[:interface]}";
|
19
|
+
ipAddress = "#{options[:ip]}";
|
20
|
+
prefixLength = #{prefix_length};
|
21
|
+
}
|
22
|
+
NIX
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.nix_module(networks)
|
26
|
+
exprs = networks.inject([]) do |exprs, network|
|
27
|
+
# Interfaces without an ip set will fallback to
|
28
|
+
# DHCP if useDHCP is set. So skip them.
|
29
|
+
if network[:ip].nil? or network[:ip].empty?
|
30
|
+
exprs
|
31
|
+
else
|
32
|
+
exprs << nix_interface_expr(network)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
<<-NIX
|
36
|
+
{ config, pkgs, ... }:
|
37
|
+
{
|
38
|
+
networking.usePredictableInterfaceNames = false;
|
39
|
+
networking.useDHCP = true;
|
40
|
+
networking.interfaces = [
|
41
|
+
#{exprs.join("\n")}
|
42
|
+
];
|
43
|
+
}
|
44
|
+
NIX
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.configure_networks(machine, networks)
|
48
|
+
if Nixos.write_config(machine, "vagrant-interfaces.nix", nix_module(networks))
|
49
|
+
machine.env.ui.info "Setting up network interfaces #{networks}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Nixos
|
3
|
+
class Config < Vagrant.plugin("2", :config)
|
4
|
+
attr_accessor :inline
|
5
|
+
attr_accessor :path
|
6
|
+
attr_accessor :expression
|
7
|
+
attr_accessor :include
|
8
|
+
attr_accessor :verbose
|
9
|
+
attr_accessor :NIX_PATH
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@inline = UNSET_VALUE
|
13
|
+
@path = UNSET_VALUE
|
14
|
+
@expression = UNSET_VALUE
|
15
|
+
@include = UNSET_VALUE
|
16
|
+
@verbose = UNSET_VALUE
|
17
|
+
@NIX_PATH = UNSET_VALUE
|
18
|
+
end
|
19
|
+
|
20
|
+
def finalize!
|
21
|
+
@inline = nil if @inline == UNSET_VALUE
|
22
|
+
@path = nil if @path == UNSET_VALUE
|
23
|
+
@expression = nil if @expression == UNSET_VALUE
|
24
|
+
@include = nil if @include == UNSET_VALUE
|
25
|
+
@verbose = nil if @verbose == UNSET_VALUE
|
26
|
+
@NIX_PATH = nil if @NIX_PATH == UNSET_VALUE
|
27
|
+
end
|
28
|
+
|
29
|
+
def expression=(v)
|
30
|
+
@expression = v.to_nix
|
31
|
+
end
|
32
|
+
|
33
|
+
def validate(machine)
|
34
|
+
errors = _detected_errors
|
35
|
+
|
36
|
+
if (path && inline) or (path && expression) or (inline && expression)
|
37
|
+
errors << "You can have one and only one of :path, :expression or :inline for nixos provisioner"
|
38
|
+
elsif !path && !inline && !expression
|
39
|
+
errors << "Missing :inline, :expression or :path for nixos provisioner"
|
40
|
+
end
|
41
|
+
|
42
|
+
if path && !File.exist?(path)
|
43
|
+
errors << "Invalid path #{path}"
|
44
|
+
end
|
45
|
+
|
46
|
+
{ "nixos provisioner" => errors }
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
#################################################
|
2
|
+
# Naughty extending of builtins.
|
3
|
+
# Add to_nix functions to convert ruby2nix (ish).
|
4
|
+
#################################################
|
5
|
+
|
6
|
+
module Nix
|
7
|
+
INDENT_STRING=" "
|
8
|
+
|
9
|
+
def self.method_missing(m, *args, &block)
|
10
|
+
NixBuilder.new(nil, m.to_sym, *args)
|
11
|
+
end
|
12
|
+
|
13
|
+
class NixBuilder
|
14
|
+
|
15
|
+
attr_accessor :exprs
|
16
|
+
attr_accessor :parent
|
17
|
+
|
18
|
+
def initialize(parent, expr, *args)
|
19
|
+
@parent = parent
|
20
|
+
@exprs = args.inject([expr]){|exs, e| exs << e}
|
21
|
+
end
|
22
|
+
|
23
|
+
def method_missing(m, *args, &block)
|
24
|
+
NixBuilder.new(self, m.to_sym, *args)
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_nix(indent = 0)
|
28
|
+
s = ""
|
29
|
+
s << "(" if @exprs[0] == :import
|
30
|
+
if @parent
|
31
|
+
s = @parent.to_nix << "."
|
32
|
+
end
|
33
|
+
s << @exprs.map{|e| e.to_nix}.join(" ")
|
34
|
+
s << ")" if @exprs[0] == :import
|
35
|
+
s
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class Symbol
|
41
|
+
def to_nix(indent = 0)
|
42
|
+
to_s
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class NilClass
|
47
|
+
def to_nix(indent = 0)
|
48
|
+
"null"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class Hash
|
53
|
+
def to_nix(indent = 0)
|
54
|
+
"{\n" +
|
55
|
+
sort {|a, b| a[0].to_s <=> b[0].to_s}.map do |key, value|
|
56
|
+
raise "Key must be a Symbol, not #{key.class}" unless key.is_a?(Symbol)
|
57
|
+
Nix::INDENT_STRING * (indent + 1)+ key.to_nix +
|
58
|
+
" = " + value.to_nix(indent + 1) + ";"
|
59
|
+
end.join("\n") + "\n" +
|
60
|
+
Nix::INDENT_STRING * indent + "}"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class Array
|
65
|
+
def to_nix(indent = 0)
|
66
|
+
"[ " + map(&:to_nix).join(" ") + " ]"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class String
|
71
|
+
def to_nix(indent = 0)
|
72
|
+
return self if self.slice(0,2) == "./"
|
73
|
+
return %{''#{self}''} if self =~ /\n/
|
74
|
+
%{"#{self}"}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
class Fixnum
|
79
|
+
def to_nix(indent = 0)
|
80
|
+
to_s
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class TrueClass
|
85
|
+
def to_nix(indent = 0)
|
86
|
+
to_s
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
class FalseClass
|
91
|
+
def to_nix(indent = 0)
|
92
|
+
to_s
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
begin
|
2
|
+
require "vagrant"
|
3
|
+
rescue LoadError
|
4
|
+
raise "The Nixos plugin must be run within Vagrant."
|
5
|
+
end
|
6
|
+
|
7
|
+
# This is a sanity check to make sure no one is attempting to install
|
8
|
+
# this into an early Vagrant version.
|
9
|
+
if Vagrant::VERSION < "1.2.0"
|
10
|
+
raise "The Nixos plugin is only compatible with Vagrant 1.2+"
|
11
|
+
end
|
12
|
+
|
13
|
+
module VagrantPlugins
|
14
|
+
module Nixos
|
15
|
+
|
16
|
+
@@nix_imports = {}
|
17
|
+
|
18
|
+
class Plugin < Vagrant.plugin("2")
|
19
|
+
name "nixos"
|
20
|
+
description <<-DESC
|
21
|
+
This plugin installs nixos guest capabilities.
|
22
|
+
DESC
|
23
|
+
|
24
|
+
guest("nixos", "linux") do
|
25
|
+
require_relative "guest"
|
26
|
+
Guest
|
27
|
+
end
|
28
|
+
|
29
|
+
guest_capability("nixos", "configure_networks") do
|
30
|
+
require_relative "cap/configure_networks"
|
31
|
+
Cap::ConfigureNetworks
|
32
|
+
end
|
33
|
+
|
34
|
+
guest_capability("nixos", "change_host_name") do
|
35
|
+
require_relative "cap/change_host_name"
|
36
|
+
Cap::ChangeHostName
|
37
|
+
end
|
38
|
+
|
39
|
+
config :nixos, :provisioner do
|
40
|
+
require_relative "config"
|
41
|
+
Config
|
42
|
+
end
|
43
|
+
|
44
|
+
provisioner :nixos do
|
45
|
+
require_relative "provisioner"
|
46
|
+
Provisioner
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Nixos
|
3
|
+
class NixosConfigError < Vagrant::Errors::VagrantError
|
4
|
+
end
|
5
|
+
|
6
|
+
class Provisioner < Vagrant.plugin("2", :provisioner)
|
7
|
+
# This is the method called when the actual provisioning should be
|
8
|
+
# done. The communicator is guaranteed to be ready at this point,
|
9
|
+
# and any shared folders or networks are already setup.
|
10
|
+
#
|
11
|
+
# No return value is expected.
|
12
|
+
def provision
|
13
|
+
conf = if @config.inline
|
14
|
+
@config.inline
|
15
|
+
elsif @config.path
|
16
|
+
File.read(@config.path)
|
17
|
+
elsif @config.expression
|
18
|
+
"{config, pkgs, ...}: with pkgs; #{@config.expression}"
|
19
|
+
else
|
20
|
+
raise NixosConfigError, "Mising :path, :inline or :expression"
|
21
|
+
end
|
22
|
+
Nixos.write_config(machine, "vagrant-provision.nix", conf)
|
23
|
+
Nixos.rebuild!(machine, @config)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Nixos
|
3
|
+
##############################################
|
4
|
+
# Not sure if this is legit. But We'll use this module
|
5
|
+
# to store the state of the nix configuration and handle
|
6
|
+
# sending it to the machine.
|
7
|
+
#############################################
|
8
|
+
|
9
|
+
@@imports = {}
|
10
|
+
|
11
|
+
# Send file to machine and report if it changed
|
12
|
+
# See _write_config
|
13
|
+
def self.write_config(machine, filename, conf)
|
14
|
+
include_config(machine, filename)
|
15
|
+
_write_config(machine, filename, conf)
|
16
|
+
end
|
17
|
+
|
18
|
+
# mark a file that should be imported to the main config
|
19
|
+
def self.include_config(machine, filename)
|
20
|
+
if @@imports[machine.id].nil?
|
21
|
+
@@imports[machine.id] = {}
|
22
|
+
end
|
23
|
+
@@imports[machine.id][filename] = true
|
24
|
+
end
|
25
|
+
|
26
|
+
def imports
|
27
|
+
end
|
28
|
+
|
29
|
+
# rebuild the base vagrant.nix configuration
|
30
|
+
def self.prepare(machine, config)
|
31
|
+
# build
|
32
|
+
conf = "{ config, pkgs, ... }:\n{"
|
33
|
+
# Add a mock provision file if it is missing as during boot the
|
34
|
+
# provisioning file may not be deployed yet.
|
35
|
+
if !machine.communicate.test("test -f /etc/nixos/vagrant-provision.nix")
|
36
|
+
_write_config(machine, "vagrant-provision.nix", "{ config, pkgs, ... }: {}")
|
37
|
+
end
|
38
|
+
# imports
|
39
|
+
include_config(machine, 'vagrant-provision.nix')
|
40
|
+
conf_paths =
|
41
|
+
@@imports[machine.id].keys.inject([]) do |paths, filename|
|
42
|
+
paths << "./#{filename}"
|
43
|
+
end
|
44
|
+
# construct the nix module
|
45
|
+
conf << %{
|
46
|
+
imports = [
|
47
|
+
#{conf_paths.join("\n\t\t")}
|
48
|
+
];
|
49
|
+
}
|
50
|
+
# default NIX_PATH
|
51
|
+
if config.NIX_PATH
|
52
|
+
conf << %{
|
53
|
+
config.environment.shellInit = ''
|
54
|
+
export NIX_PATH=#{config.NIX_PATH}:$NIX_PATH
|
55
|
+
'';
|
56
|
+
}
|
57
|
+
end
|
58
|
+
conf << "}"
|
59
|
+
# output / build the config
|
60
|
+
_write_config(machine, "vagrant.nix", conf)
|
61
|
+
end
|
62
|
+
|
63
|
+
# just do nixos-rebuild
|
64
|
+
def self.rebuild!(machine, config)
|
65
|
+
self.prepare(machine, config)
|
66
|
+
# Add a tmp vagreant.nix file if it is missing
|
67
|
+
if !machine.communicate.test("grep 'provision' </etc/nixos/vagrant.nix")
|
68
|
+
_write_config(machine, "vagrant.nix", %{{ config, pkgs, ... }: { imports = [ ./vagrant-provision.nix ];}})
|
69
|
+
end
|
70
|
+
# rebuild
|
71
|
+
rebuild_cmd = "nixos-rebuild switch"
|
72
|
+
rebuild_cmd = "#{rebuild_cmd} -I nixos-config=/etc/nixos/vagrant.nix" if config.include
|
73
|
+
rebuild_cmd = "NIX_PATH=#{config.NIX_PATH}:$NIX_PATH #{rebuild_cmd}" if config.NIX_PATH
|
74
|
+
|
75
|
+
machine.communicate.tap do |comm|
|
76
|
+
comm.execute(rebuild_cmd, sudo: true) do |type, data|
|
77
|
+
if [:stderr, :stdout].include?(type)
|
78
|
+
# Output the data with the proper color based on the stream.
|
79
|
+
color = type == :stdout ? :green : :red
|
80
|
+
|
81
|
+
options = {
|
82
|
+
new_line: false,
|
83
|
+
prefix: false,
|
84
|
+
}
|
85
|
+
options[:color] = color
|
86
|
+
|
87
|
+
machine.env.ui.info(data, options) if config.verbose
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.same?(machine, f1, f2)
|
94
|
+
machine.communicate.test("cmp --silent #{f1} #{f2}")
|
95
|
+
end
|
96
|
+
|
97
|
+
protected
|
98
|
+
|
99
|
+
# Send file to machine.
|
100
|
+
# Returns true if the uploaded file if different from any
|
101
|
+
# preexisting file, false if the file is indentical
|
102
|
+
def self._write_config(machine, filename, conf)
|
103
|
+
temp = Tempfile.new("vagrant")
|
104
|
+
temp.binmode
|
105
|
+
temp.write(conf)
|
106
|
+
temp.close
|
107
|
+
changed = true
|
108
|
+
machine.communicate.tap do |comm|
|
109
|
+
source = "/tmp/#{filename}"
|
110
|
+
target = "/etc/nixos/#{filename}"
|
111
|
+
comm.upload(temp.path, source)
|
112
|
+
if same?(machine, source, target)
|
113
|
+
changed = false
|
114
|
+
else
|
115
|
+
comm.sudo("mv #{source} #{target}")
|
116
|
+
end
|
117
|
+
end
|
118
|
+
return changed
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'vagrant-nixos/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "vagrant-nixos-plugin"
|
8
|
+
spec.version = VagrantPlugins::Nixos::VERSION
|
9
|
+
spec.authors = ["Chris Farmiloe"]
|
10
|
+
spec.email = ["chrisfarms@gmail.com"]
|
11
|
+
spec.summary = %q{Guest capabilities and nix provisioning for NixOS}
|
12
|
+
spec.description = %q{Add capabilities and basic nix configuration provisioning for NixOS guests in Vagrant}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_dependency "netaddr"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-nixos-plugin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Farmiloe
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: netaddr
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Add capabilities and basic nix configuration provisioning for NixOS guests
|
56
|
+
in Vagrant
|
57
|
+
email:
|
58
|
+
- chrisfarms@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/vagrant-nixos-plugin.rb
|
69
|
+
- lib/vagrant-nixos/cap/change_host_name.rb
|
70
|
+
- lib/vagrant-nixos/cap/configure_networks.rb
|
71
|
+
- lib/vagrant-nixos/config.rb
|
72
|
+
- lib/vagrant-nixos/guest.rb
|
73
|
+
- lib/vagrant-nixos/nix.rb
|
74
|
+
- lib/vagrant-nixos/plugin.rb
|
75
|
+
- lib/vagrant-nixos/provisioner.rb
|
76
|
+
- lib/vagrant-nixos/util.rb
|
77
|
+
- lib/vagrant-nixos/version.rb
|
78
|
+
- vagrant-nixos-plugin.gemspec
|
79
|
+
homepage: ''
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.0.14
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Guest capabilities and nix provisioning for NixOS
|
103
|
+
test_files: []
|