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

cabal2nix prevents nix flake show (IFD) #140

Open
spikespaz opened this issue Nov 10, 2023 · 11 comments
Open

cabal2nix prevents nix flake show (IFD) #140

spikespaz opened this issue Nov 10, 2023 · 11 comments

Comments

@spikespaz
Copy link

spikespaz commented Nov 10, 2023

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
@infinisil
Copy link
Member

Unfortunately not really fixable nicely here, this is a Nix bug: NixOS/nix#4265

@infinisil infinisil closed this as not planned Won't fix, can't repro, duplicate, stale Nov 13, 2023
@yorickvP
Copy link
Contributor

We could commit the cabal2nix output..

@infinisil
Copy link
Member

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.

@spikespaz
Copy link
Author

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".

@spikespaz
Copy link
Author

spikespaz commented Nov 14, 2023

Also prevents nix flake check do that you have to come up with something other than checking the status code in an integration script.

@SuperSandro2000
Copy link
Member

I would also like to see IFD not being fully required as it prevents usage in hydra.

@infinisil infinisil reopened this Nov 14, 2023
@infinisil
Copy link
Member

Fair enough, let's reconsider!

@yorickvP
Copy link
Contributor

Note that this package is already in nixpkgs without IFD via hackage

@remi-gelinas
Copy link

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 :/

@infinisil
Copy link
Member

@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?

@remi-gelinas
Copy link

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

@infinisil infinisil moved this to Todo in Nix formatting May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

5 participants