hercules-ci / flake-parts

❄️ Simplify Nix Flakes with the module system
https://flake.parts
MIT License
699 stars 38 forks source link

Attribute set is expected to be unique #202

Closed Doosty closed 7 months ago

Doosty commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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 { ..... }; }'';
      };
    };
  };
}