User host user id

This commit is contained in:
Mikhail Klementev 2020-01-07 20:01:52 +00:00
parent dad147eb91
commit 2be0f82e4a
No known key found for this signature in database
GPG Key ID: BE44DA8C062D87DC
2 changed files with 19 additions and 4 deletions

View File

@ -430,7 +430,7 @@ func main() {
log.Fatal(err)
}
err = ioutil.WriteFile(configDir+"/nix/base.nix", base_nix, 0644)
err = ioutil.WriteFile(configDir+"/nix/base.nix", baseNix(), 0644)
if err != nil {
log.Fatal(err)
}

View File

@ -1,6 +1,12 @@
package main
var base_nix = []byte(`
import (
"fmt"
"log"
"os/user"
)
var base_nix = `
{pkgs, ...}:
{
imports = [
@ -24,6 +30,7 @@ var base_nix = []byte(`
services.spice-vdagentd.enable = true;
users.extraUsers.user = {
uid = %s;
isNormalUser = true;
extraGroups = [ "audio" ];
createHome = true;
@ -58,7 +65,7 @@ startup = do
systemd.services.mount-home-user = {
description = "Mount /home/user (crutch)";
serviceConfig = {
ExecStart = "/bin/sh -c '/run/current-system/sw/bin/mount -t 9p -o trans=virtio,version=9p2000.L,uid=1000 home /home/user'";
ExecStart = "/bin/sh -c '/run/current-system/sw/bin/mount -t 9p -o trans=virtio,version=9p2000.L home /home/user'";
RemainAfterExit = "yes";
Type = "oneshot";
User = "root";
@ -106,4 +113,12 @@ startup = do
wantedBy = ["timers.target"];
};
}
`)
`
func baseNix() []byte {
u, err := user.Current()
if err != nil {
log.Fatal(err)
}
return []byte(fmt.Sprintf(base_nix, u.Uid))
}