Embed base nix configuration to binary

This commit is contained in:
Mikhail Klementev 2019-12-29 17:41:44 +00:00
parent 1251a21aba
commit 24927bc787
No known key found for this signature in database
GPG Key ID: BE44DA8C062D87DC
3 changed files with 20 additions and 3 deletions

View File

@ -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", "<nixpkgs/nixos>", "-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)

View File

@ -1,3 +1,6 @@
package main
var base_nix = []byte(`
{pkgs, ...}:
{
imports = [
@ -87,3 +90,4 @@ startup = do
wantedBy = ["timers.target"];
};
}
`)

View File

@ -1,4 +1,8 @@
package main
var local_nix_template = []byte(`
{
services.xserver.layout = "us,ru";
services.xserver.xkbOptions = "ctrl:nocaps,grp:rctrl_toggle";
}
`)