hcl2nix

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPackages

func AddPackages(src []byte, packages Packages, wr io.Writer) error

AddPackages updates config with new packages. It appends new packages to existing packages

func GenerateLockFile

func GenerateLockFile(conf *Config, packages []LockPackage, wr io.Writer) error

GenerateLockFile generates lock file

func GetOrCreateFile

func GetOrCreateFile(path string) (*os.File, error)

GetOrCreateFile gets or creates a file if it doesn't exist

func SetPackages

func SetPackages(src []byte, packages Packages, wr io.Writer) error

SetPackages updates config with new packages. It replaces existing packages with new packages

func WriteConfig

func WriteConfig(config Config, wr io.Writer) error

WriteConfig writes packages to writer

Types

type Category

type Category int

Category defines category of package

const (
	// Development is a category of package
	Development Category = iota
	// Runtime is a category of package
	Runtime = 1
)

type CategoryRevision

type CategoryRevision struct {
	Development map[string]string
	Runtime     map[string]string
	Revisions   []string
}

CategoryRevision holds category revision map and revision list

func ResolveCategoryRevisions

func ResolveCategoryRevisions(pkgs Packages, pkgVersions []LockPackage) *CategoryRevision

ResolveCategoryRevisions maps packages to their category, returns development packages, runtime packages and a list of Nix revisions

type Config

type Config struct {
	Packages       Packages        `hcl:"packages,block"`
	GoModule       *GoModule       `hcl:"gomodule,block"`
	PoetryApp      *PoetryApp      `hcl:"poetryapp,block"`
	RustApp        *RustApp        `hcl:"rustapp,block"`
	JsNpmApp       *JsNpmApp       `hcl:"jsnpmapp,block"`
	OCIArtifact    []OCIArtifact   `hcl:"oci,block"`
	ConfigFiles    []ConfigFiles   `hcl:"config,block"`
	GitHubReleases []GitHubRelease `hcl:"githubRelease,block"`
}

Config for hcl2nix

func ReadConfig

func ReadConfig(src []byte, dstErr io.Writer) (*Config, error)

ReadConfig reads config from bytes and returns Config. If any errors are encountered, they are written to dstErr

func ReadHclFile added in v0.2.1

func ReadHclFile(fileName string) (*Config, error)

ReadHclFile reads an HCL file

type ConfigFiles

type ConfigFiles struct {
	Name string `hcl:"name,label"`
	// Name of files to copy from root of project
	Files []string `hcl:"files"`
	// DestinationDir is the directory to copy config files to in the container
	// This directory will be created in the root of the image
	DestinationDir string `hcl:"destinationDir,optional"`
}

ConfigFiles holds config files to export

func (*ConfigFiles) Validate

func (c *ConfigFiles) Validate() *string

Validate validates ConfigFiles

type FileHandlers

type FileHandlers struct {
	ModFile      *os.File
	LockFile     *os.File
	FlakeFile    *os.File
	DefFlakeFile *os.File
}

FileHandlers holds file handlers

func NewFileHandlers

func NewFileHandlers(expectInit bool) (*FileHandlers, error)

NewFileHandlers creates new file handlers

type GitHubRelease added in v0.2.1

type GitHubRelease struct {
	Owner string `hcl:"owner"`
	Repo  string `hcl:"repo"`
	App   string `hcl:"app,label"`
	Dir   string `hcl:"dir,optional"`
}

GitHubRelease holds github release parameters

func ReadGitHubReleaseParams added in v0.2.1

func ReadGitHubReleaseParams(conf *Config, app string) (*GitHubRelease, error)

ReadGitHubReleaseParams reads the github release params from the config

type GoModule

type GoModule struct {
	Name       string   `hcl:"name"`
	SourcePath string   `hcl:"src"`
	LdFlags    []string `hcl:"ldFlags,optional"`
	Tags       []string `hcl:"tags,optional"`
	// VendorHash string   `hcl:"vendorHash"`
	DoCheck bool `hcl:"doCheck,optional"`
}

GoModule is a struct to hold Nix Go module parameters

type JsNpmApp

type JsNpmApp struct {
	// PackageName: Name of the Package
	PackageName string `hcl:"packageName"`
	// PackageRoot: Source path to root file.
	PackageRoot string `hcl:"packageRoot"`
	// PackageJSONPath: Path to package.json file.
	PackageJSONPath string `hcl:"packageJsonPath,optional"`
	// PackageLockPath: Path to package-lock.json file.
	PackageLockPath string `hcl:"packageLockPath,optional"`
}

JsNpmApp defines the parameters for a Javascript application.

type LockApp

type LockApp struct {
	Name string `json:"name"`
}

LockApp represents a app

type LockFile

type LockFile struct {
	App      LockApp       `json:"app"`
	Packages []LockPackage `json:"packages"`
}

LockFile represents strcuture for LockFile

type LockPackage

type LockPackage struct {
	Package *buildsafev1.Package `json:"package"`
	Runtime bool                 `json:"runtime"`
}

LockPackage represents a package

func ResolvePackages

func ResolvePackages(ctx context.Context, sc buildsafev1.SearchServiceClient, packages Packages) ([]LockPackage, error)

ResolvePackages resolves a list of packages concurrently

type Meta

type Meta struct {
	Description string `hcl:"description"`
}

Meta holds Nix lib meta parameters

type OCIArtifact

