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

Show an example default.nix that calls hello.nix #1711

Closed
wants to merge 2 commits into from

Conversation

mightybyte
Copy link
Contributor

The existing hello example nix expression shows how to modify all-packages.nix to build the package. I more frequently find myself wanting to build a local package without having to modify all-packages.nix in order to accomplish that. I couldn't figure it out from reading the manual and had to ask on IRC. It seems like this is probably a common thing, so I thought it would be worth adding to the manual.

@boxofrox
Copy link

boxofrox commented Dec 3, 2017

I've seen projects leave default.nix as is for inclusion in all-packages.nix, and instead create shell.nix to hold the (import <nixpkgs> {}).callPackage ./default.nix. Then building is done simply with nix-shell in the same folder as shell.nix.

Another option I've seen is running nix-build --eval -E '(import <nixpkgs> {}).callPackage ./default.nix on the command line.

Not sure if these are much of an improvement, but at least you don't have to rename your default.nix.

@mightybyte
Copy link
Contributor Author

@boxofrox If we do what you describe and leave default.nix as-is, then we can't run a simple nix-build in our project and have it work. Telling people to run nix-build --eval -E '(import <nixpkgs> {}).callPackage ./default.nix is not an acceptable solution. Getting a drop-dead simple UX is crucial if we want to significantly increase adoption.

I also tend to think that requiring multiple .nix files in order to build your project with nix is a really significant obstacle. So maybe it would be better to package up your above nix-build command somewhere and make it simple to run.

I don't know what the right solution is, but I think it's really important that we figure it out and prominently document it.

@veprbl
Copy link
Member

veprbl commented Mar 13, 2018

I usually just write just a single default.nix as

{ nixpkgs ? import <nixpkgs> {} }:

with nixpkgs;

stdenv.mkDerivation {
  name = "foo";
  # ...
}

This is not compatible with callPackage, but it can be easily adapted if needed.

@shlevy shlevy added the backlog label Apr 1, 2018
@shlevy shlevy self-assigned this Apr 1, 2018
@matthewbauer
Copy link
Member

@veprbl Actually that can be made compatible with callPackage fairly easily:

{ pkgs ? import <nixpkgs> {} }:

with pkgs;

stdenv.mkDerivation {
  name = "foo";
  # ...
}

pkgs is refers to itself so it works both ways (for instance you can do pkgs.pkgs.pkgs.pkgs.hello).

@grahamc
Copy link
Member

grahamc commented Sep 1, 2018

Because this is documenting Nixpkgs, this should be part of Nixpkgs' docs.

@grahamc grahamc closed this Sep 1, 2018
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

Successfully merging this pull request may close these issues.

None yet

6 participants