Unverified Commit 70b94cbb authored by David Wolff's avatar David Wolff
Browse files

immich: use finalAttrs.src for all immich derivations

Using finalAttrs.src for all derivations makes it
possible to override the source using overrideAttrs
without having to reimplement part of the logic
within the immich package.
Using finalAttrs.passthru.web in the installPhase additionally
makes it possible to override only the web derivation.
Overriding immich in passthru.machine-learning makes
sure that the exposed immich-machine-learning also
uses the updated src.
parent 1033345f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -446,7 +446,7 @@ in
      wantedBy = [ "multi-user.target" ];
      inherit (cfg.machine-learning) environment;
      serviceConfig = commonServiceConfig // {
        ExecStart = lib.getExe (cfg.package.machine-learning.override { immich = cfg.package; });
        ExecStart = lib.getExe cfg.package.machine-learning;
        Slice = "system-immich.slice";
        CacheDirectory = "immich";
        User = cfg.user;
+47 −48
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@
}:
let
  pnpm = pnpm_10;
  version = "2.2.3";

  esbuild' = buildPackages.esbuild.override {
    buildGoModule =
@@ -104,59 +103,30 @@ let
        echo "${date}" > $out/geodata-date.txt
      '';

  # Without this thumbnail generation for raw photos fails with
  #     Error: Input file has corrupt header: tiff2vips: samples_per_pixel not a whole number of bytes
  vips' = vips.overrideAttrs (prev: {
    mesonFlags = prev.mesonFlags ++ [ "-Dtiff=disabled" ];
  });
in
stdenv.mkDerivation (finalAttrs: {
  pname = "immich";
  version = "2.2.3";

  src = fetchFromGitHub {
    owner = "immich-app";
    repo = "immich";
    tag = "v${version}";
    tag = "v${finalAttrs.version}";
    hash = "sha256-OoToTRDPXWOa7d1j1xvkZt+vKWBX4eHDiIsFs3bIlvw=";
  };

  pnpmDeps = pnpm.fetchDeps {
    pname = "immich";
    inherit version src;
    inherit (finalAttrs) version src;
    fetcherVersion = 2;
    hash = "sha256-igkO0ID0/9uPtFAXL2v5bcFbCpZK2lcYEctWBKtFKdU=";
  };

  web = stdenv.mkDerivation {
    pname = "immich-web";
    inherit version src pnpmDeps;

    nativeBuildInputs = [
      nodejs
      pnpm
      pnpm.configHook
    ];

    buildPhase = ''
      runHook preBuild

      pnpm --filter @immich/sdk build
      pnpm --filter immich-web build

      runHook postBuild
    '';

    installPhase = ''
      runHook preInstall

      cd web
      cp -r build $out

      runHook postInstall
    '';
  };

  # Without this thumbnail generation for raw photos fails with
  #     Error: Input file has corrupt header: tiff2vips: samples_per_pixel not a whole number of bytes
  vips' = vips.overrideAttrs (prev: {
    mesonFlags = prev.mesonFlags ++ [ "-Dtiff=disabled" ];
  });
in
stdenv.mkDerivation {
  pname = "immich";
  inherit version src pnpmDeps;

  postPatch = ''
    # pg_dumpall fails without database root access
    # see https://github.com/immich-app/immich/issues/13971
@@ -225,7 +195,7 @@ stdenv.mkDerivation {
    \) -exec rm -r {} +

    mkdir -p "$packageOut/build"
    ln -s '${web}' "$packageOut/build/www"
    ln -s '${finalAttrs.passthru.web}' "$packageOut/build/www"
    ln -s '${geodata}' "$packageOut/build/geodata"

    echo '${builtins.toJSON buildLock}' > "$packageOut/build/build-lock.json"
@@ -254,18 +224,47 @@ stdenv.mkDerivation {
      inherit (nixosTests) immich immich-vectorchord-migration immich-vectorchord-reindex;
    };

    machine-learning = immich-machine-learning;
    machine-learning = immich-machine-learning.override {
      immich = finalAttrs.finalPackage;
    };

    web = stdenv.mkDerivation {
      pname = "immich-web";
      inherit (finalAttrs) version src pnpmDeps;

      nativeBuildInputs = [
        nodejs
        pnpm
        pnpm.configHook
      ];

      buildPhase = ''
        runHook preBuild

        pnpm --filter @immich/sdk build
        pnpm --filter immich-web build

        runHook postBuild
      '';

      installPhase = ''
        runHook preInstall

        cd web
        cp -r build $out

        runHook postInstall
      '';
    };

    inherit
      src
      web
      geodata
      pnpm
      ;
  };

  meta = {
    changelog = "https://github.com/immich-app/immich/releases/tag/${src.tag}";
    changelog = "https://github.com/immich-app/immich/releases/tag/${finalAttrs.src.tag}";
    description = "Self-hosted photo and video backup solution";
    homepage = "https://immich.app/";
    license = with lib.licenses; [
@@ -281,4 +280,4 @@ stdenv.mkDerivation {
    platforms = lib.platforms.linux ++ lib.platforms.freebsd;
    mainProgram = "server";
  };
}
})