Skip to content

Commit 720eedb

Browse files
committed
nix: add flake (crane + fenix) and nix-build CI on push to main
flake.nix provides a pure-Rust crane build (no C deps, unlike fin): the squeezed package/app, a dev shell, and flake checks (clippy with -D warnings, rustfmt, cargo-audit against advisory-db, nextest, and tarpaulin coverage on x86_64-linux). Systems are listed explicitly (x86_64-linux, aarch64-linux, aarch64-darwin) since nixpkgs-unstable dropped x86_64-darwin. Add .github/workflows/nix.yml running `nix build .#default` and `nix flake check` on push to main/master, pull requests, and manual dispatch.
1 parent c5cf359 commit 720eedb

3 files changed

Lines changed: 289 additions & 0 deletions

File tree

.github/workflows/nix.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Nix
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
nix-build:
14+
name: nix build & flake checks
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Install Nix
21+
uses: cachix/install-nix-action@v27
22+
with:
23+
extra_nix_config: |
24+
experimental-features = nix-command flakes
25+
26+
- name: Build package
27+
run: nix build .#default -L
28+
29+
- name: Flake checks (clippy, fmt, audit, tests)
30+
run: nix flake check -L

flake.lock

Lines changed: 116 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
{
2+
description = "squeezed - serve a raw PCM audio stream to Squeezelite/Squeezebox clients over SlimProto";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
7+
# Current crane doesn't expose a `nixpkgs` input, so we don't follow it.
8+
crane.url = "github:ipetkov/crane";
9+
10+
fenix = {
11+
url = "github:nix-community/fenix";
12+
inputs.nixpkgs.follows = "nixpkgs";
13+
inputs.rust-analyzer-src.follows = "";
14+
};
15+
16+
flake-utils.url = "github:numtide/flake-utils";
17+
18+
advisory-db = {
19+
url = "github:rustsec/advisory-db";
20+
flake = false;
21+
};
22+
};
23+
24+
outputs = { self, nixpkgs, crane, fenix, flake-utils, advisory-db, ... }:
25+
# nixpkgs-unstable has dropped x86_64-darwin (EOL Intel macOS), so we list
26+
# the currently-supported systems explicitly rather than eachDefaultSystem.
27+
flake-utils.lib.eachSystem [
28+
"x86_64-linux"
29+
"aarch64-linux"
30+
"aarch64-darwin"
31+
] (system:
32+
let
33+
pkgs = import nixpkgs {
34+
inherit system;
35+
};
36+
37+
inherit (pkgs) lib;
38+
39+
craneLib = crane.mkLib pkgs;
40+
41+
src = craneLib.cleanCargoSource ./.;
42+
43+
# squeezed is pure Rust — no C dependencies, no openssl, no pkg-config.
44+
# The default stdenv toolchain (for linking) is all that's needed, so
45+
# there are no extra native/build inputs.
46+
commonArgs = {
47+
inherit src;
48+
49+
pname = "squeezed";
50+
version = "0.1.0";
51+
strictDeps = true;
52+
53+
# Single-package crate with one bin target — build just that.
54+
cargoExtraArgs = "--locked --bin squeezed";
55+
};
56+
57+
craneLibLLvmTools = craneLib.overrideToolchain
58+
(fenix.packages.${system}.complete.withComponents [
59+
"cargo"
60+
"llvm-tools"
61+
"rustc"
62+
]);
63+
64+
# Cache the dependency graph separately from the crate source.
65+
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
66+
67+
squeezed = craneLib.buildPackage (commonArgs // {
68+
inherit cargoArtifacts;
69+
doCheck = false;
70+
71+
meta = {
72+
description = "Serve a raw PCM audio stream to Squeezelite/Squeezebox clients over SlimProto";
73+
homepage = "https://github.com/tsirysndr/squeezed";
74+
license = lib.licenses.mit;
75+
mainProgram = "squeezed";
76+
platforms = lib.platforms.unix;
77+
};
78+
});
79+
80+
in
81+
{
82+
checks = {
83+
inherit squeezed;
84+
85+
squeezed-clippy = craneLib.cargoClippy (commonArgs // {
86+
inherit cargoArtifacts;
87+
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
88+
});
89+
90+
squeezed-doc = craneLib.cargoDoc (commonArgs // {
91+
inherit cargoArtifacts;
92+
});
93+
94+
squeezed-fmt = craneLib.cargoFmt {
95+
inherit src;
96+
};
97+
98+
squeezed-audit = craneLib.cargoAudit {
99+
inherit src advisory-db;
100+
};
101+
102+
squeezed-nextest = craneLib.cargoNextest (commonArgs // {
103+
inherit cargoArtifacts;
104+
partitions = 1;
105+
partitionType = "count";
106+
});
107+
} // lib.optionalAttrs (system == "x86_64-linux") {
108+
squeezed-coverage = craneLib.cargoTarpaulin (commonArgs // {
109+
inherit cargoArtifacts;
110+
});
111+
};
112+
113+
packages = {
114+
default = squeezed;
115+
squeezed = squeezed;
116+
117+
squeezed-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (commonArgs // {
118+
inherit cargoArtifacts;
119+
});
120+
};
121+
122+
apps.default = flake-utils.lib.mkApp {
123+
drv = squeezed;
124+
name = "squeezed";
125+
};
126+
127+
devShells.default = pkgs.mkShell {
128+
inputsFrom = builtins.attrValues self.checks.${system};
129+
130+
nativeBuildInputs = with pkgs; [
131+
cargo
132+
rustc
133+
rustfmt
134+
clippy
135+
rust-analyzer
136+
];
137+
138+
shellHook = ''
139+
echo "🔊 squeezed dev shell — $(cargo --version)"
140+
'';
141+
};
142+
});
143+
}

0 commit comments

Comments
 (0)