git.iko.soy/typeable/nixpkgs
on master help sign in
bitwarden_rs: 1.9.1 -> 1.13.1
commit44dff89215994a99eb4981e20f2c239dab73ffb9 authorMatthijs Steen <emailmatthijs@gmail.com> dateMon 27 Jan 2020, 16:16 (7 years ago) parent3946ade
4 files changed+58−85
nixos/modules/services/security/bitwarden_rs/default.nix+30−14 pkgs/tools/security/bitwarden_rs/cargo-lock-lettre.patch−58 pkgs/tools/security/bitwarden_rs/default.nix+25−13 pkgs/top-level/all-packages.nix+3
nixos/modules/services/security/bitwarden_rs/default.nix+30−14
@@ -18,15 +18,33 @@ let
1818 else key + toUpper x) "" parts;
1919 in if builtins.match "[A-Z0-9_]+" name != null then name else partsToEnvVar parts;
2020
21− configFile = pkgs.writeText "bitwarden_rs.env" (concatMapStrings (s: s + "\n") (
22− (concatLists (mapAttrsToList (name: value:
23− if value != null then [ "${nameToEnvVar name}=${if isBool value then boolToString value else toString value}" ] else []
24− ) cfg.config))));
21+ # Due to the different naming schemes allowed for config keys,
22+ # we can only check for values consistently after converting them to their corresponding environment variable name.
23+ configEnv =
24+ let
25+ configEnv = listToAttrs (concatLists (mapAttrsToList (name: value:
26+ if value != null then [ (nameValuePair (nameToEnvVar name) (if isBool value then boolToString value else toString value)) ] else []
27+ ) cfg.config));
28+ in { DATA_FOLDER = "/var/lib/bitwarden_rs"; } // optionalAttrs (!(configEnv ? WEB_VAULT_ENABLED) || configEnv.WEB_VAULT_ENABLED == "true") {
29+ WEB_VAULT_FOLDER = "${pkgs.bitwarden_rs-vault}/share/bitwarden_rs/vault";
30+ } // configEnv;
31+
32+ configFile = pkgs.writeText "bitwarden_rs.env" (concatStrings (mapAttrsToList (name: value: "${name}=${value}\n") configEnv));
33+
34+ bitwarden_rs = pkgs.bitwarden_rs.override { inherit (cfg) dbBackend; };
2535
2636in {
2737 options.services.bitwarden_rs = with types; {
2838 enable = mkEnableOption "bitwarden_rs";
2939
40+ dbBackend = mkOption {
41+ type = enum [ "sqlite" "mysql" "postgresql" ];
42+ default = "sqlite";
43+ description = ''
44+ Which database backend bitwarden_rs will be using.
45+ '';
46+ };
47+
3048 backupDir = mkOption {
3149 type = nullOr str;
3250 default = null;
@@ -56,23 +74,20 @@ in {
5674 even though foo2 would have been converted to FOO_2.
5775 This allows working around any potential future conflicting naming conventions.
5876
59− Based on the attributes passed to this config option a environment file will be generated
77+ Based on the attributes passed to this config option an environment file will be generated
6078 that is passed to bitwarden_rs's systemd service.
6179
6280 The available configuration options can be found in
63− <link xlink:href="https://github.com/dani-garcia/bitwarden_rs/blob/1.8.0/.env.template">the environment template file</link>.
81+ <link xlink:href="https://github.com/dani-garcia/bitwarden_rs/blob/${bitwarden_rs.version}/.env.template">the environment template file</link>.
6482 '';
65− apply = config: optionalAttrs config.webVaultEnabled {
66− webVaultFolder = "${pkgs.bitwarden_rs-vault}/share/bitwarden_rs/vault";
67− } // config;
6883 };
6984 };
7085
7186 config = mkIf cfg.enable {
72− services.bitwarden_rs.config = {
73− dataFolder = "/var/lib/bitwarden_rs";
74− webVaultEnabled = mkDefault true;
75− };
87+ assertions = [ {
88+ assertion = cfg.backupDir != null -> cfg.dbBackend == "sqlite";
89+ message = "Backups for database backends other than sqlite will need customization";
90+ } ];
7691
7792 users.users.bitwarden_rs = {
7893 inherit group;
@@ -87,7 +102,7 @@ in {
87102 User = user;
88103 Group = group;
89104 EnvironmentFile = configFile;
90− ExecStart = "${pkgs.bitwarden_rs}/bin/bitwarden_rs";
105+ ExecStart = "${bitwarden_rs}/bin/bitwarden_rs";
91106 LimitNOFILE = "1048576";
92107 LimitNPROC = "64";
93108 PrivateTmp = "true";
@@ -109,6 +124,7 @@ in {
109124 path = with pkgs; [ sqlite ];
110125 serviceConfig = {
111126 SyslogIdentifier = "backup-bitwarden_rs";
127+ Type = "oneshot";
112128 User = mkDefault user;
113129 Group = mkDefault group;
114130 ExecStart = "${pkgs.bash}/bin/bash ${./backup.sh}";
pkgs/tools/security/bitwarden_rs/cargo-lock-lettre.patchdeleted−58
@@ -1,58 +0,0 @@
1−diff --git a/Cargo.lock b/Cargo.lock
2−index 2e0b695..6d23410 100644
3−--- a/Cargo.lock
4−+++ b/Cargo.lock
5−@@ -114,8 +114,8 @@ dependencies = [
6− "handlebars 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
7− "jsonwebtoken 6.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
8− "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
9−- "lettre 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
10−- "lettre_email 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
11−+ "lettre 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
12−+ "lettre_email 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
13− "libsqlite3-sys 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
14− "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
15− "multipart 0.16.1 (registry+https://github.com/rust-lang/crates.io-index)",
16−@@ -1007,13 +1007,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
17−
18− [[package]]
19− name = "lettre"
20−-version = "0.9.1"
21−+version = "0.9.2"
22− source = "registry+https://github.com/rust-lang/crates.io-index"
23− dependencies = [
24− "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
25− "bufstream 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
26−- "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
27−- "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
28− "fast_chemail 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)",
29− "hostname 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
30− "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
31−@@ -1026,14 +1024,12 @@ dependencies = [
32−
33− [[package]]
34− name = "lettre_email"
35−-version = "0.9.1"
36−+version = "0.9.2"
37− source = "registry+https://github.com/rust-lang/crates.io-index"
38− dependencies = [
39− "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
40− "email 0.0.20 (registry+https://github.com/rust-lang/crates.io-index)",
41−- "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
42−- "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
43−- "lettre 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
44−+ "lettre 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
45− "mime 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
46− "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
47− "uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
48−@@ -2858,8 +2854,8 @@ dependencies = [
49− "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a"
50− "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
51− "checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f"
52−-"checksum lettre 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "646aee0a55545eaffdf0df1ac19b500b51adb3095ec4dfdc704134e56ea23531"
53−-"checksum lettre_email 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ae1b3d43e4bb7beb9974a359cbb3ea4f93dfba6c1c0c6e9c9f82e538e0f9ab9f"
54−+"checksum lettre 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c66afaa5dfadbb81d4e00fd1d1ab057c7cd4c799c5a44e0009386d553587e728"
55−+"checksum lettre_email 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bbb68ca999042d965476e47bbdbacd52db0927348b6f8062c44dd04a3b1fd43b"
56− "checksum libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)" = "42914d39aad277d9e176efbdad68acb1d5443ab65afe0e0e4f0d49352a950880"
57− "checksum libsqlite3-sys 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fd6457c70bbff456d9fe49deaba35ec47c3e598bf8d7950ff0575ceb7a8a6ad1"
58− "checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c"
pkgs/tools/security/bitwarden_rs/default.nix+25−13
@@ -1,31 +1,43 @@
1−{ stdenv, rustPlatform, fetchFromGitHub, pkgconfig, openssl, Security, CoreServices }:
1+{ stdenv, rustPlatform, fetchFromGitHub
2+, pkgconfig, openssl
3+, Security, CoreServices
4+, dbBackend ? "sqlite", libmysqlclient, postgresql }:
25
3−rustPlatform.buildRustPackage rec {
6+let
7+ featuresFlag = "--features ${dbBackend}";
8+
9+in rustPlatform.buildRustPackage rec {
410 pname = "bitwarden_rs";
5− version = "1.9.1";
11+ version = "1.13.1";
612
713 src = fetchFromGitHub {
814 owner = "dani-garcia";
915 repo = pname;
1016 rev = version;
11− sha256 = "0jfb4b2lp2v01aw615lx0qj1qh73hyrbjn9kva7zqp74wcfw12gp";
17+ sha256 = "0af8cnpx86a096m59wmszcfyrfgf7adlqr39phbg647mgjfzwcrk";
1218 };
1319
14− cargoPatches = [
15− # type annotations required: cannot resolve `std::string::String: std::convert::AsRef<_>`
16− ./cargo-lock-lettre.patch
17− ];
18−
1920 nativeBuildInputs = [ pkgconfig ];
20− buildInputs = [ openssl ] ++ stdenv.lib.optionals stdenv.isDarwin [ Security CoreServices ];
21+ buildInputs = with stdenv.lib; [ openssl ]
22+ ++ optionals stdenv.isDarwin [ Security CoreServices ]
23+ ++ optional (dbBackend == "mysql") libmysqlclient
24+ ++ optional (dbBackend == "postgresql") postgresql;
2125
2226 RUSTC_BOOTSTRAP = 1;
2327
24− cargoSha256 = "0p39gqrqdmgqhngp1qyh6jl0sp0ifj5n3bxfqafjbspb4zph3ls4";
28+ cargoSha256 = "1v6n4aqhd5pyvvhlzhpmq7ykclfxw82wn2bg7n49b53d9p72jwq6";
29+ cargoBuildFlags = [ featuresFlag ];
30+
31+ checkPhase = ''
32+ runHook preCheck
33+ echo "Running cargo cargo test ${featuresFlag} -- ''${checkFlags} ''${checkFlagsArray+''${checkFlagsArray[@]}}"
34+ cargo test ${featuresFlag} -- ''${checkFlags} ''${checkFlagsArray+"''${checkFlagsArray[@]}"}
35+ runHook postCheck
36+ '';
2537
2638 meta = with stdenv.lib; {
27− description = "An unofficial lightweight implementation of the Bitwarden server API using Rust and SQLite";
28− homepage = https://github.com/dani-garcia/bitwarden_rs;
39+ description = "Unofficial Bitwarden compatible server written in Rust";
40+ homepage = "https://github.com/dani-garcia/bitwarden_rs";
2941 license = licenses.gpl3;
3042 maintainers = with maintainers; [ msteen ];
3143 platforms = platforms.all;
pkgs/top-level/all-packages.nix+3
@@ -791,6 +791,9 @@ in
791791 bitwarden_rs = callPackage ../tools/security/bitwarden_rs {
792792 inherit (darwin.apple_sdk.frameworks) Security CoreServices;
793793 };
794+ bitwarden_rs-sqlite = bitwarden_rs;
795+ bitwarden_rs-mysql = bitwarden_rs.override { dbBackend = "mysql"; };
796+ bitwarden_rs-postgresql = bitwarden_rs.override { dbBackend = "postgresql"; };
794797
795798 bitwarden_rs-vault = callPackage ../tools/security/bitwarden_rs/vault.nix { };
796799