Browse and listen to thousands of radio stations across the globe right from your terminal ๐ ๐ป ๐ตโจ
radio
rust
tokio
web-radio
command-line-tool
tui
1{
2 description = "TuneIn CLI - Browse and listen to thousands of radio stations across the globe right from your terminal ๐ ๐ป ๐ตโจ";
3
4 inputs = {
5 nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6
7 crane = {
8 url = "github:ipetkov/crane";
9 inputs.nixpkgs.follows = "nixpkgs";
10 };
11
12 fenix = {
13 url = "github:nix-community/fenix";
14 inputs.nixpkgs.follows = "nixpkgs";
15 inputs.rust-analyzer-src.follows = "";
16 };
17
18 flake-utils.url = "github:numtide/flake-utils";
19
20 advisory-db = {
21 url = "github:rustsec/advisory-db";
22 flake = false;
23 };
24 };
25
26 outputs = { self, nixpkgs, crane, fenix, flake-utils, advisory-db, ... }:
27 flake-utils.lib.eachDefaultSystem (system:
28 let
29 pkgs = import nixpkgs {
30 inherit system;
31 };
32
33 inherit (pkgs) lib;
34
35 craneLib = crane.lib.${system};
36
37 protoFilter = path: _type: builtins.match ".*proto$" path != null;
38 protoOrCargo = path: type:
39 (protoFilter path type) || (craneLib.filterCargoSources path type);
40
41 src = lib.cleanSourceWith {
42 src = craneLib.path ./.; # The original, unfiltered source
43 filter = protoOrCargo;
44 };
45
46 # Common arguments can be set here to avoid repeating them later
47 commonArgs = {
48 inherit src;
49
50 pname = "tunein";
51 version = "0.3.1";
52
53 buildInputs = [
54 # Add additional build inputs here
55 pkgs.openssl
56 pkgs.openssl.dev
57 pkgs.pkg-config
58 pkgs.gnumake
59 pkgs.perl
60 pkgs.protobuf
61 pkgs.alsa-lib.dev
62 ] ++ lib.optionals pkgs.stdenv.isDarwin [
63 # Additional darwin specific inputs can be set here
64 pkgs.libiconv
65 pkgs.darwin.Security
66 ];
67
68 # Additional environment variables can be set directly
69 # MY_CUSTOM_VAR = "some value";
70 };
71
72 craneLibLLvmTools = craneLib.overrideToolchain
73 (fenix.packages.${system}.complete.withComponents [
74 "cargo"
75 "llvm-tools"
76 "rustc"
77 ]);
78
79 # Build *just* the cargo dependencies, so we can reuse
80 # all of that work (e.g. via cachix) when running in CI
81 cargoArtifacts = craneLib.buildDepsOnly commonArgs;
82
83 # Build the actual crate itself, reusing the dependency
84 # artifacts from above.
85 tunein = craneLib.buildPackage (commonArgs // {
86 inherit cargoArtifacts;
87 });
88
89 in
90 {
91 checks = {
92 # Build the crate as part of `nix flake check` for convenience
93 inherit tunein;
94
95 # Run clippy (and deny all warnings) on the crate source,
96 # again, resuing the dependency artifacts from above.
97 #
98 # Note that this is done as a separate derivation so that
99 # we can block the CI if there are issues here, but not
100 # prevent downstream consumers from building our crate by itself.
101 tunein-clippy = craneLib.cargoClippy (commonArgs // {
102 inherit cargoArtifacts;
103 cargoClippyExtraArgs = "--all-targets -- --deny warnings";
104 });
105
106 tunein-doc = craneLib.cargoDoc (commonArgs // {
107 inherit cargoArtifacts;
108 });
109
110 # Check formatting
111 tunein-fmt = craneLib.cargoFmt {
112 inherit src;
113 };
114
115 # Audit dependencies
116 tunein-audit = craneLib.cargoAudit {
117 inherit src advisory-db;
118 };
119
120 # Run tests with cargo-nextest
121 # Consider setting `doCheck = false` on `tunein` if you do not want
122 # the tests to run twice
123 tunein-nextest = craneLib.cargoNextest (commonArgs // {
124 inherit cargoArtifacts;
125 partitions = 1;
126 partitionType = "count";
127 });
128 } // lib.optionalAttrs (system == "x86_64-linux") {
129 # NB: cargo-tarpaulin only supports x86_64 systems
130 # Check code coverage (note: this will not upload coverage anywhere)
131 tunein-coverage = craneLib.cargoTarpaulin (commonArgs // {
132 inherit cargoArtifacts;
133 });
134 };
135
136 packages = {
137 default = tunein;
138 tunein-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (commonArgs // {
139 inherit cargoArtifacts;
140 });
141 };
142
143 apps.default = flake-utils.lib.mkApp {
144 drv = tunein;
145 };
146
147 devShells.default = pkgs.mkShell {
148 inputsFrom = builtins.attrValues self.checks.${system};
149
150 # Additional dev-shell environment variables can be set directly
151 # MY_CUSTOM_DEVELOPMENT_VAR = "something else";
152
153 # Extra inputs can be added here
154 nativeBuildInputs = with pkgs; [
155 cargo
156 rustc
157 ];
158 };
159 });
160}