nix-community / flakelight

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

Cannot use packages in `perSystem` #16

Closed ratson closed 5 months ago

ratson commented 6 months ago

Given https://github.com/ratson/bug-report/tree/flakelight-preSystem

nix flake show github:ratson/bug-report/flakelight-preSystem is giving error error: 'checks.aarch64-linux' is not an attribute set.

hello3 in nix/packages is unable to refer to hello2 defined perSystem in flake.nix.

accelbread commented 6 months ago

Hi, thanks for reaching out!

Should not need perSystem there. Inside of perSystem, you can directly set outputs, not flakelight options, so if using perSystem, would have to set packages.x86_64-linux. Though setting it as such bypasses flakelight's packages support.

This works and is what I assume was intended:

 {
   inputs = {
     nixpkgs.url = "nixpkgs/nixos-unstable";
     flakelight.url = "github:nix-community/flakelight";
     flakelight.inputs.nixpkgs.follows = "nixpkgs";
   };
   outputs = { flakelight, ... }@inputs:
       flakelight ./. {
        inherit inputs;

-      perSystem = pkgs: {
-        packages = {
-          hello2 = pkgs.hello;
-        };
+      packages = {
+        hello2 = pkgs: pkgs.hello;
       };
     };
 }

outputs and perSystem are intended to bypass flakelight's options, so works as expected. Is there another use case I'm missing for using perSystem's packages?

ratson commented 6 months ago

@accelbread I would like to have something like

packages = pkgs: let
  base-pkg = pkgs.some-pkg;
  opts = pkgs.hello;
in {
   pkg1 = base-pkg.override {
       inherit opts;
   };
   pkg2 = base-pkg.override {
       inherit opts;
       opts2 = true;
   };
}

Is there a way to share pkgs like the above?

accelbread commented 6 months ago

Hmm, currently the above as is won't work.

packages currently can't be set to a function that takes pkgs. What can be done is:

packages = let
  override-base-pkg = pkgs: args: pkgs.some-pkg.override ({
    opts = pkgs.hello;
  } // args);
in {
   pkg1 = pkgs: override-base-pkg pkgs {};
   pkg2 = pkgs: override-base-pkg pkgs {
     opts2 = true;
   };
}

Though that is making the default available so maybe like:

packages = {
   pkg1 = pkgs: pkgs.some-pkg.override {
     opts = pkgs.hello;
   };
   pkg2 = { pkg1 }: pkg1.override {
     opts2 = true;
   };
}

If the latter works, then that is good; I use that pattern for a few flakes at work.

If former is needed, the current syntax is suboptimal. It could be improved, though doing so will need packages to be able to take pkgs as an arg. Might be possible, will have to see if I can get that working.

accelbread commented 5 months ago

Closing, feel free to re-open if theres more to discuss.