edolstra / flake-compat

MIT License
254 stars 71 forks source link

return result of all packages #26

Closed teto closed 1 year ago

teto commented 3 years ago

in a flake I work on, I need to provide a compatibility layer for other packages than the default one, exposing result gives me the possibility. I dont mind if this gets closed, just wanted to share the possibility.

With this PR, one can use the following shell.nix to reference a specific package


{ system ? builtins.currentSystem or "unknown-system" }:

(import (
let
    lock = builtins.fromJSON (builtins.readFile ./flake.lock);
  in fetchTarball {
    url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
    sha256 = lock.nodes.flake-compat.locked.narHash; }
) {
  src =  ./.;
}).result.packages.${system}.ci
sigprof commented 2 years ago

This change does not seem to be needed, because both defaultNix and shellNix are already based on result (only the value for the default key is changed, and default is not a standard name for a flake output, so a flake should not define it anyway; if you have a really nonstandard flake, you could still reach the original default value through .defaultNix.outputs.default or .shellNix.outputs.default).

So you already should be able to use .shellNix.packages.${system}.ci in your code instead of the suggested .result.packages.${system}.ci.

BTW, a more direct way to refer to the default devshell in shell.nix would be using .shellNix.default instead of just .shellNix; omitting the .default part results in Nix scanning the flake outputs and finding just a single default derivation there, which seems to work at the moment, but might break if another derivation appears in some top-level attribute of the flake output for some reason.

teto commented 2 years ago

BTW, a more direct way to refer to the default devshell in shell.nix would be using .shellNix.default instead of just .shellNix; omitting the .default part results in Nix scanning the flake outputs

I think that's the part that confused me. Now that I read the code with more flake experience, seems like you are spot on. Closing, thanks for the review.