Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions source/guides/recipes/sharing-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ Use the [`inputsFrom` attribute to `pkgs.mkShellNoCC`](https://nixos.org/manual/
# default.nix
let
pkgs = import <nixpkgs> {};
build = pkgs.callPackage ./build.nix {};
myPackage = pkgs.callPackage ./package.nix {};
in
{
inherit build;
inherit myPackage;
shell = pkgs.mkShellNoCC {
inputsFrom = [ build ];
inputsFrom = [ myPackage ];
};
}
```
Expand All @@ -32,10 +32,10 @@ Import the `shell` attribute in `shell.nix`:

## Complete example

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

```nix
# build.nix
# package.nix
{ cowsay, runCommand }:
runCommand "cowsay-output" { buildInputs = [ cowsay ]; } ''
cowsay Hello, Nix! > $out
Expand All @@ -53,7 +53,7 @@ let
pkgs = import nixpkgs { config = {}; overlays = []; };
in
{
build = pkgs.callPackage ./build.nix {};
myPackage = pkgs.callPackage ./package.nix {};
}
```

Expand All @@ -66,26 +66,26 @@ Add an attribute to `default.nix` specifying an environment:
pkgs = import nixpkgs { config = {}; overlays = []; };
in
{
build = pkgs.callPackage ./build.nix {};
myPackage = pkgs.callPackage ./package.nix {};
+ shell = pkgs.mkShellNoCC {
+ };
}
```

Move the `build` attribute into the `let` binding to be able to re-use it.
Move the `myPackage` attribute into the `let` binding to be able to re-use it.
Then take the package's dependencies into the environment with [`inputsFrom`](https://nixos.org/manual/nixpkgs/stable/#sec-pkgs-mkShell-attributes):

```diff
let
nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/tarball/nixos-23.11";
pkgs = import nixpkgs { config = {}; overlays = []; };
+ build = pkgs.callPackage ./build.nix {};
+ myPackage = pkgs.callPackage ./package.nix {};
in
{
- build = pkgs.callPackage ./build.nix {};
+ inherit build;
- myPackage = pkgs.callPackage ./package.nix {};
+ inherit myPackage;
shell = pkgs.mkShellNoCC {
+ inputsFrom = [ build ];
+ inputsFrom = [ myPackage ];
};
}
```
Expand Down
2 changes: 1 addition & 1 deletion source/tutorials/working-with-local-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ let
inherit system;
};
in
pkgs.callPackage ./build.nix { }
pkgs.callPackage ./package.nix { }
```

Add two source files to work with:
Expand Down
Loading