mirror of
https://code.dumpstack.io/tools/appvm.git
synced 2024-11-24 00:51:38 +00:00
Do not fetch remote repository
This commit is contained in:
parent
99bd71b80c
commit
0a51db3bde
77
appvm.go
77
appvm.go
|
@ -8,7 +8,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -31,63 +30,6 @@ import (
|
||||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func evalNix(expr string) (value string, err error) {
|
|
||||||
command := exec.Command("nix", "eval", "--raw", "(toString ("+expr+"))")
|
|
||||||
log.Print("Evaluating " + expr)
|
|
||||||
var stdout bytes.Buffer
|
|
||||||
command.Stdout = &stdout
|
|
||||||
err = command.Run()
|
|
||||||
value = stdout.String()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gets an expression returning AppVM config path
|
|
||||||
func getAppVMExpressionPath(name string) (paths []string, config string) {
|
|
||||||
paths = strings.Split(os.Getenv("NIX_PATH"), ":")
|
|
||||||
config = "nix/" + name + ".nix"
|
|
||||||
|
|
||||||
paths = append(paths, configDir)
|
|
||||||
|
|
||||||
for _, a := range paths {
|
|
||||||
searchpath := a
|
|
||||||
log.Print("Searching " + searchpath + " for expressions")
|
|
||||||
if _, err := os.Stat(searchpath); !os.IsNotExist(err) {
|
|
||||||
exprpath := searchpath + "/nix/" + name + ".nix"
|
|
||||||
log.Print("File exists?: ", exprpath)
|
|
||||||
if _, err := os.Stat(exprpath); !os.IsNotExist(err) {
|
|
||||||
log.Print("File exists: ", exprpath)
|
|
||||||
config = exprpath
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
log.Print("Local repo " + searchpath + " doesn't have a nix expression for " + name)
|
|
||||||
}
|
|
||||||
log.Print("Trying to use remote repo config")
|
|
||||||
|
|
||||||
rev := "1251a21abadc15b7187d485317434c9befd0f6b2"
|
|
||||||
fetchFormat := "(builtins.fetchTarball \"https://github.com/%[1]s/%[2]s/archive/" + rev + ".tar.gz\")"
|
|
||||||
splitString := strings.Split(name, "/")
|
|
||||||
|
|
||||||
if len(splitString) != 3 {
|
|
||||||
// nope, not a repo format
|
|
||||||
path, err := evalNix(fmt.Sprintf(fetchFormat, "jollheef", "appvm", name))
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("OH NO ", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
paths = []string{path}
|
|
||||||
config = path + "/nix/" + name + ".nix"
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func list(l *libvirt.Libvirt) {
|
func list(l *libvirt.Libvirt) {
|
||||||
domains, err := l.Domains()
|
domains, err := l.Domains()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -164,24 +106,9 @@ func streamStdOutErr(command *cmd.Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateVM(name string, verbose bool) (realpath, reginfo, qcow2 string, err error) {
|
func generateVM(name string, verbose bool) (realpath, reginfo, qcow2 string, err error) {
|
||||||
paths, config := getAppVMExpressionPath(name)
|
|
||||||
|
|
||||||
nixargs := []string{
|
|
||||||
"<nixpkgs/nixos>",
|
|
||||||
"-A", "config.system.build.vm",
|
|
||||||
"-I", "nixos-config=" + config,
|
|
||||||
// Taking local config from home folder
|
|
||||||
"-I" + os.Getenv("HOME"),
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, path := range paths {
|
|
||||||
nixargs = append(nixargs, "-I", path)
|
|
||||||
}
|
|
||||||
|
|
||||||
command := cmd.NewCmdOptions(cmd.Options{Buffered: false, Streaming: true},
|
command := cmd.NewCmdOptions(cmd.Options{Buffered: false, Streaming: true},
|
||||||
"nix-build",
|
"nix-build", "<nixpkgs/nixos>", "-A", "config.system.build.vm",
|
||||||
nixargs...,
|
"-I", "nixos-config=nix/"+name+".nix", "-I", ".")
|
||||||
)
|
|
||||||
|
|
||||||
if verbose {
|
if verbose {
|
||||||
go streamStdOutErr(command)
|
go streamStdOutErr(command)
|
||||||
|
|
Loading…
Reference in a new issue