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.mkLib pkgs;
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.4.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 pkgs.dbus
63 ] ++ lib.optionals pkgs.stdenv.isDarwin [
64 # Additional darwin specific inputs can be set here
65 pkgs.libiconv
66 pkgs.darwin.Security
67 ];
68
69 # Additional environment variables can be set directly
70 # MY_CUSTOM_VAR = "some value";
71 };
72
73 craneLibLLvmTools = craneLib.overrideToolchain
74 (fenix.packages.${system}.complete.withComponents [
75 "cargo"
76 "llvm-tools"
77 "rustc"
78 ]);
79
80 # Build *just* the cargo dependencies, so we can reuse
81 # all of that work (e.g. via cachix) when running in CI
82 cargoArtifacts = craneLib.buildDepsOnly commonArgs;
83
84 # Build the actual crate itself, reusing the dependency
85 # artifacts from above.
86 tunein = craneLib.buildPackage (commonArgs // {
87 inherit cargoArtifacts;
88 });
89
90 in
91 {
92 checks = {
93 # Build the crate as part of `nix flake check` for convenience
94 inherit tunein;
95
96 # Run clippy (and deny all warnings) on the crate source,
97 # again, resuing the dependency artifacts from above.
98 #
99 # Note that this is done as a separate derivation so that
100 # we can block the CI if there are issues here, but not
101 # prevent downstream consumers from building our crate by itself.
102 tunein-clippy = craneLib.cargoClippy (commonArgs // {
103 inherit cargoArtifacts;
104 cargoClippyExtraArgs = "--all-targets -- --deny warnings";
105 });
106
107 tunein-doc = craneLib.cargoDoc (commonArgs // {
108 inherit cargoArtifacts;
109 });
110
111 # Check formatting
112 tunein-fmt = craneLib.cargoFmt {
113 inherit src;
114 };
115
116 # Audit dependencies
117 tunein-audit = craneLib.cargoAudit {
118 inherit src advisory-db;
119 };
120
121 # Run tests with cargo-nextest
122 # Consider setting `doCheck = false` on `tunein` if you do not want
123 # the tests to run twice
124 tunein-nextest = craneLib.cargoNextest (commonArgs // {
125 inherit cargoArtifacts;
126 partitions = 1;
127 partitionType = "count";
128 });
129 } // lib.optionalAttrs (system == "x86_64-linux") {
130 # NB: cargo-tarpaulin only supports x86_64 systems
131 # Check code coverage (note: this will not upload coverage anywhere)
132 tunein-coverage = craneLib.cargoTarpaulin (commonArgs // {
133 inherit cargoArtifacts;
134 });
135 };
136
137 packages = {
138 default = tunein;
139 tunein-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (commonArgs // {
140 inherit cargoArtifacts;
141 });
142 };
143
144 apps.default = flake-utils.lib.mkApp {
145 drv = tunein;
146 };
147
148 devShells.default = pkgs.mkShell {
149 inputsFrom = builtins.attrValues self.checks.${system};
150
151 # Additional dev-shell environment variables can be set directly
152 # MY_CUSTOM_DEVELOPMENT_VAR = "something else";
153
154 # Extra inputs can be added here
155 nativeBuildInputs = with pkgs; [
156 cargo
157 rustc
158 ];
159 };
160 });
161}