diff options
| author | seth <[email protected]> | 2024-03-20 02:28:43 -0400 |
|---|---|---|
| committer | seth <[email protected]> | 2024-03-20 06:34:42 +0000 |
| commit | faa038757ced955bb5c0a98dae7be6e7185af677 (patch) | |
| tree | 319cbd2e11cf74e2a464dbaf42370ec1f8eb57de /nix/derivation.nix | |
| parent | 362b80924010d0e425dc41885c8ee148f6d9ca36 (diff) | |
nix: cleanup derivation + static package
Diffstat (limited to 'nix/derivation.nix')
| -rw-r--r-- | nix/derivation.nix | 104 |
1 files changed, 54 insertions, 50 deletions
diff --git a/nix/derivation.nix b/nix/derivation.nix index 5c504ee..3456e6c 100644 --- a/nix/derivation.nix +++ b/nix/derivation.nix @@ -2,57 +2,61 @@ lib, stdenv, naersk, - CoreFoundation, - Security, - SystemConfiguration, + darwin, 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 +}: +naersk.buildPackage { + pname = "teawiebot"; + version = + toString (lib.importTOML ../Cargo.toml).package.version + + "-${self.shortRev or self.dirtyShortRev or "dirty"}"; + + src = lib.fileset.toSource { + root = ../.; + fileset = lib.fileset.unions [ + ../src + ../Cargo.toml + ../Cargo.lock + ../build.rs ]; - - GIT_SHA = builtins.substring 0 7 self.rev or "dirty"; - - RUSTFLAGS = - lib.optionalString lto " -C lto=thin -C embed-bitcode=yes -Zdylib-lto" - + lib.optionalString optimizeSize " -C codegen-units=1 -C panic=abort -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]; - }; - } + }; + + buildInputs = lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ + CoreFoundation + Security + SystemConfiguration + ]); + + env = { + GIT_SHA = self.shortRev or self.dirtyShortRev or "unknown-dirty"; + CARGO_BUILD_RUSTFLAGS = lib.concatStringsSep " " ( + lib.optionals lto [ + "-C" + "lto=thin" + "-C" + "embed-bitcode=yes" + "-Zdylib-lto" + ] + ++ lib.optionals optimizeSize [ + "-C" + "codegen-units=1" + "-C" + "panic=abort" + "-C" + "strip=symbols" + "-C" + "opt-level=z" + ] + ); + }; + + meta = with lib; { + mainProgram = "teawiebot"; + description = "funni bot"; + homepage = "https://github.com/getchoo/teawiebot"; + license = licenses.mit; + maintainers = with maintainers; [getchoo]; + }; +} |
