summaryrefslogtreecommitdiff
path: root/parts/derivation.nix
diff options
context:
space:
mode:
Diffstat (limited to 'parts/derivation.nix')
-rw-r--r--parts/derivation.nix60
1 files changed, 44 insertions, 16 deletions
diff --git a/parts/derivation.nix b/parts/derivation.nix
index f95446f..8fc5bd8 100644
--- a/parts/derivation.nix
+++ b/parts/derivation.nix
@@ -1,20 +1,48 @@
{
lib,
- stdenv,
- craneLib,
+ rustPlatform,
self,
- ...
-}:
-craneLib.buildPackage {
- src = craneLib.cleanCargoSource self;
- inherit (self.packages.${stdenv.hostPlatform.system}) cargoArtifacts;
+ lto ? true,
+ optimizeSize ? false,
+}: let
+ filter = path: type: let
+ path' = toString path;
+ base = baseNameOf path';
+ parent = baseNameOf (dirOf path');
- meta = with lib; {
- mainProgram = "teawiebot";
- description = "funni bot";
- homepage = "https://github.com/getchoo/teawiebot";
- license = licenses.mit;
- platforms = with platforms; unix;
- maintainers = with maintainers; [getchoo];
- };
-}
+ dirBlocklist = ["parts"];
+
+ matches = lib.any (suffix: lib.hasSuffix suffix base) [".rs"];
+ isCargo = base == "Cargo.lock" || base == "Cargo.toml";
+ isCopypasta = parent == "copypastas";
+ isAllowedDir = !(builtins.elem base dirBlocklist);
+ in
+ (type == "directory" && isAllowedDir) || matches || isCargo || isCopypasta;
+
+ filterSource = src:
+ lib.cleanSourceWith {
+ src = lib.cleanSource src;
+ inherit filter;
+ };
+in
+ rustPlatform.buildRustPackage {
+ pname = "teawiebot";
+ version = builtins.substring 0 8 self.lastModifiedDate or "dirty";
+
+ src = filterSource self;
+
+ cargoLock.lockFile = ../Cargo.lock;
+
+ RUSTFLAGS =
+ lib.optionalString lto " -C lto=thin -C embed-bitcode=yes"
+ + lib.optionalString optimizeSize " -C codegen-units=1 -C strip=symbols -C opt-level=z";
+
+ meta = with lib; {
+ mainProgram = "teawiebot";
+ description = "funni bot";
+ homepage = "https://github.com/getchoo/teawiebot";
+ license = licenses.mit;
+ platforms = with platforms; unix;
+ maintainers = with maintainers; [getchoo];
+ };
+ }