nixy

package
v1.6.1-master Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ProfileSandboxMountPath        = "/profile"
	WorkspaceDirSandboxMountPath   = "/workspace"
	WorkspaceFlakeSandboxMountPath = "/workspace-flake"
)

Functions

func GetGitRootForWorkspace added in v1.6.0

func GetGitRootForWorkspace(ctx context.Context, dir string) (string, bool)

func InitNixyFile

func InitNixyFile(parent context.Context, dest string) error

func InitWorkspace

func InitWorkspace(parent context.Context) error

func ProfileCreate

func ProfileCreate(ctx context.Context, name string) error

ProfileCreate creates a new profile with the given name

func ProfileEdit

func ProfileEdit(ctx context.Context, name string) error

ProfileEdit opens the profile metadata in the user's editor

func ProfileList

func ProfileList(ctx context.Context) ([]string, error)

ProfileList returns all available profiles

func XDGDataDir

func XDGDataDir() string

Types

type Build

type Build struct {
	Packages []*NormalizedPackage `yaml:"packages"`
	Paths    []string             `yaml:"paths"`
	Command  string               `yaml:"command"`
	Dir      string               `yaml:"dir,omitempty"`
}

func (Build) BuildDir added in v1.6.0

func (b Build) BuildDir(projectDir string) string

func (Build) OutputDir added in v1.6.0

func (b Build) OutputDir(projectDir string) string

func (Build) ResolvedDir added in v1.6.0

func (b Build) ResolvedDir() string

type Context

type Context struct {
	context.Context

	NixyProfile string
	NixyMode    Mode
	NixyBinPath string
	InNixyShell bool

	PWD string

	// Nixy Constants
	NixyDataDir string
}

func NewContext

func NewContext(parent context.Context, workspaceDir string) (*Context, error)

func (*Context) IsLocalMode

func (ctx *Context) IsLocalMode() bool

type ExecutorArgs

type ExecutorArgs struct {
	NixBinaryMountedPath  string
	ProfileDirMountedPath string
	FakeHomeMountedPath   string
	NixDirMountedPath     string

	WorkspaceFlakeDirHostPath    string
	WorkspaceFlakeDirMountedPath string

	EnvVars executorEnvVars
}

func UseBubbleWrap

func UseBubbleWrap(ctx *Context, runtimePaths *RuntimePaths) (*ExecutorArgs, error)

func UseDocker

func UseDocker(ctx *Context, runtimePaths *RuntimePaths) (*ExecutorArgs, error)

func UseLocal

func UseLocal(ctx *Context, runtimePaths *RuntimePaths) (*ExecutorArgs, error)

type ExecutorMountPath

type ExecutorMountPath struct {
	HostPath  string
	MountPath string
	ReadOnly  bool
}

type InShellNixy

type InShellNixy struct {
	PWD    string `yaml:"-"`
	Logger *slog.Logger
	Nixy
}

func LoadInNixyShell

func LoadInNixyShell(parent context.Context) (*InShellNixy, error)

func (*InShellNixy) Build

func (n *InShellNixy) Build(ctx context.Context, target string) error

type Mode

type Mode string
const (
	LocalMode          Mode = "local"
	LocalIgnoreEnvMode Mode = "local-ignore-env"
	DockerMode         Mode = "docker"
	BubbleWrapMode     Mode = "bubblewrap"
)

func (Mode) String

func (m Mode) String() string

type NixPackage

type NixPackage struct {
	Name   string
	Commit string
}

type NixPkgsMap added in v1.4.0

type NixPkgsMap map[string]string

func (NixPkgsMap) DefaultCommit added in v1.4.0

func (m NixPkgsMap) DefaultCommit() string

func (NixPkgsMap) List added in v1.4.0

func (m NixPkgsMap) List() []string

type Nixy

type Nixy struct {
	NixPkgs   NixPkgsMap           `yaml:"nixpkgs"`
	Packages  []*NormalizedPackage `yaml:"packages"`
	Libraries []string             `yaml:"libraries,omitempty"`

	Env map[string]string `yaml:"env,omitempty"`

	// OnShellEnter runs at the final step in nixy shell lifecycle
	OnShellEnter string `yaml:"onShellEnter,omitempty"`

	// OnShellExit is not used as of now, will try to use it in future
	OnShellExit string `yaml:"onShellExit,omitempty"`

	Builds map[string]Build `yaml:"builds,omitempty"`

	// Mounts are only for non-local execution modes
	Mounts []NixyMount `yaml:"mounts,omitempty"`
	// contains filtered or unexported fields
}

