diff --git a/.gitignore b/.gitignore index 7c04006..e716fc6 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 0000000..f8a169d --- /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 0000000..f79d1be --- /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 0000000..21536f6 --- /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 0000000..cc1835c --- /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; + }; +}