gytis-ivaskevicius / flake-utils-plus

Use Nix flakes without any fluff.
MIT License
494 stars 54 forks source link

Build fails with nix-darwin: The option `_module.args.inputs' is defined multiple times. #113

Closed azuwis closed 2 years ago

azuwis commented 2 years ago

Demo flake.nix https://gist.github.com/azuwis/47a67c40f61afaa02362b79a0496afeb:

{
  description = "Darwin demo";

  inputs = {
    nixpkgs.url = github:nixos/nixpkgs/nixpkgs-unstable;
    utils.url = "github:gytis-ivaskevicius/flake-utils-plus/v1.3.1";

    darwin.url = "github:lnl7/nix-darwin/master";
    darwin.inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = inputs@{ self, nixpkgs, utils, darwin, ... }:
    utils.lib.mkFlake {
      inherit self inputs;

      hosts.demo.system = "aarch64-darwin";
      hosts.demo.output = "darwinConfigurations";
      hosts.demo.builder = args: darwin.lib.darwinSystem (removeAttrs args [ "system" ]);
    };
}

Error log:

$ nix build 'git+https://gist.github.com/azuwis/47a67c40f61afaa02362b79a0496afeb?ref=main#darwinConfigurations.demo.system'            
trace: warning: literalExample is deprecated, use literalExpression instead, or use literalDocBook for a non-Nix description.
trace: lib.crossLists is deprecated, use lib.cartesianProductOfSets instead
trace: warning: literalExample is deprecated, use literalExpression instead, or use literalDocBook for a non-Nix description.
trace: warning: lib.mkFixStrictness has no effect and will be removed. It returns its argument unmodified, so you can just remove any calls.
trace: `lib.nixpkgsVersion` is deprecated, use `lib.version` instead!
trace: warning: lib.readPathsFromFile is deprecated, use a list instead
trace: Warning: `showVal` is deprecated and will be removed in the next release, please use `traceSeqN`
trace: lib.zip is deprecated, use lib.zipAttrsWith instead
error: The option `_module.args.inputs' is defined multiple times.

       Definition values:
       - In `/nix/store/5m88sbxj815z8bzrij15bp4w4siakw1i-source/eval-config.nix'
       - In `<unknown-file>'
(use '--show-trace' to show detailed location information)
$ nix-info -m    
 - system: `"aarch64-darwin"`
 - host os: `Darwin 21.3.0, macOS 12.2.1`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.6.1`
 - channels(azuwis): `""`
 - channels(root): `""`
 - nixpkgs: `/nix/store/a94a18pdxp29hggy2v5aij4z11h54y8p-source`
bbbbbailey commented 2 years ago

I implemented a hacky fix and confirmed that my M1 system builds using the fix, I'll take the weekend to clean it up and issue a PR.

montchr commented 2 years ago

@bbuscarino If you track the latest from the master branch in your flake-utils-plus input, do you get different results?

utils.url = "github:gytis-ivaskevicius/flake-utils-plus";

Also, I recall running into some issue recently with Nix 2.6.x on a MBP. Not sure if that's been fixed – I'm still running 2.5.1 at the moment. But I may give the latest version another shot soon.

montchr commented 2 years ago

And, FWIW, I've been using this library with nix-darwin for a while without issue – I don't think https://github.com/LnL7/nix-darwin/issues/319 as mentioned in this project's readme is applicable any longer – see also https://github.com/LnL7/nix-darwin/pull/317.

I've been using the darwin-support branch from https://github.com/divnix/digga for a few weeks now, but that uses this library behind the scenes. But even prior to that, I had been using FUP on darwin without issue.

I was able to use darwin.lib.darwinSystem as a direct input to the builder option using the latest version of flake-utils-plus:

https://github.com/montchr/dotfield/blob/c6bbf0ab1ac38621f67e9bb37ef96e272cf2df3b/flake.nix#L165

What happens if you try something like this:

hosts.demo.builder = darwin.lib.darwinSystem;
bbbbbailey commented 2 years ago

@montchr The latest master flake-utils-plus and nix-darwin is where this pops up.

Looking through the histories of each repository, it's not clear to me why this didn't break earlier. I recently upgraded to M1 and hit this bug when migrating. flake-utils-plus and nix-darwin both add pkgs and inputs to the module args:

My fix opts to pass inputs and pkgs via the builder function if the output is darwinConfigurations, which solves the problem. The fix in question.

gytis-ivaskevicius commented 2 years ago

Can any of you test it with the latest version of FUP? I've added a little example which seems to evaluate https://github.com/gytis-ivaskevicius/flake-utils-plus/tree/master/examples/darwin

azuwis commented 2 years ago

Can any of you test it with the latest version of FUP? I've added a little example which seems to evaluate https://github.com/gytis-ivaskevicius/flake-utils-plus/tree/master/examples/darwin

The example builds fine with:

    nixpkgs.url = github:nixos/nixpkgs/release-21.05;

but not with:

    nixpkgs.url = github:nixos/nixpkgs/nixpkgs-unstable;

error message:

$ nix build .#darwinConfigurations.Hostname1.system
warning: Git tree '/private/tmp/flake-utils-plus' is dirty
trace: lib.crossLists is deprecated, use lib.cartesianProductOfSets instead
trace: warning: literalExample is deprecated, use literalExpression instead, or use literalDocBook for a non-Nix description.
trace: warning: lib.mkFixStrictness has no effect and will be removed. It returns its argument unmodified, so you can just remove any calls.
trace: `lib.nixpkgsVersion` is deprecated, use `lib.version` instead!
trace: warning: lib.readPathsFromFile is deprecated, use a list instead
trace: Warning: `showVal` is deprecated and will be removed in the next release, please use `traceSeqN`
trace: lib.zip is deprecated, use lib.zipAttrsWith instead
error: The option `_module.args.inputs' is defined multiple times.

       Definition values:
       - In `/nix/store/fl382jvr5cjyv0za2nlanz8n5ic52czp-source/eval-config.nix'
       - In `<unknown-file>'
(use '--show-trace' to show detailed location information)
infinisil commented 2 years ago

Randomly stumbling upon this. https://github.com/NixOS/nixpkgs/pull/160489 is causing this to fail now when it didn't before. The reason it's failing is as the error says, the inputs argument is defined twice, the first of which points to https://github.com/LnL7/nix-darwin/blob/17fbc68a6110edbff67e55f7450230a697ecb17e/eval-config.nix#L17, while the second one is not as clear, but it should point to https://github.com/gytis-ivaskevicius/flake-utils-plus/blob/06dba5f3b4fa2cc0bfc98ce9cd6f9a4d8db11d46/lib/mkFlake.nix#L181. The error message could be improved by adding a _file attribute to the module there.

azuwis commented 2 years ago

For anyone interested, you can use:

utils.url = "github:gytis-ivaskevicius/flake-utils-plus/pull/117/head";

as a temporary workaround.

ForsakenHarmony commented 2 years ago

Any plans for the fix to get merged?

fufexan commented 2 years ago

@ForsakenHarmony both PRs adding it (#117 and #119) fail the tests. We can't merge the fix before making sure tests work as well.

@gytis-ivaskevicius planning to fix that PR?

gytis-ivaskevicius commented 2 years ago

Fixed in master

ForsakenHarmony commented 2 years ago

That's great, thanks