system

package
v0.0.0-...-b17047e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 2, 2026 License: GPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyClosures

func CopyClosures(src System, dest System, paths []string, extraNixOpts nixopts.NixOptionsSet) error

Invoke the `nix-copy-closure` command to copy between two types of systems.

Types

type CachedPasswordProvider

type CachedPasswordProvider struct {
	// contains filtered or unexported fields
}

func (*CachedPasswordProvider) GetPassword

func (p *CachedPasswordProvider) GetPassword() (string, error)

func (*CachedPasswordProvider) PromptForPassword

func (p *CachedPasswordProvider) PromptForPassword(ctx context.Context, prompt string) (string, error)

type Command

type Command struct {
	Name   string
	Args   []string
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
	Env    map[string]string
	// contains filtered or unexported fields
}

func NewCommand

func NewCommand(name string, args ...string) *Command

func (*Command) AsRoot

func (c *Command) AsRoot(elevator *RootElevator) *Command

func (*Command) BuildArgs

func (c *Command) BuildArgs() []string

Build an arguments array, suitable for passing to exec.Command or other argument string slice parameters.

This does not set environment variables; use BuildShellWrapper() for that or use cmd.Env directly at the call site for System.Run() implementations.

func (*Command) BuildShellWrapper

func (c *Command) BuildShellWrapper() ([]string, error)

Build a safe `sh -c` wrapper that can support setting environment variables for a process inline.

This is required for environments that sanitize environment variables, such as when commands are ran using `sudo` or other root elevation commands, or running commands on systems using SSH without proper AcceptEnv settings configured.

func (*Command) InheritEnv

func (c *Command) InheritEnv(vars ...string)

Inherit the passed environment variables' values explicitly into the command's env map.

Useful when passing variables over `sudo` or SSH environment variable sanitation barriers.

func (*Command) SetEnv

func (c *Command) SetEnv(key string, value string)

type CommandRunner

type CommandRunner interface {
	Run(cmd *Command) (int, error)
	Logger() logger.Logger
	HasCommand(cmd string) bool
}

type Filesystem

type Filesystem interface {
	Stat(path string) (os.FileInfo, error)
	ReadLink(path string) (string, error)
	MkdirAll(path string, perm os.FileMode) error
	ReadFile(path string) ([]byte, error)
	CreateFile(path string) error
	ReadDir(path string) ([]os.FileInfo, error)
	RealPath(path string) (string, error)
	Glob(pattern string) ([]string, error)
}

type LocalFilesystem

type LocalFilesystem struct{}

func (LocalFilesystem) CreateFile

func (LocalFilesystem) CreateFile(path string) error

func (LocalFilesystem) Glob

func (LocalFilesystem) Glob(pattern string) ([]string, error)

func (LocalFilesystem) MkdirAll

func (LocalFilesystem) MkdirAll(path string, perm os.FileMode) error

func (LocalFilesystem) ReadDir

func (LocalFilesystem) ReadDir(path string) ([]os.FileInfo, error)

func (LocalFilesystem) ReadFile

func (LocalFilesystem) ReadFile(path string) ([]byte, error)
func (LocalFilesystem) ReadLink(name string) (string, error)

func (LocalFilesystem) RealPath

func (LocalFilesystem) RealPath(path string) (string, error)

func (LocalFilesystem) Stat

func (LocalFilesystem) Stat(path string) (os.FileInfo, error)

type LocalSystem

type LocalSystem struct {
	// contains filtered or unexported fields
}

func NewLocalSystem

func NewLocalSystem(logger logger.Logger) *LocalSystem

func (*LocalSystem) FS

func (l *LocalSystem) FS() Filesystem

func (*LocalSystem) HasCommand

func (l *LocalSystem) HasCommand(name string) bool

func (*LocalSystem) IsNixOS

func (l *LocalSystem) IsNixOS() bool

func (*LocalSystem) IsRemote

func (l *LocalSystem) IsRemote() bool

func (*LocalSystem) Logger

func (l *LocalSystem) Logger() logger.Logger

func (*LocalSystem) Run

func (l *LocalSystem) Run(cmd *Command) (int, error)

type NixStoreType

