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

feat: add convenience eachDefaultSystemMap #60

Merged
merged 1 commit into from
May 17, 2022

Conversation

Misterio77
Copy link
Contributor

@Misterio77 Misterio77 commented Apr 24, 2022

Hello!

As mentioned in #59, eachSystemMap is really powerful now (and helps avoid using //).

It would be nice if we had a eachDefaultSystemMap = eachSystemMap defaultSystems, so we don't have to let it in every flake. So here it is.

For reference, here's an example flake that outputs a module and a package using eachDefaultSystem (with the older defaultPackage and co):

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, utils }:
    rec {
      nixosModules.example = import ./module.nix;
      nixosModule = nixosModules.example;
    } // (utils.lib.eachDefaultSystem (system: rec {
      packages.example = (import nixpkgs { inherit system; }).callPackage ./default.nix { };
      defaultPackage = packages.example;
    }));
}

And using eachDefaultSystemMap (with the newer *.default attribute):

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    utils.url = "github:misterio77/flake-utils/each-default-system-map";
  };

  outputs = { self, nixpkgs, utils }: {
    nixosModules = rec {
      example = import ./module.nix;
      default = example;
    };

    packages = utils.lib.eachDefaultSystemMap (system: rec {
      example = (import nixpkgs { inherit system; }).callPackage ./default.nix { };
      default = example;
    });
  };
}

Thanks!

@Mic92
Copy link
Member

Mic92 commented May 14, 2022

I think the function makes sense. @zimbatm what is your thought?

@aakropotkin
Copy link

aakropotkin commented May 15, 2022

Document it front and center in the README and merge this bad boy.
I added a second example to my original issue that conditionally adds defaultPackage for Nix versions < 2.7.

@zimbatm zimbatm merged commit 04c1b18 into numtide:master May 17, 2022
@zimbatm
Copy link
Member

zimbatm commented May 17, 2022

Does anybody want to send a docs PR? Please 🙏

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

Successfully merging this pull request may close these issues.

4 participants