type OCIArtifact struct {
	Artifact string `hcl:"environment,label"`
	// Name of the image . Ex: ttl.sh/myproject/app:1h
	Name string `hcl:"name"`
	// OCI Layers in the image
	Layers []string `hcl:"layers,optional"`
	// OCI Layers in the image
	IsBase bool `hcl:"isBase,optional"`
	// Cmd defines the default arguments to the entrypoint of the container.
	Cmd []string `hcl:"cmd,optional"`
	// Entrypoint defines a list of arguments to use as the command to execute when the container starts.
	Entrypoint []string `hcl:"entrypoint,optional"`
	// Env is a list of environment variables to be used in a container.
	EnvVars []string `hcl:"envVars,optional"`
	// ExposedPorts a set of ports to expose from a container running this image. Ex: ["80/tcp", "443/tcp"]
	ExposedPorts []string `hcl:"exposedPorts,optional"`
	// Names of configs to import
	ImportConfigs []string `hcl:"importConfigs,optional"`
}

OCIArtifact to export Nix package outputs to an artifact

func (*OCIArtifact) Validate

func (c *OCIArtifact) Validate(conf *Config) *string

Validate validates OCI Config

type Packages

type Packages struct {
	// Maybe these should be of type Set? https://github.com/deckarep/golang-set
	Development []string `hcl:"development"`
	Runtime     []string `hcl:"runtime"`
}

Packages holds package parameters

type Poetry

type Poetry struct {
	Name         string            `toml:"name"`
	Version      string            `toml:"version"`
	Description  string            `toml:"description"`
	Authors      []string          `toml:"authors"`
	License      string            `toml:"license"`
	Readme       string            `toml:"readme"`
	Dependencies map[string]string `toml:"dependencies"`
	Scripts      map[string]string `toml:"scripts"`
}

Poetry defines structs to match the structure of the TOML file

type PoetryApp

type PoetryApp struct {
	// ProjectDir: path to the root of the project.
	ProjectDir string `hcl:"projectDir"`
	// Src: project source (defaults to projectDir).
	Src string `hcl:"src,optional"`
	// Pyproject: path to pyproject.toml (defaults to projectDir + "/pyproject.toml").
	Pyproject string `hcl:"pyproject,optional"`
	// Poetrylock: poetry.lock file path (defaults to projectDir + "/poetry.lock").
	Poetrylock string `hcl:"poetrylock,optional"`
	// PreferWheels: Use wheels rather than sdist as much as possible (defaults to false).
	PreferWheels bool `hcl:"preferWheels,optional"`
	// CheckGroups: Which Poetry 1.2.0+ dependency groups to run unit tests (defaults to [ "dev" ]).
	CheckGroups []string `hcl:"checkGroups,optional"`
}

PoetryApp defines the parameters for a poetry application.

type PoetryBuildSystem

type PoetryBuildSystem struct {
	Requires     []string `toml:"requires"`
	BuildBackend string   `toml:"build-backend"`
}

PoetryBuildSystem defines structs to match the structure of the TOML file

type PoetryConfig

type PoetryConfig struct {
	Tool        PoetryTool        `toml:"tool"`
	BuildSystem PoetryBuildSystem `toml:"build-system"`
}

PoetryConfig defines structs to match the structure of the TOML file

type PoetryTool

type PoetryTool struct {
	Poetry Poetry `toml:"poetry"`
}

PoetryTool defines structs to match the structure of the TOML file

type RustApp

type RustApp struct {
	// WorkspaceSrc: Source of the workspace.
	WorkspaceSrc string `hcl:"workspaceSrc"`
	// CrateName: name of the project.
	CrateName string `hcl:"projectName"`
	// Release: To enable or disable the release mode, defaults to "true".
	Release bool `hcl:"release"`
	// RustVersion: Version of Rust
	RustVersion string `hcl:"rustVersion,optional"`
	// RustToolChain: Used to override the toolchain
	RustToolChain string `hcl:"rustToolchain,optional"`
	// RustChannel: To support legacy use, this can be a version when supplied alone. Defaults to "stable".
	RustChannel string `hcl:"rustChannel,optional"`
	// RustProfile: Can be set to "minimal" or "default".
	RustProfile string `hcl:"rustProfile,optional"`
	// RootFeatures: A list of activated features on your workspace's crates.
	RootFeatures []string `hcl:"rootFeatures,optional"`
	// FetchCrateAlternativeRegistry: A fetcher for crates on alternative registries.
	FetchCrateAlternativeRegistry string `hcl:"fetchCrateAlternativeRegistry,optional"`
	// HostPlatformCPU: Equivalent to rust's target-cpu codegen option.
	HostPlatformCPU string `hcl:"hostPlatformCPU,optional"`
	// HostPlatformFeatures: Equivalent to rust's target-feature codegen option.
	HostPlatformFeatures []string `hcl:"hostPlatformFeatures,optional"`
	// ExtraRustComponents: Extra rust components to be added with the build process
	ExtraRustComponents []string `hcl:"extraRustComponents,optional"`
	// CargoUnstableFlags: Flags that affect cargo unstable features.
	CargoUnstableFlags []string `hcl:"cargoUnstableFlags,optional"`
	// RustcLinkFlags: Pass extra flags directly to rustc during non-build invocations
	RustcLinkFlags []string `hcl:"rustcLinkFlags,optional"`
	// RustcBuildFlags: Pass extra flags directly to Rustc during build invocations
	RustcBuildFlags []string `hcl:"rustcBuildFlags,optional"`
}

RustApp defines the parameters for a rust application.

Jump to

Keyboard shortcuts

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