Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to create shell.nix from nix-shell arguments #1967

Open
wchresta opened this issue Mar 12, 2018 · 5 comments
Open

Option to create shell.nix from nix-shell arguments #1967

wchresta opened this issue Mar 12, 2018 · 5 comments
Assignees

Comments

@wchresta
Copy link
Member

wchresta commented Mar 12, 2018

It is very easy to initiate a nix-environment through nix-shell that has a given set of derivations active. This is relatively easy to understand for new users and use right away. There are also a lot of tips and comments that rely on nix-shell's arguments.

The step from giving a derivation name in the command line (nix-shell -p python37) to creating a well formatted shell.nix is not small. It would be helpful for new users if there was an option or command for the nix-shell command that turns the current arguments into an equivalent shell.nix that has the same effect.

That way, a user can not only quickly recreate a previous environment, but can also learn how shell.nix files are supposed to look like and how packages and environment are connected together. This can be seen as both, a quality of life feature, as well as a mini-tutorial for nix-derivations.

Example:

$ nix-shell -p "haskellPackages.ghcWithPackages (p: [p.lens p.JuicyPixels])"
[environment with ghc and lens, JuicyPixels]
$ nix-shell init -p "haskellPackages.ghcWithPackages (p: [p.lens p.JuicyPixels])"
Created shell.nix. You can use nix-shell without arguments now.
$ cat shell.nix
# nix-shell init -p "haskellPackages.ghcWithPackages (p: [p.lens p.JuicyPixels])"
{ pkgs ? import <nixpkgs> {} }:
with pkgs;

# Insert some useful and helpful comments explaining what the expressions do
stdenv.mkDerivation rec {
  name = "env";
  buildInputs = [ (haskellPackages.ghcWithPackages (p: [p.lens p.JuicyPixels]))
                ];
}
$ nix-shell
[environment with ghc and lens, JuicyPixels]

Ref: nixpkgs #36634

@prusnak
Copy link
Member

prusnak commented Oct 6, 2018

It might be also worth considering whether we want to edit the shell.nix file from currently running shell.

For example, if I run pipenv install foo it will install package into currently running pipenv and update the Pipfile file, so next-time when I run pipenv in this directory, the environment will contain this new package as well.

@stale
Copy link

stale bot commented Feb 14, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Feb 14, 2021
@PierreR
Copy link

PierreR commented Jul 24, 2021

Sound like a great idea to me. I am constantly copy/paste the same basic shell.nix which is not that nice.

@stale stale bot removed the stale label Jul 24, 2021
@stale
Copy link

stale bot commented Apr 17, 2022

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Apr 17, 2022
@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/how-do-nix-profiles-and-flakes-fit-together/28139/4

@stale stale bot removed the stale label May 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants