From f487968dda8894465c2245cd271e3761b28ceb1a Mon Sep 17 00:00:00 2001 From: Ben Siraphob Date: Fri, 18 Mar 2022 21:53:06 -0500 Subject: [PATCH] Add Nix flake --- .gitignore | 3 +++ default.nix | 9 ++++++++ flake.lock | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 18 ++++++++++++++++ package.nix | 47 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 137 insertions(+) create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 package.nix diff --git a/.gitignore b/.gitignore index 7c04006c..e716fc6f 100644 --- a/.gitignore +++ b/.gitignore @@ -143,3 +143,6 @@ dmypy.json \.idea/ swaglyrics/unsupported.txt + +# Flake +result diff --git a/default.nix b/default.nix new file mode 100644 index 00000000..f8a169dc --- /dev/null +++ b/default.nix @@ -0,0 +1,9 @@ +(import ( + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + in fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; } +) { + src = ./.; +}).defaultNix diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..f79d1be8 --- /dev/null +++ b/flake.lock @@ -0,0 +1,60 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1641205782, + "narHash": "sha256-4jY7RCWUoZ9cKD8co0/4tFARpWB+57+r1bLLvXNJliY=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "b7547d3eed6f32d06102ead8991ec52ab0a4f1a7", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1647297614, + "narHash": "sha256-ulGq3W5XsrBMU/u5k9d4oPy65pQTkunR4HKKtTq0RwY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "73ad5f9e147c0d2a2061f1d4bd91e05078dc0b58", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-compat": "flake-compat", + "nixpkgs": "nixpkgs", + "utils": "utils" + } + }, + "utils": { + "locked": { + "lastModified": 1644229661, + "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..21536f64 --- /dev/null +++ b/flake.nix @@ -0,0 +1,18 @@ +{ + description = "Swaglyrics for Spotify"; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + utils.url = "github:numtide/flake-utils"; + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; + }; + + outputs = { self, nixpkgs, utils, ... }: + utils.lib.eachDefaultSystem (system: + with import nixpkgs { inherit system; }; { + defaultPackage = callPackage ./package.nix {}; + } + ); +} diff --git a/package.nix b/package.nix new file mode 100644 index 00000000..cc1835c5 --- /dev/null +++ b/package.nix @@ -0,0 +1,47 @@ +{ lib, python3, fetchFromGitHub, ncurses }: + +python3.pkgs.buildPythonApplication rec { + pname = "swaglyrics"; + version = "unstable-2021-06-17"; + + src = fetchFromGitHub { + owner = "SwagLyrics"; + repo = "SwagLyrics-For-Spotify"; + rev = "99fe764a9e45cac6cb9fcdf724c7d2f8cb4524fb"; + sha256 = "sha256-O48T1WsUIVnNQb8gmzSkFFHTOiFOKVSAEYhF9zUqZz0="; + }; + + propagatedBuildInputs = with python3.pkgs; [ + unidecode colorama beautifulsoup4 flask requests swspotify + ]; + + preConfigure = '' + substituteInPlace setup.py \ + --replace 'beautifulsoup4==4.9.3' 'beautifulsoup4>=4.9.3' \ + --replace 'unidecode==1.2.0' 'unidecode>=1.2.0' \ + --replace 'flask==2.0.1' 'flask>=2.0.1' + ''; + + preBuild = "export HOME=$NIX_BUILD_TOP"; + + # disable tests which touch network + disabledTests = [ + "test_database_for_unsupported_song" + "test_that_lyrics_works_for_unsupported_songs" + "test_that_get_lyrics_works" + "test_lyrics_are_shown_in_tab" + "test_songchanged_can_raise_songplaying" + ]; + + checkInputs = with python3.pkgs; + [ blinker swspotify pytestCheckHook flask mock flask_testing ] + ++ [ ncurses ]; + + meta = with lib; { + description = "Lyrics fetcher for currently playing Spotify song"; + homepage = "https://github.com/SwagLyrics/SwagLyrics-For-Spotify"; + license = licenses.mit; + maintainers = with maintainers; [ siraben ]; + platforms = platforms.unix; + }; +}