diff options
| -rw-r--r-- | flake.lock | 141 | ||||
| -rw-r--r-- | flake.nix | 43 | ||||
| -rw-r--r-- | parts/default.nix | 15 | ||||
| -rw-r--r-- | parts/derivation.nix | 60 | ||||
| -rw-r--r-- | parts/packages.nix | 25 | ||||
| -rw-r--r-- | parts/toolchain.nix | 24 |
6 files changed, 73 insertions, 235 deletions
@@ -1,22 +1,6 @@ { "nodes": { - "advisory-db": { - "flake": false, - "locked": { - "lastModified": 1693432889, - "narHash": "sha256-0daNvQDpL4R17vPG/ieybIblUYf6a2dbWr/mwc4pPUA=", - "owner": "rustsec", - "repo": "advisory-db", - "rev": "a6c90b9cd0246a19e9e073ad47bf5f5c6dcb9fc1", - "type": "github" - }, - "original": { - "owner": "rustsec", - "repo": "advisory-db", - "type": "github" - } - }, - "compat": { + "flake-compat": { "flake": false, "locked": { "lastModified": 1673956053, @@ -32,51 +16,21 @@ "type": "github" } }, - "crane": { + "flake-utils": { "inputs": { - "flake-compat": [ - "compat" - ], - "flake-utils": [ - "utils" - ], - "nixpkgs": [ - "nixpkgs" - ], - "rust-overlay": "rust-overlay" - }, - "locked": { - "lastModified": 1693608196, - "narHash": "sha256-qs1rDvXXjrKdobPvTdn9qKjV0/RE2uqCCTHD/c6AAo8=", - "owner": "ipetkov", - "repo": "crane", - "rev": "80432e15452e55a72403da3bc91837508a4ccae3", - "type": "github" - }, - "original": { - "owner": "ipetkov", - "repo": "crane", - "type": "github" - } - }, - "fenix": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ], - "rust-analyzer-src": "rust-analyzer-src" + "systems": "systems" }, "locked": { - "lastModified": 1693549280, - "narHash": "sha256-Se0ceJDij5fJvucwTpuDZyuQOWnJfP/hX3XzTBuAzXg=", - "owner": "nix-community", - "repo": "fenix", - "rev": "5b116a689c22ed2495c2b0f857539519a2951ce2", + "lastModified": 1692799911, + "narHash": "sha256-3eihraek4qL744EvQXsK1Ha6C3CR7nnT8X2qWap4RNk=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "f9e7cf818399d17d347f847525c5a5a8032e4e44", "type": "github" }, "original": { - "owner": "nix-community", - "repo": "fenix", + "owner": "numtide", + "repo": "flake-utils", "type": "github" } }, @@ -139,12 +93,8 @@ }, "pre-commit": { "inputs": { - "flake-compat": [ - "compat" - ], - "flake-utils": [ - "utils" - ], + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", "gitignore": "gitignore", "nixpkgs": [ "nixpkgs" @@ -169,56 +119,9 @@ }, "root": { "inputs": { - "advisory-db": "advisory-db", - "compat": "compat", - "crane": "crane", - "fenix": "fenix", "nixpkgs": "nixpkgs", "parts": "parts", - "pre-commit": "pre-commit", - "utils": "utils" - } - }, - "rust-analyzer-src": { - "flake": false, - "locked": { - "lastModified": 1693419148, - "narHash": "sha256-CRVhqY3yc9J0BFFxpUQFe56TWJKsiT2bjlb4Oo1cq2o=", - "owner": "rust-lang", - "repo": "rust-analyzer", - "rev": "321334429efd79e9db2b85e43c8f91eb2ce60f6c", - "type": "github" - }, - "original": { - "owner": "rust-lang", - "ref": "nightly", - "repo": "rust-analyzer", - "type": "github" - } - }, - "rust-overlay": { - "inputs": { - "flake-utils": [ - "crane", - "flake-utils" - ], - "nixpkgs": [ - "crane", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1691374719, - "narHash": "sha256-HCodqnx1Mi2vN4f3hjRPc7+lSQy18vRn8xWW68GeQOg=", - "owner": "oxalica", - "repo": "rust-overlay", - "rev": "b520a3889b24aaf909e287d19d406862ced9ffc9", - "type": "github" - }, - "original": { - "owner": "oxalica", - "repo": "rust-overlay", - "type": "github" + "pre-commit": "pre-commit" } }, "systems": { @@ -235,24 +138,6 @@ "repo": "default", "type": "github" } - }, - "utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1692799911, - "narHash": "sha256-3eihraek4qL744EvQXsK1Ha6C3CR7nnT8X2qWap4RNk=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "f9e7cf818399d17d347f847525c5a5a8032e4e44", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } } }, "root": "root", @@ -18,42 +18,11 @@ inputs.nixpkgs-lib.follows = "nixpkgs"; }; - # used for cargo audit - advisory-db = { - url = "github:rustsec/advisory-db"; - flake = false; - }; - - # our build framework - crane = { - url = "github:ipetkov/crane"; - inputs.nixpkgs.follows = "nixpkgs"; - inputs.flake-compat.follows = "compat"; - inputs.flake-utils.follows = "utils"; - }; - - # toolchain management - fenix = { - url = "github:nix-community/fenix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - pre-commit = { url = "github:cachix/pre-commit-hooks.nix"; inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs-stable.follows = "nixpkgs"; - inputs.flake-compat.follows = "compat"; - inputs.flake-utils.follows = "utils"; - }; - - # this is just to avoid having multiple versions in flake.lock - compat = { - url = "github:edolstra/flake-compat"; - flake = false; }; - - # ditto - utils.url = "github:numtide/flake-utils"; }; outputs = { @@ -64,7 +33,17 @@ parts.lib.mkFlake {inherit inputs;} { imports = [ pre-commit.flakeModule - ./parts + + ./parts/deployment.nix + ./parts/dev.nix + ./parts/packages.nix + ]; + + systems = [ + "x86_64-linux" + "x86_64-darwin" + "aarch64-linux" + "aarch64-darwin" ]; }; } 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; - }; - }; -} |
