vagrant-nixos 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ Vagrantfile
2
+ .vagrant/
3
+ Gemfile.lock
4
+ pkg/
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,22 @@
1
+ # NixOS Vagrant Plugin
2
+
3
+ This plugin makes working with [NixOS](http://nixos.org) guests much easier to work with in [Vagrant](http://www.vagrantup.com) by:
4
+
5
+ * Allowing network configurations from Vagrantfile (Vagrant does not have a default NixOS guest capability)
6
+ * Provide a convention for nixos
7
+
8
+ ## Usage:
9
+
10
+ ```bash
11
+ $ vagrant plugin install vagrant-nixos
12
+ ...
13
+ ```
14
+
15
+ ## How it works
16
+
17
+ In nixos we don't mess around with the files in `/etc` instead we write delarative expressions for the system configuration starting in `/etc/nixos/configuration.nix`.
18
+
19
+ This plugin sets some ground rules for nixos boxes to keep this configuration clean.
20
+
21
+ Box creators should ensure that their `configuration.nix` file imports an empty file `/etc/nixos/vagrant.nix` which will be overwritten by `vagrant-nixos` during `vagrant up` or `vagrant provision` and a `nixos-rebuild switch` will be triggerd.
22
+
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,72 @@
1
+ require 'set'
2
+ require 'tempfile'
3
+
4
+ require "vagrant/util/template_renderer"
5
+
6
+ module VagrantPlugins
7
+ module Nixos
8
+ module Cap
9
+ class ConfigureNetworks
10
+ include Vagrant::Util
11
+
12
+ def self.nix_interface_expr(options)
13
+ <<-NIX
14
+ {
15
+ name = "eth#{options[:interface]}";
16
+ ipAddress = "#{options[:ip]}";
17
+ subnetMask = "#{options[:netmask]}";
18
+ }
19
+ NIX
20
+ end
21
+
22
+ def self.nix_interface_module(networks)
23
+ exprs = networks.inject([]) do |exprs, network|
24
+ # Interfaces without an ip set will fallback to
25
+ # DHCP if useDHCP is set. So skip them.
26
+ if network[:ip].empty?
27
+ exprs
28
+ else
29
+ exprs << nix_interface_expr(network)
30
+ end
31
+ end
32
+ <<-NIX
33
+ { config, pkgs, ... }:
34
+ {
35
+ networking.useDHCP = true;
36
+ networking.interfaces = [
37
+ #{exprs.join("\n")}
38
+ ];
39
+ }
40
+ NIX
41
+ end
42
+
43
+ def self.configure_networks(machine, networks)
44
+ machine.communicate.tap do |comm|
45
+ # build the network config
46
+ conf = nix_interface_module(networks)
47
+
48
+ # Perform the careful dance necessary to reconfigure
49
+ # the network interfaces
50
+ temp = Tempfile.new("vagrant")
51
+ temp.binmode
52
+ temp.write(conf)
53
+ temp.close
54
+
55
+ puts conf
56
+
57
+ # add the network config
58
+ filename = "vagrant-interfaces.nix"
59
+ comm.upload(temp.path, "/tmp/#{filename}")
60
+ comm.sudo("mv /tmp/#{filename} /etc/nixos/#{filename}")
61
+
62
+ # TODO: check that the network config is referenced in vagrant.nix
63
+
64
+ # cleanup
65
+ temp.unlink
66
+ end
67
+ end
68
+
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,9 @@
1
+ module VagrantPlugins
2
+ module Nixos
3
+ class Guest < Vagrant.plugin("2", :guest)
4
+ def detect?(machine)
5
+ machine.communicate.test("test -f /etc/nixos/configuration.nix")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,33 @@
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
+ class Plugin < Vagrant.plugin("2")
16
+ name "nixos"
17
+ description <<-DESC
18
+ This plugin installs nixos guest capabilities.
19
+ DESC
20
+
21
+ guest("nixos", "linux") do
22
+ require_relative "guest"
23
+ Guest
24
+ end
25
+
26
+ guest_capability("nixos", "configure_networks") do
27
+ require_relative "cap/configure_networks"
28
+ Cap::ConfigureNetworks
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module Nixos
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ require "vagrant-nixos/version"
2
+ require "vagrant-nixos/plugin"
3
+
4
+ module VagrantPlugins
5
+ module Nixos
6
+ lib_path = Pathname.new(File.expand_path("../nixos", __FILE__))
7
+ autoload :Action, lib_path.join("action")
8
+ autoload :Errors, lib_path.join("errors")
9
+
10
+ # This returns the path to the source of this plugin.
11
+ def self.source_root
12
+ @source_root ||= Pathname.new(File.expand_path("../../../", __FILE__))
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
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"
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
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-nixos
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chris Farmiloe
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.5'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.5'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Add capabilities and basic nix configuration provisioning for NixOS guests
47
+ in Vagrant
48
+ email:
49
+ - chrisfarms@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - lib/vagrant-nixos.rb
60
+ - lib/vagrant-nixos/cap/configure_networks.rb
61
+ - lib/vagrant-nixos/guest.rb
62
+ - lib/vagrant-nixos/plugin.rb
63
+ - lib/vagrant-nixos/version.rb
64
+ - vagrant-nixos.gemspec
65
+ homepage: ''
66
+ licenses:
67
+ - MIT
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ segments:
79
+ - 0
80
+ hash: 867435977267935838
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ segments:
88
+ - 0
89
+ hash: 867435977267935838
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 1.8.23
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Guest capabilities and nix provisioning for NixOS
96
+ test_files: []