func (*Nixy) SyncToDisk

func (nixy *Nixy) SyncToDisk(file string) error

SyncToDisk writes the nixy config to disk. When rawNode is set, it preserves the original YAML structure (comments, ordering). When rawNode is nil, it encodes the struct with deduplication (for new files).

type NixyMount added in v1.4.0

type NixyMount struct {
	Source      string `yaml:"source"`
	Destination string `yaml:"dest"`
	ReadOnly    bool   `yaml:"readonly,omitempty"`
}

NixyMount is for mounting a host file system path to a path in nixy shell It is effective only in non-local modes

type NixyWrapper added in v1.5.0

type NixyWrapper struct {
	Context *Context

	sync.Mutex `yaml:"-"`
	Logger     *slog.Logger `yaml:"-"`

	PWD string

	*Nixy
	// contains filtered or unexported fields
}

func LoadFromFile

func LoadFromFile(parent context.Context, f string) (*NixyWrapper, error)

func (*NixyWrapper) Build added in v1.5.0

func (nixy *NixyWrapper) Build(ctx *Context, target string) error

func (*NixyWrapper) Shell added in v1.5.0

func (n *NixyWrapper) Shell(ctx *Context, program string) error

type NormalizedPackage

type NormalizedPackage struct {
	*NixPackage
	*URLPackage
}

func (*NormalizedPackage) MarshalYAML

func (p *NormalizedPackage) MarshalYAML() (any, error)

func (*NormalizedPackage) UnmarshalYAML

func (p *NormalizedPackage) UnmarshalYAML(value *yaml.Node) error

type Profile

type Profile struct {
	Name              string `json:"name"`
	NixPkgsCommitHash string `json:"nixpkgs,omitempty"`
	ProfilePath       string `json:"profilePath,omitempty"` // ~/.local/share/nixy/profiles/<name>
}

Profile represents profile metadata and runtime state.

func GetProfile

func GetProfile(_ *Context, name string) (*Profile, error)

GetProfile loads an existing profile from disk

func NewProfile

func NewProfile(ctx *Context, name string, runtimePaths *RuntimePaths) (*Profile, error)

NewProfile creates a new profile metadata instance.

func (*Profile) Save

func (p *Profile) Save() error

Save persists the profile to disk as YAML metadata.

type RuntimePaths added in v1.5.0

type RuntimePaths struct {
	Name             string // profile name (used for directory organization)
	BasePath         string // ~/.local/share/nixy/profiles/<name>
	WorkspaceNixyDir string // project-local .nixy directory, when a workspace is available
	FakeHomeDir      string // fake home directory for sandboxing
	NixDir           string // nix store directory
	StaticNixBinPath string // path to static nix binary
}

RuntimePaths represents the filesystem paths needed for nixy runtime execution. These paths are always created and used for the selected profile namespace.

func NewRuntimePaths added in v1.5.0

func NewRuntimePaths(name string, workspaceDir ...string) (*RuntimePaths, error)

NewRuntimePaths creates and initializes the runtime paths for a given profile name. This is always called for the selected profile namespace.

func (*RuntimePaths) CreateDirs added in v1.5.0

func (rp *RuntimePaths) CreateDirs() error

CreateDirs creates all necessary directories for the runtime paths

func (*RuntimePaths) Dirs

func (rp *RuntimePaths) Dirs() []string

type URLAndSHA added in v1.5.0

type URLAndSHA struct {
	URL    string `yaml:"url"`
	SHA256 string `yaml:"sha256"`
}

type URLPackage

type URLPackage struct {
	Name        string               `yaml:"name"`
	Sources     map[string]URLAndSHA `yaml:"sources"`
	InstallHook string               `yaml:"installHook,omitempty"`
	BinPaths    []string             `yaml:"binPaths,omitempty"`
}

type WorkspaceFlakeGenParams

type WorkspaceFlakeGenParams struct {
	NixPkgs          NixPkgsMap
	WorkspaceDirPath string
	Packages         []*NormalizedPackage
	Libraries        []string
	Builds           map[string]Build
	EnvVars          map[string]string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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