Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

headphones: init at 0.5.19 #46514

Merged
merged 3 commits into from Feb 18, 2019
Merged

headphones: init at 0.5.19 #46514

merged 3 commits into from Feb 18, 2019

Conversation

rembo10
Copy link
Contributor

@rembo10 rembo10 commented Sep 11, 2018

Motivation for this change

Add headphones package and service for NixOS. I can add myself as a maintainer - I just wasn't sure if I should do that with this pull request or separately.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Fits CONTRIBUTING.md.

@worldofpeace
Copy link
Contributor

I can add myself as a maintainer - I just wasn't sure if I should do that with this pull request or separately.

You can do that in here, it just needs to be a separate commit.

Also I was really tempted to improve your package so I went right ahead and did it for you 🤣

diff --git a/pkgs/servers/headphones/default.nix b/pkgs/servers/headphones/default.nix
index 37ddcd03a94..3d428a5ac58 100644
--- a/pkgs/servers/headphones/default.nix
+++ b/pkgs/servers/headphones/default.nix
@@ -1,6 +1,6 @@
-{ stdenv, fetchFromGitHub, python2 }:
+{ stdenv, fetchFromGitHub, python2, makeWrapper }:
 
-stdenv.mkDerivation rec {
+python2.pkgs.buildPythonApplication rec {
   name = "headphones-${version}";
   version = "0.5.19";
 
@@ -11,15 +11,18 @@ stdenv.mkDerivation rec {
     sha256 = "0z39gyan3ksdhnjxxs7byamrzmrk8cn15g300iqigzvgidff1lq0";
   };
 
+  dontBuild = true;
+  doCheck = false;
+
+  nativeBuildInputs = [ makeWrapper ];
   buildInputs = [ python2 ];
 
   installPhase = ''
     mkdir -p $out
     cp -R * $out/
-    mkdir $out/bin
-    echo -e "#!/usr/bin/env sh\n${python2}/bin/python $out/Headphones.py \$*" > $out/bin/headphones
-    chmod +x $out/bin/headphones
-    echo "v${version}" >> $out/version.txt
+
+    mkdir -p $out/bin
+    makeWrapper $out/Headphones.py $out/bin/headphones
   '';
 
   meta = with stdenv.lib; {

Using buildPythonApplication will do some nice stuff for python specific packaging such as automatically patching the shebangs, etc.

@rembo10
Copy link
Contributor Author

rembo10 commented Sep 11, 2018

Awesome, thanks! I was originally just copying I think the one from couchpotato. I made those changes and also added myself as a maintainer in separate commits

@rembo10 rembo10 mentioned this pull request Sep 11, 2018
9 tasks
@rembo10
Copy link
Contributor Author

rembo10 commented Sep 13, 2018

I made those changes

@rembo10
Copy link
Contributor Author

rembo10 commented Sep 13, 2018

Updated the nixos module in line with comments @aanderse made on #46607

mkdir -p $out/bin
cp -R {data,headphones,lib,Headphones.py} $out/

makeWrapper $out/Headphones.py $out/bin/headphones
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this almost the same as just copying Headphones.py to bin/headphones? Except without polluting top-level $out and in a way that is convenient for patchShebangs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No - that doesn't seem to work because it breaks the imports. Unless I'm doing something wrong? I just changed the makeWrapper line to cp $out/Headphones.py $out/bin/headphones

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the imports are relative to where the main script is called - so it's no longer the case if the main file is being copied to and run from another location

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh so Headphones.py needs to be at that location. That was my assumption at first.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. As the lib/ layout is not for importing this as a library package anyway, in such cases I do something like $out/lib/headphones, copy the entire source-directory there, then wrap the scripts from there.

@rembo10
Copy link
Contributor Author

rembo10 commented Sep 16, 2018

Moved the module from services/networking to services/misc

@ryantm
Copy link
Member

ryantm commented Feb 18, 2019

@GrahamcOfBorg build headphones

@ryantm ryantm merged commit 8107a09 into NixOS:master Feb 18, 2019
description = "Host to listen on.";
};
port = mkOption {
type = types.ints.u16;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, there's types.port for the future

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants