diff options
| -rw-r--r-- | .envrc | 2 | ||||
| -rw-r--r-- | .github/workflows/ci.yaml | 12 | ||||
| -rw-r--r-- | .github/workflows/clippy.yaml | 6 | ||||
| -rw-r--r-- | .github/workflows/docker.yaml | 2 | ||||
| -rw-r--r-- | .github/workflows/nix.yaml | 31 | ||||
| -rw-r--r-- | flake.lock | 39 | ||||
| -rw-r--r-- | flake.nix | 101 | ||||
| -rw-r--r-- | nix/derivation.nix | 7 | ||||
| -rw-r--r-- | nix/dev/checks.nix | 27 | ||||
| -rw-r--r-- | nix/dev/docker.nix | 25 | ||||
| -rw-r--r-- | nix/dev/flake.lock | 145 | ||||
| -rw-r--r-- | nix/dev/flake.nix | 62 | ||||
| -rw-r--r-- | nix/dev/procfile.nix | 13 | ||||
| -rw-r--r-- | nix/dev/shell.nix | 45 | ||||
| -rw-r--r-- | nix/dev/static.nix | 39 | ||||
| -rw-r--r-- | nix/dev/treefmt.nix | 21 | ||||
| -rw-r--r-- | nix/docker.nix | 43 |
17 files changed, 190 insertions, 430 deletions
@@ -1,6 +1,6 @@ # only use flake when `nix-direnv` is installed if has nix_direnv_version; then - use flake ./nix/dev + use flake fi dotenv_if_exists diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 44e7de3..ebaf53a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -25,7 +25,6 @@ jobs: uses: dtolnay/rust-toolchain@stable with: toolchain: stable - components: clippy - name: Setup Rust cache uses: Swatinem/rust-cache@v2 @@ -33,8 +32,8 @@ jobs: - name: Run build run: cargo build --locked --release - format: - name: Check formatting + format-and-lint: + name: Format & lint runs-on: ubuntu-latest @@ -50,14 +49,11 @@ jobs: - name: Run treefmt run: | - pushd nix/dev - nix fmt - popd - git diff --color=always --exit-code + nix flake check --all-systems --print-build-logs --show-trace release-gate: name: CI Release Gate - needs: [build, format] + needs: [build, format-and-lint] runs-on: ubuntu-latest diff --git a/.github/workflows/clippy.yaml b/.github/workflows/clippy.yaml index a37fde3..b827057 100644 --- a/.github/workflows/clippy.yaml +++ b/.github/workflows/clippy.yaml @@ -38,18 +38,18 @@ jobs: - name: Install SARIF tools run: | nix profile install \ - --inputs-from ./nix/dev \ + --inputs-from . \ github:getchoo/nix-exprs#{clippy-sarif,sarif-fmt} - name: Fetch Cargo deps run: | - nix develop ./nix/dev#ci --command \ + nix develop .#ci --command \ cargo fetch --locked - name: Run Clippy continue-on-error: true run: | - nix develop ./nix/dev#ci --command \ + nix develop .#ci --command \ cargo clippy \ --all-features \ --all-targets \ diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 5f45bec..221516b 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -35,7 +35,7 @@ jobs: nix build \ --fallback \ --print-build-logs \ - ./nix/dev#container-"$ARCH" + .#container-"$ARCH" # exit if no `result` from nix build [ ! -L result ] && exit 1 diff --git a/.github/workflows/nix.yaml b/.github/workflows/nix.yaml deleted file mode 100644 index ab0987c..0000000 --- a/.github/workflows/nix.yaml +++ /dev/null @@ -1,31 +0,0 @@ -name: Nix - -on: - push: - branches: [main] - pull_request: - workflow_dispatch: - -jobs: - check: - name: Check flake - - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Install Nix - uses: DeterminateSystems/nix-installer-action@v10 - - - name: Setup Nix cache - uses: DeterminateSystems/magic-nix-cache-action@v4 - - - name: Run nix flake check - run: | - nix flake check \ - --all-systems \ - --fallback \ - --print-build-logs \ - --show-trace @@ -1,5 +1,26 @@ { "nodes": { + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1713680591, + "narHash": "sha256-3pbv7UgAgetwz9YdjzIT/lZ6Rgj6wj6MR4mphBLyDjU=", + "owner": "nix-community", + "repo": "fenix", + "rev": "19aaa94a73cc670a4d87e84f0909966cd8f8cd79", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1713442664, @@ -18,8 +39,26 @@ }, "root": { "inputs": { + "fenix": "fenix", "nixpkgs": "nixpkgs" } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1713628977, + "narHash": "sha256-iN5QUlUq527lswmBC+RopfXdu6Xx7mmTaBSH2l59FtM=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "55d9a533b309119c8acd13061581b43ae8840823", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } } }, "root": "root", @@ -1,13 +1,19 @@ { description = "teawie moment"; - inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; outputs = { self, nixpkgs, ... - }: let + } @ inputs: let systems = [ "x86_64-linux" "aarch64-linux" @@ -17,17 +23,100 @@ forAllSystems = fn: nixpkgs.lib.genAttrs systems (system: fn nixpkgs.legacyPackages.${system}); in { - nixosModules.default = import ./nix/module.nix self; + checks = forAllSystems ({ + lib, + pkgs, + ... + }: { + actionlint = pkgs.runCommand "check-actionlint" {} '' + ${lib.getExe pkgs.actionlint} ${./.github/workflows}/* + touch $out + ''; - packages = forAllSystems ({ + deadnix = pkgs.runCommand "check-deadnix" {} '' + ${lib.getExe pkgs.deadnix} --fail ${./.} + touch $out + ''; + + editorconfig = pkgs.runCommand "check-editorconfig" {} '' + cd ${./.} + ${lib.getExe pkgs.editorconfig-checker} \ + -exclude '.git' . + + touch $out + ''; + + rustfmt = pkgs.runCommand "check-rustfmt" {nativeBuildInputs = [pkgs.cargo pkgs.rustfmt];} '' + cd ${./.} + cargo fmt -- --check + touch $out + ''; + + statix = pkgs.runCommand "check-statix" {} '' + ${lib.getExe pkgs.statix} check ${./.} + touch $out + ''; + }); + + devShells = forAllSystems ({ pkgs, system, ... }: { - teawiebot = pkgs.callPackage ./nix/derivation.nix {inherit self;}; - default = self.packages.${system}.teawiebot; + default = pkgs.mkShell { + packages = [ + # rust tools + pkgs.clippy + pkgs.rustfmt + pkgs.rust-analyzer + + # nix tools + pkgs.deadnix + pkgs.nil + pkgs.statix + + # misc formatter/linters + pkgs.actionlint + self.formatter.${system} + + pkgs.redis + ]; + + inputsFrom = [self.packages.${system}.teawiebot]; + RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}"; + }; + + ci = pkgs.mkShell { + packages = [ + pkgs.clippy + pkgs.rustfmt + + self.formatter.${system} + ]; + + inputsFrom = [self.packages.${system}.teawiebot]; + }; }); + formatter = forAllSystems (pkgs: pkgs.alejandra); + + nixosModules.default = import ./nix/module.nix self; + + packages = forAllSystems ({ + pkgs, + system, + ... + }: let + crossBuildsFor = arch: import ./nix/docker.nix {inherit pkgs arch inputs;}; + in + { + teawiebot = pkgs.callPackage ./nix/derivation.nix {inherit self;}; + + default = self.packages.${system}.teawiebot; + } + // crossBuildsFor "x86_64" + // crossBuildsFor "aarch64"); + overlays.default = _: prev: { teawiebot = prev.callPackage ./nix/derivation.nix {inherit self;}; }; diff --git a/nix/derivation.nix b/nix/derivation.nix index fa4867a..6a25976 100644 --- a/nix/derivation.nix +++ b/nix/derivation.nix @@ -3,7 +3,7 @@ stdenv, rustPlatform, darwin, - self, + self ? {inherit ((lib.importTOML ../Cargo.toml).package) version;}, lto ? true, optimizeSize ? false, }: @@ -11,7 +11,8 @@ rustPlatform.buildRustPackage { pname = "teawiebot"; version = (lib.importTOML ../Cargo.toml).package.version - + "-${self.shortRev or self.dirtyShortRev or "unknown-dirty"}"; + + "-" + + self.shortRev or self.dirtyShortRev or self.version or "unknown"; __structuredAttrs = true; @@ -43,7 +44,7 @@ rustPlatform.buildRustPackage { ); in { - GIT_SHA = self.shortRev or self.dirtyShortRev or "unknown-dirty"; + GIT_SHA = self.shortRev or self.dirtyShortRev or "unknown"; } // lib.optionalAttrs lto (toRustFlags { lto = "thin"; diff --git a/nix/dev/checks.nix b/nix/dev/checks.nix deleted file mode 100644 index 1d65625..0000000 --- a/nix/dev/checks.nix +++ /dev/null @@ -1,27 +0,0 @@ -{ - perSystem = { - lib, - pkgs, - ... - }: { - checks = { - actionlint = pkgs.runCommand "check-actionlint" {} '' - ${lib.getExe pkgs.actionlint} ${../../.github/workflows}/* - touch $out - ''; - - editorconfig = pkgs.runCommand "check-editorconfig" {} '' - cd ${../../.} - ${lib.getExe pkgs.editorconfig-checker} \ - -exclude '.git' . - - touch $out - ''; - - statix = pkgs.runCommand "check-statix" {} '' - ${lib.getExe pkgs.statix} check ${../../.} - touch $out - ''; - }; - }; -} diff --git a/nix/dev/docker.nix b/nix/dev/docker.nix deleted file mode 100644 index b209015..0000000 --- a/nix/dev/docker.nix +++ /dev/null @@ -1,25 +0,0 @@ -{withSystem, ...}: { - perSystem = { - lib, - pkgs, - self', - ... - }: let - containerFor = arch: - pkgs.dockerTools.buildLayeredImage { - name = "teawiebot"; - tag = "latest-${arch}"; - contents = [pkgs.dockerTools.caCertificates]; - config.Cmd = [ - (lib.getExe self'.packages."teawiebot-static-${arch}") - ]; - - architecture = withSystem "${arch}-linux" ({pkgs, ...}: pkgs.pkgsStatic.go.GOARCH); - }; - in { - packages = { - container-x86_64 = containerFor "x86_64"; - container-aarch64 = containerFor "aarch64"; - }; - }; -} diff --git a/nix/dev/flake.lock b/nix/dev/flake.lock deleted file mode 100644 index cb3fec6..0000000 --- a/nix/dev/flake.lock +++ /dev/null @@ -1,145 +0,0 @@ -{ - "nodes": { - "fenix": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ], - "rust-analyzer-src": "rust-analyzer-src" - }, - "locked": { - "lastModified": 1713421495, - "narHash": "sha256-5vVF9W1tJT+WdfpWAEG76KywktKDAW/71mVmNHEHjac=", - "owner": "nix-community", - "repo": "fenix", - "rev": "fd47b1f9404fae02a4f38bd9f4b12bad7833c96b", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "fenix", - "type": "github" - } - }, - "flake-parts": { - "inputs": { - "nixpkgs-lib": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1712014858, - "narHash": "sha256-sB4SWl2lX95bExY2gMFG5HIzvva5AVMJd4Igm+GpZNw=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "9126214d0a59633752a136528f5f3b9aa8565b7d", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "flake-parts", - "type": "github" - } - }, - "get-flake": { - "locked": { - "lastModified": 1694475786, - "narHash": "sha256-s5wDmPooMUNIAAsxxCMMh9g68AueGg63DYk2hVZJbc8=", - "owner": "ursi", - "repo": "get-flake", - "rev": "ac54750e3b95dab6ec0726d77f440efe6045bec1", - "type": "github" - }, - "original": { - "owner": "ursi", - "repo": "get-flake", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1713442664, - "narHash": "sha256-LoExypse3c/uun/39u4bPTN4wejIF7hNsdITZO41qTw=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "d764f230634fa4f86dc8d01c6af9619c7cc5d225", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "procfile-nix": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1713576892, - "narHash": "sha256-458FHKn05FCX+fTOuHEobfJjADBKitzrd1SoPXSQOJc=", - "owner": "getchoo", - "repo": "procfile-nix", - "rev": "04cfa7931e996cb81c5848b559cb316c7f907b56", - "type": "github" - }, - "original": { - "owner": "getchoo", - "repo": "procfile-nix", - "type": "github" - } - }, - "root": { - "inputs": { - "fenix": "fenix", - "flake-parts": "flake-parts", - "get-flake": "get-flake", - "nixpkgs": "nixpkgs", - "procfile-nix": "procfile-nix", - "treefmt-nix": "treefmt-nix" - } - }, - "rust-analyzer-src": { - "flake": false, - "locked": { - "lastModified": 1713373173, - "narHash": "sha256-octd9BFY9G/Gbr4KfwK4itZp4Lx+qvJeRRcYnN+dEH8=", - "owner": "rust-lang", - "repo": "rust-analyzer", - "rev": "46702ffc1a02a2ac153f1d1ce619ec917af8f3a6", - "type": "github" - }, - "original": { - "owner": "rust-lang", - "ref": "nightly", - "repo": "rust-analyzer", - "type": "github" - } - }, - "treefmt-nix": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1711963903, - "narHash": "sha256-N3QDhoaX+paWXHbEXZapqd1r95mdshxToGowtjtYkGI=", - "owner": "numtide", - "repo": "treefmt-nix", - "rev": "49dc4a92b02b8e68798abd99184f228243b6e3ac", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "treefmt-nix", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/nix/dev/flake.nix b/nix/dev/flake.nix deleted file mode 100644 index 1442839..0000000 --- a/nix/dev/flake.nix +++ /dev/null @@ -1,62 +0,0 @@ -{ - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - - flake-parts = { - url = "github:hercules-ci/flake-parts"; - inputs.nixpkgs-lib.follows = "nixpkgs"; - }; - - fenix = { - url = "github:nix-community/fenix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - - get-flake.url = "github:ursi/get-flake"; - - treefmt-nix = { - url = "github:numtide/treefmt-nix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - - procfile-nix = { - url = "github:getchoo/procfile-nix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - }; - - outputs = inputs: - inputs.flake-parts.lib.mkFlake {inherit inputs;} { - systems = [ - "x86_64-linux" - "aarch64-linux" - "x86_64-darwin" - "aarch64-darwin" - ]; - - imports = [ - # dev utils - ./checks.nix - ./procfile.nix - ./shell.nix - ./treefmt.nix - - # special, private builds - ./docker.nix - ./static.nix - - inputs.treefmt-nix.flakeModule - inputs.procfile-nix.flakeModule - ]; - - perSystem = { - lib, - system, - ... - }: { - _module.args = { - teawiebot' = lib.mapAttrs (lib.const (v: v.${system} or v)) (inputs.get-flake ../../.); - }; - }; - }; -} diff --git a/nix/dev/procfile.nix b/nix/dev/procfile.nix deleted file mode 100644 index 4b1c665..0000000 --- a/nix/dev/procfile.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ - perSystem = { - lib, - pkgs, - ... - }: { - procfiles.daemons = { - processes = { - redis = lib.getExe' pkgs.redis "redis-server"; - }; - }; - }; -} diff --git a/nix/dev/shell.nix b/nix/dev/shell.nix deleted file mode 100644 index c5589ef..0000000 --- a/nix/dev/shell.nix +++ /dev/null @@ -1,45 +0,0 @@ -{ - perSystem = { - config, - pkgs, - self', - teawiebot', - ... - }: { - devShells = { - default = pkgs.mkShell { - packages = [ - # rust tools - pkgs.clippy - pkgs.rustfmt - pkgs.rust-analyzer - - # nix tools - pkgs.deadnix - pkgs.nil - pkgs.statix - - # misc formatter/linters - pkgs.actionlint - self'.formatter - - config.procfiles.daemons.package - ]; - - inputsFrom = [teawiebot'.packages.teawiebot]; - RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}"; - }; - - ci = pkgs.mkShell { - packages = [ - pkgs.clippy - pkgs.rustfmt - - self'.formatter - ]; - - inputsFrom = [teawiebot'.packages.teawiebot]; - }; - }; - }; -} diff --git a/nix/dev/static.nix b/nix/dev/static.nix deleted file mode 100644 index e8780f4..0000000 --- a/nix/dev/static.nix +++ /dev/null @@ -1,39 +0,0 @@ -{ - perSystem = { - lib, - pkgs, - inputs', - teawiebot', - ... - }: let - crossTargets = with pkgs.pkgsCross; { - x86_64 = musl64.pkgsStatic; - aarch64 = aarch64-multiplatform.pkgsStatic; - }; - - rustStdFor = pkgs: inputs'.fenix.packages.targets.${pkgs.stdenv.hostPlatform.rust.rustcTarget}.stable.rust-std; - toolchain = with inputs'.fenix.packages; - combine (lib.flatten [ - stable.cargo - stable.rustc - (map rustStdFor (lib.attrValues crossTargets)) - ]); - - rustPlatformFor = pkgs: - pkgs.makeRustPlatform ( - lib.genAttrs ["cargo" "rustc"] (lib.const toolchain) - ); - crossPlatforms = lib.mapAttrs (lib.const rustPlatformFor) crossTargets; - - buildTeawieWith = rustPlatform: - teawiebot'.packages.teawiebot.override { - inherit rustPlatform; - optimizeSize = true; - }; - in { - packages = { - teawiebot-static-x86_64 = buildTeawieWith crossPlatforms.x86_64; - teawiebot-static-aarch64 = buildTeawieWith crossPlatforms.aarch64; - }; - }; -} diff --git a/nix/dev/treefmt.nix b/nix/dev/treefmt.nix deleted file mode 100644 index 5e1fd1f..0000000 --- a/nix/dev/treefmt.nix +++ /dev/null @@ -1,21 +0,0 @@ -{ - perSystem = { - treefmt = { - projectRootFile = "flake.nix"; - - programs = { - alejandra.enable = true; - deadnix.enable = true; - rustfmt.enable = true; - }; - - settings.global = { - excludes = [ - "./target" - "./flake.lock" - "./Cargo.lock" - ]; - }; - }; - }; -} diff --git a/nix/docker.nix b/nix/docker.nix new file mode 100644 index 0000000..79f49cc --- /dev/null +++ b/nix/docker.nix @@ -0,0 +1,43 @@ +{ + pkgs, + arch, + inputs, +}: let + inherit (pkgs) lib; + inputs' = lib.mapAttrs (_: lib.mapAttrs (_: v: v.${pkgs.system} or v)) inputs; + + crossTargets = with pkgs.pkgsCross; { + x86_64 = musl64.pkgsStatic; + aarch64 = aarch64-multiplatform.pkgsStatic; + }; + + rustStdFor = pkgs: inputs'.fenix.packages.targets.${pkgs.stdenv.hostPlatform.rust.rustcTarget}.stable.rust-std; + toolchain = with inputs'.fenix.packages; + combine (lib.flatten [ + stable.cargo + stable.rustc + (map rustStdFor (lib.attrValues crossTargets)) + ]); + + rustPlatformFor = pkgs: + pkgs.makeRustPlatform ( + lib.genAttrs ["cargo" "rustc"] (lib.const toolchain) + ); + crossPlatforms = lib.mapAttrs (lib.const rustPlatformFor) crossTargets; +in { + "teawiebot-static-${arch}" = inputs'.self.packages.teawiebot.override { + rustPlatform = crossPlatforms.${arch}; + optimizeSize = true; + }; + + "container-${arch}" = pkgs.dockerTools.buildLayeredImage { + name = "teawiebot"; + tag = "latest-${arch}"; + contents = [pkgs.dockerTools.caCertificates]; + config.Cmd = [ + (lib.getExe inputs'.self.packages."teawiebot-static-${arch}") + ]; + + architecture = inputs.nixpkgs.legacyPackages."${arch}-linux".pkgsStatic.go.GOARCH; + }; +} |
