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

reSnap: init at 2.5.2 #334700

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

reSnap: init at 2.5.2 #334700

wants to merge 1 commit into from

Conversation

404Wolf
Copy link

@404Wolf 404Wolf commented Aug 14, 2024

Description of changes

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added the 8.has: maintainer-list (update) This PR changes `maintainers/maintainer-list.nix` label Aug 14, 2024
@ofborg ofborg bot added 8.has: package (new) This PR adds a new package 11.by: package-maintainer This PR was created by the maintainer of the package it changes 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild 10.rebuild-linux: 1-10 10.rebuild-linux: 1 labels Aug 14, 2024
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/4426

Comment on lines 24 to 20
meta = with lib; {
description = " Take screnshots of your reMarkable tablet over SSH";
homepage = "https://github.com/cloudsftp/reSnap";
license = with licenses; [mit];
maintainers = with maintainers; [_404wolf];
mainProgram = "reSnap";
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
meta = with lib; {
description = " Take screnshots of your reMarkable tablet over SSH";
homepage = "https://github.com/cloudsftp/reSnap";
license = with licenses; [mit];
maintainers = with maintainers; [_404wolf];
mainProgram = "reSnap";
};
meta = {
description = " Take screnshots of your reMarkable tablet over SSH";
homepage = "https://github.com/cloudsftp/reSnap";
license = with lib.licenses; [ mit ];
maintainers = with lib.maintainers; [ _404wolf ];
mainProgram = "reSnap";
};

Comment on lines 10 to 29
runtimeInputs = with pkgs; [
ffmpeg
feh
imagemagick_light
lz4
];
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't use pkgs inside the derivation. Instead, add the dependencies to the inputs.

Suggested change
runtimeInputs = with pkgs; [
ffmpeg
feh
imagemagick_light
lz4
];
runtimeInputs = [
ffmpeg
feh
imagemagick_light
lz4
];

Comment on lines 2 to 4
lib,
pkgs,
fetchFromGitHub,
writeShellApplication,
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't use pkgs inside the derivation. Instead, add the dependencies to the inputs.

Suggested change
lib,
pkgs,
fetchFromGitHub,
writeShellApplication,
lib,
fetchFromGitHub,
writeShellApplication,
ffmpeg,
feh,
imagemagick_light,
lz4,

lz4
];

text = "${fetchFromGitHub {
Copy link
Contributor

Choose a reason for hiding this comment

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

File should be formatted with nixfmt

