Ignore local ({local,monitor}.nix) settings

This commit is contained in:
Mikhail Klementev 2018-07-12 07:30:16 +00:00
parent 9447b6d1f6
commit 252610af57
4 changed files with 41 additions and 1 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
nix/local.nix
nix/monitor.nix

View file

@ -9,6 +9,7 @@ package main
import ( import (
"fmt" "fmt"
"io"
"io/ioutil" "io/ioutil"
"log" "log"
"net" "net"
@ -119,14 +120,51 @@ func list(l *libvirt.Libvirt) {
} }
} }
func copyFile(to, from string) (err error) {
source, err := os.Open(from)
if err != nil {
return err
}
defer source.Close()
destination, err := os.Create(to)
if err != nil {
return
}
_, err = io.Copy(destination, source)
if err != nil {
destination.Close()
return
}
return destination.Close()
}
func start(l *libvirt.Libvirt, name string) { func start(l *libvirt.Libvirt, name string) {
// Currently binary-only installation is not supported, because we need *.nix configurations // Currently binary-only installation is not supported, because we need *.nix configurations
gopath := os.Getenv("GOPATH") gopath := os.Getenv("GOPATH")
err := os.Chdir(gopath + "/src/github.com/jollheef/appvm") appvmPath := gopath + "/src/github.com/jollheef/appvm"
err := os.Chdir(appvmPath)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
// Copy templates
if _, err := os.Stat(appvmPath + "/nix/local.nix"); os.IsNotExist(err) {
err = copyFile(appvmPath+"/nix/local.nix.template", appvmPath+"/nix/local.nix")
if err != nil {
log.Fatal(err)
}
}
if _, err := os.Stat(appvmPath + "/nix/monitor.nix"); os.IsNotExist(err) {
err = copyFile(appvmPath+"/nix/monitor.nix.template", appvmPath+"/nix/monitor.nix")
if err != nil {
log.Fatal(err)
}
}
stdout, stderr, ret, err := system.System("nix-build", "<nixpkgs/nixos>", "-A", "config.system.build.vm", stdout, stderr, ret, err := system.System("nix-build", "<nixpkgs/nixos>", "-A", "config.system.build.vm",
"-I", "nixos-config=nix/"+name+".nix", "-I", ".") "-I", "nixos-config=nix/"+name+".nix", "-I", ".")
if err != nil { if err != nil {