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

Attribute set is expected to be unique #202

Closed
Doosty opened this issue Dec 25, 2023 · 2 comments
Closed

Attribute set is expected to be unique #202

Doosty opened this issue Dec 25, 2023 · 2 comments

Comments

@Doosty
Copy link

Doosty commented Dec 25, 2023

Im not sure if i am using this right but of these three options nixosConfigurations works when defined multiple times but homeConfigurations and colmena give error: The option `flake.homeConfigurations' is defined multiple times while it's expected to be unique.

Help much appreciated.

module file 1

  flake.nixosConfigurations = { "host1" = inputs.nixpkgs.lib.nixosSystem { ..... };  };
  flake.homeConfigurations = { "user@host1" = inputs.home-manager.lib.homeManagerConfiguration { ..... };
  flake.colmena = { "host1" = { ..... };

module file 2

  flake.nixosConfigurations = { "host2" = inputs.nixpkgs.lib.nixosSystem { ..... };  };
  flake.homeConfigurations = { "user@host2" = inputs.home-manager.lib.homeManagerConfiguration { ..... };
  flake.colmena = { "host2" = { ..... };
@terlar
Copy link

terlar commented Dec 26, 2023

I think this is due to the attribute not having any merging strategy defined. In order to have a merging strategy you need to define an option for the attribute. I think this question was answered in #201.

You can use the mkSubmoduleOptions from flake-parts-lib.

See the example how it is done for nixosConfigurations:
https://github.com/hercules-ci/flake-parts/blob/main/modules/nixosConfigurations.nix#L14

@Doosty
Copy link
Author

Doosty commented Dec 26, 2023

That works, thank you. For anyone wondering, all i did was import this file in my flake.nix and now homeConfigurations work the same as nixosConfigurations.

{ lib, flake-parts-lib, ... }:
let
  inherit (lib)
    mkOption
    types
    literalExpression
    ;
  inherit (flake-parts-lib)
    mkSubmoduleOptions
    ;
in
{
  options = {
    flake = mkSubmoduleOptions {
      homeConfigurations = mkOption {
        type = types.lazyAttrsOf types.raw;
        default = { };
        description = ''Instantiated Home-Manager configurations.'';
        example = literalExpression ''{ "user@host" = inputs.home-manager.lib.homeManagerConfiguration { ..... }; }'';
      };
    };
  };
}

@Doosty Doosty closed this as completed Dec 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants