vagrant-nixos-plugin 0.0.6 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.md +21 -0
- data/LICENSE.txt +1 -1
- data/README.md +70 -52
- data/lib/vagrant-nixos-plugin.rb +3 -17
- data/lib/vagrant-nixos/config.rb +76 -49
- data/lib/vagrant-nixos/nix.rb +57 -57
- data/lib/vagrant-nixos/plugin.rb +22 -37
- data/lib/vagrant-nixos/provisioner.rb +103 -25
- data/lib/vagrant-nixos/version.rb +3 -3
- data/vagrant-nixos-plugin.gemspec +5 -6
- metadata +8 -24
- data/lib/vagrant-nixos/cap/change_host_name.rb +0 -30
- data/lib/vagrant-nixos/cap/configure_networks.rb +0 -56
- data/lib/vagrant-nixos/guest.rb +0 -13
- data/lib/vagrant-nixos/util.rb +0 -122
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c911867561067b8671b40f4b276be48f34cb9370
|
4
|
+
data.tar.gz: 226ab372bd8459b6bc873ab2b6c468d530598895
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c27a65d2dd4fd2c4c109854ca62bb4d359b54e536648be0deb5ef4ae4a3ee102a251ebf0b414d30480cb7868e749be4336e1108d90771d448dfba664ced096d
|
7
|
+
data.tar.gz: a7ffeadd3f6495e5bc8caf29ce45d710e2614407d5c66bdcdb03d499a8d182506006c2364fcd87c9ba0bc521560d0495417c8be24e3e8392e4985d8d56de5cc0
|
data/History.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
0.1.1 / 2015-10-18
|
3
|
+
==================
|
4
|
+
|
5
|
+
Previous release was a bit hasty
|
6
|
+
|
7
|
+
* Misc cleanup and fixes
|
8
|
+
|
9
|
+
0.1.0 / 2015-10-18
|
10
|
+
==================
|
11
|
+
|
12
|
+
Big refactor / fork of the vagrant-nixos plugin.
|
13
|
+
|
14
|
+
Vagrant 1.6.4+ has capabilities to setup the hostname and networking by
|
15
|
+
writing to /etc/nixos/vagrant-hostname.nix and
|
16
|
+
/etc/nixos/vagrant-networking.nix respectively but doesn't run
|
17
|
+
`nixos-rebuild switch`.
|
18
|
+
|
19
|
+
This is a complementary plugin that just takes care of the provisioning. All
|
20
|
+
of the nice Nix+ruby DLS is from the original plugin.
|
21
|
+
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
# NixOS Vagrant Plugin
|
2
2
|
|
3
|
-
This plugin
|
3
|
+
This plugin adds nix provisioning for [NixOS](http://nixos.org) guests to
|
4
|
+
[Vagrant](http://www.vagrantup.com).
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
Vagrant 1.6.4+ itself already provides capabilities to change the hostname and
|
7
|
+
networking settings by generating `/etc/nixos/vagrant-{network,hostname}.nix`
|
8
|
+
files but then doesn't invoke `nixos-rebuild switch`.
|
9
|
+
|
10
|
+
This plugin takes care of that, plus gives different ways for the user to
|
11
|
+
configure the VM using a special DSL.
|
8
12
|
|
9
13
|
## Install:
|
10
14
|
|
@@ -20,35 +24,40 @@ $ vagrant plugin install vagrant-nixos-plugin
|
|
20
24
|
```ruby
|
21
25
|
Vagrant.configure("2") do |config|
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
}
|
27
|
+
# Use a suitable NixOS base. VM built with nixbox are tested to work with
|
28
|
+
# this plugin.
|
29
|
+
config.vm.box = "zimbatm/nixos-15.09-x86_64"
|
30
|
+
|
31
|
+
# set hostname
|
32
|
+
config.vm.hostname = "nixy"
|
33
|
+
|
34
|
+
# Setup networking
|
35
|
+
config.vm.network "private_network", ip: "172.16.16.16"
|
36
|
+
|
37
|
+
# Add the htop package
|
38
|
+
config.vm.provision :nixos, expression: {
|
39
|
+
environment: {
|
40
|
+
systemPackages: [ :htop ]
|
41
|
+
}
|
42
|
+
}
|
40
43
|
|
41
44
|
end
|
42
45
|
```
|
43
46
|
|
44
|
-
In the above `Vagrantfile` example we provision the box using the
|
47
|
+
In the above `Vagrantfile` example we provision the box using the
|
48
|
+
`:expression` method, which will perform a simple ruby -> nix conversion.
|
49
|
+
`:expression` provisioning creates a nix module that executes with `pkgs` in
|
50
|
+
scope. It is roughly equivilent to the below version that uses the `:inline`
|
51
|
+
method.
|
45
52
|
|
46
53
|
```ruby
|
47
|
-
config.vm.provision :nixos,
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
}
|
54
|
+
config.vm.provision :nixos,
|
55
|
+
inline: %{
|
56
|
+
{config, pkgs, ...}: with pkgs; {
|
57
|
+
environment.systemPackages = [ htop ];
|
58
|
+
}
|
59
|
+
},
|
60
|
+
NIX_PATH: "/custom/path/to/nixpkgs"
|
52
61
|
```
|
53
62
|
|
54
63
|
The above example also shows the optional setting of a custom `NIX_PATH` path.
|
@@ -56,56 +65,65 @@ The above example also shows the optional setting of a custom `NIX_PATH` path.
|
|
56
65
|
You can also use an external nix configuration file:
|
57
66
|
|
58
67
|
```ruby
|
59
|
-
config.vm.provision :nixos, :
|
68
|
+
config.vm.provision :nixos, path: "configuration.nix"
|
60
69
|
```
|
61
70
|
|
62
71
|
If you need provisioning to be included explicitly during rebuild use:
|
63
72
|
|
64
73
|
```ruby
|
65
74
|
config.vm.provision :nixos,
|
66
|
-
|
67
|
-
|
75
|
+
path: “configuration.nix”,
|
76
|
+
include: true
|
68
77
|
```
|
69
78
|
|
70
79
|
You can enable verbose provision output during rebuild process with:
|
71
80
|
|
72
81
|
```ruby
|
73
82
|
config.vm.provision :nixos,
|
74
|
-
|
75
|
-
|
83
|
+
path: “configuration.nix”,
|
84
|
+
verbose: true
|
76
85
|
```
|
77
86
|
|
78
|
-
If you need to use functions or access values using dot syntax you can use the
|
87
|
+
If you need to use functions or access values using dot syntax you can use the
|
88
|
+
`Nix` module:
|
79
89
|
|
80
90
|
```ruby
|
81
|
-
config.vm.provision :nixos, :
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
}
|
91
|
+
config.vm.provision :nixos, expression: {
|
92
|
+
services: {
|
93
|
+
postgresql: {
|
94
|
+
enable: true,
|
95
|
+
package: Nix.pkgs.postgresql93,
|
96
|
+
enableTCPIP: true,
|
97
|
+
authentication: Nix.lib.mkForce(%{
|
98
|
+
local all all trust
|
99
|
+
host all all 127.0.0.1/32 trust
|
100
|
+
}),
|
101
|
+
initialScript: "/etc/nixos/postgres.sql"
|
102
|
+
}
|
103
|
+
}
|
104
|
+
}
|
95
105
|
```
|
96
106
|
|
97
107
|
|
98
108
|
## How it works
|
99
109
|
|
100
|
-
In nixos we don't mess around with the files in `/etc` instead we write
|
110
|
+
In nixos we don't mess around with the files in `/etc` instead we write
|
111
|
+
expressions for the system configuration starting in
|
112
|
+
`/etc/nixos/configuration.nix`.
|
101
113
|
|
102
|
-
This plugin sets some ground rules for nixos boxes to keep this configuration
|
114
|
+
This plugin sets some ground rules for nixos boxes to keep this configuration
|
115
|
+
clean and provisioning possible.
|
103
116
|
|
104
|
-
Box creators should ensure that their `configuration.nix` file imports an nix
|
117
|
+
Box creators should ensure that their `configuration.nix` file imports an nix
|
118
|
+
module `/etc/nixos/vagrant.nix` which will be overwritten by
|
119
|
+
`vagrant-nixos-plugin` during `vagrant up` or `vagrant provision`.
|
105
120
|
|
106
|
-
See the configuration in our
|
121
|
+
See the configuration in our
|
122
|
+
[NixOS packer template](http://github.com/zimbatm/nixbox) for an example.
|
107
123
|
|
108
124
|
## Issues
|
109
125
|
|
110
|
-
It's a bit slow on the initial boot/provision at the moment as it must run
|
126
|
+
It's a bit slow on the initial boot/provision at the moment as it must run
|
127
|
+
nixos-rebuild several times. This is far from ideal I'm sure I'll find a
|
128
|
+
better place to hook in the rebuild step soon.
|
111
129
|
|
data/lib/vagrant-nixos-plugin.rb
CHANGED
@@ -1,17 +1,3 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
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
|
1
|
+
require 'vagrant-nixos/version'
|
2
|
+
require 'vagrant-nixos/plugin'
|
3
|
+
require 'vagrant-nixos/nix'
|
data/lib/vagrant-nixos/config.rb
CHANGED
@@ -1,51 +1,78 @@
|
|
1
1
|
module VagrantPlugins
|
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
|
-
|
2
|
+
module Nixos
|
3
|
+
class Config < Vagrant.plugin("2", :config)
|
4
|
+
# Some inline nix configuration data
|
5
|
+
# @return [String, nil]
|
6
|
+
attr_accessor :inline
|
7
|
+
|
8
|
+
# The path to some nix configuration file
|
9
|
+
# @return [String, nil]
|
10
|
+
attr_accessor :path
|
11
|
+
|
12
|
+
# Some inline ruby DSL that generates nix configuration data
|
13
|
+
# @return [Hash, nil]
|
14
|
+
attr_accessor :expression
|
15
|
+
|
16
|
+
# Include /etc/nixos/vagrant.nix in the build
|
17
|
+
# @return [true, false]
|
18
|
+
attr_accessor :include
|
19
|
+
|
20
|
+
# Show debug information during the build
|
21
|
+
# @return [true, false]
|
22
|
+
attr_accessor :verbose
|
23
|
+
|
24
|
+
# Override the default NIX_PATH
|
25
|
+
# @return [String, nil]
|
26
|
+
attr_accessor :NIX_PATH
|
27
|
+
|
28
|
+
# Configure which files to import in the vagrant.nix file
|
29
|
+
# @return [Array<String>]
|
30
|
+
attr_accessor :imports
|
31
|
+
|
32
|
+
def initialize
|
33
|
+
@inline = UNSET_VALUE
|
34
|
+
@path = UNSET_VALUE
|
35
|
+
@expression = UNSET_VALUE
|
36
|
+
@include = UNSET_VALUE
|
37
|
+
@verbose = UNSET_VALUE
|
38
|
+
@NIX_PATH = UNSET_VALUE
|
39
|
+
@imports = [
|
40
|
+
"./vagrant-network.nix",
|
41
|
+
"./vagrant-hostname.nix",
|
42
|
+
"./vagrant-provision.nix",
|
43
|
+
]
|
44
|
+
end
|
45
|
+
|
46
|
+
def finalize!
|
47
|
+
@inline = nil if @inline == UNSET_VALUE
|
48
|
+
@path = nil if @path == UNSET_VALUE
|
49
|
+
@expression = nil if @expression == UNSET_VALUE
|
50
|
+
@include = false if @include == UNSET_VALUE
|
51
|
+
@verbose = false if @verbose == UNSET_VALUE
|
52
|
+
@NIX_PATH = nil if @NIX_PATH == UNSET_VALUE
|
53
|
+
end
|
54
|
+
|
55
|
+
def expression=(v)
|
56
|
+
@expression = v.to_nix
|
57
|
+
end
|
58
|
+
|
59
|
+
def validate(machine)
|
60
|
+
errors = _detected_errors
|
61
|
+
|
62
|
+
if (path && inline) or (path && expression) or (inline && expression)
|
63
|
+
errors << "You can have one and only one of :path, :expression or :inline for nixos provisioner"
|
64
|
+
end
|
65
|
+
|
66
|
+
if path && !File.exist?(path)
|
67
|
+
errors << "Invalid path #{path}"
|
68
|
+
end
|
69
|
+
|
70
|
+
unless imports.is_a?(Array)
|
71
|
+
errors << "Expected imports to be an array of paths"
|
72
|
+
end
|
73
|
+
|
74
|
+
{ "nixos provisioner" => errors }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
51
78
|
end
|
data/lib/vagrant-nixos/nix.rb
CHANGED
@@ -4,91 +4,91 @@
|
|
4
4
|
#################################################
|
5
5
|
|
6
6
|
module Nix
|
7
|
-
|
7
|
+
INDENT_STRING=" "
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
def self.method_missing(m, *args, &block)
|
10
|
+
NixBuilder.new(nil, m.to_sym, *args)
|
11
|
+
end
|
12
12
|
|
13
|
-
|
13
|
+
class NixBuilder
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
attr_accessor :exprs
|
16
|
+
attr_accessor :parent
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
def initialize(parent, expr, *args)
|
19
|
+
@parent = parent
|
20
|
+
@exprs = args.inject([expr]){|exs, e| exs << e}
|
21
|
+
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
def method_missing(m, *args, &block)
|
24
|
+
NixBuilder.new(self, m.to_sym, *args)
|
25
|
+
end
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
38
|
end
|
39
39
|
|
40
40
|
class Symbol
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
def to_nix(indent = 0)
|
42
|
+
to_s
|
43
|
+
end
|
44
44
|
end
|
45
45
|
|
46
46
|
class NilClass
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
def to_nix(indent = 0)
|
48
|
+
"null"
|
49
|
+
end
|
50
50
|
end
|
51
51
|
|
52
52
|
class Hash
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
62
|
end
|
63
63
|
|
64
64
|
class Array
|
65
|
-
|
66
|
-
|
67
|
-
|
65
|
+
def to_nix(indent = 0)
|
66
|
+
"[ " + map(&:to_nix).join(" ") + " ]"
|
67
|
+
end
|
68
68
|
end
|
69
69
|
|
70
70
|
class String
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
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
76
|
end
|
77
77
|
|
78
78
|
class Fixnum
|
79
|
-
|
80
|
-
|
81
|
-
|
79
|
+
def to_nix(indent = 0)
|
80
|
+
to_s
|
81
|
+
end
|
82
82
|
end
|
83
83
|
|
84
84
|
class TrueClass
|
85
|
-
|
86
|
-
|
87
|
-
|
85
|
+
def to_nix(indent = 0)
|
86
|
+
to_s
|
87
|
+
end
|
88
88
|
end
|
89
89
|
|
90
90
|
class FalseClass
|
91
|
-
|
92
|
-
|
93
|
-
|
91
|
+
def to_nix(indent = 0)
|
92
|
+
to_s
|
93
|
+
end
|
94
94
|
end
|
data/lib/vagrant-nixos/plugin.rb
CHANGED
@@ -1,52 +1,37 @@
|
|
1
1
|
begin
|
2
|
-
|
2
|
+
require "vagrant"
|
3
3
|
rescue LoadError
|
4
|
-
|
4
|
+
raise "The Nixos plugin must be run within Vagrant."
|
5
5
|
end
|
6
6
|
|
7
7
|
# This is a sanity check to make sure no one is attempting to install
|
8
8
|
# this into an early Vagrant version.
|
9
|
-
if Vagrant::VERSION < "1.
|
10
|
-
|
9
|
+
if Vagrant::VERSION < "1.6.4"
|
10
|
+
raise "The Nixos plugin is only compatible with Vagrant 1.6.4+"
|
11
11
|
end
|
12
12
|
|
13
13
|
module VagrantPlugins
|
14
|
-
|
14
|
+
module Nixos
|
15
15
|
|
16
|
-
|
16
|
+
@@nix_imports = {}
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
class Plugin < Vagrant.plugin("2")
|
19
|
+
name "nixos"
|
20
|
+
description <<-DESC
|
21
|
+
This plugin add nixos provisioning capabilities.
|
22
|
+
DESC
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
config :nixos, :provisioner do
|
25
|
+
require_relative "config"
|
26
|
+
Config
|
27
|
+
end
|
28
|
+
|
29
|
+
provisioner :nixos do
|
30
|
+
require_relative "provisioner"
|
31
|
+
Provisioner
|
32
|
+
end
|
28
33
|
|
29
|
-
|
30
|
-
require_relative "cap/configure_networks"
|
31
|
-
Cap::ConfigureNetworks
|
32
|
-
end
|
34
|
+
end
|
33
35
|
|
34
|
-
|
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
|
36
|
+
end
|
52
37
|
end
|
@@ -1,27 +1,105 @@
|
|
1
1
|
module VagrantPlugins
|
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
|
-
|
2
|
+
module Nixos
|
3
|
+
NixosConfigError = Class.new(Vagrant::Errors::VagrantError)
|
4
|
+
|
5
|
+
CONFIG_HEADER = "# This file is overwritten by the vagrant-nixos plugin\n"
|
6
|
+
|
7
|
+
class Provisioner < Vagrant.plugin("2", :provisioner)
|
8
|
+
# This is the method called when the actual provisioning should be
|
9
|
+
# done. The communicator is guaranteed to be ready at this point,
|
10
|
+
# and any shared folders or networks are already setup.
|
11
|
+
#
|
12
|
+
# No return value is expected.
|
13
|
+
def provision
|
14
|
+
prov = if config.inline
|
15
|
+
config.inline
|
16
|
+
elsif config.path
|
17
|
+
File.read(config.path)
|
18
|
+
elsif config.expression
|
19
|
+
"{config, pkgs, ...}: with pkgs; #{@config.expression}"
|
20
|
+
else
|
21
|
+
"{}"
|
22
|
+
end
|
23
|
+
write_config('vagrant-provision.nix', prov)
|
24
|
+
rebuild!
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
# just do nixos-rebuild
|
30
|
+
def rebuild!
|
31
|
+
prepare!
|
32
|
+
|
33
|
+
# rebuild
|
34
|
+
rebuild_cmd = "nixos-rebuild switch"
|
35
|
+
rebuild_cmd = "#{rebuild_cmd} -I nixos-config=/etc/nixos/vagrant.nix" if config.include
|
36
|
+
rebuild_cmd = "NIX_PATH=#{config.NIX_PATH}:$NIX_PATH #{rebuild_cmd}" if config.NIX_PATH
|
37
|
+
|
38
|
+
machine.communicate.tap do |comm|
|
39
|
+
comm.execute(rebuild_cmd, sudo: true) do |type, data|
|
40
|
+
if [:stderr, :stdout].include?(type)
|
41
|
+
# Output the data with the proper color based on the stream.
|
42
|
+
color = type == :stdout ? :green : :red
|
43
|
+
|
44
|
+
options = {
|
45
|
+
new_line: false,
|
46
|
+
prefix: false,
|
47
|
+
}
|
48
|
+
options[:color] = color
|
49
|
+
|
50
|
+
machine.env.ui.info(data, options) if config.verbose
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# rebuild the base vagrant.nix configuration
|
57
|
+
def prepare!
|
58
|
+
# build
|
59
|
+
conf = <<CONF
|
60
|
+
{ config, pkgs, ... }:
|
61
|
+
{
|
62
|
+
imports = [
|
63
|
+
#{config.imports.join("\n ")}
|
64
|
+
];
|
65
|
+
CONF
|
66
|
+
# default NIX_PATH
|
67
|
+
conf << <<CONF if config.NIX_PATH
|
68
|
+
config.environment.shellInit = ''
|
69
|
+
export NIX_PATH=#{config.NIX_PATH}:$NIX_PATH
|
70
|
+
'';
|
71
|
+
CONF
|
72
|
+
conf << '}'
|
73
|
+
# output / build the config
|
74
|
+
|
75
|
+
write_config("vagrant.nix", conf)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Send file to machine.
|
79
|
+
# Returns true if the uploaded file if different from any
|
80
|
+
# preexisting file, false if the file is indentical
|
81
|
+
def write_config(filename, conf)
|
82
|
+
temp = Tempfile.new("vagrant")
|
83
|
+
temp.binmode
|
84
|
+
temp.write(CONFIG_HEADER + conf)
|
85
|
+
temp.close
|
86
|
+
changed = true
|
87
|
+
machine.communicate.tap do |comm|
|
88
|
+
source = "/tmp/#{filename}"
|
89
|
+
target = "/etc/nixos/#{filename}"
|
90
|
+
comm.upload(temp.path, source)
|
91
|
+
if same?(source, target)
|
92
|
+
changed = false
|
93
|
+
else
|
94
|
+
comm.sudo("mv #{source} #{target}")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
return changed
|
98
|
+
end
|
99
|
+
|
100
|
+
def same?(f1, f2)
|
101
|
+
machine.communicate.test("cmp --silent #{f1} #{f2}")
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
27
105
|
end
|
@@ -6,11 +6,11 @@ require 'vagrant-nixos/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "vagrant-nixos-plugin"
|
8
8
|
spec.version = VagrantPlugins::Nixos::VERSION
|
9
|
-
spec.authors = ["Chris Farmiloe"]
|
10
|
-
spec.email = ["chrisfarms@gmail.com"]
|
11
|
-
spec.summary = %q{
|
12
|
-
spec.description = %q{Add
|
13
|
-
spec.homepage = ""
|
9
|
+
spec.authors = ["Chris Farmiloe", "zimbatm"]
|
10
|
+
spec.email = ["chrisfarms@gmail.com", "zimbatm@zimbatm.com"]
|
11
|
+
spec.summary = %q{Vagrant Nix provisioning plugin for NixOS}
|
12
|
+
spec.description = %q{Add basic nix configuration provisioning for NixOS guests in Vagrant}
|
13
|
+
spec.homepage = "https://github.com/zimbatm/vagrant-nixos-plugin"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -20,5 +20,4 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.5"
|
22
22
|
spec.add_development_dependency "rake"
|
23
|
-
spec.add_dependency "netaddr"
|
24
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-nixos-plugin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Farmiloe
|
8
|
+
- zimbatm
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2015-
|
12
|
+
date: 2015-10-18 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
@@ -38,45 +39,28 @@ dependencies:
|
|
38
39
|
- - '>='
|
39
40
|
- !ruby/object:Gem::Version
|
40
41
|
version: '0'
|
41
|
-
|
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
|
42
|
+
description: Add basic nix configuration provisioning for NixOS guests in Vagrant
|
57
43
|
email:
|
58
44
|
- chrisfarms@gmail.com
|
45
|
+
- zimbatm@zimbatm.com
|
59
46
|
executables: []
|
60
47
|
extensions: []
|
61
48
|
extra_rdoc_files: []
|
62
49
|
files:
|
63
50
|
- .gitignore
|
64
51
|
- Gemfile
|
52
|
+
- History.md
|
65
53
|
- LICENSE.txt
|
66
54
|
- README.md
|
67
55
|
- Rakefile
|
68
56
|
- lib/vagrant-nixos-plugin.rb
|
69
|
-
- lib/vagrant-nixos/cap/change_host_name.rb
|
70
|
-
- lib/vagrant-nixos/cap/configure_networks.rb
|
71
57
|
- lib/vagrant-nixos/config.rb
|
72
|
-
- lib/vagrant-nixos/guest.rb
|
73
58
|
- lib/vagrant-nixos/nix.rb
|
74
59
|
- lib/vagrant-nixos/plugin.rb
|
75
60
|
- lib/vagrant-nixos/provisioner.rb
|
76
|
-
- lib/vagrant-nixos/util.rb
|
77
61
|
- lib/vagrant-nixos/version.rb
|
78
62
|
- vagrant-nixos-plugin.gemspec
|
79
|
-
homepage:
|
63
|
+
homepage: https://github.com/zimbatm/vagrant-nixos-plugin
|
80
64
|
licenses:
|
81
65
|
- MIT
|
82
66
|
metadata: {}
|
@@ -99,5 +83,5 @@ rubyforge_project:
|
|
99
83
|
rubygems_version: 2.0.14
|
100
84
|
signing_key:
|
101
85
|
specification_version: 4
|
102
|
-
summary:
|
86
|
+
summary: Vagrant Nix provisioning plugin for NixOS
|
103
87
|
test_files: []
|
@@ -1,30 +0,0 @@
|
|
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
|
-
|
@@ -1,56 +0,0 @@
|
|
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
|
data/lib/vagrant-nixos/guest.rb
DELETED
data/lib/vagrant-nixos/util.rb
DELETED
@@ -1,122 +0,0 @@
|
|
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
|
-
|