Building Flutter application (Saber notes

Hello,
i started to package saber notes:

{ lib
, fetchFromGitHub
, flutter319
, gst_all_1
, libunwind
, webkitgtk
, orc
, webkitgtk_4_1

, targetFlutterPlatform ? "linux"
}:

let
  src = fetchFromGitHub {
    owner = "saber-notes";
    repo = "saber";
    rev = "main";
    hash = "sha256-SPNWl1viSOapIZpGZcLRL19VTU2K8p1sng4yrRhF1+o=";
  };

  pubspecLock = lib.importJSON ./pubspec.lock.json; # convert using cat pubspec.lock | nix run nixpkgs#yj
in

flutter319.buildFlutterApplication (rec {
  pname = "saber-notes";
  version = "0.25.1-main";

  inherit src;

  inherit pubspecLock;
  inherit targetFlutterPlatform;

  nativeBuildInputs = [ gst_all_1.gstreamer libunwind gst_all_1.gst-plugins-base webkitgtk orc webkitgtk_4_1];

  gitHashes = {
    "json2yaml" = "sha256-Vb0Bt11OHGX5+lDf8KqYZEGoXleGi5iHXVS2k7CEmDw=";
  };

  meta = with lib; {
    homepage = "https://saber.adil.hanney.org/";
    mainProgram = "saber"; #TODO
    platforms = [ "x86_64-linux" "aarch64-linux" ];
    description = "Saber Flutter Application";
    license = licenses.gpl3;
    maintainers = with maintainers; [ "" ];
  };
})

But there is a package called PDFium that still trys to download stuff from the internet which of course fails

[   +1 ms] CMake Error at flutter/ephemeral/.plugin_symlinks/printing/windows/DownloadProject.cmake:179 (message):
[   +2 ms]   Build step for pdfium failed: 1
[        ] Call Stack (most recent call first):
[        ]   flutter/ephemeral/.plugin_symlinks/printing/linux/CMakeLists.txt:37 (download_project)

Is there a way to fix this? The PDFium package seems to come deep down from dependency hell and despite searching and LLM asking I am still clouless.

I also tried to build without a sandbox but that did not seem to change the error. (I need this package relatively urgently so something like that would also be ok for me)

Thanks a lot in advance!

Thanks a lot for the fast answer!

Looks promising!
I will try to fix it tomorrow

Hello
Do you mind sharing your package?
I would really like to try out saber too.

It’s shared above, at the PR link.

As soon as I got it working I will post it here again if you want. I will also try to get it into nixpkgs, but I have never contributed to nixpkgs before, so it might take a bit of time.

Ok, so i fixed some more errors but now I get a really weird one: mv: missing destination file operand after '/nix/store/yaxqlrnzws86zb6bzax21i57x7vkzpv7-saber-notes-0.25.1-main/app'

Despite never using mv in the script. I have no idea how to fix this. Can someone help?

This is my current version:

{ lib
, fetchFromGitHub
, flutter
, gst_all_1
, libunwind
, webkitgtk
, orc
, webkitgtk_4_1
, stdenv
, fetchurl


, targetFlutterPlatform ? "linux"
}:

let
  src = fetchFromGitHub {
    owner = "saber-notes";
    repo = "saber";
    rev = "main";
    hash = "sha256-SPNWl1viSOapIZpGZcLRL19VTU2K8p1sng4yrRhF1+o=";
  };

  pubspecLock = lib.importJSON ./pubspec.lock.json; # convert using cat pubspec.lock | nix run nixpkgs#yj


  pdfium-binaries = stdenv.mkDerivation rec {
    pname = "pdfium-binaries";
    version = "5200";
    src = fetchurl {
      url = "https://github.com/bblanchon/pdfium-binaries/releases/download/chromium/${version}/pdfium-linux-x64.tgz";
      hash = "sha256-Dmjn8MdhmltKkUMfrVFtZlzFLww0HXAbIarXGmxtQdk=";
    };
    dontUnpack = true;
    installPhase = ''
      runHook preInstall
      mkdir $out
      tar xvf $src -C $out/
      runHook postInstall
    '';
     meta = {
      description = "Binary distribution of PDFium";
      homepage = "https://github.com/bblanchon/pdfium-binaries";
      license = with lib.licenses; [ asl20 ];
      sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
      maintainers = with lib.maintainers; [ aucub ];
      platforms = [ "x86_64-linux" ];
    };
  };
in

flutter.buildFlutterApplication (rec {
  pname = "saber-notes";
  version = "0.25.1-main";

  inherit src;

  inherit pubspecLock;
  inherit targetFlutterPlatform;


  customSourceBuilders = {
    printing =
      { version, src, ... }:
      stdenv.mkDerivation rec {
        pname = "printing";
        inherit version src;
        inherit (src) passthru;
        patches = [ ./printing.patch ];
        installPhase = ''
          runHook preInstall
          mkdir $out
          cp -a ./* $out/
          runHook postInstall
        '';
      };
  };
  
  buildPhase = ''
    # Create a fake os-release file
    touch ./os-release
    '';

  env.PDFIUM_DIR = "${pdfium-binaries}";

  nativeBuildInputs = [ gst_all_1.gstreamer libunwind gst_all_1.gst-plugins-base webkitgtk orc webkitgtk_4_1];

  gitHashes = {
    "json2yaml" = "sha256-Vb0Bt11OHGX5+lDf8KqYZEGoXleGi5iHXVS2k7CEmDw=";
  };

  meta = with lib; {
    homepage = "https://saber.adil.hanney.org/";
    mainProgram = "saber"; #TODO
    platforms = [ "x86_64-linux" "aarch64-linux" ];
    description = "Saber Flutter Application";
    license = licenses.gpl3;
    maintainers = with maintainers; [ "jon011235" ];
  };
})

Thanks a lot in advance!

If I delete the buildphase it complains about /etc/os-release/ not existing (already in the build phase). I did not find any hints on how to fix this yet but I will have a more thorough look into the documentation.

While currently it at least gets to the install phase

This is the error i get:

[ +14 ms] Failed obtaining PRETTY_NAME for Linux: PathNotFoundException: Cannot open file, path = ‘/usr/lib/os-release’ (OS Error: No such file or directory,
errno = 2)

Thanks a lot for your help!

You’ll have to figure out which part of the build upstream process is attempting to read os-release and patch it to a constant string such as NixOS. Some build processes just are annoying like that and attempt to do impure things.