Skip to content

Commit

Permalink
feat: nix (#3)
Browse files Browse the repository at this point in the history
* feat: nix

* fix: update rust toolchain

* feat: add build ci

---------

Co-authored-by: Towry <[email protected]>
  • Loading branch information
towry and towry committed May 20, 2024
1 parent 6d96065 commit 5d8c449
Show file tree
Hide file tree
Showing 6 changed files with 268 additions and 0 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: nix ci

on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

env:
SPEC_SPLIT_DOTS: 160
CI_NIX_SHELL: true

jobs:
release-build:
strategy:
matrix:
include:
- target: x86_64-apple-darwin
os: macOS-latest
name: path-git-format-${{ github.ref_name }}-x86_64-darwin.tar.gz
arch: x86_64

- target: aarch64-apple-darwin
os: macOS-latest
name: path-git-format-${{ github.ref_name }}-aarch64-darwin.tar.gz
arch: aarch64
useDaemon: [false, false]
runs-on: ${{ matrix.os }}
steps:
- name: Download source
uses: actions/checkout@v4
- uses: cachix/install-nix-action@v26
with:
install_url: https://releases.nixos.org/nix/nix-2.9.2/install
extra_nix_config: |
experimental-features = nix-command flakes
- uses: cachix/cachix-action@v14
if: ${{ success() }}
with:
name: towry
useDaemon: ${{ matrix.useDaemon }}
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
- name: Enter env
run: nix develop
- name: build
if: ${{ success() }}
run: make release && tar -czvf ${{ matrix.name }} -C ./target/release/ path-git-format
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.name }}
path: |
./path-git-format*.tar.gz
retention-days: 1

release:
permissions:
contents: write
runs-on: ubuntu-latest
needs: [release-build]
steps:
- uses: actions/download-artifact@v4
with:
merge-multiple: true

- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
draft: true
files: |
path-git-*.tar.gz
generate_release_notes: true
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
on: [push]

name: CI

jobs:
check:
name: Rust project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install latest nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
components: rustfmt, clippy

# `cargo check` command here will use installed `nightly`
# as it is set as an "override" for current directory

- name: Run cargo check
uses: actions-rs/cargo@v1
with:
command: check
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# will have compiled files and executables
debug/
target/
result

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Expand Down
100 changes: 100 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
description = "path-git-format";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = {
self,
nixpkgs,
flake-utils,
fenix,
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
manifest = (nixpkgs.lib.importTOML ./Cargo.toml).package;
rust = fenix.packages.${system}.fromToolchainFile {
dir = ./.;
sha256 = "sha256-jUR2Sd3jhDJIvcuMLBgxtTqa3ELWF38V7IqoZT8EzVU=";
# sha256 = nixpkgs.lib.fakeSha256;
};
buildInputs =
[
pkgs.openssl
]
++ nixpkgs.lib.optionals pkgs.stdenv.isDarwin [pkgs.libiconv pkgs.darwin.apple_sdk.frameworks.Security];
in {
devShells.default = pkgs.mkShell {
packages = [rust pkgs.pkg-config];
buildInputs = buildInputs;
};
packages = {
default = pkgs.stdenv.mkDerivation {
pname = "${manifest.name}";
version = "${manifest.version}";
src = self;
nativeBuildInputs = [rust pkgs.pkg-config];
buildInputs = buildInputs;

buildPhase = ''
export HOME=$(pwd)
cargo --version
make release
'';
installPhase = ''
mkdir -p $out/bin
cp ./target/release/path-git-format $out/bin/
tar -czvf path-git-format.tar.gz -C ./target/release/ path-git-format
'';
meta = {
description = "A simple utility to format path with git repo info from stdin";
homepage = "https://github.com/towry/path-git-format";
license = pkgs.lib.licenses.unlicense;
};
};
};
});
}
5 changes: 5 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[toolchain]
channel = "nightly-2024-05-02"
components = ["clippy", "rustfmt"]
profile = "default"
targets = []

0 comments on commit 5d8c449

Please sign in to comment.