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

Add mkSimpleFlake? #25

Open
srid opened this issue May 27, 2022 · 8 comments
Open

Add mkSimpleFlake? #25

srid opened this issue May 27, 2022 · 8 comments
Labels
enhancement New feature or request requires upstream change Issues that need a change in Nix, Nixpkgs, etc

Comments

@srid
Copy link
Contributor

srid commented May 27, 2022

In https://github.com/srid/haskell-template I'm using flake-parts in place of flake-utils. The minimal code I came up with in order to replace the latter's eachDefaultSystem is as follows:

  outputs = { self, nixpkgs, flake-parts, ... }:
    flake-parts.lib.mkFlake { inherit self; } {
      systems = nixpkgs.lib.systems.flakeExposed;
      perSystem = { self', inputs', pkgs, system, ... }:
        ..

https://github.com/srid/haskell-template/blob/3fc6858830ecee3d2fe1dfe9a8bfa2047cf561ac/flake.nix#L14-L19

Since I imagine most non-monorepos using flake-parts to repeat the above verbatim, would it be worthwhile to expose a function that obviates both systems and perSystem? i.e.

  outputs = { self, flake-parts, ... }:
    flake-parts.lib.mkSimpleFlake { inherit self; } ({ self', inputs', pkgs, system, ... }: 
      ...
    );

ie., mkSimpleFlake is like mkFlake but uses all systems built by Hydra, as well as assumes the user specifies a single-module flake.

@roberth
Copy link
Member

roberth commented May 27, 2022

In your example, you could still import at the perSystem level, but for consistency, reusable ones should be written for the "top level", as that is the more powerful one. Mixing the two will create confusion errors and a mkSimpleFlake that doesn't support those imports would make the solution unnecessarily hard. This would include adding templates, or a nixosConfigurations.example.

A default value for systems might be a good idea. I hope that the need for this option will go away with a flake format redesign.
It gets you halfway there without adding to the learning curve.

  outputs = { self, nixpkgs, flake-parts, ... }:
    flake-parts.lib.mkFlake { inherit self; } {
      perSystem = { self', inputs', pkgs, system, ... }:
        ..

@srid
Copy link
Contributor Author

srid commented May 27, 2022

A default value for systems might be a good idea [..] It gets you halfway there without adding to the learning curve.

Agreed, I think that's a good idea. 👍🏿

@roberth
Copy link
Member

roberth commented May 27, 2022

Interesting project btw. It would be interesting to turn the template into a reusable module. That way you could achieve a new level of user-friendliness, if you capture the most common haskellPackages configuration and "tricks" in options.

@roberth
Copy link
Member

roberth commented May 27, 2022

And unlike with a template, existing users will benefit from improvements.

@srid
Copy link
Contributor Author

srid commented May 30, 2022

Interesting project btw. It would be interesting to turn the template into a reusable module. That way you could achieve a new level of user-friendliness, if you capture the most common haskellPackages configuration and "tricks" in options.

Done! https://github.com/srid/haskell-flake

Perhaps worth creating a page listing all the flake-parts modules in existence. A module registry of some sorts.

@roberth
Copy link
Member

roberth commented May 30, 2022

Made a start with that in start/index.html earlier. Don't ask me why I wrote that in raw html 😂; #31

@roberth
Copy link
Member

roberth commented Nov 10, 2022

It'd make sense for nixpkgs.flakeModule (TBD) to set a mkDefault for systems, as well as provide nixpkgs.* options for initializing pkgs differently, similar to how NixOS does it, but without the legacy options.

@roberth roberth added enhancement New feature or request requires upstream change Issues that need a change in Nix, Nixpkgs, etc labels Feb 1, 2023
@roberth
Copy link
Member

roberth commented Feb 1, 2023

This can be resolved by Nix not requiring the enumeration of supported systems

Alternatively, or in addition, a nixpkgs flake module could set a default value. nixpkgs does not have a flakeModule yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request requires upstream change Issues that need a change in Nix, Nixpkgs, etc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants