From 3487e80c98f2b065eb892d85ef5e8c920bb1698a Mon Sep 17 00:00:00 2001 From: "Agatha V. Lovelace" Date: Sat, 27 Jan 2024 20:40:37 +0100 Subject: [PATCH] Add CI and Nix flake --- .envrc | 1 + .github/workflows/build_nix.yml | 31 +++++++++++ .gitignore | 1 + flake.lock | 95 +++++++++++++++++++++++++++++++++ flake.nix | 36 +++++++++++++ 5 files changed, 164 insertions(+) create mode 100644 .envrc create mode 100644 .github/workflows/build_nix.yml create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.github/workflows/build_nix.yml b/.github/workflows/build_nix.yml new file mode 100644 index 0000000..38d5abb --- /dev/null +++ b/.github/workflows/build_nix.yml @@ -0,0 +1,31 @@ +on: push +name: "Build Nix package on Ubuntu" + +env: + RUSTFLAGS: "-Dwarnings" + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v23 + - name: Building package + run: nix build + - name: Get repository name + run: echo "REPO_NAME=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV + - name: Get commit hash + run: echo "COMMIT_HASH=${GITHUB_SHA::6}" >> $GITHUB_ENV + - uses: actions/upload-artifact@v3 + with: + name: ${{ env.REPO_NAME }}-${{ env.COMMIT_HASH }}-x86_64-linux + path: result/bin/${{ env.REPO_NAME }} + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v23 + - name: Lint + run: nix develop --command cargo clippy --all-targets --all-features + - name: Test + run: nix develop --command cargo test diff --git a/.gitignore b/.gitignore index ea8c4bf..2d5df85 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +.direnv diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..4b7030b --- /dev/null +++ b/flake.lock @@ -0,0 +1,95 @@ +{ + "nodes": { + "naersk": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1697664192, + "narHash": "sha256-nRTG3rYEGFV2+putRiC96+kNXDyKaPJgT6K/1FWN7yo=", + "owner": "nix-community", + "repo": "naersk", + "rev": "636a9b5dd7f2ad7d7c3af929ecf95e4d4fab9e97", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "master", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1697915759, + "narHash": "sha256-WyMj5jGcecD+KC8gEs+wFth1J1wjisZf8kVZH13f1Zo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "51d906d2341c9e866e48c2efcaac0f2d70bfd43e", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1697915759, + "narHash": "sha256-WyMj5jGcecD+KC8gEs+wFth1J1wjisZf8kVZH13f1Zo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "51d906d2341c9e866e48c2efcaac0f2d70bfd43e", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "naersk": "naersk", + "nixpkgs": "nixpkgs_2", + "utils": "utils" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..b31635d --- /dev/null +++ b/flake.nix @@ -0,0 +1,36 @@ +{ + inputs = { + naersk.url = "github:nix-community/naersk/master"; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, utils, naersk }: + utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + naersk-lib = pkgs.callPackage naersk { }; + + nativeBuildInputs = with pkgs; [ pkg-config alsaLib ]; + buildInputs = with pkgs; [ openssl ]; + in { + packages.default = naersk-lib.buildPackage { + src = ./.; + inherit nativeBuildInputs buildInputs; + }; + devShells.default = with pkgs; + mkShell { + buildInputs = [ + cargo + rustc + rustfmt + pre-commit + rustPackages.clippy + rust-analyzer + ] ++ buildInputs; + inherit nativeBuildInputs; + + RUST_SRC_PATH = rustPlatform.rustLibSrc; + }; + }); +}