Naively one would expect that the core functionality of a package manager is "building packages". With nix the situation seems to be a little different: One distributes nix-files/expression (in channels or .nix files) which define derivations (nix-instantiate
) which can be built (nix-build
) to produce binary artifacts which are installed (nix-env -i
) into an environment. At no point a traditional "package file" containing the built artifacts is produced, that can be copied to different machines and/or distributed e.g. as GitHub-releases.
Question:
Is it possible to produce binary packages (i.e. pre-built derivations) with nix tooling?
If not, is this an intentional omission or just a missing feature.
As pointed out by JonRinger on discourse, nix copy
can be used for this purpose, as follows.
If we were to distribute nixpkgs.ag's as a package, we could run:
nix copy nixpkgs.ag --to file://ag.pkg
# We now have a local directory `ag.pkg` which we can tar-up and distribute
# On the client machine, we run the following to install the package
nix copy --from file://ag.pkg nixpkgs.ag
See nix copy --help
for some more details.
Note: this program is EXPERIMENTAL and subject to change.