return result of all packages #26

Closed
teto wants to merge 1 commit from support-packages into master
teto commented 2021-09-15 12:15:10 +00:00 (Migrated from github.com)

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
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 2022-06-29 20:41:53 +00:00 (Migrated from github.com)

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.

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 2022-06-29 22:03:19 +00:00 (Migrated from github.com)

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.

> 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.

Pull request closed

Sign in to join this conversation.
No description provided.