vagrant-nixos 0.0.2 → 0.0.3

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.
data/README.md CHANGED
@@ -32,7 +32,7 @@ Vagrant.configure("2") do |config|
32
32
  environment: {
33
33
  systemPackages: [ :htop ]
34
34
  }
35
- }, :NIX_PATH => "/custom/path/to/nixpkgs"
35
+ }
36
36
 
37
37
  end
38
38
  ```
@@ -40,14 +40,33 @@ end
40
40
  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.
41
41
 
42
42
  ```ruby
43
- config.vm.provision :nixos, :inline => %{
44
- {config, pkgs, ...}: with pkgs; {
45
- environment.systemPackages = [ htop ];
46
- }
47
- }, :NIX_PATH => "/custom/path/to/nixpkgs"
43
+ config.vm.provision :nixos, :inline => %{
44
+ {config, pkgs, ...}: with pkgs; {
45
+ environment.systemPackages = [ htop ];
46
+ }
47
+ }, :NIX_PATH => "/custom/path/to/nixpkgs"
48
48
  ```
49
49
 
50
- Both examples show the optional configuring of a custom `NIX_PATH` path.
50
+ The above example also shows the optional setting of a custom `NIX_PATH` path.
51
+
52
+ If you need to use functions or access values using dot syntax you can use the `Nix` module:
53
+
54
+ ```ruby
55
+ config.vm.provision :nixos, :expression => {
56
+ services: {
57
+ postgresql: {
58
+ enable: true,
59
+ package: Nix.pkgs.postgresql93,
60
+ enableTCPIP: true,
61
+ authentication: Nix.lib.mkForce(%{
62
+ local all all trust
63
+ host all all 127.0.0.1/32 trust
64
+ }),
65
+ initialScript: "/etc/nixos/postgres.sql"
66
+ }
67
+ }
68
+ }
69
+ ```
51
70
 
52
71
 
53
72
  ## How it works
data/lib/vagrant-nixos.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "vagrant-nixos/version"
2
2
  require "vagrant-nixos/plugin"
3
3
  require "vagrant-nixos/util"
4
+ require "vagrant-nixos/nix"
4
5
 
5
6
  module VagrantPlugins
6
7
  module Nixos
@@ -0,0 +1,78 @@
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
+ if @parent
30
+ s = @parent.to_nix << "."
31
+ end
32
+ s << @exprs.map{|e| e.to_nix}.join(" ")
33
+ end
34
+ end
35
+ end
36
+
37
+ class Symbol
38
+ def to_nix(indent = 0)
39
+ to_s
40
+ end
41
+ end
42
+
43
+ class NilClass
44
+ def to_nix(indent = 0)
45
+ "null"
46
+ end
47
+ end
48
+
49
+ class Hash
50
+ def to_nix(indent = 0)
51
+ "{\n" +
52
+ sort {|a, b| a[0].to_s <=> b[0].to_s}.map do |key, value|
53
+ raise "Key must be a Symbol, not #{key.class}" unless key.is_a?(Symbol)
54
+ Nix::INDENT_STRING * (indent + 1)+ key.to_nix +
55
+ " = " + value.to_nix(indent + 1) + ";"
56
+ end.join("\n") + "\n" +
57
+ Nix::INDENT_STRING * indent + "}"
58
+ end
59
+ end
60
+
61
+ class Array
62
+ def to_nix(indent = 0)
63
+ "[ " + map(&:to_nix).join(" ") + " ]"
64
+ end
65
+ end
66
+
67
+ class String
68
+ def to_nix(indent = 0)
69
+ # TODO: escape ${var} in string
70
+ "''#{self}''"
71
+ end
72
+ end
73
+
74
+ class Fixnum
75
+ def to_nix(indent = 0)
76
+ to_s
77
+ end
78
+ end
@@ -103,54 +103,3 @@ module VagrantPlugins
103
103
  end
104
104
  end
105
105
 
106
- #################################################
107
- # Naughty extending of builtins.
108
- # Add to_nix functions to convert ruby2nix (ish).
109
- #################################################
110
-
111
- module Nix
112
- INDENT_STRING=" "
113
- end
114
-
115
- class Symbol
116
- def to_nix(indent = 0)
117
- to_s
118
- end
119
- end
120
-
121
- class NilClass
122
- def to_nix(indent = 0)
123
- "null"
124
- end
125
- end
126
-
127
- class Hash
128
- def to_nix(indent = 0)
129
- "{\n" +
130
- sort {|a, b| a[0].to_s <=> b[0].to_s}.map do |key, value|
131
- raise "Key must be a Symbol, not #{key.class}" unless key.is_a?(Symbol)
132
- Nix::INDENT_STRING * (indent + 1)+ key.to_nix +
133
- " = " + value.to_nix(indent + 1) + ";"
134
- end.join("\n") + "\n" +
135
- Nix::INDENT_STRING * indent + "}"
136
- end
137
- end
138
-
139
- class Array
140
- def to_nix(indent = 0)
141
- "[ " + map(&:to_nix).join(" ") + " ]"
142
- end
143
- end
144
-
145
- class String
146
- def to_nix(indent = 0)
147
- # TODO: escape ${var} in string
148
- "''#{self}''"
149
- end
150
- end
151
-
152
- class Fixnum
153
- def to_nix(indent = 0)
154
- to_s
155
- end
156
- end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module Nixos
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-nixos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-02 00:00:00.000000000 Z
12
+ date: 2014-02-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -61,6 +61,7 @@ files:
61
61
  - lib/vagrant-nixos/cap/configure_networks.rb
62
62
  - lib/vagrant-nixos/config.rb
63
63
  - lib/vagrant-nixos/guest.rb
64
+ - lib/vagrant-nixos/nix.rb
64
65
  - lib/vagrant-nixos/plugin.rb
65
66
  - lib/vagrant-nixos/provisioner.rb
66
67
  - lib/vagrant-nixos/util.rb
@@ -81,7 +82,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
81
82
  version: '0'
82
83
  segments:
83
84
  - 0
84
- hash: -2672908896929741571
85
+ hash: -423762119542471155
85
86
  required_rubygems_version: !ruby/object:Gem::Requirement
86
87
  none: false
87
88
  requirements:
@@ -90,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
91
  version: '0'
91
92
  segments:
92
93
  - 0
93
- hash: -2672908896929741571
94
+ hash: -423762119542471155
94
95
  requirements: []
95
96
  rubyforge_project:
96
97
  rubygems_version: 1.8.23