Skip to content

Commit

Permalink
use an example with an explicit build-time dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
fricklerhandwerk committed Nov 13, 2023
1 parent 400a564 commit 766aeae
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions source/guides/recipes/sharing-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@ Import the `shell` attribute in `shell.nix`:

## Complete example

Assuming your build is defined in `build.nix`:
Assume your build is defined in `build.nix`:

```nix
# build.nix
{ hello }: hello
{ cowsay, runCommand }:
runCommand "cowsay-output" { buildInputs = [ cowsay ]; } ''
cowsay Hello, Nix! > $out
''
```

and your project is defined in `default.nix`:
In this example, `cowsay` is declared as a build-time dependency using `buildInputs`.

Further assume your project is defined in `default.nix`:

```nix
# default.nix
Expand Down Expand Up @@ -81,27 +86,22 @@ Then take the package's dependencies into the environment with `inputsFrom`:
+ inherit build;
shell = pkgs.mkShell {
+ inputsFrom = [ build ];
+ packages = [ which ];
};
}
```

:::{note}
Here we also added `which` to the shell's `packages` to be able to quickly check the presence of the build inputs.
:::

Finally, import the `shell` attribute in `shell.nix`:

```nix
# shell.nix
(import ./.).shell
```

Test the development environment:
Check the development environment, it contains the build-time dependency `cowsay`:

```console
$ nix-shell --pure
[nix-shell]$ which gcc
[nix-shell]$ cowsay shell.nix
```

## Next steps
Expand Down

0 comments on commit 766aeae

Please sign in to comment.