Skip to content
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

Add "bundle" command to Nix #3880

Merged
merged 6 commits into from Jul 31, 2020
Merged

Add "bundle" command to Nix #3880

merged 6 commits into from Jul 31, 2020

Conversation

matthewbauer
Copy link
Member

@matthewbauer matthewbauer commented Jul 30, 2020

This adds a ‘nix bundle’ command which hooks into nix-bundle. It can
be used in a similar way as nix-bundle, with the benefit of hooking
into the new “app” functionality. For instance,

$ nix bundle nixpkgs#jq
$ ./jq --help
jq - commandline JSON processor [version 1.6]
...
$ scp jq machine-without-nix:
$ ssh machine-without-nix ./jq
jq - commandline JSON processor [version 1.6]
...

Note that nix-bundle currently requires Linux to run. Other bundlers
might not have that requirement.

“bundlers” are meant to be reusable, so that, other repos can
implement their own bundling.

Fixes #3705

This adds a ‘nix export’ command which hooks into nix-bundle. It can
be used in a similar way as nix-bundle, with the benefit of hooking
into the new “app” functionality. For instance,

$ nix export nixpkgs#jq
$ ./jq --help
jq - commandline JSON processor [version 1.6]
...
$ scp jq machine-without-nix:
$ ssh machine-without-nix ./jq
jq - commandline JSON processor [version 1.6]
...

Note that nix-bundle currently requires Linux to run. Other exporters
might not have that requirement.

“exporters” are meant to be reusable, so that, other repos can
implement their own bundling.

Fixes NixOS#3705
@grahamc
Copy link
Member

grahamc commented Jul 30, 2020

Would this be applicable to something like the nixos-generators project? This looks like something that would require fairly substantial docs.

@grahamc
Copy link
Member

grahamc commented Jul 30, 2020

Oops, that sounds pretty down on the idea. I'm super in to it. I'd love to be able to easily export closures in some fashion, especially being pluggable.

@matthewbauer
Copy link
Member Author

Would this be applicable to something like the nixos-generators project? This looks like something that would require fairly substantial docs.

So this doesn't 100% fit into nixos-generators, but I think we might be able to tweak the exporters format to handle this. Right now, we are expecting the flake to be an "App", like is expected in nix run. nixos-generators wants a NixOS configuration. Flakes do know about nixos configurations, so it is definitely possible to add support. We'd probably want to separate them so there's no ambiguity. So we could have "appExporters" and "nixosExporters".

@zimbatm
Copy link
Member

zimbatm commented Jul 30, 2020

I like that the exporter is itself a derivation so we can keep this composable.

Copy link
Member

@edolstra edolstra left a comment

Choose a reason for hiding this comment

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

Thanks, looks great!

src/nix/export.cc Outdated Show resolved Hide resolved
src/nix/export.cc Outdated Show resolved Hide resolved

using namespace nix;

struct CmdExport : InstallableCommand
Copy link
Member

Choose a reason for hiding this comment

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

The name export is pretty vague and overloaded (e.g. we already have a nix-store --export). It's worth noting that this command does not actually export anything by itself since the build result is in the Nix store.

Maybe bundle (though that's not really correct either)?

Or an "apply" flag to nix build analogous to nix eval --apply, e.g. nix build --apply-generator github:matthewbauer/nix-bundle hello.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I thought export would imply it doesn't just have to be nix-bundle proper, but it is a little confusing. I suppose you could make an exporter / bundler that just produces a .nar though.

src/nix/export.cc Outdated Show resolved Hide resolved
src/nix/export.cc Outdated Show resolved Hide resolved
@edolstra
Copy link
Member

BTW nix run now also works on regular packages, e.g. nix run nixpkgs#gimp works. Maybe the exporter should be applied to an store path rather than an app. Whether the exporter can handle a package containing multiple programs is up to the exporter.

@matthewbauer matthewbauer changed the title Add "export" to Nix Add "bundle" command to Nix Jul 30, 2020
@matthewbauer
Copy link
Member Author

matthewbauer commented Jul 30, 2020

Renamed from "export" to "bundle" for now. Open to other names (or consolidation with another command). I like having it be top-level as it's quite similar in function to "build" / "run", though.

@matthewbauer
Copy link
Member Author

BTW nix run now also works on regular packages, e.g. nix run nixpkgs#gimp works. Maybe the exporter should be applied to an store path rather than an app. Whether the exporter can handle a package containing multiple programs is up to the exporter.

I like having a single entry point for these things since it means you don't have to guess what to run. At the very least, something like this would need hints of which store path to run. Right now "program" is just a path with context to an executable.

@edolstra edolstra merged commit 0604cfd into NixOS:master Jul 31, 2020

struct CmdBundle : InstallableCommand
{
std::string bundler = "github:matthewbauer/nix-bundle";
Copy link
Member

Choose a reason for hiding this comment

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

is the plan to integrate this with nixpkgs or another shared github org?

Copy link
Member

@Mic92 Mic92 Aug 21, 2020

Choose a reason for hiding this comment

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

I also would say this should be in github.com/NixOS/nix-bundle and there should be a hydra jobset to make sure all artifacts are in the binary cache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integrate nix-bundle into new Nix command
5 participants