Hello! I am attempting to package the password manager software “bitwarden_rs”. This software requires the unstable release of Rust to compile. I would like to use rustPlatform.buildRustPackage
due to its convenience, but I am not sure how to use it with unstable rustc
. It appears that the version of rustc
in nixos-unstable
is 1.35.0 (Stable), so the following nix expression fails to compile the software.
with import (fetchTarball https://nixos.org/channels/nixos-unstable/nixexprs.tar.xz) {};
rustPlatform.buildRustPackage rec {
pname = "bitwarden_rs";
version = "1.9.1";
src = fetchFromGitHub {
owner = "dani-garcia";
repo = pname;
rev = version;
sha256 = "0jfb4b2lp2v01aw615lx0qj1qh73hyrbjn9kva7zqp74wcfw12gp";
};
cargoSha256 = "1ffbg8giqq674zgji5iihiy36051yxypz8wij3fzygp3paj16wsk";
nativeBuildInputs = [python3 cmake pkg-config openssl];
buildInputs = [ sqlite ];
}
The documentation for builtRustPackage
here does not mention anything about this.
This is my first attempt at nix packaging, so I may be missing something obvious.
3 Likes
I’m fairly certain that is already packaged.
Yup. Even has a module. See master/nixos/modules/services/security/bitwarden_rs
Wow! I have no idea how I missed that, but that solves my problem. Thank you.
Rizary
January 9, 2020, 12:44am
4
Hi! I came up with the same question and find this thread. Even though it has been closed, I am still wondering on how do I make unstable rustc from mozilla-nixpkgs’ rust-overlay for another package that I’m working on, but still leverage from rustPlatform
feature.
I think the answer didn’t solved the question in general and maybe the correct answer will help beginners in the future.
You can always pass an overlay when importing nixpkgs:
mozillaOverlay = builtins.fetchurl { url = ...; sha256 = ...; };
with import <nixpkgs> { overlays = [ mozillaOverlay ]; };
Another possibility is to create a new Rust platform using your preferred nightly version. E.g., you could create a function such as:
{ callPackage, fetchFromGitHub, makeRustPlatform }:
# The date of the nighly version to use.
date:
let
mozillaOverlay = fetchFromGitHub {
owner = "mozilla";
repo = "nixpkgs-mozilla";
rev = "9f35c4b09fd44a77227e79ff0c1b4b6a69dff533";
sha256 = "18h0nvh55b5an4gmlgfbvwbyqj91bklf1zymis6lbdh75571qaz0";
};
mozilla = callPackage "${mozillaOverlay.out}/package-set.nix" {};
rustNightly = (mozilla.rustChannelOf { inherit date; channel = "nightly"; }).rust;
in makeRustPlatform {
cargo = rustNightly;
rustc = rustNightly;
}
You can then use this function to create Rust platforms for a given nightly. E.g.:
let
rustPlatform = callPackage ./rust-platform-nightly.nix {};
in (rustPlatform "2019-07-30").buildRustPackage rec {
# ...
}
8 Likes
SRGOM
August 27, 2020, 7:49pm
7
This is how to use danieldk’s way to make a platform.
mozilla_rust_channel = ( nixpkgs.rustChannelOf rustVersion );
new_rustc= mozilla_rust_channel.rust;
new_cargo= mozilla_rust_channel.cargo;
new_fetchCargoTarball=nixpkgs.rustPlatform.fetchCargoTarball.override{
cargo = new_cargo ;
};
new_buildRustPackage =nixpkgs.rustPlatform.buildRustPackage.override{
cargo = new_cargo;
rustc = new_rustc;
fetchCargoTarball = new_fetchCargoTarball;
};
new_rustcSrc = mozilla_rust_channel.rust-src;
new_rustPlatform = {
rust = {
rustc = new_rustc;
cargo = new_cargo;
};
fetchCargoTarball = new_fetchCargoTarball;
buildRustPackage = new_buildRustPackage;
rustcSrc = new_rustcSrc;
};
1 Like
It’s interesting you have to do all that to make it work. I am still using what I wrote in my post and it still works in CI.
Function to make a nightly Rust platform:
{ callPackage, fetchFromGitHub, makeRustPlatform }:
# The date of the nighly version to use.
date:
let
sources = import ./sources.nix;
mozilla = callPackage "${sources.mozilla}/package-set.nix" {};
rustNightly = (mozilla.rustChannelOf { inherit date; channel = "nightly"; }).rust;
in makeRustPlatform {
cargo = rustNightly;
Used here:
, fetchgit
# Native build inputs
, maturin
, rustNightly
# Build inputs
, python
}:
(rustNightly "2020-01-20").buildRustPackage rec {
pname = "alpino-tokenizer";
version = "0.1.1";
name = "${python.libPrefix}-${pname}-${version}";
src = fetchgit {
url = "https://git.sr.ht/~danieldk/alpino-tokenizer-python";
rev = version;
sha256 = "14f345wcqbkfrxxifs64b9686sn5g8sxlr7zsvncq2zqykcasspq";
};
But maybe I am not using what is necessary to trigger the error that you are encountering?
1 Like
SRGOM
October 5, 2020, 10:52am
9
For posterity: My earlier comment is effective now in https://github.com/asdf8dfafjk/nixpkgs-mozilla/ .