summaryrefslogtreecommitdiff
path: root/parts/derivation.nix
blob: fb7031381a9f0c97f43a07f834960bcd1fd4d586 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{
  lib,
  naersk,
  version,
  lto ? false,
  optimizeSize ? false,
}: let
  filter = path: type: let
    path' = toString path;
    base = baseNameOf path';
    parent = baseNameOf (dirOf path');

    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
  naersk.buildPackage {
    pname = "teawiebot";
    inherit version;

    src = filterSource ../.;

    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];
    };
  }