To use the gerbil-utils package in your Gerbil Scheme project with a Nix Flake, follow these steps:
1. Add gerbil-utils as a Dependency in Your Flake
If you're using a Nix Flake, you'll want to include the gerbil-utils package in your flake.nix. Since gerbil-utils is not a standard Nix package, you can fetch it from its GitHub repository.
Here’s an example of how to add it as an input to your flake:
nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs"; # Or your preferred nixpkgs version
[Redacted Person] = {
url = "github:fare/gerbil-utils";
flake = false; # Since this repo doesn't yet support flakes
};
};
outputs = { self, nixpkgs, gerbil-utils }: {
packages = {
default = nixpkgs.lib.mkShell {
buildInputs = [
(nixpkgs.gerbil-unstable) # Use the Gerbil package
(pkgs.fetchFromGitHub {
owner = "fare";
repo = "gerbil-utils";
rev = "master"; # Or a specific commit / tag
sha256 = "<checksum>"; # Replace with the actual sha256 for the repo
})
];
};
};
};
}
2. Set Up Your Environment with gerbil-nix-env.sh
The repository provides a script, gerbil-nix-env.sh, to configure your environment when working with Nix and [Redacted Person].
Source the script in your shell:
sh
source ./repos/gerbil-utils/gerbil-nix-env.sh
This script sets up important environment variables like GERBIL_LOADPATH and GAMBOPT for compiling and loading Gerbil packages.
Ensure GERBIL_LOADPATH is correctly set up. This is especially important if you’re using libraries from gerbil-utils alongside your own project.
3. Install and Link gerbil-utils
Since gerbil-utils is a Gerbil package, you need to install and link it in your Gerbil Scheme project:
sh
$ git clone https://github.com/fare/gerbil-utils.git
$ cd gerbil-utils
$ gxpkg link github.com/fare/gerbil-utils $PWD
$ ./build.ss
Alternatively, if you’re using Nix Flakes and want to avoid manual installation, ensure your project is built in the same environment where gerbil-utils is included as a dependency.
4. Use gerbil-utils in Your Project
In your Gerbil Scheme code, you can use the utilities provided by gerbil-utils under the clan namespace. For example:
scheme
(import :clan/foo) ;; Replace `foo` with the specific module you want to use
Make sure your GERBIL_LOADPATH includes the path to gerbil-utils. The gerbil-nix-env.sh script takes care of this, but you can also manually verify it:
sh
echo $GERBIL_LOADPATH
5. Testing Your Project
gerbil-utils provides a standardized testing infrastructure that you can adopt in your project. Place your test files in a t/ directory, following the naming conventions described in the README.md.
For example, if you want to test a module foo.ss, create a test file t/foo-test.ss that defines a test-suite:
scheme
(def foo-test
(test-suite "testing foo"
(test-case "test case 1"
;; Your test code here
)))
Run your tests using the Gerbil test runner.
6. Nix-Specific Notes
If you’re working in an interactive Nix shell, use the gerbil-nix-env.sh script to set up the environment.
When building your project in a Nix Flake environment, ensure that the GERBIL_LOADPATH and GERBIL_HOME variables are correctly propagated. You can achieve this by exporting them in your flake.nix or in a wrapper script.
Summary
Add gerbil-utils to your flake.nix.
Use the gerbil-nix-env.sh script to configure your environment.
Install and build gerbil-utils using gxpkg.
Import gerbil-utils modules in your Gerbil Scheme code.
Follow the standardized testing conventions for your project.
By following the steps above, you can seamlessly integrate gerbil-utils into your Gerbil Scheme project using a Nix Flake.