From 912fcf7df98f69ff36522cfad967f156065e1902 Mon Sep 17 00:00:00 2001 From: Logan Walls <2934282+LoganWalls@users.noreply.github.com> Date: Wed, 29 May 2024 03:01:36 -0400 Subject: [PATCH] chore: packaging as nix flake * chore(release): release hac v0.1.0 * package as nix flake --------- Co-authored-by: wiru --- .github/workflows/release.yml | 3 + Cargo.toml | 6 ++ flake.lock | 103 ++++++++++++++++++++++++++++++++++ flake.nix | 75 +++++++++++++++++++++++++ rust-toolchain.toml | 4 ++ 5 files changed, 191 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 rust-toolchain.toml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 87eeeaf..5c76f22 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,6 +34,9 @@ jobs: os: ubuntu-22.04 timeout-minutes: 60 steps: + - name: Install dependencies + if: startsWith(matrix.os, 'ubuntu') + run: sudo apt-get update && sudo apt-get install -y pkg-config libssl-dev - name: Checkout repository uses: actions/checkout@v4 diff --git a/Cargo.toml b/Cargo.toml index 6f4f184..378761b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,12 @@ members = ["hac-config", "hac-core", "hac-client", "hac-colors", "hac-cli"] default-members = ["hac-client"] resolver = "2" +[workspace.metadata.crane] +name = "hac" + +[workspace.package] +version = "0.1.0" + [workspace.dependencies] hac-config = { path = "hac-config" } hac-core = { path = "hac-core" } diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..13b8177 --- /dev/null +++ b/flake.lock @@ -0,0 +1,103 @@ +{ + "nodes": { + "crane": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1716745752, + "narHash": "sha256-8K1R9Yg4r08rYk86Yq+lu3E9L3uRUb4xMqYHgl0VGS0=", + "owner": "ipetkov", + "repo": "crane", + "rev": "19ca94ec2d288de334ae932107816b4a97736cd8", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1716509168, + "narHash": "sha256-4zSIhSRRIoEBwjbPm3YiGtbd8HDWzFxJjw5DYSDy1n8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "bfb7a882678e518398ce9a31a881538679f6f092", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1716862669, + "narHash": "sha256-7oTPM9lcdwiI1cpRC313B+lHawocgpY5F07N+Rbm5Uk=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "47b2d15658b37716393b2463a019000dbd6ce4bc", + "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 0000000..1965fa5 --- /dev/null +++ b/flake.nix @@ -0,0 +1,75 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + crane = { + url = "github:ipetkov/crane"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + outputs = { + nixpkgs, + rust-overlay, + crane, + ... + }: let + inherit (nixpkgs) lib; + withSystem = f: + lib.fold lib.recursiveUpdate {} + (map f ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"]); + in + withSystem ( + system: let + pkgs = import nixpkgs { + inherit system; + overlays = [rust-overlay.overlays.default]; + }; + inherit (pkgs) stdenv lib; + toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; + buildDeps = + [pkgs.openssl] + ++ lib.optionals stdenv.isDarwin (with pkgs.darwin.apple_sdk.frameworks; [ + SystemConfiguration + ]); + crate = craneLib.buildPackage { + # Filter src to only .rs, .toml, and .scm files to avoid needless recompiles + src = let + schemeFilter = path: _type: builtins.match ".*scm$" path != null; + schemeOrCargo = path: type: + (schemeFilter path type) || (craneLib.filterCargoSources path type); + in + lib.cleanSourceWith { + src = craneLib.path ./.; + filter = schemeOrCargo; + }; + strictDeps = true; + buildInputs = buildDeps; + nativeBuildInputs = lib.optionals stdenv.isLinux [pkgs.pkg-config]; + doNotSign = stdenv.isDarwin; # Build seems to break when this is true on Darwin + }; + in { + apps.${system}.default = let + name = crate.pname or crate.name; + exe = crate.passthru.exePath or "/bin/${name}"; + in { + type = "app"; + program = "${crate}${exe}"; + }; + packages.${system}.default = crate; + checks.${system} = {inherit crate;}; + devShells.${system}.default = pkgs.mkShell { + packages = with pkgs; + [ + toolchain + rust-analyzer-unwrapped + ] + ++ buildDeps; + RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library"; + }; + } + ); +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..90e92de --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "stable" +components = ["rust-src"] +profile = "default"