mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
flatpak: use host-spawn to find default shell
This commit is contained in:
@ -41,6 +41,26 @@ modules:
|
||||
only-arches:
|
||||
- aarch64
|
||||
|
||||
# We use this to get a proper PTY on our host spawn. We should eventually
|
||||
# replace this with using dbus directly.
|
||||
- name: host-spawn
|
||||
buildsystem: simple
|
||||
build-commands:
|
||||
- mkdir -p /app/bin
|
||||
- mv ./host-spawn-* /app/bin/host-spawn
|
||||
- chmod +x /app/bin/host-spawn
|
||||
sources:
|
||||
- type: file
|
||||
url: https://github.com/1player/host-spawn/releases/download/1.4.1/host-spawn-x86_64
|
||||
sha256: d81bb6125ec73a9a2e26266c48787367fbcb665d67c2e7fb42217f0981106cf7
|
||||
only-arches:
|
||||
- x86_64
|
||||
- type: file
|
||||
url: https://github.com/1player/host-spawn/releases/download/1.4.1/host-spawn-aarch64
|
||||
sha256: 29bff846d72e37093b3fdf7859bae16addd64acc98087f8c059548df3c2273c4
|
||||
only-arches:
|
||||
- aarch64
|
||||
|
||||
- name: ghostty
|
||||
buildsystem: simple
|
||||
build-commands:
|
||||
|
@ -344,6 +344,9 @@ pub const Config = struct {
|
||||
if (self.command == null or wd_home) command: {
|
||||
const alloc = self._arena.?.allocator();
|
||||
|
||||
// We don't do this in flatpak because SHELL in Flatpak is
|
||||
// always set to /bin/sh
|
||||
if (!internal_os.isFlatpak()) {
|
||||
// First look up the command using the SHELL env var.
|
||||
if (std.process.getEnvVarOwned(alloc, "SHELL")) |value| {
|
||||
log.debug("default shell source=env value={s}", .{value});
|
||||
@ -352,6 +355,7 @@ pub const Config = struct {
|
||||
// If we don't need the working directory, then we can exit now.
|
||||
if (!wd_home) break :command;
|
||||
} else |_| {}
|
||||
}
|
||||
|
||||
// We need the passwd entry for the remainder
|
||||
const pw = try passwd.get(alloc);
|
||||
|
@ -2,6 +2,7 @@ const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const ArenaAllocator = std.heap.ArenaAllocator;
|
||||
const internal_os = @import("os/main.zig");
|
||||
|
||||
const log = std.log.scoped(.passwd);
|
||||
|
||||
@ -45,6 +46,39 @@ pub fn get(alloc: Allocator) !Entry {
|
||||
|
||||
var result: Entry = .{};
|
||||
|
||||
// If we're in flatpak then our entry is always empty so we grab it
|
||||
// by shelling out to the host. note that we do HAVE an entry in the
|
||||
// sandbox but only the username is correct.
|
||||
//
|
||||
// Note: we wrap our getent call in a /bin/sh login shell because
|
||||
// some operating systems (NixOS tested) don't set the PATH for various
|
||||
// utilities properly until we get a login shell.
|
||||
if (internal_os.isFlatpak()) {
|
||||
log.info("flatpak detected, will use host-spawn to get our entry", .{});
|
||||
const exec = try std.ChildProcess.exec(.{
|
||||
.allocator = alloc,
|
||||
.argv = &[_][]const u8{
|
||||
"/app/bin/host-spawn",
|
||||
"-pty",
|
||||
"/bin/sh",
|
||||
"-l",
|
||||
"-c",
|
||||
try std.fmt.allocPrint(
|
||||
alloc,
|
||||
"getent passwd {s}",
|
||||
.{std.mem.sliceTo(pw.pw_name, 0)},
|
||||
),
|
||||
},
|
||||
});
|
||||
if (exec.term == .Exited) {
|
||||
// Shell and home are the last two entries
|
||||
var it = std.mem.splitBackwards(u8, exec.stdout, ":");
|
||||
result.shell = it.next() orelse null;
|
||||
result.home = it.next() orelse null;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if (pw.pw_shell) |ptr| {
|
||||
const source = std.mem.sliceTo(ptr, 0);
|
||||
const sh = try alloc.alloc(u8, source.len);
|
||||
|
Reference in New Issue
Block a user