summaryrefslogtreecommitdiff
path: root/parts
diff options
context:
space:
mode:
authorseth <[email protected]>2023-09-07 16:18:29 -0400
committerseth <[email protected]>2023-09-07 17:15:26 -0400
commitf741b550612103dafc1b2ff405de6a816ac5d760 (patch)
tree12842ff11c7b9afc91923463f1d1cdde553117f1 /parts
parentd5b333e95878fb895bc6bba402b9a3d920f737a3 (diff)
flake: switch to nixpkgs rust infra
Diffstat (limited to 'parts')
-rw-r--r--parts/default.nix15
-rw-r--r--parts/derivation.nix60
-rw-r--r--parts/packages.nix25
-rw-r--r--parts/toolchain.nix24
4 files changed, 49 insertions, 75 deletions
diff --git a/parts/default.nix b/parts/default.nix
deleted file mode 100644
index 0f093f8..0000000
--- a/parts/default.nix
+++ /dev/null
@@ -1,15 +0,0 @@
-_: {
- imports = [
- ./deployment.nix
- ./dev.nix
- ./packages.nix
- ./toolchain.nix
- ];
-
- systems = [
- "x86_64-linux"
- "x86_64-darwin"
- "aarch64-linux"
- "aarch64-darwin"
- ];
-}
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];
+ };
+ }
diff --git a/parts/packages.nix b/parts/packages.nix
index 6c5d10b..7126a4e 100644
--- a/parts/packages.nix
+++ b/parts/packages.nix
@@ -1,29 +1,14 @@
{self, ...}: {
perSystem = {
- craneLib,
+ lib,
pkgs,
system,
...
}: {
- packages = {
- cargoArtifacts = craneLib.buildDepsOnly {src = craneLib.cleanCargoSource self;};
-
- teawiebot = pkgs.callPackage ./derivation.nix {inherit craneLib self;};
-
- teawiebot-smol =
- self.packages.${system}.teawiebot.overrideAttrs (_: {
- # statically link musl, optimize for size
- CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl";
-
- CARGO_BUILD_RUSTFLAGS = "-C lto=fat -C embed-bitcode=yes \
- -C target-feature=+crt-static -C opt-level=z -C strip=symbols -C codegen-units=1";
-
- CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER = let
- inherit (pkgs.pkgsStatic.stdenv) cc;
- in "${cc}/bin/${cc.targetPrefix}cc";
- });
-
+ packages = lib.fix (f: {
+ teawiebot = pkgs.callPackage ./derivation.nix {inherit self;};
+ teawiebot-smol = f.teawiebot.override {optimizeSize = true;};
default = self.packages.${system}.teawiebot;
- };
+ });
};
}
diff --git a/parts/toolchain.nix b/parts/toolchain.nix
deleted file mode 100644
index e2201f9..0000000
--- a/parts/toolchain.nix
+++ /dev/null
@@ -1,24 +0,0 @@
-{inputs, ...}: {
- perSystem = {system, ...}: let
- pkgs = import inputs.nixpkgs {
- inherit system;
- overlays = [inputs.fenix.overlays.default];
- };
-
- toolchain = with pkgs.fenix;
- with stable;
- combine [
- cargo
- rustc
- rustfmt
- clippy
- targets."x86_64-unknown-linux-musl".stable.rust-std
- ];
- in {
- _module.args = {
- inherit pkgs toolchain;
-
- craneLib = (inputs.crane.mkLib pkgs).overrideToolchain toolchain;
- };
- };
-}