nix-community / flakelight

Framework for simplifying flake setup [maintainer=@accelbread]
MIT License
177 stars 3 forks source link

Is it possible to make available packages depend on system? #21

Closed rickynils closed 1 week ago

rickynils commented 1 month ago

Sometimes I have specific packages that I don't want to build for specific systems. Is it possible to somehow specify this in flakelight? The only way I found is this:

packages = {
  my-package = { stdenv, ... }: if stdenv.hostPlatform.system == "x86_64-linux" then null else ...
}

This makes the package disappear from nix flake show if I'm on an x86_64-linux system. However, if I'm on another system the package will actually be visible (because it is not evaluated to null unless --all-systems is used). This feels a bit hacky and inconvenient.

accelbread commented 1 month ago

Hmm, thats likely the best way at the moment, except for using outputs.packages instead of packages.

I'll see about fixing this.

Probably, I'll make it so that packages gets a system arg with the system it is generating for.

rickynils commented 1 month ago

(I deleted my comment by mistake, so here it is again)

A system arg would great. Preferably a top-level arg (like { pkgs, system }: <attrs of pkg defs>), but maybe it has to be per-package.

I have a similar need for checks. It works a little bit better today since it has a top-level pkgs argument (pkgs: <attrs of checks>), but not needing to look att pkgs.stdenv would be even nicer.

rickynils commented 1 month ago

So, setting a package to null doesn't really work. For example, when using --all-systems you will then get errors because the package checks doesn't handle the fact that a package can be null. Also devShells seem to fail evaluate, but I'm not sure why.

accelbread commented 1 week ago

Apologies for the delay, have been busy.

I've fixed this in 32bf894a5033451cc1bc252086e33c0e1ef6859e.

Now if packages is a function it also gets a system arg. An example of use is in the test added along with the change.

Unfortunately, unlike checks, packages can't get pkgs as an arg since that would cause infinite recursion (pkgs is defined in terms of packages). It can however get the system.

Also, in checks, you don't need to look at pkgs.stdenv, can just use pkgs.system.

Thanks for the report! Feel free to reopen or open a new issue if there is still an issue.

accelbread commented 1 week ago

Added docs in f34d07dd57bf0df4d0695a1067b3c12307f2bd5e.