summaryrefslogtreecommitdiff
path: root/nix/package.nix
blob: 483c786c4d952860605d34e6b78fc02bb940e696 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
{
  lib,
  stdenv,
  openssl,
  pkg-config,
  removeReferencesTo,
  rustPlatform,

  self,
  lto ? true,
  optimizeSize ? false,
}:

let
  inherit (self) lastModifiedDate;
  date =
    let
      year = lib.substring 0 4 lastModifiedDate;
      month = lib.substring 4 2 lastModifiedDate;
      day = lib.substring 6 2 lastModifiedDate;
    in
    if (self ? "lastModifiedDate") then
      lib.concatStringsSep "-" [
        year
        month
        day
      ]
    else
      "0";
in

rustPlatform.buildRustPackage {
  pname = "nixpkgs-tracker-bot";
  version = "0.2.0-unstable-${date}";

  src = lib.fileset.toSource {
    root = ../.;
    fileset = lib.fileset.unions [
      ../Cargo.lock
      ../Cargo.toml

      ../crates
    ];
  };

  cargoLock.lockFile = ../Cargo.lock;

  nativeBuildInputs = [
    pkg-config
    removeReferencesTo
  ];

  buildInputs = [ openssl ];

  # `-C panic="abort"` breaks checks
  doCheck = !optimizeSize;

  postFixup = lib.optionalString stdenv.hostPlatform.isStatic ''
    find "$out" \
      -type f \
      -exec remove-references-to -t ${stdenv.cc.libc} -t ${openssl.dev} '{}' +
  '';

  env =
    let
      rustFlags =
        lib.optionalAttrs lto {
          lto = "thin";
          embed-bitcode = "yes";
        }
        // lib.optionalAttrs optimizeSize {
          codegen-units = 1;
          opt-level = "s";
          panic = "abort";
          strip = "symbols";
        };
    in
    {
      RUSTFLAGS = toString (lib.mapAttrsToList (name: value: "-C ${name}=${toString value}") rustFlags);
    }
    // lib.optionalAttrs stdenv.hostPlatform.isStatic {
      OPENSSL_STATIC = 1;
    };

  meta = {
    description = "Discord app for tracking Nixpkgs pull requests";
    homepage = "https://github.com/getchoo/nixpkgs-tracker-bot";
    license = lib.licenses.mit;
    maintainers = [ lib.maintainers.getchoo ];
    mainProgram = "nixpkgs-tracker-bot";
  };
}