Skip to content

Commit db46415

Browse files
DrRuhemstange
authored andcommitted
add nix-based packaging
1 parent 5312858 commit db46415

File tree

5 files changed

+345
-0
lines changed

5 files changed

+345
-0
lines changed

.envrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use_flake

.github/workflows/nix-packaging.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This is a basic workflow to help you get started with Actions
2+
3+
name: "Nix Packaging"
4+
5+
# Controls when the workflow will run
6+
on:
7+
# Triggers the workflow on push or pull request events but only for the "main" branch
8+
push:
9+
branches: [ "main" ]
10+
pull_request:
11+
branches: [ "main" ]
12+
13+
# Allows you to run this workflow manually from the Actions tab
14+
workflow_dispatch:
15+
16+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
17+
jobs:
18+
build:
19+
name: "Build Samply using nix flake"
20+
runs-on: ubuntu-22.04
21+
timeout-minutes: 30
22+
steps:
23+
- uses: actions/checkout@v3
24+
- uses: cachix/install-nix-action@v17
25+
with:
26+
nix_path: nixpkgs=channel:nixos-22.05
27+
# - uses: cachix/cachix-action@v10
28+
# with:
29+
# name: samply
30+
# authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
31+
32+
- name: Build samply with nix
33+
run: nix build -L .#

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
target
22
profile.json
33
.DS_Store
4+
.direnv/
5+
6+
result-bin
47

58
# These libxul blobs are too big to put them in the repo.
69
# The benchmarks example downloads them from the Mozilla symbol server on demand.

flake.lock

+164
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
{
2+
description = "Samply";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
6+
7+
crane = {
8+
url = "github:ipetkov/crane";
9+
inputs.nixpkgs.follows = "nixpkgs";
10+
};
11+
12+
flake-utils.url = "github:numtide/flake-utils";
13+
14+
advisory-db = {
15+
url = "github:rustsec/advisory-db";
16+
flake = false;
17+
};
18+
19+
rust-overlay = {
20+
url = "github:oxalica/rust-overlay";
21+
inputs = {
22+
nixpkgs.follows = "nixpkgs";
23+
flake-utils.follows = "flake-utils";
24+
};
25+
};
26+
27+
};
28+
29+
outputs = { self, nixpkgs, crane, flake-utils, advisory-db, ... }@inputs:
30+
flake-utils.lib.eachSystem [ "aarch64-darwin" "x86_64-darwin" "aarch64-linux" "x86_64-linux" ] (system:
31+
let
32+
pkgs = import nixpkgs {
33+
inherit system;
34+
overlays = [
35+
(import inputs.rust-overlay)
36+
];
37+
};
38+
39+
inherit (pkgs) lib;
40+
41+
42+
toolchain-settings = {
43+
extensions = [ "rust-src" ];
44+
targets = [ "aarch64-apple-darwin" "x86_64-apple-darwin" "aarch64-unknown-linux-gnu" "x86_64-unknown-linux-gnu" ];
45+
};
46+
# stable
47+
rust-toolchain = pkgs.rust-bin.stable.latest.default.override toolchain-settings;
48+
# nightly
49+
# rust-toolchain = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default.override toolchain-settings);
50+
51+
craneLib = (crane.mkLib pkgs).overrideToolchain rust-toolchain;
52+
53+
src = craneLib.cleanCargoSource ./.;
54+
55+
buildInputs = with pkgs; [
56+
# Add additional build inputs here
57+
openssl
58+
pkg-config
59+
];
60+
61+
62+
63+
# Build *just* the cargo dependencies, so we can reuse
64+
# all of that work (e.g. via cachix) when running in CI
65+
cargoArtifacts = craneLib.buildDepsOnly {
66+
inherit src buildInputs;
67+
};
68+
69+
# Build the actual crate itself, reusing the dependency
70+
# artifacts from above.
71+
samply = craneLib.buildPackage {
72+
inherit cargoArtifacts src buildInputs;
73+
pname = "samply";
74+
cargoExtraArgs = "--bin samply";
75+
};
76+
in
77+
{
78+
checks = {
79+
# Build the crate as part of `nix flake check` for convenience
80+
inherit samply;
81+
82+
# Run clippy (and deny all warnings) on the crate source,
83+
# again, resuing the dependency artifacts from above.
84+
#
85+
# Note that this is done as a separate derivation so that
86+
# we can block the CI if there are issues here, but not
87+
# prevent downstream consumers from building our crate by itself.
88+
cargo-clippy = craneLib.cargoClippy {
89+
inherit cargoArtifacts src buildInputs;
90+
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
91+
};
92+
93+
cargo-doc = craneLib.cargoDoc {
94+
inherit cargoArtifacts src buildInputs;
95+
};
96+
97+
# Check formatting
98+
cargo-fmt = craneLib.cargoFmt {
99+
inherit src;
100+
};
101+
102+
# Audit dependencies
103+
cargo-audit = craneLib.cargoAudit {
104+
inherit src advisory-db;
105+
};
106+
107+
# Run tests with cargo-nextest
108+
# Consider setting `doCheck = false` on `samply` if you do not want
109+
# the tests to run twice
110+
cargo-nextest = craneLib.cargoNextest {
111+
inherit cargoArtifacts src buildInputs;
112+
partitions = 1;
113+
partitionType = "count";
114+
};
115+
} // lib.optionalAttrs (system == "x86_64-linux") {
116+
# NB: cargo-tarpaulin only supports x86_64 systems
117+
# Check code coverage (note: this will not upload coverage anywhere)
118+
cargo-coverage = craneLib.cargoTarpaulin {
119+
inherit cargoArtifacts src;
120+
};
121+
};
122+
123+
packages.default = samply;
124+
125+
apps.default = flake-utils.lib.mkApp {
126+
drv = samply;
127+
};
128+
129+
overlays = final: prev: {
130+
inherit samply;
131+
};
132+
133+
devShells.default = pkgs.mkShell {
134+
inputsFrom = builtins.attrValues self.checks;
135+
136+
packages = with pkgs; [
137+
rust-toolchain
138+
rust-analyzer
139+
] ++ buildInputs;
140+
141+
};
142+
}
143+
);
144+
}

0 commit comments

Comments
 (0)