Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danielrolls/shellify
Quickly generate shell.nix files once you have a working shell
https://github.com/danielrolls/shellify
nix nix-shell nixos utility
Last synced: 2 months ago
JSON representation
Quickly generate shell.nix files once you have a working shell
- Host: GitHub
- URL: https://github.com/danielrolls/shellify
- Owner: danielrolls
- License: apache-2.0
- Created: 2023-03-23T17:02:36.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-10-26T22:24:45.000Z (3 months ago)
- Last Synced: 2024-10-28T00:42:14.453Z (3 months ago)
- Topics: nix, nix-shell, nixos, utility
- Language: Haskell
- Homepage:
- Size: 1.4 MB
- Stars: 19
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Shellify
[![Hackage](https://img.shields.io/badge/hackage-shellify-brightgreen.svg)](http://hackage.haskell.org/package/shellify)
Want to quicky get something to build and to have it reproducable and sharable? With [`nix`](https://nixos.org/manual/nix/stable/command-ref/nix-shell.html) it is easy to quickly add dependencies to get something to build. It's also easy to work quickly and iteratively. With this tool, once you're done you can save a `shell.nix` so that you and anybody else can quickly and instantly rebuild with an identical environment with all the same dependencies. Just swap out `nix-shell` or `nix` for `nix-shellify` to create the necessary `shell.nix` in the local directory. It makes saving a basic working `shell.nix` almost instant. Take a look at the short examples below to see the workflow.
## Prerequisites
This utility assumes [nix is installed](https://nixos.org/download.html).
## Example usage without flakes
![Interactive demo showing how to use shellify with flakes](docs/legacy-nix-demo.gif)
I want to run a program called `foo`. When I run `./foo` it complains I don't have python. So I run `nix-shell -p python` and try running `./foo` again.
Now it complains I don't have asciidoc so I come out of the shell and edit the last command to add asciidoc by running `nix-shell -p python asciidoc`. Now it works.
I exit my shell and change `nix-shell -p python asciidoc` to `nix-shellify -p python asciidoc`. It then creates a `shell.nix` which I keep next to foo. It looks like this:
```nix
{ pkgs ? import {} }:pkgs.mkShell {
buildInputs = [
pkgs.asciidoc
pkgs.python
];}
```Now I can just type `nix-shell` and I have what I need to run foo. I can share and everybody else can run foo too without the same search. They also don't need to run it in a conatainer or VM or to maintain depenencies on their system themself.
## Example usage with flakes
![Interactive demo showing how to use shellify with flakes](https://user-images.githubusercontent.com/50051176/258610444-6e848fa4-a675-4aa3-b3b6-d099605bc4b7.gif)
I want to run something called `foo`. When I run `./foo` it complains I don't have python. So I run `nixshell nixpkgs#python` and try running `./foo` again.
Now it complains I didn't have asciidoc so I come out of the shell and edit the last command to add asciideoc by running `nix shell nixpkgs#python nixpkgs#asciidoc`. Now it works.
I exit my shell and change `nix shell nixpkgs#python nixpkgs#asciidoc` to `nix-shellify shell nixpkgs#python nixpkgs#asciidoc`. I do this by quickly extending `nix` to `nix-shellify` using tab completion. It then creates a `flake.nix` and `shell.nix` which I commit in git next to foo. Now I can just type `nix develop` and I have what I need to run foo. I can share and everybody else can quickly run foo too with the same environment. I can also go on to modify my nix files e.g. to run as an app or run an initialisation command when starting the shell.