diff --git a/appvm.go b/appvm.go index 4559aa2..d08d73f 100644 --- a/appvm.go +++ b/appvm.go @@ -118,7 +118,7 @@ func copyFile(from, to string) (err error) { func prepareTemplates(appvmPath string) (err error) { if _, err = os.Stat(appvmPath + "/nix/local.nix"); os.IsNotExist(err) { - err = copyFile(appvmPath+"/nix/local.nix.template", appvmPath+"/nix/local.nix") + err = ioutil.WriteFile(configDir+"/nix/local.nix", local_nix_template, 0644) if err != nil { return } @@ -143,7 +143,7 @@ func generateVM(name string, verbose bool) (realpath, reginfo, qcow2 string, err log.Print(vmConfigPath) command := cmd.NewCmdOptions(cmd.Options{Buffered: false, Streaming: true}, "nix-build", "", "-A", "config.system.build.vm", - "-I", "nixos-config="+vmConfigPath, "-I", ".") + "-I", "nixos-config="+vmConfigPath, "-I", configDir) if verbose { go streamStdOutErr(command) } @@ -232,7 +232,7 @@ func stupidProgressBar() { func start(l *libvirt.Libvirt, name string, verbose bool) { // Currently binary-only installation is not supported, because we need *.nix configurations - appvmPath := os.Getenv("GOPATH") + "/src/code.dumpstack.io/tools/appvm" + appvmPath := configDir // Copy templates err := prepareTemplates(appvmPath) @@ -327,9 +327,18 @@ func autoBalloon(l *libvirt.Libvirt, memoryMin, adjustPercent uint64) { table.Render() } +var configDir = os.Getenv("HOME") + "/.config/appvm/" + func main() { os.Mkdir(os.Getenv("HOME")+"/appvm", 0700) + os.MkdirAll(configDir+"/nix", 0700) + + err := ioutil.WriteFile(configDir+"/nix/base.nix", base_nix, 0644) + if err != nil { + log.Fatal(err) + } + c, err := net.DialTimeout("unix", "/var/run/libvirt/libvirt-sock", time.Second) if err != nil { log.Fatal(err) diff --git a/nix/base.nix b/base.nix.go similarity index 98% rename from nix/base.nix rename to base.nix.go index f4ec425..d8cdc54 100644 --- a/nix/base.nix +++ b/base.nix.go @@ -1,3 +1,6 @@ +package main + +var base_nix = []byte(` {pkgs, ...}: { imports = [ @@ -87,3 +90,4 @@ startup = do wantedBy = ["timers.target"]; }; } +`) diff --git a/nix/local.nix.template b/local.nix.template.go similarity index 67% rename from nix/local.nix.template rename to local.nix.template.go index c46afac..5ecad5f 100644 --- a/nix/local.nix.template +++ b/local.nix.template.go @@ -1,4 +1,8 @@ +package main + +var local_nix_template = []byte(` { services.xserver.layout = "us,ru"; services.xserver.xkbOptions = "ctrl:nocaps,grp:rctrl_toggle"; } +`)