I want to copy the nixfmt formatter config from my common flake into my desktop flake and server flake.
The common flake contains the setup recommended in the documentation for nixfmt:
{
inputs.nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-24.05";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
in {
formatter = pkgs.nixfmt-rfc-style;
}
);
When running nix fmt
it formats the flake as expected.
The other repos contain the following:
inputs.nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-24.05";
inputs.flake-utils.url = "github:numtide/flake-utils";
common.url = "path:/path/to/common/flake";
outputs = { self, nixpkgs, flake-utils, common }: flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
in {
formatter = common.formatter;
}
);
When running nix fmt
it here fails with:
error: attribute 'formatter.x86_64-linux.type' does not exist
However, when checking if that attribute exists using builtins.trace
, like this:
formatter = builtins.trace common.formatter.x86_64-linux.type common.formatter;
it very much exists and prints: trace: derivation
.
When I try to set it manually using formatter.x86_64-linux.type = "derivation"
it complains that the attribute already exists.
What is going wrong here and how can I make it work?