Files
latchd/legacy/go/session/env.go
Zane Walker faf5b27328 feat: ship Rust login manager and GitLab release pipeline
Replace the legacy Go implementation as the production path, quarantine the reference tree, add deterministic release packaging and version metadata, and run verification through GitLab CI.
2026-09-25 21:33:46 +05:30

74 lines
1.7 KiB
Go

// session — environment variable setup for latchd sessions.
//
// Mirrors vendor/src/post_login/env_variables.rs.
package session
import (
"fmt"
"os"
"strconv"
)
func SetBasicVariables(user, home, shell, path string) {
os.Chdir(home)
os.Setenv("HOME", home)
os.Setenv("SHELL", shell)
os.Setenv("USER", user)
os.Setenv("LOGNAME", user)
os.Setenv("PATH", path)
}
func SetDisplay(display string) {
os.Setenv("DISPLAY", display)
}
func RemoveXDG() {
for _, v := range []string{
"XDG_SESSION_CLASS", "XDG_CURRENT_DESKTOP", "XDG_SESSION_DESKTOP",
"XDG_SEAT", "XDG_VTNR", "XDG_RUNTIME_DIR", "XDG_SESSION_ID",
"XDG_CONFIG_DIR", "XDG_CACHE_HOME", "XDG_DATA_HOME",
"XDG_STATE_HOME", "XDG_DATA_DIRS", "XDG_CONFIG_DIRS",
} {
os.Unsetenv(v)
}
}
func SetSessionParams(sessionType string) {
os.Setenv("XDG_SESSION_CLASS", "user")
os.Setenv("XDG_SESSION_TYPE", sessionType)
}
func SetSeatVars(tty uint8) {
setOrOwn("XDG_SEAT", "seat0")
setOrOwn("XDG_VTNR", strconv.Itoa(int(tty)))
}
func SetSessionVars(uid uint32) {
setOrOwn("XDG_RUNTIME_DIR", fmt.Sprintf("/run/user/%d", uid))
setOrOwn("XDG_SESSION_ID", "1")
}
func SetXDGCommonPaths(home string) {
setOrOwn("XDG_CONFIG_HOME", home+"/.config")
setOrOwn("XDG_CACHE_HOME", home+"/.cache")
setOrOwn("XDG_DATA_HOME", home+"/.local/share")
setOrOwn("XDG_STATE_HOME", home+"/.local/state")
setOrOwn("XDG_DATA_DIRS", "/usr/local/share:/usr/share")
setOrOwn("XDG_CONFIG_DIRS", "/etc/xdg")
}
func SetDesktopVars(currentDesktop, sessionDesktop string) {
if currentDesktop != "" {
setOrOwn("XDG_CURRENT_DESKTOP", currentDesktop)
}
if sessionDesktop != "" {
setOrOwn("XDG_SESSION_DESKTOP", sessionDesktop)
}
}
func setOrOwn(k, v string) {
if _, ok := os.LookupEnv(k); !ok {
os.Setenv(k, v)
}
}