Skip to content

[package outputs] generate buildInputs for package-outputs in flake #1721

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

Merged
merged 3 commits into from
Jan 17, 2024

Conversation

savil
Copy link
Collaborator

@savil savil commented Jan 11, 2024

Summary

This PR reads the outputs field from the Config for a package.

For packages with non-default outputs in the config, we specify:

  1. They are not to be taken from the binary cache
  2. They are exempt from the flakeInput.buildInputs() that are specified in the generated flake's devshell.buildInputs

Instead, we generate a symlinkJoin derivation of the form:

            (pkgs.symlinkJoin {
              name = "prometheus-combined";
              paths = [
                # each output is printed here
                nixpkgs-fd04be-pkgs.prometheus.cli
                nixpkgs-fd04be-pkgs.prometheus.out
              ];
            })

This prometheus-combined derivation is useful so that when we derive the nix-profile from the flake's buildInputs as in #1692, it is treated as a single package. Without this, we could inline each output as a distinct buildInput in the flake's devshell, but then the nix profile would treat each output as its own package.

How was it tested?

Added testscript unit-test. Also, ran the same steps inside the testscript manually.

setup:

# add package with multiple outputs
devbox add prometheus --outputs cli,out

# add package for a specific nixpkgs commit hash (as a control)
devbox add github:nixos/nixpkgs/fd04bea4cbf76f86f244b9e2549fca066db8ddff#hello

then the generated flake is:

❯ cat .devbox/gen/flake/flake.nix
{
   description = "A devbox shell";

   inputs = {
     nixpkgs.url = "github:NixOS/nixpkgs/fd04bea4cbf76f86f244b9e2549fca066db8ddff";
     nixpkgs-fd04be.url = "github:NixOS/nixpkgs/fd04bea4cbf76f86f244b9e2549fca066db8ddff";
     gh-nixos-nixpkgs-fd04bea4cbf76f86f244b9e2549fca066db8ddff.url = "github:NixOS/nixpkgs/fd04bea4cbf76f86f244b9e2549fca066db8ddff";
   };

   outputs = {
     self,
     nixpkgs,
     nixpkgs-fd04be,
     gh-nixos-nixpkgs-fd04bea4cbf76f86f244b9e2549fca066db8ddff,
   }:
      let
        pkgs = nixpkgs.legacyPackages.x86_64-darwin;
        nixpkgs-fd04be-pkgs = (import nixpkgs-fd04be {
          system = "x86_64-darwin";
          config.allowUnfree = true;
          config.permittedInsecurePackages = [
          ];
        });
        gh-nixos-nixpkgs-fd04bea4cbf76f86f244b9e2549fca066db8ddff-pkgs = (import gh-nixos-nixpkgs-fd04bea4cbf76f86f244b9e2549fca066db8ddff {
          system = "x86_64-darwin";
          config.allowUnfree = true;
          config.permittedInsecurePackages = [
          ];
        });
      in
      {
        devShells.x86_64-darwin.default = pkgs.mkShell {
          buildInputs = [
            (builtins.fetchClosure {
              fromStore = "https://cache.nixos.org";
              fromPath = "/nix/store/0djljz0g4s6f55xcnw7fpzcy7af7rxid-go-1.21.4";
              inputAddressed = true;
            })




            (pkgs.symlinkJoin {
              name = "prometheus-combined";
              paths = [
                nixpkgs-fd04be-pkgs.prometheus.cli
                nixpkgs-fd04be-pkgs.prometheus.out
              ];
            })
            gh-nixos-nixpkgs-fd04bea4cbf76f86f244b9e2549fca066db8ddff-pkgs.hello
          ];
        };
      };
 }

this leads to $buildInputs in a devbox shell to be:

❯ echo $buildInputs
/nix/store/0djljz0g4s6f55xcnw7fpzcy7af7rxid-go-1.21.4 /nix/store/9dn3rzv04x63n0kz2jwpgz82rdlsa56h-prometheus-combined /nix/store/4xy6iv0ph2v6w7n06cw5ra7cmyvignkm-hello-2.12.1

where the prometheus-combined derivation has the cli and out outputs combined:

