top | item 30684160

(no title)

Shoue | 4 years ago

> - Can't build with nix-build. After long time searching it seems like you're supposed to run nix-build -E 'with import <nixpkgs> {}; callPackage ./default.nix {}' - shouldn't there be a simpler way for this common case?

This is because the default.nix you have is exporting a lambda that expects arguments to be saturated, `callPackage` does this for you automagically hence why you have to use it.

Instead you probably want the nixpkgs import line _inside_ default.nix, either in a let-in binding or using the `?` operator to default a lambda argument to something, usually nixpkgs itself bound to a `pkgs` argument so you can use `pkgs`[0].

Even better, you can use Niv to pin nixpkgs to a specific nixpkgs commit so that it doesn't change as you update your system's nixpkgs channel with the `nix-channel` command because `<nixpkgs>` is special syntax referring to what's stored in your $NIX_PATH[1].

[0]: see the default argument section: https://nixos.wiki/wiki/Nix_Expression_Language [1]: https://nixos.org/guides/nix-pills/nix-search-paths.html

discuss

order

pmarreck|4 years ago

You provided what is probably a logical explanation but didn't answer the question in the way he meant it (I think), which is: Addressing common use-cases should be a simple matter. Addressing complex use-cases should ALSO be a simple matter ideally, but is permitted to be a complex matter. Here we have a case where a common use-case is addressed by a complex-seeming solution (unless you are essentially "degreed" in Nix, apparently, and understand exactly why partial function application won't work here or whatever). Or are you saying he's actually doing it wrong and built the nix file wrong?

I'm about to dive headfirst into this nix business and this is intimidating, lol

soraminazuki|4 years ago

> Addressing common use-cases should be a simple matter.

Fully agree, but the given example isn't such a case but rather incorrect code.

The example is somewhat akin to writing the following Python code and expecting it to print "hello".

    def main():
        print 'hello'
It wouldn't work because you need to call the main function. It's not a problem of Python not addressing common use cases.