Skip to content

Commit

Permalink
sandwich-contexts: more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasjm committed Dec 3, 2024
1 parent 295f1ef commit 060aa4b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sandwich-contexts/lib/Test/Sandwich/Contexts/Nix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ introduceNixContext'' nodeOptions nixpkgsDerivation = introduce' nodeOptions "In

-- | Introduce a Nix environment containing the given list of packages, using the current 'NixContext'.
-- These packages are mashed together using the Nix @symlinkJoin@ function. Their binaries will generally
-- be found in "\<environment path\>\/bin".
-- be found in @\<environment path\>\/bin@.
introduceNixEnvironment :: (
HasBaseContext context, HasNixContext context
, MonadUnliftIO m
Expand Down
6 changes: 4 additions & 2 deletions sandwich-site/docs/context-libraries/sandwich-contexts.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ The [sandwich-contexts](https://hackage.haskell.org/package/sandwich-contexts) p

The [Test.Sandwich.Contexts.Nix](https://hackage.haskell.org/package/sandwich-contexts/docs/Test-Sandwich-Contexts-Nix.html) module allows you to introduce a `NixContext`. A `NixContext` essentially represents a snapshot of the [Nixpkgs](https://github.com/NixOS/nixpkgs) package collection, plus some auxiliary stuff like a build cache to keep things speedy.

You can introduce any version of Nixpkgs that you [want](https://hackage.haskell.org/package/sandwich-contexts/docs/Test-Sandwich-Contexts-Nix.html#t:NixpkgsDerivation). Some are provided in the library, such as [nixpkgsRelease2405](https://hackage.haskell.org/package/sandwich-contexts/docs/Test-Sandwich-Contexts-Nix.html#v:nixpkgsRelease2405). A basic usage example is as follows:
You can introduce any version of Nixpkgs that you [want](https://hackage.haskell.org/package/sandwich-contexts/docs/Test-Sandwich-Contexts-Nix.html#t:NixpkgsDerivation). Some are provided in the library, such as [nixpkgsRelease2405](https://hackage.haskell.org/package/sandwich-contexts/docs/Test-Sandwich-Contexts-Nix.html#v:nixpkgsRelease2405). Once you introduce a `NixContext`, you can use it to build Nix artifacts. For example, the [introduceNixEnvironment](https://hackage.haskell.org/package/sandwich-contexts-0.3.0.1/docs/Test-Sandwich-Contexts-Nix.html#v:introduceNixEnvironment) function will allow you to build an environment with a given list of packages.

```haskell title="https://github.com/codedownio/sandwich/blob/master/demos/demo-nix/app/Main.hs"
```haskell title="https://github.com/codedownio/sandwich/blob/master/demos/demo-nix/app/Main.hs"p
nixDemo :: TopSpec
nixDemo =
introduceNixContext nixpkgsRelease2405 $
Expand All @@ -22,6 +22,8 @@ nixDemo =
info [i|Found binaries in environment: #{binaries}|]
```

This test will log the various binaries that are available, such as `emacs`, `emacsclient`, and `firefox`. You can now use these artifacts in tests.

## File contexts

The [Test.Sandwich.Contexts.Files](https://hackage.haskell.org/package/sandwich-contexts/docs/Test-Sandwich-Contexts-Files.html) module allows you to introduce named files as contexts.

0 comments on commit 060aa4b

Please sign in to comment.