Derivation to build nix-doc using Home Manager
gvolpe opened this issue · comments
Hi,
I installed nix-doc
and the plugin via nix-env
as suggested but I would like to be able to install it via Home Manager. I came up with this derivation that only installs nix-doc
but I'm not really familiar with buildRustPackage
and the whole Rust environment.
This works but I want to believe there's a better way to only build nix-doc
other than cd nix-doc
and then cd ..
?
{ rustPlatform }:
rustPlatform.buildRustPackage rec {
pname = "nix-doc";
version = "v0.3.1";
src = builtins.fetchTarball {
url = "https://github.com/lf-/nix-doc/archive/${version}.tar.gz";
sha256 = "1hiz0fsbsl74m585llg2n359gs8i2m6jh8zdikkwxd8xq7qmw032";
};
cargoSha256 = "06b36jv8hk4gqqm4nbh9gfszncvixs3zcjph45wlx7z5m61y9sdg";
preBuild = "cd nix-doc/";
postBuild = "cd ..";
doCheck = false;
}
I don't know about the specifics of home-manager, so I'm not sure what the reason is to avoid building the library (closure size? others?), but I'll have a crack anyway:
This repository is shipped as a cargo workspace. https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/rust/default.nix appears to suggest an option called buildAndTestSubdir, which does basically the same thing as your trick.
We are a cargo workspace, so it would be possible to pass --packages (iirc) to cargo build to only build the one package you want, but it appears that the Nix infrastructure doesn't support flags to cargo (?).
Also, with naersk, the alternate rust infrastructure used here for compatibility with older nixpkgs versions, there's a specific packages list parameter, confusingly named "targets" (as a target is also a term used in cross compiling), that you can see in our default.nix. If you're interested, you can submit a pull request to add support for making the plugin optional by passing a parameter to our default.nix (nixpkgs' lib.optional is a function that would be useful) by gating adding the plugin to that targets list. I totally get why you might not want to use my packaging for closure size reasons though, as it would probably mean pulling in another rustc.
FWIW this derivation is not Home Manager specific but a simple derivation. It would be similar to what you would do if you had to create a derivation to make nix-doc
available upstream on Nixpkgs. Any plans to do that btw? :)
We are a cargo workspace, so it would be possible to pass --packages (iirc) to cargo build to only build the one package you want, but it appears that the Nix infrastructure doesn't support flags to cargo (?).
I'm not really sure but I can have a look.
If you're interested, you can submit a pull request to add support for making the plugin optional by passing a parameter to our default.nix (nixpkgs' lib.optional is a function that would be useful) by gating adding the plugin to that targets list.
For now what I have works but I raised this issue to see if I could improve it. I'll get back to you in case I find out how to do so :)
@gvolpe I might try to get it into nixpkgs, it could be fun I suppose, especially given we already have most of the work done :)
And it's not like I'd be required to actively maintain it any more than I maintain this tool 🤔. Might have a crack at it later this week depending on how much time/energy I have for open source after work.
That'd be awesome! Nixpkgs maintainers are pretty helpful usually :)