From ae10fb686c25d959f1c3e1bd77b4248b7fde2106 Mon Sep 17 00:00:00 2001 From: xenofem Date: Thu, 9 May 2024 07:33:20 -0400 Subject: [PATCH] jankily package actual-server for nix --- .gitignore | 1 + flake.lock | 24 ++++++++++ flake.nix | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 .gitignore create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e2f5dd2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +result \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..b63e781 --- /dev/null +++ b/flake.lock @@ -0,0 +1,24 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1713297878, + "narHash": "sha256-hOkzkhLT59wR8VaMbh1ESjtZLbGi+XNaBN6h49SPqEc=", + "path": "/nix/store/6bf943g0mlhymyffs9dflzgc78r93s60-source", + "rev": "66adc1e47f8784803f2deb6cacd5e07264ec2d5c", + "type": "path" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..8c04432 --- /dev/null +++ b/flake.nix @@ -0,0 +1,126 @@ +{ + description = "Actual budget app"; + + outputs = { self, nixpkgs }: let + pkgs = import nixpkgs { + system = "x86_64-linux"; + }; + pname = "actual-server"; + version = "24.4.0"; + src = pkgs.fetchFromGitHub { + owner = "actualbudget"; + repo = pname; + rev = "v${version}"; + sha256 = "1lq5lqa3818ajyn4cs8paw0iy4ibpggzsp9p1l4xwpa1xz10jb52"; + }; + package = pkgs.stdenv.mkDerivation (finalAttrs: { + inherit pname version src; + + nativeBuildInputs = with pkgs; [ + yarn-berry + nodejs + python3 + jq + moreutils + makeWrapper + ]; + + yarnOfflineCache = pkgs.stdenvNoCC.mkDerivation { + name = "actual-deps"; + nativeBuildInputs = with pkgs; [ yarn-berry ]; + inherit (finalAttrs) src; + + NODE_EXTRA_CA_CERTS = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"; + + supportedArchitectures = builtins.toJSON { + os = [ "darwin" "linux" ]; + cpu = [ "arm" "arm64" "ia32" "x64" ]; + libc = [ "glibc" "musl" ]; + }; + + configurePhase = '' + runHook preConfigure + + export HOME="$NIX_BUILD_TOP" + export YARN_ENABLE_TELEMETRY=0 + + yarn config set enableGlobalCache false + yarn config set cacheFolder $out + yarn config set supportedArchitectures --json "$supportedArchitectures" + + runHook postConfigure + ''; + + buildPhase = '' + runHook preBuild + + mkdir -p $out + yarn install --immutable --mode skip-build + + runHook postBuild + ''; + + dontInstall = true; + + outputHashAlgo = "sha256"; + outputHash = "sha256-Ie8Y13I7Vo3P7iYODP3YcsKicYbYSbcj1lyMoMwoTO0="; + outputHashMode = "recursive"; + }; + + patchPhase = '' + sed -i '1i#!${pkgs.nodejs}/bin/node' app.js + ''; + + configurePhase = '' + runHook preConfigure + + export HOME="$NIX_BUILD_TOP" + export YARN_ENABLE_TELEMETRY=0 + export npm_config_nodedir=${pkgs.nodejs} + + yarn config set enableGlobalCache false + yarn config set cacheFolder $yarnOfflineCache + + runHook postConfigure + ''; + + buildPhase = '' + runHook preBuild + + yarn install --immutable-cache # --immutable + yarn build + yarn workspaces focus --all --production + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + mkdir -p $out/{bin,lib} + + mkdir $out/lib/actual + cp -r package.json app.js src migrations node_modules $out/lib/actual/ + + chmod +x $out/lib/actual/app.js + + wrapProgram $out/lib/actual/app.js $out/bin/actual --chdir $out/lib/actual + + runHook postInstall + ''; + + fixupPhase = '' + runHook preFixup + + patchShebangs $out/lib + + runHook postFixup + ''; + }); + in rec { + packages.x86_64-linux = { + "${pname}" = package; + default = package; + }; + }; +}