cabal2nix prevents `nix flake show` (IFD)
The formatter is specified like this:
{
inputs = {
nixpkgs-lib.url = "github:nix-community/nixpkgs.lib";
systems.url = "github:nix-systems/default";
nixfmt.url = "github:serokell/nixfmt";
};
outputs = { self, nixpkgs-lib, systems, nixfmt }:
let
inherit (self.lib) lib;
eachSystem = lib.genAttrs (import systems);
in {
# ...
formatter = eachSystem (system: nixfmt.packages.${system}.default);
};
}
When you run nix flake show:
warning: formatter.aarch64-darwin omitted (use '--all-systems' to show)
warning: formatter.aarch64-linux omitted (use '--all-systems' to show)
warning: formatter.x86_64-darwin omitted (use '--all-systems' to show)
error:
… while evaluating the attribute 'packages.x86_64-linux.default'
at /nix/store/wfjzvlbfj7ccczbphcbd16ncgxs2bj24-source/flake.nix:73:11:
72| packages = rec {
73| default = nixfmt;
| ^
74| nixfmt = pkgs.haskellPackages.nixfmt;
… while evaluating the attribute 'haskellPackages.nixfmt'
at /nix/store/wfjzvlbfj7ccczbphcbd16ncgxs2bj24-source/flake.nix:31:15:
30| packageOverrides = self: super: {
31| nixfmt = self.callCabal2nix "nixfmt" src { };
| ^
32| };
(stack trace truncated; use '--show-trace' to show the full trace)
error: cannot build '/nix/store/770ly489hm8i079paqjq2153c0izx7k6-cabal2nix-nixfmt.drv' during evaluation because the option 'allow-import-from-derivation' is disabled
Unfortunately not really fixable nicely here, this is a Nix bug: https://github.com/NixOS/nix/issues/4265
We could commit the cabal2nix output..
Yeah that would work, it's just not nice, since it requires manual updates (or setting up automated ones). I don't think that's worth it for a bug that should really be fixed in Nix.
For the sake of having this formatter be adopted by anyone, I wouldn't be waiting for Nix to solve this particular issue for us. It's been an issue for quite some time now, and I can't say "run nix flake show to see what this provides" and instead I have to say "use this complicated Nix eval piped to sed".
Also prevents nix flake check do that you have to come up with something other than checking the status code in an integration script.
I would also like to see IFD not being fully required as it prevents usage in hydra.
Fair enough, let's reconsider!
Note that this package is already in nixpkgs without IFD via hackage
This is actually blocking my ability to use nix fmt as well - specifying the nixfmt package here: https://github.com/remi-gelinas/rosetta/blob/trunk/flake.nix#L45
Results in nix fmt failing. Targeting the aarch64-darwin package on an M1 machine, it still attempts to evaluate the formatters for other systems, and encounters IFD as aarch64-darwin can't build the cabal2nix package for x86_64-linux.
Not sure if this specifically is a Nix issue or a nixfmt issue, or one that I can work around, but it's really blocking my attempt to adopt nixfmt :/
@remi-gelinas Hmm I just tried it on an aarch64-darwin machine, but couldn't reproduce the problem. I also don't see why it would need to build anything for x86_64-linux. Can you share exactly how you're getting the problem along with the error message?
I just did an isolated reproduction attempt with a barebones flake like so:
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs?rev=c4ce542c774aa505fd80d86d9d5de51349328e43";
nixfmt.url = "github:NixOS/nixfmt?rev=3bcb63c13e7aaf0b8e14081cf0c14c44f62e840a";
};
outputs = {nixpkgs, nixfmt, ...}: let
supportedSystems = [
"aarch64-darwin"
"x86_64-linux"
];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
in {
formatter = forAllSystems (system: nixfmt.packages.${system}.nixfmt);
};
}
and it works correctly, totally as expected. I am assuming the problem lies somewhere in my usage of flake-parts to generate the flake options then. Seems to not be an actual issue! That being said, I do still have to explicitly allow IFD for flake operations to work as expected, so this issue is still a problem
We're closing this. This isn't the place to track cabal2nix's requirement on IFD, nor papercuts with using IFD and flakes. We could vendor the results of running cabal2nix, but we don't think it's worth the effort: it would get out of sync or require more CI to keep it in sync.
This only affects people using our flake, we encourage people to instead consume nixfmt from nixpkgs.
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/formatting-team-meeting-2025-07-22/67066/1