-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathflake.nix
More file actions
105 lines (92 loc) · 3.88 KB
/
Copy pathflake.nix
File metadata and controls
105 lines (92 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
{
description = "RustCat — an animated tray cat whose speed tracks CPU usage (Linux/KDE port)";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
crane = {
url = "github:ipetkov/crane";
};
};
outputs = { self, nixpkgs, flake-utils, crane }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
# crane's toolchain derived from nixpkgs rust.
craneLib = crane.mkLib pkgs;
# Only Rust source matters for reproducibility; assets are read by
# build.rs and embedded, so filtering to just the crate tree is fine.
src = craneLib.path ./.;
# trayicon's Linux/KDE backend is pure Rust (zbus + ico), so the build
# needs no native GUI libraries. Git is required by build.rs to extract
# the short commit hash shown in the About dialog.
nativeBuildInputs = with pkgs; [
git
makeWrapper
];
# Runtime helper tools so dialogs / system monitor work out of the box
# on a KDE Plasma system. They are optional — the app degrades
# gracefully if a tool is missing.
runtimeDeps = with pkgs.kdePackages; [
kdialog
plasma-systemmonitor
];
# nixpkgs' rustc-1.95 ships a broken *default* target spec: omitting the
# target makes cargo refuse to build proc-macros ("target does not
# support these crate types"). Explicitly setting CARGO_BUILD_TARGET
# loads the proper target spec and the build succeeds. Harmless on
# toolchains where the default already works.
#
# crane's buildDepsOnly runs `cargo check` and does not forward
# `cargoBuildTarget` to that command, so we set CARGO_BUILD_TARGET as an
# env var, which cargo reads directly (equivalent to --target).
cargoBuildEnv = {
CARGO_BUILD_TARGET = pkgs.stdenv.hostPlatform.config;
};
# Build dependencies only, then the real package, so that dependency
# changes don't rebuild crates unnecessarily.
cargoArtifacts = craneLib.buildDepsOnly {
inherit src nativeBuildInputs;
pname = "rustcat-deps";
version = "0.0.0";
env = cargoBuildEnv;
};
rustCat = craneLib.buildPackage {
inherit src cargoArtifacts nativeBuildInputs;
pname = "rustcat";
# version is intentionally omitted: crane derives it from Cargo.toml
# (buildPackage: `version = args.version or crateName.version`), so
# the Nix output name stays in sync with the crate version instead of
# drifting after a bump.
# No tests in this project.
doCheck = false;
env = cargoBuildEnv;
postInstall = ''
# Wrap so runtime helper tools are on PATH without polluting the
# user's environment.
wrapProgram $out/bin/rust_cat \
--prefix PATH : ${pkgs.lib.makeBinPath runtimeDeps}
# Desktop entry + icon for application launchers. The icon goes to
# pixmaps/ (the freedesktop location for non-themed icons).
install -Dm644 ${self}/assets/rustcat.desktop $out/share/applications/rustcat.desktop
install -Dm644 ${self}/assets/appIcon.ico $out/share/pixmaps/rustcat.ico
'';
};
in
{
packages.default = rustCat;
packages.rustcat = rustCat;
devShells.default = pkgs.mkShell {
inherit nativeBuildInputs;
buildInputs = runtimeDeps ++ [
pkgs.cargo
pkgs.rustc
pkgs.rust-analyzer
];
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
};
apps.default = {
type = "app";
program = "${rustCat}/bin/rust_cat";
};
});
}