❯ ls -al /nix/store/9dn3rzv04x63n0kz2jwpgz82rdlsa56h-prometheus-combined/bin/
total 0
dr-xr-xr-x 4 root wheel 128 Dec 31  1969 .
dr-xr-xr-x 4 root wheel 128 Dec 31  1969 ..
lrwxr-xr-x 1 root wheel  76 Dec 31  1969 prometheus -> /nix/store/hizpsf2f5gc7l810328382xicjb9gc73-prometheus-2.48.1/bin/prometheus
lrwxr-xr-x 1 root wheel  78 Dec 31  1969 promtool -> /nix/store/8x6psdqn3945pbs0ww5wanmfhvvz2iyl-prometheus-2.48.1-cli/bin/promtool

Copy link
Collaborator Author

savil commented Jan 11, 2024

@savil savil force-pushed the savil/package-outputs-2 branch 2 times, most recently from 0e3f58f to 252f808 Compare January 11, 2024 23:14
@savil savil requested a review from gcurtis January 11, 2024 23:14
@savil savil changed the title [package outputs] generate selected output in flake [package outputs] generate buildInputs for package-outputs in flake Jan 11, 2024
@savil savil marked this pull request as ready for review January 11, 2024 23:14
@savil savil force-pushed the savil/package-outputs-1 branch from 373895c to 4d73d2c Compare January 11, 2024 23:20
@savil savil force-pushed the savil/package-outputs-2 branch from 252f808 to 7677c6e Compare January 11, 2024 23:20
Base automatically changed from savil/package-outputs-1 to main January 12, 2024 00:14
Copy link
Contributor

@mikeland73 mikeland73 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, will let @gcurtis take a look as well.

@savil savil force-pushed the savil/package-outputs-2 branch from 7677c6e to fc6f68a Compare January 12, 2024 23:58
@savil savil changed the base branch from main to savil/profile-from-flake-2 January 12, 2024 23:58
@savil savil force-pushed the savil/profile-from-flake-2 branch from 062cc7f to 93ef16e Compare January 13, 2024 00:07
@savil savil force-pushed the savil/package-outputs-2 branch from fc6f68a to 89f58f9 Compare January 13, 2024 00:07
@savil savil force-pushed the savil/profile-from-flake-2 branch from 93ef16e to 9fe6bea Compare January 13, 2024 00:14
@savil savil force-pushed the savil/package-outputs-2 branch from 89f58f9 to 4dad679 Compare January 13, 2024 00:14
@savil savil force-pushed the savil/profile-from-flake-2 branch from 9fe6bea to b0dd286 Compare January 13, 2024 00:59
@savil savil force-pushed the savil/package-outputs-2 branch from 4dad679 to 18c071e Compare January 13, 2024 00:59
@savil savil force-pushed the savil/package-outputs-2 branch from 18c071e to afd3f9e Compare January 16, 2024 18:13
@savil savil force-pushed the savil/profile-from-flake-2 branch from 336ce68 to 1f0aead Compare January 16, 2024 18:24
@savil savil force-pushed the savil/package-outputs-2 branch from afd3f9e to c06ca5b Compare January 16, 2024 18:24
@savil savil force-pushed the savil/profile-from-flake-2 branch from 1f0aead to 62f5cb2 Compare January 16, 2024 22:25
@savil savil force-pushed the savil/package-outputs-2 branch from c06ca5b to 1f3c4f3 Compare January 16, 2024 22:25
@savil savil force-pushed the savil/profile-from-flake-2 branch from 62f5cb2 to 7fc9961 Compare January 16, 2024 23:08
@savil savil force-pushed the savil/package-outputs-2 branch from 1f3c4f3 to 687ed4e Compare January 16, 2024 23:08
Base automatically changed from savil/profile-from-flake-2 to main January 17, 2024 01:14
@savil savil force-pushed the savil/package-outputs-2 branch from 687ed4e to 02ef19d Compare January 17, 2024 01:14
@savil savil force-pushed the savil/package-outputs-2 branch from 02ef19d to 8da2bd0 Compare January 17, 2024 01:35
@savil savil merged commit a09dbdc into main Jan 17, 2024
@savil savil deleted the savil/package-outputs-2 branch January 17, 2024 02:02
mikeland73 added a commit that referenced this pull request Jan 18, 2024
mikeland73 added a commit that referenced this pull request Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants