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

Package pdfpc-extractor for NixOS users #114

Closed
wants to merge 2 commits into from

Conversation

data-niklas
Copy link

@data-niklas data-niklas commented Oct 24, 2023

This PR will add a NixOS flake, which builds the pdfpc-extractor and exposes it as a package.

Usage

  1. Add the flake to your own flake.nix as input
  2. Use the package inputs.polylux.defaultPackage.${pkgs.system} (under the assumption that the flake was named polylux in your inputs), which will build pdfpc-extractor

Dev env

Either run

  • nix build to build the package into the result directory
    or run
  • nix develop to enter a dev env where you should be able to run cargo build commands as usual

@andreasKroepelin
Copy link
Collaborator

Cool! Can you add a note to the installation section in this file? https://github.com/andreasKroepelin/polylux/blob/main/book/src/external/pdfpc.md

Also, I don't really know much about Nix, so it's hard for me to review... @drupol, can you have a look maybe?

@drupol
Copy link
Contributor

drupol commented Oct 24, 2023

Sure, will do that tomorrow!

I'm using the pdfpc extractor in a presentation, with its own nix file. I'll let you know what I think of this PR tomorrow.

@data-niklas
Copy link
Author

I slightly restructured the installation instruction section to streamline instructions for different OS, so we now have 3 subtitles for

  • Source
  • Arch Linux
  • NixOS

@drupol
Copy link
Contributor

drupol commented Oct 25, 2023

Dear @data-niklas,

Here's my take on this:

{
  description = "Polylux packages";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    systems.url = "github:nix-systems/default";
  };

  outputs = inputs @ { self, flake-parts, ... }: flake-parts.lib.mkFlake { inherit inputs; } {
    imports = [
      inputs.flake-parts.flakeModules.easyOverlay
    ];

    systems = import inputs.systems;

    perSystem = { config, self', inputs', pkgs, system, lib, ... }:
      let
        pdfpc-extractor = pkgs.rustPlatform.buildRustPackage {
          pname = "pdfpc-extractor";
          version = "dev";

          src = ./pdfpc-extractor;

          cargoHash = "sha256-VTJRfDFprKIrwfw5lU9/RnDuGLQ7nXBEc/dms5YVupM=";

          meta.mainProgram = "polylux2pdfpc";
        };
      in
      {
        formatter = pkgs.nixpkgs-fmt;

        overlayAttrs = self'.packages;

        packages = {
          pdfpc-extractor = pdfpc-extractor;
          default = pdfpc-extractor;
        };

        apps = {
          default = {
            type = "app";
            program = lib.getExec self'.packages.pdfpc-extractor;
          };
        };

        devShells.default = pkgs.mkShell {
          name = "polylux-devshell";
          buildInputs = with pkgs; [
            cargo
            rustc
          ];
        };
      };
  };
}

When I have to add a flake to a project, I try to limit to the maximum the external dependencies it depends on to avoid bad surprises. Therefore, I don't think using the contrib project naersk is needed here since we can build pdfpc-extractor with just the nixpkgs repository.
Moreover, I don't think requiring flake-utils is needed as well since we can use flake-parts which is already in nixpkgs and it has a better design (check NixOS Discourse about this).

I also expose pdfpc-extractor in the packages but also as an app that we can just run by doing: nix run github:andreaskroepelin/polylux#pdfpdf-extractor

I don't use the old flake syntax defaultPackages either and there's a default formatter which is set as well.

I forgot to add the default overlay, I will do that as soon as I'm back on a computer.

Let me know what you think of all of this.

PS: I'm currently travelling to Germany to make a talk (where the slides were made with Typst/Polylux) so there might be some delay in my replies.

@data-niklas
Copy link
Author

data-niklas commented Oct 25, 2023

Awesome! I reused the naersk Rust template from another template, as I was not so familiar withe the other methods to package Rust programs. If your version works and is more minimal, great.

How will the cargoHash work between updates? I tried to use your flake locally and got mismatched cargoHashes, as my local version is slightly different. Does it only base the hash on the cargo dependencies?

I think we then need to at least document somewhere, that the cargoHash needs to be updated, when the Rust dependencies change.

Currently it is obtained by inserting a fake checksum into the expression and building the package once

Sadly the checksum would need to be updated by a NixOS user. Alternatively we could try to add the polylux package into nixpkgs, as I assume that pdfpc-extractor is updated less frequently than e.g. the polylux core.

@data-niklas
Copy link
Author

Else I would just more or less replace the flake with your more minimal flake

@drupol
Copy link
Contributor

drupol commented Jan 20, 2024

Package has been merged in Nix today @ NixOS/nixpkgs#280525

@data-niklas
Copy link
Author

Great! In that case I can and will close this PR.

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

Successfully merging this pull request may close these issues.

3 participants