From c8b67a4478a799c9670f324dfaf6e3ec2f27c3e1 Mon Sep 17 00:00:00 2001 From: AlphaKeks Date: Thu, 27 Jun 2024 11:53:56 +0200 Subject: [PATCH] tooling: replace nix-shell with flake we can now build docker images with nix! yay! --- .envrc | 2 +- Cargo.lock | 128 ++++++++++++++++++++++---------------------------- Cargo.toml | 5 +- Justfile | 62 ++++++++----------------- compose.yml | 1 + flake.lock | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++ shell.nix | 4 -- 8 files changed, 336 insertions(+), 125 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix delete mode 100644 shell.nix diff --git a/.envrc b/.envrc index 4a4726a5..c4b17d79 100644 --- a/.envrc +++ b/.envrc @@ -1 +1 @@ -use_nix +use_flake diff --git a/Cargo.lock b/Cargo.lock index 63200b20..3052c1e5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -166,15 +166,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "atomic" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d818003e740b63afc82337e3160717f4f63078720a810b7b903e70a5d1d2994" -dependencies = [ - "bytemuck", -] - [[package]] name = "atomic-waker" version = "1.1.2" @@ -326,9 +317,9 @@ dependencies = [ [[package]] name = "backtrace" -version = "0.3.72" +version = "0.3.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17c6a35df3749d2e8bb1b7b21a976d82b15548788d2735b9d82f329268f71a11" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" dependencies = [ "addr2line", "cc", @@ -365,9 +356,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" dependencies = [ "serde", ] @@ -437,12 +428,6 @@ version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" -[[package]] -name = "bytemuck" -version = "1.16.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b236fc92302c97ed75b38da1f4917b5cdda4984745740f153a5d3059e48d725e" - [[package]] name = "byteorder" version = "1.5.0" @@ -457,9 +442,9 @@ checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "cc" -version = "1.0.99" +version = "1.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" +checksum = "c891175c3fb232128f48de6590095e59198bbeb8620c310be349bfc3afd12c7b" [[package]] name = "cfg-if" @@ -857,9 +842,9 @@ dependencies = [ [[package]] name = "displaydoc" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", @@ -949,7 +934,7 @@ checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181" dependencies = [ "futures-core", "futures-sink", - "spin 0.9.8", + "spin", ] [[package]] @@ -1308,9 +1293,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.9.2" +version = "1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f3935c160d00ac752e09787e6e6bfc26494c2183cc922f1bc678a60d4733bc2" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" [[package]] name = "httpdate" @@ -1418,7 +1403,7 @@ dependencies = [ "tokio", "tokio-rustls 0.26.0", "tower-service", - "webpki-roots 0.26.2", + "webpki-roots 0.26.3", ] [[package]] @@ -1591,11 +1576,11 @@ dependencies = [ [[package]] name = "lazy_static" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" dependencies = [ - "spin 0.5.2", + "spin", ] [[package]] @@ -1616,7 +1601,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", "libc", ] @@ -1680,9 +1665,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.2" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "mime" @@ -1708,9 +1693,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" dependencies = [ "adler", ] @@ -1842,9 +1827,9 @@ dependencies = [ [[package]] name = "object" -version = "0.35.0" +version = "0.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8ec7ab813848ba4522158d5517a6093db1ded27575b070f4177b8d12b41db5e" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" dependencies = [ "memchr", ] @@ -1891,7 +1876,7 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.5.1", + "redox_syscall 0.5.2", "smallvec", "windows-targets 0.52.5", ] @@ -2058,9 +2043,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.85" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -2194,11 +2179,11 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" +checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", ] [[package]] @@ -2295,7 +2280,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots 0.26.2", + "webpki-roots 0.26.3", "winreg", ] @@ -2309,7 +2294,7 @@ dependencies = [ "cfg-if", "getrandom", "libc", - "spin 0.9.8", + "spin", "untrusted", "windows-sys 0.52.0", ] @@ -2386,7 +2371,7 @@ version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", "errno", "libc", "linux-raw-sys", @@ -2543,7 +2528,7 @@ version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", "core-foundation", "core-foundation-sys", "libc", @@ -2604,9 +2589,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.117" +version = "1.0.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +checksum = "d947f6b3163d8857ea16c4fa0dd4840d52f3041039a85decd46867eb1abef2e4" dependencies = [ "itoa", "ryu", @@ -2779,12 +2764,6 @@ dependencies = [ "similar", ] -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - [[package]] name = "spin" version = "0.9.8" @@ -2806,11 +2785,10 @@ dependencies = [ [[package]] name = "sqlformat" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce81b7bd7c4493975347ef60d8c7e8b742d4694f4c49f93e0a12ea263938176c" +checksum = "f895e3734318cc55f1fe66258926c9b910c124d47520339efecbb6c59cec7c1f" dependencies = [ - "itertools 0.12.1", "nom", "unicode_categories", ] @@ -2920,7 +2898,7 @@ checksum = "1ed31390216d20e538e447a7a9b959e06ed9fc51c37b514b46eb758016ecd418" dependencies = [ "atoi", "base64 0.21.7", - "bitflags 2.5.0", + "bitflags 2.6.0", "byteorder", "bytes", "chrono", @@ -2965,7 +2943,7 @@ checksum = "7c824eb80b894f926f89a0b9da0c7f435d27cdd35b8c655b114e58223918577e" dependencies = [ "atoi", "base64 0.21.7", - "bitflags 2.5.0", + "bitflags 2.6.0", "byteorder", "chrono", "crc", @@ -3066,9 +3044,9 @@ dependencies = [ [[package]] name = "subtle" -version = "2.5.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" @@ -3144,9 +3122,9 @@ dependencies = [ [[package]] name = "testcontainers-modules" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87dc086b8c791e5696de6de4e0d79de2cb9f8a1ac4552d46d6211a42d81d6d0f" +checksum = "0f148193fc3c61b11d363732a42d43eb332329b3b4a4148fca8b0af1fdc8a4b7" dependencies = [ "testcontainers", ] @@ -3214,9 +3192,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +checksum = "c55115c6fbe2d2bef26eb09ad74bde02d8255476fc0c7b515ef09fbb35742d82" dependencies = [ "tinyvec_macros", ] @@ -3383,7 +3361,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e9cd434a998747dd2c4276bc96ee2e0c7a2eadf3cae88e52be55a05fa9053f5" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", "bytes", "http 1.1.0", "http-body 1.0.0", @@ -3605,16 +3583,22 @@ dependencies = [ "serde_json", "url", "utoipa", + "utoipa-swagger-ui-vendored", "zip", ] +[[package]] +name = "utoipa-swagger-ui-vendored" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c20d6689d3a5693eec4d21f6b9d7c54f37468b856da8e98a7bb316f7b32df6e3" + [[package]] name = "uuid" -version = "1.9.0" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ea73390fe27785838dcbf75b91b1d84799e28f1ce71e6f372a5dc2200c80de5" +checksum = "5de17fd2f7da591098415cff336e12965a28061ddace43b59cb3c430179c9439" dependencies = [ - "atomic", "getrandom", "serde", ] @@ -3752,9 +3736,9 @@ checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" [[package]] name = "webpki-roots" -version = "0.26.2" +version = "0.26.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c452ad30530b54a4d8e71952716a212b08efd0f3562baa66c29a618b07da7c3" +checksum = "bd7c23921eeb1713a4e851530e9b9756e4fb0e89978582942612524cf09f01cd" dependencies = [ "rustls-pki-types", ] diff --git a/Cargo.toml b/Cargo.toml index 70d3fba0..e2534769 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -84,10 +84,7 @@ features = [ [dependencies.utoipa-swagger-ui] version = "7.1.0" -features = [ - "axum", - "reqwest", # required for build.rs so downloads work without curl -] +features = ["axum", "vendored"] [dependencies.tracing] version = "0.1" diff --git a/Justfile b/Justfile index ab7ea0e3..19405a2a 100644 --- a/Justfile +++ b/Justfile @@ -1,65 +1,39 @@ set dotenv-load := true default: - @just --list - -build *ARGS: - cargo build --workspace {{ARGS}} + @just --list clippy *ARGS: - cargo clippy --workspace --all-features --no-deps --tests {{ARGS}} + cargo clippy --workspace --all-features --no-deps --tests {{ARGS}} fmt *ARGS: - cargo +nightly fmt --all {{ARGS}} + cargo +nightly fmt --all {{ARGS}} doc *ARGS: - cargo doc --workspace --all-features --document-private-items {{ARGS}} - cargo run --package spec-generator > api-spec.json + cargo doc --workspace --all-features --document-private-items {{ARGS}} + cargo run --package spec-generator > api-spec.json sqlx-cache *ARGS: - cargo sqlx prepare --workspace {{ARGS}} -- --tests + cargo sqlx prepare --workspace {{ARGS}} -- --tests test *ARGS: - cargo test --workspace {{ARGS}} -- --nocapture - -run *ARGS: - cargo run {{ARGS}} + cargo test --workspace {{ARGS}} -- --nocapture run-with-console *ARGS: - RUSTFLAGS="--cfg tokio_unstable" cargo +nightly run --features console {{ARGS}} + RUSTFLAGS="--cfg tokio_unstable" cargo +nightly run --features console {{ARGS}} -database: - docker compose up --detach --wait cs2kz-database +create-database: + docker compose up --detach --wait cs2kz-database clean-database: - docker compose down --timeout 1 cs2kz-database - sudo rm -rf ./database/volumes/cs2kz - -database-connection: - #!/usr/bin/env bash - if command -v mycli &>/dev/null; then - export cmd=mycli - elif command -v mariadb &>/dev/null; then - export cmd=mariadb - else - export cmd=mysql - fi - - export cmd="$cmd \ - -u schnose \ - -pcsgo-kz-is-dead-boys \ - -h 127.0.0.1 \ - -P "$DATABASE_PORT" \ - -D cs2kz - " - - eval "$cmd" + docker compose down --timeout 1 cs2kz-database + sudo rm -rf {{justfile_directory()}}/database/volumes/cs2kz -migrations *ARGS: - sqlx migrate run --source {{justfile_directory()}}/database/migrations {{ARGS}} +run-migrations *ARGS: + sqlx migrate run --source {{justfile_directory()}}/database/migrations {{ARGS}} precommit: - just clippy - just fmt - just doc - just sqlx-cache + just clippy + just fmt + just doc + just sqlx-cache diff --git a/compose.yml b/compose.yml index e04a6365..b22827a9 100644 --- a/compose.yml +++ b/compose.yml @@ -17,6 +17,7 @@ services: env_file: - .env - .env.docker + image: cs2kz-api build: context: . dockerfile: ./Dockerfile diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..9952ec38 --- /dev/null +++ b/flake.lock @@ -0,0 +1,131 @@ +{ + "nodes": { + "crane": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1719249093, + "narHash": "sha256-0q1haa3sw6GbmJ+WhogMnducZGjEaCa/iR6hF2vq80I=", + "owner": "ipetkov", + "repo": "crane", + "rev": "9791c77eb7e98b8d8ac5b0305d47282f994411ca", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1718543737, + "narHash": "sha256-e8S/ODM1vkKHIexSVn9nIvne7vRO5M+35VAq/6JOYto=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "683aa7c4e385509ca651d49eeb35e58c7a1baad6", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1719145550, + "narHash": "sha256-K0i/coxxTEl30tgt4oALaylQfxqbotTSNb1/+g+mKMQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e4509b3a560c87a8d4cb6f9992b8915abf9e36d8", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1718428119, + "narHash": "sha256-WdWDpNaq6u1IPtxtYHHWpl5BmabtpmLnMAx0RdJ/vo8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e6cea36f83499eb4e9cd184c8a8e823296b50ad5", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs_2", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1719281921, + "narHash": "sha256-LIBMfhM9pMOlEvBI757GOK5l0R58SRi6YpwfYMbf4yc=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "b6032d3a404d8a52ecfc8571ff0c26dfbe221d07", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..b98339fe --- /dev/null +++ b/flake.nix @@ -0,0 +1,128 @@ +{ + inputs = { + nixpkgs.url = github:NixOS/nixpkgs/nixos-24.05; + flake-utils.url = github:numtide/flake-utils; + rust-overlay.url = github:oxalica/rust-overlay; + crane.url = github:ipetkov/crane; + }; + + outputs = { nixpkgs, rust-overlay, flake-utils, crane, ... }: flake-utils.lib.eachDefaultSystem (system: + let + inherit (nixpkgs) lib; + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { + inherit system overlays; + }; + + # fixed versions of stable & nightly toolchains + rust-stable = pkgs.rust-bin.stable."1.79.0"; + rust-nightly = pkgs.rust-bin.nightly."2024-06-24"; + + # function for instantiating a stable toolchain with a set of components + mkToolchain = extensions: rust-stable.minimal.override { + inherit extensions; + }; + + # tell crane which toolchain to use for builds + craneLib = (crane.mkLib pkgs).overrideToolchain (mkToolchain [ "rust-src" ]); + + # common attributes for building both dependencies and the application itself + commonArgs = { + src = lib.cleanSourceWith { + src = ./.; + name = "source"; + filter = path: type: (craneLib.filterCargoSources path type) + || (builtins.any (pattern: ((builtins.match pattern path) != null)) [ + ".*README.md$" + ".*sqlx/query-.*json$" + ".*database/fixtures/.*sql$" + ".*database/migrations/.*sql$" + ]); + }; + + nativeBuildInputs = [ + (mkToolchain [ "rust-src" "clippy" ]) + ]; + }; + + # build dependencies & api crate + cs2kz-api = craneLib.buildPackage (commonArgs // { + cargoArtifacts = craneLib.buildDepsOnly commonArgs; + + # most of the tests are integration tests that need docker + # they all run in CI anyway + doCheck = false; + }); + in + { + packages = { + inherit cs2kz-api; + default = cs2kz-api; + + dockerImage = pkgs.dockerTools.buildLayeredImage { + name = "cs2kz-api"; + tag = "latest"; + contents = [ pkgs.depotdownloader ]; + config = { + Cmd = [ "${cs2kz-api}/bin/cs2kz-api" ]; + }; + }; + }; + + devShells.default = pkgs.mkShell { + nativeBuildInputs = [ + (mkToolchain [ "rust-src" "clippy" "rust-analyzer" ]) + rust-nightly.rustfmt + ] ++ (with pkgs; [ + just + docker-client + mariadb_110 + sqlx-cli + tokio-console + depotdownloader + ]); + }; + + apps = + let + mkRunnable = { script, env ? { } }: ( + let + wrapped = pkgs.writeShellScript "runnable" '' + ${lib.strings.concatStrings (lib.mapAttrsToList (key: value: ''export ${key}="${value}"'') env)} + ${script} + ''; + in + { + type = "app"; + program = "${wrapped}"; + } + ); + in + { + rustfmt = mkRunnable { + script = '' + "${rust-nightly.rustfmt}/bin/cargo-fmt" --all "$@" + ''; + }; + + precommit = mkRunnable { + script = '' + set -eux + just clippy + nix run .#rustfmt + just doc + just sqlx-cache + ''; + }; + + console = mkRunnable { + script = '' + "${rust-nightly.cargo}/bin/cargo" run -F console "$@" + ''; + env = { + RUSTFLAGS = "--cfg tokio_unstable"; + }; + }; + }; + }); +} diff --git a/shell.nix b/shell.nix deleted file mode 100644 index ad819b72..00000000 --- a/shell.nix +++ /dev/null @@ -1,4 +0,0 @@ -{ pkgs ? import {} }: -pkgs.mkShell { - nativeBuildInputs = with pkgs; [ mariadb_110 sqlx-cli just ]; -}