I like it; it’s easy to understand. I’m getting the following error, though. I’m using your expression as is; only replacing "project-name" with "hello-haskell-flake".
$ nix build
warning: Git tree '/home/amy/github/hello-haskell-flake' is dirty
warning: creating lock file '/home/amy/github/hello-haskell-flake/flake.lock'
warning: Git tree '/home/amy/github/hello-haskell-flake' is dirty
error: attribute 'walloper' missing
at /nix/store/l868qm2zjpl3bip6cx8kivpjf466fcs8-source/flake.nix:36:26:
35|
36| defaultPackage = self.packages.${system}.walloper;
| ^
37|
(use '--show-trace' to show detailed location information)
Also, I would like to be able to use flakes as NixOS modules. I believe that just requires adding something like this (changing hello to the package name, of course).
Ah, damn it. That was an oversight on my side. The default package should relate to packages.pkg, i.e. in the example above it should be defaultPackage = self.packages.${system}.pkg;
The full, and now hopefully correct, file would be
However, it seems to have the same issue as the default Haskell template.
nix flake show github:mhwombat/hello-haskell-flake
github:mhwombat/hello-haskell-flake/408d723baba37be72b69c44488c6621d685bc385
├───defaultPackage
error: cannot build '/nix/store/faz0ibrbnfa0c8zskmxfvxirpw205b18-cabal2nix-hello-haskell-flake.drv' during evaluation because the option 'allow-import-from-derivation' is disabled
(use '--show-trace' to show detailed location information)
I really like the way you’ve written it, though. I find it easier to understand than the template.
@cdepillabout , I was intrigued by cabal2nixWithoutIFD. I understand it’s a proof-of-concept, but could it be a solution to this problem, at least for Haskell?
This is a big simplification, but the way I see it, there are two “camps” of people in the Nix community: Pro-IFD and Anti-IFD.
Pro-IFD: These are people that generally think IFD should be used for packaging things. Most Haskellers fall into this camp (given tools like haskell.nix and callCabal2nix), as well as users of the other FOO2nix tools.
Using IFD can often really simplify your day-to-day maintenance of Nix code. I fall into this camp, and I personally feel like it is an anti-pattern to try to do Haskell develop with Nix and not rely on something like haskell.nix or callCabal2nix.
Anti-IFD: These are people that think Nix should try to evolve without relying on the IFD functionality. There are a bunch of good reasons for not allowing IFD. You see evidence of this mindset with Nixpkgs/Hydra not allowing IFD, and flakes not allowing IFD by default for things like nix flake show.
I’m not sure if there are many people trying to work on unifying these two camps. (Although one person that comes to mind is @Ericson2314 with a bunch of his recent RFCs: Pull requests · NixOS/rfcs · GitHub).
cabal2nixWithoutIFD (and more generally, PureNix) is an attempt to replicate most of the functionality of cabal2nix, but implemented entirely in Nix. The idea came from poetry2nix, which works basically the same. This type of approach gives you all the benefits of something like cabal2nix, but without requiring IFD.
Although, in practice, cabal2nix relies on Cabal-the-library, which is incredibly complex. Porting the necessary functionality from Cabal to cabal2nixWithoutIFD would be quite an undertaking. My guess is that cabal2nixWithoutIFD will forever stay a neat proof-of-concept, and never become a tool that is actually used.
(edit: The above explanation paints people as either being pro-IFD or anti-IFD, but in practice almost everyone sees the benefits of IFD, and understands the drawbacks. Most people are firmly in the middle.)
Thank you so much for that explanation! I’m very interested in this issue now.
I’m trying an approach that I expect will probably fail, but will be a good learning experience for me. I am using cabal build directly in a flake, with a configuration that tells it not to try to connect to the Internet. For the moment, I have a simple Haskell program with no dependencies on anything except base. I’m just curious to see how far I’ll get.