diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml deleted file mode 100644 index ced6425f..00000000 --- a/.github/workflows/check.yml +++ /dev/null @@ -1,66 +0,0 @@ -name: Check - -on: - push: - branches: ['main'] - pull_request: - -jobs: - rustfmt: - name: Run rustfmt - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Install Rust - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable - components: rustfmt - - - name: Setup Rust cache - uses: Swatinem/rust-cache@v2 - - - name: Run rustfmt - run: cargo fmt --all -- --check - - clippy: - name: Run Clippy scan - runs-on: ubuntu-latest - - permissions: - security-events: write - - steps: - - uses: actions/checkout@v4 - - - name: Install Rust - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable - components: clippy - - - name: Setup Rust cache - uses: Swatinem/rust-cache@v2 - - - name: Install SARIF tools - run: cargo install clippy-sarif sarif-fmt - - - name: Fetch Cargo deps - run: cargo fetch --locked - - - name: Run Clippy - continue-on-error: true - run: | - cargo clippy \ - --all-features \ - --all-targets \ - --message-format=json \ - | clippy-sarif | tee /tmp/clippy.sarif | sarif-fmt - - - name: Upload results - uses: github/codeql-action/upload-sarif@v3 - with: - sarif_file: /tmp/clippy.sarif - wait-for-processing: true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..f54bdf23 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,79 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + workflow_dispatch: + +jobs: + build: + name: Build (${{ matrix.os }}) + + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + use-nix: true + - os: windows-latest + use-nix: false + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Rust + if: ${{ !matrix.use-nix }} + uses: actions-rust-lang/setup-rust-toolchain@v1 + + - name: Install Nix + if: ${{ matrix.use-nix }} + uses: DeterminateSystems/nix-installer-action@v15 + + - name: Setup Nix cache + if: ${{ matrix.use-nix }} + uses: DeterminateSystems/magic-nix-cache-action@v8 + + - name: Build + if: ${{ !matrix.use-nix }} + run: cargo build --locked + + - name: Build + if: ${{ matrix.use-nix }} + run: nix build --print-build-logs .#refraction-debug + + flake: + name: Flake checks + + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@v15 + + - name: Setup Nix cache + uses: DeterminateSystems/magic-nix-cache-action@v8 + + - name: Run checks + run: | + nix flake check --print-build-logs --show-trace + + # Make sure all above jobs finished successfully + release-gate: + name: CI Release gate + needs: [build, flake] + + if: ${{ always() }} + + runs-on: ubuntu-latest + + steps: + - name: Exit with error + if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }} + run: exit 1 diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml new file mode 100644 index 00000000..8834daa5 --- /dev/null +++ b/.github/workflows/clippy.yml @@ -0,0 +1,47 @@ +name: Clippy + +on: + push: + branches: [main] + paths: + - 'Cargo.toml' + - 'Cargo.lock' + - '**.rs' + pull_request: + paths: + - 'Cargo.toml' + - 'Cargo.lock' + - '**.rs' + workflow_dispatch: + +jobs: + clippy: + name: Run scan + + runs-on: ubuntu-latest + + permissions: + security-events: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@v13 + + - name: Setup Nix cache + uses: DeterminateSystems/magic-nix-cache-action@v7 + + - name: Generate sarif report + id: clippy-run + run: | + nix build --print-build-logs .#clippy-report + [ -L result ] || exit 1 + echo "sarif-file=$(readlink -f result)" >> "$GITHUB_OUTPUT" + + - name: Upload results + uses: github/codeql-action/upload-sarif@v3 + with: + sarif_file: ${{ steps.clippy-run.outputs.sarif-file }} + wait-for-processing: true diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index c150bf69..413b3063 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -2,21 +2,24 @@ name: Docker on: push: - branches: ['main'] + branches: [main] pull_request: workflow_dispatch: jobs: build: name: Build image - runs-on: ubuntu-latest strategy: + fail-fast: false matrix: - arch: [x86_64, aarch64] + arch: [amd64, arm64] + + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@v4 - name: Install Nix uses: DeterminateSystems/nix-installer-action@v15 @@ -41,10 +44,26 @@ jobs: if-no-files-found: error retention-days: 3 + # Make sure all above jobs finished successfully + release-gate: + name: Docker Release gate + needs: [build] + + if: ${{ always() }} + + runs-on: ubuntu-latest + + steps: + - name: Exit with error + if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }} + run: exit 1 + push: name: Push image - needs: build + + if: ${{ github.event_name == 'push' }} + runs-on: ubuntu-latest permissions: @@ -54,16 +73,15 @@ jobs: REGISTRY: ghcr.io USERNAME: ${{ github.actor }} - if: github.event_name == 'push' - steps: - - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@v4 - name: Determine image name run: | echo "IMAGE_NAME=${REPOSITORY,,}" >> "$GITHUB_ENV" env: - REPOSITORY: '${{ github.repository }}' + REPOSITORY: ${{ github.repository }} - name: Download images uses: actions/download-artifact@v4 @@ -83,15 +101,15 @@ jobs: run: | set -eu - architectures=("x86_64" "aarch64") + architectures=("amd64" "arm64") for arch in "${architectures[@]}"; do docker load < images/container-"$arch"/*.tar.gz docker tag refraction:latest-"$arch" "$TAG"-"$arch" - docker push ${{ env.TAG }}-"$arch" + docker push "$TAG"-"$arch" done docker manifest create "$TAG" \ - --amend "$TAG"-x86_64 \ - --amend "$TAG"-aarch64 + --amend "$TAG"-amd64 \ + --amend "$TAG"-arm64 docker manifest push "$TAG" diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml deleted file mode 100644 index ec472fa0..00000000 --- a/.github/workflows/nix.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: Nix - -on: - push: - branches: ['main'] - pull_request: - workflow_dispatch: - -jobs: - build: - name: Build - strategy: - matrix: - os: [ubuntu-latest, macos-latest] - - runs-on: ${{ matrix.os }} - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Install Nix - uses: DeterminateSystems/nix-installer-action@v15 - - - name: Setup Nix cache - uses: DeterminateSystems/magic-nix-cache-action@v8 - - - name: Build refraction - run: nix build --fallback --print-build-logs - - check: - name: Check flake - - strategy: - matrix: - os: [ubuntu-latest, macos-latest] - - runs-on: ${{ matrix.os }} - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Install Nix - uses: DeterminateSystems/nix-installer-action@v15 - - - name: Setup Nix cache - uses: DeterminateSystems/magic-nix-cache-action@v8 - - - name: Run checks - run: | - nix flake check --print-build-logs --show-trace diff --git a/.github/workflows/update-flake.yml b/.github/workflows/update-flake.yml index 23356023..6d17418c 100644 --- a/.github/workflows/update-flake.yml +++ b/.github/workflows/update-flake.yml @@ -15,9 +15,6 @@ jobs: contents: write pull-requests: write - env: - PR_BRANCH: 'update-lockfiles' - steps: - name: Checkout repository uses: actions/checkout@v4 @@ -27,9 +24,9 @@ jobs: - name: Update flake.lock id: update - uses: DeterminateSystems/update-flake-lock@main + uses: DeterminateSystems/update-flake-lock@v23 with: - pr-title: "nix: update flake.lock" + pr-title: 'nix: update flake.lock' - name: Enable Pull Request Automerge uses: peter-evans/enable-pull-request-automerge@v3 diff --git a/flake.lock b/flake.lock index 083a8213..57965550 100644 --- a/flake.lock +++ b/flake.lock @@ -1,31 +1,16 @@ { "nodes": { - "flake-checks": { - "locked": { - "lastModified": 1726652014, - "narHash": "sha256-TdbcCjW6z3VsFg1uvrvCdp0pzFXUyP8qegp8dSmQuaE=", - "owner": "getchoo", - "repo": "flake-checks", - "rev": "108aa8f5a8a610ae14c1edb61017dd750b666ed6", - "type": "github" - }, - "original": { - "owner": "getchoo", - "repo": "flake-checks", - "type": "github" - } - }, "nixpkgs": { "locked": { "lastModified": 1727335715, "narHash": "sha256-1uw3y94dA4l22LkqHRIsb7qr3rV5XdxQFqctINfx8Cc=", - "owner": "nixos", + "owner": "NixOS", "repo": "nixpkgs", "rev": "28b5b8af91ffd2623e995e20aee56510db49001a", "type": "github" }, "original": { - "owner": "nixos", + "owner": "NixOS", "ref": "nixpkgs-unstable", "repo": "nixpkgs", "type": "github" @@ -33,29 +18,7 @@ }, "root": { "inputs": { - "flake-checks": "flake-checks", - "nixpkgs": "nixpkgs", - "rust-overlay": "rust-overlay" - } - }, - "rust-overlay": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1727404165, - "narHash": "sha256-kZCiYpQJBZ3kL9QymS88mCxpQwqo8KqvZeHk6LATuY8=", - "owner": "oxalica", - "repo": "rust-overlay", - "rev": "76f0a61e733259e1034dd6523e039d04932ffefc", - "type": "github" - }, - "original": { - "owner": "oxalica", - "repo": "rust-overlay", - "type": "github" + "nixpkgs": "nixpkgs" } } }, diff --git a/flake.nix b/flake.nix index e8c3db88..52f0c33c 100644 --- a/flake.nix +++ b/flake.nix @@ -1,108 +1,127 @@ { description = "Discord bot for Prism Launcher"; - inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; - - flake-checks.url = "github:getchoo/flake-checks"; - - rust-overlay = { - url = "github:oxalica/rust-overlay"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - }; - - outputs = { - self, - nixpkgs, - flake-checks, - rust-overlay, - }: let - systems = [ - "x86_64-linux" - "aarch64-linux" - "x86_64-darwin" - "aarch64-darwin" - ]; - - forAllSystems = fn: nixpkgs.lib.genAttrs systems (system: fn nixpkgs.legacyPackages.${system}); - in { - checks = forAllSystems (pkgs: let - flake-checks' = flake-checks.lib.mkChecks { - inherit pkgs; - root = ./.; - }; - in { - check-actionlint = flake-checks'.actionlint; - check-alejandra = flake-checks'.alejandra; - check-deadnix = flake-checks'.deadnix; - check-rustfmt = flake-checks'.rustfmt; - check-statix = flake-checks'.statix; - }); - - devShells = forAllSystems (pkgs: { - default = pkgs.mkShell { - packages = with pkgs; [ - redis - - # linters & formatters - actionlint - nodePackages.prettier - - # rust tools - clippy - rustfmt - rust-analyzer - - # nix tools - self.formatter.${system} - deadnix - nil - statix - ]; - - inputsFrom = [self.packages.${pkgs.system}.refraction]; - RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}"; - }; - }); - - formatter = forAllSystems (pkgs: pkgs.alejandra); - - nixosModules.default = import ./nix/module.nix self; - - packages = forAllSystems ({ - lib, - pkgs, - system, - ... - }: let - packages' = self.packages.${system}; - - mkStatic = pkgs.callPackage ./nix/static.nix { - inherit (self.packages.${pkgs.system}) refraction; - rust-overlay = rust-overlay.packages.${system}; + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + outputs = + { + self, + nixpkgs, + }: + let + inherit (nixpkgs) lib; + systems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + + forAllSystems = lib.genAttrs systems; + nixpkgsFor = nixpkgs.legacyPackages; + in + { + checks = forAllSystems ( + system: + let + pkgs = nixpkgsFor.${system}; + mkCheck = + name: deps: script: + pkgs.runCommand name { nativeBuildInputs = deps; } '' + ${script} + touch $out + ''; + in + { + actionlint = mkCheck "check-actionlint" [ pkgs.actionlint ] "actionlint ${./.github/workflows}/*"; + deadnix = mkCheck "check-deadnix" [ pkgs.deadnix ] "deadnix --fail ${self}"; + statix = mkCheck "check-statix" [ pkgs.statix ] "statix check ${self}"; + nixfmt = mkCheck "check-nixfmt" [ pkgs.nixfmt-rfc-style ] "nixfmt --check ${self}"; + rustfmt = mkCheck "check-rustfmt" [ + pkgs.cargo + pkgs.rustfmt + ] "cd ${self} && cargo fmt -- --check"; + } + ); + + devShells = forAllSystems ( + system: + let + pkgs = nixpkgsFor.${system}; + in + { + default = pkgs.mkShell { + packages = with pkgs; [ + redis + + # linters & formatters + actionlint + nodePackages.prettier + + # rust tools + clippy + rustfmt + rust-analyzer + + # nix tools + self.formatter.${system} + nil + statix + ]; + + inputsFrom = [ self.packages.${pkgs.system}.refraction ]; + RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}"; + }; + } + ); + + formatter = forAllSystems (system: nixpkgsFor.${system}.nixfmt-rfc-style); + + nixosModules.default = import ./nix/module.nix self; + + # For CI + legacyPackages = forAllSystems ( + system: + let + pkgs = nixpkgsFor.${system}; + in + { + clippy-report = pkgs.callPackage ./nix/clippy.nix { inherit (self.packages.${system}) refraction; }; + + refraction-debug = (self.packages.${system}.refraction.override { lto = false; }).overrideAttrs ( + finalAttrs: _: { + cargoBuildType = "debug"; + cargoCheckType = finalAttrs.cargoBuildType; + } + ); + } + ); + + packages = forAllSystems ( + system: + let + pkgs = nixpkgsFor.${system}; + packages' = self.packages.${system}; + + refractionPackages = lib.makeScope pkgs.newScope (lib.flip self.overlays.default pkgs); + + mkStatic = pkgs.callPackage ./nix/static.nix { }; + containerize = pkgs.callPackage ./nix/containerize.nix { }; + in + { + inherit (refractionPackages) refraction; + + static-x86_64 = mkStatic { arch = "x86_64"; }; + static-aarch64 = mkStatic { arch = "aarch64"; }; + container-amd64 = containerize packages'.static-x86_64; + container-arm64 = containerize packages'.static-aarch64; + + default = packages'.refraction; + } + ); + + overlays.default = final: _: { + refraction = final.callPackage ./nix/package.nix { }; }; - - mkContainerFor = refraction: - pkgs.dockerTools.buildLayeredImage { - name = "refraction"; - tag = "latest-${refraction.stdenv.hostPlatform.qemuArch}"; - config.Cmd = [(lib.getExe refraction)]; - inherit (refraction) architecture; - }; - in { - refraction = pkgs.callPackage ./nix/derivation.nix {inherit self;}; - - static-x86_64 = mkStatic {arch = "x86_64";}; - static-aarch64 = mkStatic {arch = "aarch64";}; - container-x86_64 = mkContainerFor packages'.static-x86_64; - container-aarch64 = mkContainerFor packages'.static-aarch64; - - default = packages'.refraction; - }); - - overlays.default = _: prev: { - refraction = prev.callPackage ./nix/derivation.nix {inherit self;}; }; - }; } diff --git a/nix/clippy.nix b/nix/clippy.nix new file mode 100644 index 00000000..9c360a9e --- /dev/null +++ b/nix/clippy.nix @@ -0,0 +1,39 @@ +{ + cargo, + clippy, + clippy-sarif, + refraction, + rustPlatform, + sarif-fmt, + stdenv, +}: + +stdenv.mkDerivation { + pname = "${refraction.pname}-sarif-report"; + inherit (refraction) + version + src + cargoDeps + buildInputs + ; + + nativeBuildInputs = [ + cargo + clippy + clippy-sarif + rustPlatform.cargoSetupHook + sarif-fmt + ]; + + buildPhase = '' + cargo clippy \ + --all-features \ + --all-targets \ + --tests \ + --message-format=json \ + | clippy-sarif | tee $out | sarif-fmt + ''; + + dontInstall = true; + dontFixup = true; +} diff --git a/nix/containerize.nix b/nix/containerize.nix new file mode 100644 index 00000000..558a7c89 --- /dev/null +++ b/nix/containerize.nix @@ -0,0 +1,9 @@ +{ lib, dockerTools }: +refraction: + +dockerTools.buildLayeredImage { + name = "refraction"; + tag = "latest-${refraction.passthru.dockerArchitecture}"; + config.Cmd = [ (lib.getExe refraction) ]; + architecture = refraction.passthru.dockerArchitecture; +} diff --git a/nix/derivation.nix b/nix/derivation.nix deleted file mode 100644 index 0e86a181..00000000 --- a/nix/derivation.nix +++ /dev/null @@ -1,67 +0,0 @@ -{ - lib, - stdenv, - go, - rustPlatform, - darwin, - self, - lto ? true, - optimizeSize ? false, -}: -rustPlatform.buildRustPackage { - pname = "refraction"; - version = - (lib.importTOML ../Cargo.toml).package.version - + "-${self.shortRev or self.dirtyShortRev or "unknown-dirty"}"; - - __structuredAttrs = true; - - src = lib.fileset.toSource { - root = ../.; - fileset = lib.fileset.unions [ - ../src - ../build.rs - ../Cargo.lock - ../Cargo.toml - ../tags - ]; - }; - - cargoLock = { - lockFile = ../Cargo.lock; - }; - - buildInputs = lib.optionals stdenv.hostPlatform.isDarwin (with darwin.apple_sdk.frameworks; [ - CoreFoundation - Security - SystemConfiguration - ]); - - env = let - toRustFlags = lib.mapAttrs' ( - name: - lib.nameValuePair - "CARGO_PROFILE_RELEASE_${lib.toUpper (builtins.replaceStrings ["-"] ["_"] name)}" - ); - in - lib.optionalAttrs lto (toRustFlags { - lto = "thin"; - }) - // lib.optionalAttrs optimizeSize (toRustFlags { - codegen-units = "1"; - opt-level = "s"; - panic = "abort"; - strip = "symbols"; - }); - - # useful for container images - passthru.architecture = go.GOARCH; - - meta = with lib; { - mainProgram = "refraction"; - description = "Discord bot for Prism Launcher"; - homepage = "https://github.com/PrismLauncher/refraction"; - license = licenses.gpl3Plus; - maintainers = with maintainers; [getchoo Scrumplex]; - }; -} diff --git a/nix/module.nix b/nix/module.nix index 5572e4be..4e6d8a69 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -1,17 +1,17 @@ -self: { +self: +{ config, lib, pkgs, ... -}: let +}: +let cfg = config.services.refraction; defaultUser = "refraction"; - inherit - (lib) + inherit (lib) getExe literalExpression - mdDoc mkEnableOption mkIf mkOption @@ -19,13 +19,14 @@ self: { optionals types ; -in { +in +{ options.services.refraction = { enable = mkEnableOption "refraction"; - package = mkPackageOption self.packages.${pkgs.stdenv.hostPlatform.system} "refraction" {}; + package = mkPackageOption self.packages.${pkgs.stdenv.hostPlatform.system} "refraction" { }; user = mkOption { - description = mdDoc '' + description = '' User under which the service should run. If this is the default value, the user will be created, with the specified group as the primary group. @@ -38,7 +39,7 @@ in { }; group = mkOption { - description = mdDoc '' + description = '' Group under which the service should run. If this is the default value, the group will be created. ''; @@ -50,7 +51,7 @@ in { }; redisUrl = mkOption { - description = mdDoc '' + description = '' Connection to a redis server. If this needs to include credentials that shouldn't be world-readable in the Nix store, set environmentFile and override the `REDIS_URL` entry. @@ -64,7 +65,7 @@ in { }; environmentFile = mkOption { - description = mdDoc '' + description = '' Environment file as defined in {manpage}`systemd.exec(5)` ''; type = types.nullOr types.path; @@ -84,10 +85,8 @@ in { systemd.services."refraction" = { enable = true; - wantedBy = ["multi-user.target"]; - after = - ["network.target"] - ++ optionals (cfg.redisUrl == "local") ["redis-refraction.service"]; + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ] ++ optionals (cfg.redisUrl == "local") [ "redis-refraction.service" ]; script = '' ${getExe cfg.package} @@ -95,9 +94,10 @@ in { environment = { BOT_REDIS_URL = - if cfg.redisUrl == "local" - then "unix:${config.services.redis.servers.refraction.unixSocket}" - else cfg.redisUrl; + if cfg.redisUrl == "local" then + "unix:${config.services.redis.servers.refraction.unixSocket}" + else + cfg.redisUrl; }; serviceConfig = { @@ -141,9 +141,7 @@ in { }; }; - groups = mkIf (cfg.group == defaultUser) { - ${defaultUser} = {}; - }; + groups = mkIf (cfg.group == defaultUser) { ${defaultUser} = { }; }; }; }; } diff --git a/nix/package.nix b/nix/package.nix new file mode 100644 index 00000000..4bc93e6a --- /dev/null +++ b/nix/package.nix @@ -0,0 +1,68 @@ +{ + lib, + stdenv, + go, + rustPlatform, + lto ? !optimizeSize, + optimizeSize ? false, +}: + +let + fs = lib.fileset; + toRustFlags = flags: toString (lib.mapAttrsToList (name: value: "-C ${name}=${value}") flags); +in +assert lib.assertMsg (lto -> !optimizeSize) "`lto` and `optimizeSize` are mutually exclusive"; +rustPlatform.buildRustPackage rec { + pname = "refraction"; + inherit (passthru.cargoToml.package) version; + + src = fs.toSource { + root = ../.; + fileset = fs.intersection (fs.gitTracked ../.) ( + fs.unions [ + ../src + ../build.rs + ../Cargo.lock + ../Cargo.toml + ../tags + ] + ); + }; + + cargoLock.lockFile = ../Cargo.lock; + + # `panic=abort` breaks tests womp womp + doCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform && !optimizeSize; + + env = { + RUSTFLAGS = toRustFlags ( + lib.optionalAttrs lto { + lto = "thin"; + embed-bicode = "yes"; + } + // lib.optionalAttrs optimizeSize { + codegen-units = "1"; + opt-level = "s"; + panic = "abort"; + strip = "symbols"; + } + ); + }; + + passthru = { + cargoToml = lib.importTOML ../Cargo.toml; + # For container images + dockerArchitecture = go.GOARCH; + }; + + meta = { + description = "Discord bot for Prism Launcher"; + homepage = "https://github.com/PrismLauncher/refraction"; + license = lib.licenses.gpl3Plus; + maintainers = with lib.maintainers; [ + getchoo + Scrumplex + ]; + mainProgram = "refraction"; + }; +} diff --git a/nix/static.nix b/nix/static.nix index 5d2c2bed..8df03c80 100644 --- a/nix/static.nix +++ b/nix/static.nix @@ -1,27 +1,9 @@ -{ - lib, - refraction, - rust-overlay, - pkgsCross, -}: {arch}: let - targets = with pkgsCross; { +{ pkgsCross }: +let + crossPlatformFor = with pkgsCross; { x86_64 = musl64.pkgsStatic; aarch64 = aarch64-multiplatform.pkgsStatic; }; - - getRustcTarget = pkgs: pkgs.stdenv.hostPlatform.rust.rustcTarget; - toolchain = rust-overlay.rust.minimal.override { - extensions = ["rust-std"]; - targets = lib.mapAttrsToList (lib.const getRustcTarget) targets; - }; - - mkRustPlatformWith = pkgs: - pkgs.makeRustPlatform ( - lib.genAttrs ["cargo" "rustc"] (lib.const toolchain) - ); - rustPlatforms = lib.mapAttrs (lib.const mkRustPlatformWith) targets; in - refraction.override { - rustPlatform = rustPlatforms.${arch}; - optimizeSize = true; - } +{ arch }: +crossPlatformFor.${arch}.callPackage ./package.nix { optimizeSize = true; } diff --git a/src/handlers/event/mod.rs b/src/handlers/event/mod.rs index 528317dd..efaca475 100644 --- a/src/handlers/event/mod.rs +++ b/src/handlers/event/mod.rs @@ -42,7 +42,7 @@ pub async fn handle( // ignore new messages from bots // note: the webhook_id check allows us to still respond to PK users if (new_message.author.bot && new_message.webhook_id.is_none()) - || new_message.is_own(ctx) + || (new_message.author == **ctx.cache.current_user()) { trace!("Ignoring message {} from bot", new_message.id); return Ok(()); diff --git a/src/main.rs b/src/main.rs index 848fad89..0a4ec235 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,7 +58,7 @@ async fn setup( trace!("Redis connection looks good!"); } - let http_client = api::HttpClient::default(); + let http_client = ::default(); let octocrab = octocrab::instance(); let data = Data { diff --git a/src/storage/mod.rs b/src/storage/mod.rs index e482b4ff..1aad0bee 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -35,7 +35,7 @@ impl Storage { let mut con = self.client.get_multiplexed_async_connection().await?; // Just store some value. We only care about the presence of this key - con.set_ex(key, 0, 7 * 24 * 60 * 60).await?; // 1 week + () = con.set_ex(key, 0, 7 * 24 * 60 * 60).await?; // 1 week Ok(()) } @@ -54,7 +54,8 @@ impl Storage { debug!("Caching launcher version as {version}"); let mut con = self.client.get_multiplexed_async_connection().await?; - con.set_ex(LAUNCHER_VERSION_KEY, version, 24 * 60 * 60) + () = con + .set_ex(LAUNCHER_VERSION_KEY, version, 24 * 60 * 60) .await?; // 1 day Ok(()) @@ -73,7 +74,8 @@ impl Storage { debug!("Caching stargazer count as {stargazers}"); let mut con = self.client.get_multiplexed_async_connection().await?; - con.set_ex(LAUNCHER_STARGAZER_KEY, stargazers, 60 * 60) + () = con + .set_ex(LAUNCHER_STARGAZER_KEY, stargazers, 60 * 60) .await?; Ok(())