garn v0.0.19: Bringing existing flake files into your garn project
Release announcement for garn version v0.0.19, which includes the ability to import Nix flakes from the internet and from your repository.
Today we're releasing Garn v0.0.19, which includes the ability to import existing flake files into your Garn project.
This is useful for depending on flakes hosted online, for example on GitHub. But it can also help with migrating existing Nix flake projects over to Garn.
Importing flakes from online sources
You can pull in flake files from git repositories using importFromGithub, importFromGitlab, and importFromSourcehut.
For example the following Garn file creates an environment with Jujutsu installed (an alternative CLI tool for git repos):
const flake = garn.importFromGithub({ repo: "martinvonz/jj", revOrRef: "v0.11.0", }); export const devEnv = garn.emptyEnvironment.withDevTools([ flake.getPackage("default"), ]);
You can enter the Environment with garn enter devEnv. Inside there, you will have access to the jj executable. And wherever you run this it will be the same version everywhere.
If you want to import a repo that's not on GitHub, GitLab or SourceHut, you can use the lower-level importFlake.
Importing flakes from within your repo
You can use callFlake to import an existing flake file that is checked into the same repo as your Garn file. This is mostly useful for migrating existing nixified repos to Garn.
Working with imported flakes
These imported flakes can be combined with your existing Garn project using the ImportedFlake helpers.
You can convert apps, checks, dev-shells, and packages from your flake file into Garn Executables, Checks, Environments, and Packages, respectively.
Here is an example for what a Garn file could look like that imports an existing flake file from ./legacy/flake.nix:
const flake = callFlake("./legacy"); export const main = mkNpmProject({ description: "some project", src: ".", nodeVersion: "18", }) .add(() => ({ // expose the formatter from the imported flake file format: flake.getApp("format"), // run all checks from the imported flake file. allChecks: flake.allChecks, // build all packages from the imported flake file. allPackages: flake.allPackages, }))
We hope this will make it easier to get started with Garn.
Full v0.0.19 changelog
- Add garn.javascript.prettier plugin to automatically format and check javascript formatting using prettier.
- Add garn.callFlake helper to allow importing flake files by local path.
- Add garn.importFlake helper to allow importing flake files by url, e.g. from GitHub.
Continue Reading
We've added incremental compilation to garnix. In this blog, we discuss prior art on incremental compilation in Nix, and describe our own design.
A short note about custom typing for functions in Nix