type NixStoreType string
const (
	NixStoreTypeSSH   NixStoreType = "ssh"
	NixStoreTypeSSHNG NixStoreType = "ssh-ng"
)

type PasswordProvider

type PasswordProvider interface {
	GetPassword() (string, error)
	PromptForPassword(ctx context.Context, prompt string) (string, error)
}

type RootElevator

type RootElevator struct {
	Command          string
	Flags            []string
	Method           settings.PasswordInputMethod
	PasswordProvider PasswordProvider
}

func ElevatorFromConfig

func ElevatorFromConfig(cfg *settings.RootCommandSettings) (*RootElevator, error)

func (*RootElevator) PromptIfNecessary

func (e *RootElevator) PromptIfNecessary(ctx context.Context) error

type SFTPFilesystem

type SFTPFilesystem struct {
	// contains filtered or unexported fields
}

func NewSFTPFilesystem

func NewSFTPFilesystem(client *sftp.Client) *SFTPFilesystem

func (*SFTPFilesystem) CreateFile

func (f *SFTPFilesystem) CreateFile(path string) error

func (*SFTPFilesystem) Glob

func (f *SFTPFilesystem) Glob(pattern string) ([]string, error)

func (*SFTPFilesystem) MkdirAll

func (f *SFTPFilesystem) MkdirAll(path string, perm os.FileMode) error

func (*SFTPFilesystem) ReadDir

func (f *SFTPFilesystem) ReadDir(path string) ([]os.FileInfo, error)

func (*SFTPFilesystem) ReadFile

func (f *SFTPFilesystem) ReadFile(path string) ([]byte, error)
func (f *SFTPFilesystem) ReadLink(path string) (string, error)

func (*SFTPFilesystem) RealPath

func (f *SFTPFilesystem) RealPath(path string) (string, error)

func (*SFTPFilesystem) Stat

func (f *SFTPFilesystem) Stat(path string) (os.FileInfo, error)

type SSHConfig

type SSHConfig struct {
	User    string
	Address string
	Port    int

	AuthMethods         []ssh.AuthMethod
	HostKeyVerification settings.HostKeyVerificationType
	KnownHostsFiles     []string

	StoreType NixStoreType
	// contains filtered or unexported fields
}

func NewSSHConfig

func NewSSHConfig(ctx context.Context, host string, log logger.Logger, options SSHConfigOptions) (*SSHConfig, error)

Initialize a new SSH configuration that can be passed to configure an SSH system instance.

The context is required to construct the password callback such that it can be canceled gracefully.

type SSHConfigOptions

type SSHConfigOptions struct {
	AgentManager        *sshUtils.AgentManager
	KnownHostsFiles     []string
	HostKeyVerification settings.HostKeyVerificationType
	PrivateKeyCmd       []string
}

type SSHSystem

type SSHSystem struct {
	// contains filtered or unexported fields
}

func NewSSHSystem

func NewSSHSystem(cfg *SSHConfig, log logger.Logger) (*SSHSystem, error)

func (*SSHSystem) Address

func (s *SSHSystem) Address() string

func (*SSHSystem) AddressWithScheme

func (s *SSHSystem) AddressWithScheme() string

func (*SSHSystem) Clone

func (s *SSHSystem) Clone() (*SSHSystem, error)

Create a new SSH connection instance from the existing information of this instance.

Caller must keep the `cfg` field alive until ALL clones are closed.

func (*SSHSystem) Close

func (s *SSHSystem) Close()

func (*SSHSystem) FS

func (s *SSHSystem) FS() Filesystem

func (*SSHSystem) HasCommand

func (s *SSHSystem) HasCommand(name string) bool

func (*SSHSystem) IsNixOS

func (s *SSHSystem) IsNixOS() bool

func (*SSHSystem) IsRemote

func (s *SSHSystem) IsRemote() bool

func (*SSHSystem) Logger

func (s *SSHSystem) Logger() logger.Logger

func (*SSHSystem) Reconnect

func (s *SSHSystem) Reconnect() error

func (*SSHSystem) Run

func (s *SSHSystem) Run(cmd *Command) (int, error)

type System

type System interface {
	CommandRunner
	IsNixOS() bool
	IsRemote() bool
	FS() Filesystem
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址