lastfmpris/flake.nix
2025-01-26 00:21:38 -08:00

112 lines
3.6 KiB
Nix

{
description = "lastfmpris";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
};
outputs = { self, nixpkgs, flake-utils, rust-overlay, }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [rust-overlay.overlays.default];
};
package = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).package;
toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
rustPlatform = pkgs.makeRustPlatform {
cargo = toolchain;
rustc = toolchain;
};
in {
packages = flake-utils.lib.flattenTree rec {
default = lastfmpris;
lastfmpris = rustPlatform.buildRustPackage {
pname = package.name;
inherit (package) version;
# uncomment this and let the build fail, then get the current hash
# very scuffed but endorsed!
#cargoHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
cargoHash = "sha256-KOMEvg3iGjmMEFxsrIqD4SaDw63ojiNNNqCfzRlbYLw=";
nativeBuildInputs = with pkgs; [ pkg-config ];
buildInputs = with pkgs; [ openssl dbus ];
src = ./.;
meta.mainProgram = package.name;
};
};
devShells.default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [ pkg-config ];
buildInputs = with pkgs; [ openssl dbus ];
packages = with pkgs; [
toolchain
rust-analyzer-unwrapped
];
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
};
}) // {
homeManagerModules = rec {
default = lastfmpris;
lastfmpris = { config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.lastfmpris;
iniFmt = pkgs.formats.ini {};
in {
options.services.lastfmpris = {
enable = mkEnableOption "Enables the lastfmpris mpris scrobbling daemon";
package = mkOption {
type = types.package;
default = self.packages.${pkgs.stdenv.hostPlatform.system}.default;
};
settings = mkOption {
type = iniFmt.type;
description = "Configuration (https://git.reidlab.pink/reidlab/lastfmpris/src/branch/main/config.example.ini)";
example = literalExpression ''
{
global = {
username = "ILoveLastDotFm";
password = "lastfm4lyfe";
api_key = "t8mb4e0kn9it150amaeezbcfe3iusy8o";
api_secret = "jd47iz6h1u2kbnbfm8c763lzrj1o89h3";
};
}
'';
};
};
config = mkIf cfg.enable {
systemd.user.services.lastfmpris = {
Unit = {
Description = "a rust application to scrobble your currently playing song on last.fm with mpris";
After = [ "graphical-session-pre.target" ];
PartOf = [ "graphical-session.target" ];
};
Install = {
WantedBy = [ "graphical-session.target" ];
};
Service = {
Type = "simple";
ExecStart = "${lib.getExe cfg.package}";
Restart = "on-failure";
RestartSec = 1;
};
};
xdg.configFile."lastfmpris/config.ini".source = (iniFmt.generate "config.ini" cfg.settings);
};
};
};
};
}