Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brokenpip3/asdf2nix
asdf2nix is a tool that translates an asdf .tool-versions file into a flake or execute a nix shell
https://github.com/brokenpip3/asdf2nix
asdf flake nix
Last synced: 3 months ago
JSON representation
asdf2nix is a tool that translates an asdf .tool-versions file into a flake or execute a nix shell
- Host: GitHub
- URL: https://github.com/brokenpip3/asdf2nix
- Owner: brokenpip3
- License: mit
- Created: 2024-03-24T22:27:59.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-09-20T08:17:11.000Z (5 months ago)
- Last Synced: 2024-10-04T16:44:12.715Z (4 months ago)
- Topics: asdf, flake, nix
- Language: Python
- Homepage: https://www.brokenpip3.com/posts/2024-27-06-nix-tiny-tools/
- Size: 44.9 KB
- Stars: 12
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# asdf2nix
**asdf2nix** is a tool that converts an [asdf](https://asdf-vm.com/) `.tool-versions` file into a Nix flake or run a nix shell, simplifying the process of transitioning from asdf to Nix.
## Usage
To use **asdf2nix**, run the following command in your project root where the `.tool-versions` file is located:
```bash
nix run github:brokenpip3/asdf2nix --
```You can also specify the file location as an argument if it's in a different directory.
**Note:** Make sure Nix is installed on your system and that flakes are enabled before using this tool.
## Commands
### Flake
```bash
nix run github:brokenpip3/asdf2nix -- flake
```This command generates a flake based on the packages listed in the `.tool-versions` file:
```bash
$ cat .tool-versions
terraform 1.5.2
nodejs 16.15.0$ nix run github:brokenpip3/asdf2nix -- flake
{
description = "A flake with devshell generated from .tools-version";inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
terraform_1_5_2.url = github:NixOS/nixpkgs/0b9be173860cd1d107169df87f1c7af0d5fac4aa;
nodejs_16_15_0.url = github:NixOS/nixpkgs/7b7fe29819c714bb2209c971452506e78e1d1bbd;};
outputs = { self, nixpkgs, flake-utils, ... }@inputs:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
terraform = inputs.terraform_1_5_2.legacyPackages.${system}.terraform;
nodejs = inputs.nodejs_16_15_0.legacyPackages.${system}.nodejs;in
{
devShells.default = pkgs.mkShell {
packages = [
terraform
nodejs];
};
}
);
}
```### Shell
```bash
nix run github:brokenpip3/asdf2nix -- shell
```This command generates and executes a Nix shell based on the packages specified in the `.tool-versions` file.
```bash
$ cat .tool-versions
terraform 1.5.2
nodejs 16.15.0$ nix run github:brokenpip3/asdf2nix -- shell
Generating shell from .tool-versions: nix shell nixpkgs/0b9be173860cd1d107169df87f1c7af0d5fac4aa#terraform nixpkgs/7b7fe29819c714bb2209c971452506e78e1d1bbd#nodejs$ terraform version
Terraform v1.5.2
on linux_amd64
...
```## Limitations
Due to the fact that not all patch versions are present, a slight change between patch versions is tolerated (e.g., `3.4.1` vs `3.4.3`), while a change in minor/major versions will not be considered.
## Credits
* Special thanks to `RikudouSage` for the versions [database](https://github.com/RikudouSage/NixPackageHistoryBackend).
* This repository was initialized with:
```bash
nix flake init -t github:brokenpip3/my-flake-templates#python-poetry
```