fetchFromGitHub,
writeShellApplication,
}:
writeShellApplication {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're using writeShellApplication, we don't have a version or src attributes, but they're pretty useful to have, so we can do something like this:

Suggested change
writeShellApplication {
let
name = "reSnap";
version = "2.5.2";
src = fetchFromGitHub {
owner = "cloudsftp";
repo = "reSnap";
rev = "v${version}";
hash = "sha256-P+q5NMGtXE2XCcGGHZJGw8RoOqJSHSv7oyMLkn/ltfY=";
};
in
writeShellApplication {
inherit name;
runtimeInputs = [
feh
ffmpeg
imagemagick_light
lz4
];
text = "${src}/reSnap.sh";
meta = {
description = " Take screnshots of your reMarkable tablet over SSH";
homepage = "https://github.com/cloudsftp/reSnap";
license = with lib.licenses; [ mit ];
maintainers = with lib.maintainers; [ _404wolf ];
mainProgram = "reSnap";
};
}

Also, the latest git revision seems to be the same as the latest tagged release (2.5.2), so we should use that, instead.

Can you update the commit message and the PR title to reflect this?

@404Wolf 404Wolf force-pushed the add-resnap branch 3 times, most recently from 7e9084e to 72a9e5a Compare August 20, 2024 06:48
@404Wolf
Copy link
Author

404Wolf commented Aug 20, 2024

Cool, I've made all the changes, but I rebased the wrong things and am fixing a git issue now. This should be ready to merge soon

@404Wolf 404Wolf changed the title Add remarkable resnap reSnap: init at 2.5.2 Aug 20, 2024
@404Wolf
Copy link
Author

404Wolf commented Aug 20, 2024

I think it's all fixed and ready! Thanks again for all the great feedback!

name = "reSnap";
version = "2.5.2";

src = stdenv.mkDerivation {
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that you're using mkDerivation to patch the script name. However, we should use stdenvNoCC since we're not compiling anything.

Suggested change
src = stdenv.mkDerivation {
src = stdenvNoCC.mkDerivation {

Copy link
Author

Choose a reason for hiding this comment

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

Oh, super cool, thanks for showing me this!

pkgs/by-name/re/resnap/package.nix Outdated Show resolved Hide resolved
@eljamm eljamm mentioned this pull request Aug 20, 2024
13 tasks
@404Wolf 404Wolf force-pushed the add-resnap branch 3 times, most recently from da1552a to 62c1dcf Compare August 20, 2024 14:55
Copy link
Contributor

@eljamm eljamm left a comment

Choose a reason for hiding this comment

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

LGTM!

@eljamm eljamm added the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Aug 20, 2024
Copy link
Member

Choose a reason for hiding this comment

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

Please rebase

pkgs/by-name/re/resnap/package.nix Outdated Show resolved Hide resolved
Comment on lines 24 to 32
phases = [
"unpackPhase"
"patchPhase"
"installPhase"
];
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
phases = [
"unpackPhase"
"patchPhase"
"installPhase"
];

'';
};
in
writeShellApplication {
Copy link
Member

Choose a reason for hiding this comment

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

Why not copy the code from src to a subdirectory in out and have a proper application with pname, version, etc?

"installPhase"
];
postPatch = ''
substituteInPlace ./reSnap.sh --replace-quiet "\$0" "reSnap"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
substituteInPlace ./reSnap.sh --replace-quiet "\$0" "reSnap"
substituteInPlace ./reSnap.sh --replace-fail "\$0" "reSnap"

pkgs/by-name/re/resnap/package.nix Outdated Show resolved Hide resolved
@404Wolf 404Wolf force-pushed the add-resnap branch 2 times, most recently from 4771e0d to bbed8c0 Compare August 22, 2024 15:22
@github-actions github-actions bot removed the 8.has: maintainer-list (update) This PR changes `maintainers/maintainer-list.nix` label Aug 22, 2024
@404Wolf
Copy link
Author

404Wolf commented Aug 22, 2024

Hey @SuperSandro2000, good call about wrapping with mkDerivation, I've made the change. If I'm reading right you want to remove explicit phases -- why is this? And how does the current state look? Thanks!

@emilylange emilylange removed their request for review August 22, 2024 22:51
@404Wolf
Copy link
Author

404Wolf commented Aug 26, 2024

@SuperSandro2000 not to be annoying, but have you had a chance to look this over again?

@eljamm
Copy link
Contributor

eljamm commented Aug 27, 2024

Hey @404Wolf, I think you're doing great so far, but I believe the package can still be improved further:

  • We don't need two mkDerivation since we can put everything in one
  • We don't need writeShellApplication anymore as we can just copy the script to the output
  • Use finalAttrs instead of rec (see Documentation: guide for using let in vs rec vs finalAttrs #315337).
  • Whenever we override a phase like installPhase, we should always add the pre- and post- hooks.
  • Contrary to my first suggestion, it's discouraged to set phases according to the stdenv docs since it's easy to forget those that run important things.

As such, here is what I think the derivation should look like:

package.nix
{
  lib,
  stdenvNoCC,
  fetchFromGitHub,
  ffmpeg,
  feh,
  imagemagick_light,
  lz4,
}:
stdenvNoCC.mkDerivation (finalAttrs: {
  pname = "resnap";
  version = "2.5.2";

  src = fetchFromGitHub {
    owner = "cloudsftp";
    repo = "reSnap";
    rev = "v${finalAttrs.version}";
    hash = "sha256-thVyf1gTDPLQVtZKoWL7SGiWI++ICWqmF/Ar57I3WP8=";
  };

  buildInputs = [
    ffmpeg
    feh
    imagemagick_light
    lz4
  ];

  installPhase = ''
    runHook preInstall

    install -D ./reSnap.sh $out/bin/reSnap

    runHook postInstall
  '';

  postFixup = ''
    substituteInPlace $out/bin/reSnap \
      --replace-fail "\$0" "reSnap"
  '';

  meta = {
    description = "Take screnshots of your reMarkable tablet over SSH";
    homepage = "https://github.com/cloudsftp/reSnap";
    license = with lib.licenses; [ mit ];
    maintainers = with lib.maintainers; [ _404wolf ];
    mainProgram = "reSnap";
  };
})

Let me know what you think and if you have any questions regarding this, don't hesitate to ask.

@404Wolf 404Wolf force-pushed the add-resnap branch 3 times, most recently from 2f7d629 to 7ebf0f2 Compare August 27, 2024 16:14
@404Wolf
Copy link
Author

404Wolf commented Aug 27, 2024

Hey @404Wolf, I think you're doing great so far, but I believe the package can still be improved further:

* We don't need two `mkDerivation` since we can put everything in one

* We don't need `writeShellApplication` anymore as we can just copy the script to the output

* Use `finalAttrs` instead of `rec` (see [Documentation: guide for using `let in` vs `rec` vs `finalAttrs` #315337](https://github.com/NixOS/nixpkgs/issues/315337)).

* Whenever we override a phase like `installPhase`, we should always add the `pre-` and `post-` hooks.

* Contrary to my first suggestion, it's discouraged to set `phases` according to the [stdenv docs](https://github.com/NixOS/nixpkgs/blob/420d0cc6f27b2b7f117be67aa721dd7154ffb003/doc/stdenv/stdenv.chapter.md#phases-var-stdenv-phases) since it's easy to forget those that run important things.

As such, here is what I think the derivation should look like:
package.nix

Let me know what you think and if you have any questions regarding this, don't hesitate to ask.

I could be wrong, but I don't think that buildInputs are available at runtime; it didn't seem to work. I cleaned it up a bit by only using one mkDerivation though, and just manually append to the PATH instead of writeShellApplication, and by reusing the name. Let me know what you think. Thanks for looking it over :)

@eljamm
Copy link
Contributor

eljamm commented Aug 27, 2024

I believe runtimeInputs will work in this case, but if that doesn't, we can wrap the executable with the PATH:

  nativeBuildInputs = [ makeWrapper ];

  runtimeInputs = [
    ffmpeg
    feh
    imagemagick_light
    lz4
  ];

  postFixup = ''
    substituteInPlace $out/bin/reSnap \
      --replace-fail "\$0" "reSnap"

    wrapProgram $out/bin/reSnap \
      --set PATH "${lib.makeBinPath finalAttrs.runtimeInputs}"
  '';

homepage = "https://github.com/cloudsftp/reSnap";
license = with lib.licenses; [ mit ];
maintainers = with lib.maintainers; [ _404wolf ];
mainProgram = name;
Copy link
Contributor

Choose a reason for hiding this comment

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

Changes to meta should not cause a rebuild, which would happen if name changes. We should explicitly set this.

Suggested change
mainProgram = name;
mainProgram = "reSnap";

Comment on lines 29 to 45
installPhase = ''
runHook preInstall

mkdir -p $out/bin
echo PATH="\$PATH:${
lib.strings.makeBinPath [
ffmpeg
feh
imagemagick_light
lz4
]
}" > $out/bin/reSnap
cat ./reSnap.sh >> $out/bin/reSnap
chmod +x $out/bin/reSnap

runHook postInstall
'';
Copy link
Contributor

Choose a reason for hiding this comment

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

We can use runtimeInputs or wrap the executable instead of doing this.

Suggested change
installPhase = ''
runHook preInstall
mkdir -p $out/bin
echo PATH="\$PATH:${
lib.strings.makeBinPath [
ffmpeg
feh
imagemagick_light
lz4
]
}" > $out/bin/reSnap
cat ./reSnap.sh >> $out/bin/reSnap
chmod +x $out/bin/reSnap
runHook postInstall
'';
installPhase = ''
runHook preInstall
install -D ./reSnap.sh $out/bin/reSnap
runHook postInstall
'';


postFixup = ''
substituteInPlace $out/bin/reSnap \
--replace-fail "\$0" ${name}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
--replace-fail "\$0" ${name}
--replace-fail "\$0" reSnap

Comment on lines 14 to 19
pname = lib.strings.toLower name;
version = "2.5.2";

src = fetchFromGitHub {
owner = "cloudsftp";
repo = name;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
pname = lib.strings.toLower name;
version = "2.5.2";
src = fetchFromGitHub {
owner = "cloudsftp";
repo = name;
pname = "resnap;
version = "2.5.2";
src = fetchFromGitHub {
owner = "cloudsftp";
repo = "reSnap";

Comment on lines 10 to 12
let
name = "reSnap";
in
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let
name = "reSnap";
in

@wegank wegank removed the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Aug 31, 2024
Copy link
Contributor

@eljamm eljamm left a comment

Choose a reason for hiding this comment

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

LGTM

@eljamm eljamm added the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Aug 31, 2024
@404Wolf
Copy link
Author

404Wolf commented Sep 13, 2024

Hey @SuperSandro2000, any chance you could look this over at some point? I think it's ready to merge. Thanks!

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/4607

Comment on lines +31 to +45
postFixup = ''
substituteInPlace $out/bin/reSnap \
--replace-fail "\$0" reSnap

wrapProgram $out/bin/reSnap \
--suffix PATH : "${lib.makeBinPath finalAttrs.runtimeInputs}"
'';

installPhase = ''
runHook preInstall

install -D reSnap.sh $out/bin/reSnap

runHook postInstall
'';
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
postFixup = ''
substituteInPlace $out/bin/reSnap \
--replace-fail "\$0" reSnap
wrapProgram $out/bin/reSnap \
--suffix PATH : "${lib.makeBinPath finalAttrs.runtimeInputs}"
'';
installPhase = ''
runHook preInstall
install -D reSnap.sh $out/bin/reSnap
runHook postInstall
'';
installPhase = ''
runHook preInstall
install -D reSnap.sh $out/bin/reSnap
runHook postInstall
'';
postFixup = ''
substituteInPlace $out/bin/reSnap \
--replace-fail "\$0" reSnap
wrapProgram $out/bin/reSnap \
--suffix PATH : "${lib.makeBinPath finalAttrs.runtimeInputs}"
'';

Fixup is executed after install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.has: package (new) This PR adds a new package 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild 10.rebuild-linux: 1-10 10.rebuild-linux: 1 11.by: package-maintainer This PR was created by the maintainer of the package it changes 12.approvals: 1 This PR was reviewed and approved by one reputable person
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants