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

lib: add forSystems #171864

Closed
wants to merge 1 commit into from
Closed

Conversation

MatthewCroughan
Copy link
Contributor

Description of changes

This adds a function lib.forSystems which is similar to forAllSystems from the c-hello flake template

Co-authored-by: Justin Restivo justin@restivo.me

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 22.05 Release Notes (or backporting 21.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

lib/flakes.nix Show resolved Hide resolved
@MatthewCroughan
Copy link
Contributor Author

MatthewCroughan commented May 6, 2022

@alyssais Currently all of our https://github.com/NixOS/templates contain the following boiler plate:

      # System types to support.
      supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];

      # Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
      forAllSystems = nixpkgs.lib.genAttrs supportedSystems;

      # Nixpkgs instantiated for supported system types.
      nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });

But if we merge this, we would be able to reduce it to this:

    forAllSystems = 
      nixpkgs.lib.forSystems
      [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]
      nixpkgs;

Copy link
Member

@jtojnar jtojnar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned on Matrix, I do not think it add value either.

In your examples, you can just use nixpkgs.legacyPackages directly. And I would say most of the time, you will actually want to pass extra arguments to nixpkgs, and in that case you would be instantiating Nixpkgs twice (first in legacyPackages just to get path, and then in your function).

Also see #123117, #124866, #155709, #171235. We probably want to stabilize an API first.

lib/flakes.nix Show resolved Hide resolved
lib/flakes.nix Outdated Show resolved Hide resolved
lib/flakes.nix Outdated Show resolved Hide resolved
@MatthewCroughan MatthewCroughan force-pushed the mc/forSystems branch 2 times, most recently from 4b968d0 to c8956b2 Compare May 6, 2022 22:40
Co-authored-by: Justin Restivo <justin@restivo.me>
@adisbladis
Copy link
Member

With the same motivation as #173093 (comment) I'm closing this.
The lib namespace is not a place for experimental features.

@adisbladis adisbladis closed this May 15, 2022
@roberth roberth mentioned this pull request Dec 28, 2022
13 tasks
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