diff options
| author | seth <[email protected]> | 2023-12-15 02:40:21 -0500 |
|---|---|---|
| committer | seth <[email protected]> | 2023-12-15 16:41:13 -0500 |
| commit | aad424b4ba9989be4536390749ad0de351dd13ef (patch) | |
| tree | fe99931dc498d69c8d09d23c4b5aed7661212231 /nix/derivation.nix | |
| parent | 03223e6e6d061a18b66a69092c59e6a0cb6d1d3f (diff) | |
flake: move nix to folder to nix/
Diffstat (limited to 'nix/derivation.nix')
| -rw-r--r-- | nix/derivation.nix | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/nix/derivation.nix b/nix/derivation.nix new file mode 100644 index 0000000..061baea --- /dev/null +++ b/nix/derivation.nix @@ -0,0 +1,58 @@ +{ + lib, + stdenv, + naersk, + CoreFoundation, + Security, + SystemConfiguration, + self, + 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"; + version = builtins.substring 0 8 self.lastModifiedDate or "dirty"; + + src = filterSource ../.; + + buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ + CoreFoundation + Security + SystemConfiguration + ]; + + GIT_SHA = builtins.substring 0 7 self.rev or "dirty"; + + 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; linux ++ darwin; + maintainers = with maintainers; [getchoo]; + }; + } |
