Skip to content

Commit

Permalink
Move to Nix
Browse files Browse the repository at this point in the history
  • Loading branch information
DanNixon committed Sep 27, 2023
1 parent 203058f commit 8da76e3
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 28 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
40 changes: 12 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,30 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- name: Setup
run: rustup component add clippy rustfmt
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v20

- name: Format
run: cargo fmt -- --check
run: nix build -L .#fmt

- name: Clippy
run: cargo clippy -- -Dwarnings
run: nix build -L .#clippy

- name: cargo-deny
uses: EmbarkStudios/cargo-deny-action@v1

build-and-test:
name: Build and Test
runs-on: ubuntu-latest
run: nix develop --command cargo-deny check

steps:
- uses: actions/checkout@v1

- name: Build and Test
run: cargo test
- name: Test
run: nix build -L .#test

release:
name: Release
if: ${{ github.ref_type == 'tag' }}
build:
name: Build
needs:
- build-and-test
- formatting-and-quality
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v20

- name: Build
run: cargo build --release

- name: Publish release
uses: softprops/action-gh-release@v1
with:
files: target/release/git-collage
fail_on_unmatched_files: true
run: nix build -L
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
result
119 changes: 119 additions & 0 deletions flake.lock

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

91 changes: 91 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";

fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};

naersk = {
url = "github:nix-community/naersk";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = { self, nixpkgs, flake-utils, fenix, naersk }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = (import nixpkgs) {
inherit system;
};

toolchain = fenix.packages.${system}.toolchainOf {
channel = "1.72";
date = "2023-09-19";
sha256 = "dxE7lmCFWlq0nl/wKcmYvpP9zqQbBitAQgZ1zx9Ooik=";
};

naersk' = pkgs.callPackage naersk {
cargo = toolchain.rust;
rustc = toolchain.rust;
};

cargo = builtins.fromTOML ( builtins.readFile ./Cargo.toml );
name = cargo.package.name;
version = cargo.package.version;

nativeBuildInputs = with pkgs; [ pkg-config ];
buildInputs = with pkgs; [ openssl ];

in {
devShell = pkgs.mkShell {
nativeBuildInputs = nativeBuildInputs ++ [ toolchain.toolchain ];
buildInputs = buildInputs;
packages = with pkgs; [ cargo-deny ];
};

packages = rec {
default = naersk'.buildPackage {
name = name;
version = version;

src = ./.;

nativeBuildInputs = nativeBuildInputs;
buildInputs = buildInputs;
};

fmt = naersk'.buildPackage {
src = ./.;

nativeBuildInputs = nativeBuildInputs;
buildInputs = buildInputs;

mode = "fmt";
};

clippy = naersk'.buildPackage {
src = ./.;

nativeBuildInputs = nativeBuildInputs;
buildInputs = buildInputs;

mode = "clippy";
};

test = naersk'.buildPackage {
src = ./.;

nativeBuildInputs = nativeBuildInputs;
buildInputs = buildInputs;

mode = "test";

# Ensure detailed test output appears in nix build log
cargoTestOptions = x: x ++ ["1>&2"];
};
};
}
);
}

0 comments on commit 8da76e3

Please sign in to comment.