# `Nerves.Artifact`
[🔗](https://github.com/nerves-project/nerves/blob/v1.15.0/lib/nerves/artifact.ex#L10)

Package artifacts are the product of compiling a package with a
specific toolchain.

# `base_dir`

```elixir
@spec base_dir() :: String.t()
```

Get the base dir for where an artifact for a package should be stored.

The directory for artifacts will be found in the directory returned
by `Nerves.Env.data_dir/0` (i.e. `"/Users/fhunleth/.nerves/artifacts/"`).
This location can be overridden by the environment variable `NERVES_ARTIFACTS_DIR`.

# `build`

```elixir
@spec build(Nerves.Package.t(), Nerves.Package.t()) :: :ok | {:error, File.posix()}
```

Builds the package and produces an  See Nerves.Artifact
for more information.

# `build_path`

```elixir
@spec build_path(Nerves.Package.t()) :: binary()
```

Get the path to where the artifact is built

# `build_path_link`

```elixir
@spec build_path_link(Nerves.Package.t()) :: Path.t()
```

Get the path where the global artifact will be linked to.
This path is typically a location within build_path, but can be
vary on different build platforms.

# `build_runner`

```elixir
@spec build_runner(keyword()) :: {module(), keyword()}
```

# `checksum`

```elixir
@spec checksum(Nerves.Package.t(), [{:short, non_neg_integer()}]) :: String.t()
```

Produce a base16 encoded checksum for the package from the list of files
and expanded folders listed in the checksum config key.

# `clean`

```elixir
@spec clean(Nerves.Package.t()) :: :ok | {:error, term()}
```

Cleans the artifacts for the package build_runners of all packages.

# `dir`

```elixir
@spec dir(Nerves.Package.t()) :: String.t()
```

The full path to the artifact.

# `download_name`

```elixir
@spec download_name(Nerves.Package.t(), [{:checksum_short, non_neg_integer()}]) ::
  String.t()
```

Get the artifact download name

# `download_path`

```elixir
@spec download_path(Nerves.Package.t()) :: String.t()
```

Get the path to where the artifact archive is downloaded to.

# `env_var`

```elixir
@spec env_var(Nerves.Package.t()) :: String.t()
```

Determine the environment variable which would be set to override the path.

# `env_var?`

```elixir
@spec env_var?(Nerves.Package.t()) :: boolean()
```

Check to see if the artifact path is being set from the system env.

# `expand_sites`

```elixir
@spec expand_sites(Nerves.Package.t()) :: [{module(), term()}]
```

Expands the sites helpers from `artifact_sites` in the nerves_package config.

Artifact sites can pass options as a third parameter for adding headers
or query string parameters. For example, if you are trying to resolve
artifacts hosted in a private Github repo, use `:github_api` and
pass a tag and personal access token into the sites helper:

```elixir
{:github_api, "owner/repo", token: "1234567", tag: "v0.1.0"}
```

Or pass query parameters for the URL:

```elixir
{:prefix, "https://my-organization.com", query_params: %{"id" => "1234567", "token" => "abcd"}}
```

You can also use this to add an authorization header for files behind basic auth.

```elixir
{:prefix, "http://my-organization.com/", headers: [{"Authorization", "Basic " <> System.get_env("BASIC_AUTH")}}]}
```

# `ext`

```elixir
@spec ext(Nerves.Package.t()) :: String.t()
```

Determines the extension for an artifact based off its type.
Toolchains use xz compression.

# `host_tuple`

```elixir
@spec host_tuple(Nerves.Package.t()) :: String.t()
```

Get the host_tuple for the package. Toolchains are specifically build to run
on a host for a target. Other packages are host agnostic for now. They are
marked as `portable`.

# `name`

```elixir
@spec name(Nerves.Package.t()) :: String.t()
```

Get the artifact name

# `stale?`

```elixir
@spec stale?(Nerves.Package.t()) :: boolean()
```

Determines if the artifact for a package is stale and needs to be rebuilt.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
