From f238f247195434bf1031b8eb08082f754616da3f Mon Sep 17 00:00:00 2001 From: Michael Raitza Date: Mon, 3 Feb 2025 17:03:48 +0100 Subject: [PATCH] Adds Nix flake build files --- flake.lock | 282 +++++++++++++++++++++++++++++++++++++++++++ flake.nix | 152 +++++++++++++++++++++++ scripts/update-flake | 48 ++++++++ 3 files changed, 482 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100755 scripts/update-flake diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..5b56a9ff4 --- /dev/null +++ b/flake.lock @@ -0,0 +1,282 @@ +{ + "nodes": { + "advisory-db": { + "flake": false, + "locked": { + "lastModified": 1722017365, + "narHash": "sha256-9wYR5NZIgI+qzMDlJrUzevR31fvFQRgfjlYp50Xp3Ts=", + "owner": "rustsec", + "repo": "advisory-db", + "rev": "9d024c07ee8c18609b43436bc865abf46636e250", + "type": "github" + }, + "original": { + "owner": "rustsec", + "repo": "advisory-db", + "type": "github" + } + }, + "crane": { + "inputs": { + "nixpkgs": [ + "heartwood", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1722907532, + "narHash": "sha256-i/j/dMZPR7uJoQPFTa6UCahLu8kMtozYuR83lIKMERM=", + "owner": "ipetkov", + "repo": "crane", + "rev": "d0c8f4ed8571c533b31c1d68e4ebc534b790cc5c", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_3": { + "inputs": { + "systems": "systems_3" + }, + "locked": { + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "heartwood": { + "inputs": { + "advisory-db": "advisory-db", + "crane": "crane", + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + }, + "locked": { + "lastModified": 1732803596, + "narHash": "sha256-M4oz9tWjI/eqV4Gz1b512MEmvsZ5u3R9y6P9VeeH9CA=", + "ref": "refs/namespaces/z6MksFqXN3Yhqk8pTJdUGLwATkRfQvwZXPqR2qMEhbS9wzpT/refs/tags/v1.1.0", + "rev": "60d503e77115232f88537e30367714212c49085b", + "revCount": 2147, + "type": "git", + "url": "https://seed.radicle.xyz/z3gqcJUoA1n9HaHKufZs5FCSGazv5.git" + }, + "original": { + "ref": "refs/namespaces/z6MksFqXN3Yhqk8pTJdUGLwATkRfQvwZXPqR2qMEhbS9wzpT/refs/tags/v1.1.0", + "type": "git", + "url": "https://seed.radicle.xyz/z3gqcJUoA1n9HaHKufZs5FCSGazv5.git" + } + }, + "nix-playwright-browsers": { + "inputs": { + "flake-utils": "flake-utils_3", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1727577780, + "narHash": "sha256-yoBul0Y7WDdjqUiJgWTMBrrYnyC/5ObdEsuI5P7Xdgw=", + "owner": "voidus", + "repo": "nix-playwright-browsers", + "rev": "6e6ffee8c9e0961b24d8f0eb4df3cc13535b3055", + "type": "github" + }, + "original": { + "owner": "voidus", + "repo": "nix-playwright-browsers", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1722940684, + "narHash": "sha256-X8JnSq0ruRWsU4PdYuxV+8W4W66F1lnCcxIZZMWzo4E=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a3103d68517c6ad262ea27c96fc4a38ad81be7a0", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "release-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1727348695, + "narHash": "sha256-J+PeFKSDV+pHL7ukkfpVzCOO7mBSrrpJ3svwBFABbhI=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "1925c603f17fc89f4c8f6bf6f631a802ad85d784", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1738574474, + "narHash": "sha256-rvyfF49e/k6vkrRTV4ILrWd92W+nmBDfRYZgctOyolQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "fecfeb86328381268e29e998ddd3ebc70bbd7f7c", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "heartwood": "heartwood", + "nix-playwright-browsers": "nix-playwright-browsers", + "nixpkgs": "nixpkgs_3", + "rust-overlay": "rust-overlay_2" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "heartwood", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1722910815, + "narHash": "sha256-v6Vk/xlABhw2QzOa6xh3Jx/IvmlbKbOazFM+bDFQlWU=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "7df2ac544c203d21b63aac23bfaec7f9b919a733", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "rust-overlay_2": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1738635966, + "narHash": "sha256-5MbJhh6nz7tx8FYVOJ0+ixMaEn0ibGzV/hScPMmqVTE=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "1ff8663cd75a11e61f8046c62f4dbb05d1907b44", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_3": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..29637258a --- /dev/null +++ b/flake.nix @@ -0,0 +1,152 @@ +{ + description = "Radicle Desktop App"; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11"; + flake-utils.url = "github:numtide/flake-utils"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + heartwood = { + url = "git+https://seed.radicle.xyz/z3gqcJUoA1n9HaHKufZs5FCSGazv5.git?ref=refs/namespaces/z6MksFqXN3Yhqk8pTJdUGLwATkRfQvwZXPqR2qMEhbS9wzpT/refs/tags/v1.1.0"; + }; + nix-playwright-browsers.url = "github:voidus/nix-playwright-browsers"; + }; + + outputs = { + self, + nixpkgs, + flake-utils, + rust-overlay, + heartwood, + nix-playwright-browsers, + ... + }@inputs: + (flake-utils.lib.eachDefaultSystem (system: let + pkgs = import nixpkgs { + inherit system; + overlays = [ + (import rust-overlay) + nix-playwright-browsers.overlays.${system}.default + ]; + }; + inherit (pkgs) lib; + in { + + checks = { + radicle-desktop = self.packages.${system}.radicle-desktop.overrideAttrs ({ doCheck = true; }); + }; + + devShells.default = pkgs.mkShell { + name = "radicle-desktop-env"; + inputsFrom = [ self.checks.${system}.radicle-desktop ]; + nativeBuildInputs = with pkgs; [ + cargo-watch + cargo-nextest + ripgrep + rust-analyzer + ]; + env = self.checks.${system}.radicle-desktop.env // { + }; + }; + + packages = { + default = self.packages.${system}.radicle-desktop; + twemoji-assets = pkgs.fetchFromGitHub { + owner = "twitter"; + repo = "twemoji"; + rev = "v14.0.2"; + hash = "sha256-YoOnZ5uVukzi/6bLi22Y8U5TpplPzB7ji42l+/ys5xI="; + }; + + radicle-desktop = pkgs.callPackage ( + { + lib, + fetchNpmDeps, + rust-bin, + makeRustPlatform, + cargo-tauri, + nodejs, + npmHooks, + pkg-config, + wrapGAppsHook4, + glib, + gtk3, + libsoup_3, + openssl, + webkitgtk_4_1, + git, + playwright-browsers_v1_47_0, + }: let + rTc = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain; + rustPlatform = pkgs.makeRustPlatform { + cargo = rTc; + rustc = rTc; + }; + in rustPlatform.buildRustPackage rec { + pname = "radicle-desktop"; + inherit (with builtins; (fromJSON (readFile ./package.json))) version; + + src = ./.; + + cargoDeps = rustPlatform.importCargoLock { lockFile = ./Cargo.lock; }; + + npmDeps = fetchNpmDeps { + name = pname + "-npm-deps-" + version; + inherit src; + hash = "sha256-ZbLre35Y5Ym4sYGrJDQGeQSzllDiE1X9SGaF837ROZo="; # npmDepsHash : Update canary, don't touch! + }; + + nativeBuildInputs = [ + cargo-tauri.hook + nodejs + npmHooks.npmConfigHook + pkg-config + wrapGAppsHook4 + ]; + + buildInputs = [ + glib gtk3 libsoup_3 openssl webkitgtk_4_1 + ]; + + postPatch = '' + patchShebangs scripts/copy-katex-assets scripts/check-js scripts/check-rs + mkdir -p public/twemoji + cp -t public/twemoji -r -- ${self.packages.${system}.twemoji-assets}/assets/svg/* + : >scripts/install-twemoji-assets + ''; + + doCheck = false; + nativeCheckInputs = [ git ]; + + env = { + HW_RELEASE = "nix-" + (heartwood.shortRev or "unknown-ref"); + PLAYWRIGHT_BROWSERS_PATH = playwright-browsers_v1_47_0; + PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD = 1; + PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS = true; + RUST_SRC_PATH = "${rTc}/lib/rustlib/src/rust/library"; + }; + + preCheck = '' + bins="tests/tmp/bin/heartwood/$HW_RELEASE" + mkdir -p "$bins" + cp -t "$bins" -- ${heartwood.packages.${system}.radicle}/bin/* + printf "$HW_RELEASE" >tests/support/heartwood-release + ''; + + checkPhase = '' + npm run test:unit + scripts/check-js + scripts/check-rs + ''; + + passthru.env = env; + meta = { + description = "Radicle Desktop App"; + license = lib.licenses.gpl3; + maintainers = [ ]; + }; + }) {}; + }; + })); +} diff --git a/scripts/update-flake b/scripts/update-flake new file mode 100755 index 000000000..28fe75a76 --- /dev/null +++ b/scripts/update-flake @@ -0,0 +1,48 @@ +#!/bin/sh + +set -eu + +usage() { + printf \ + 'Update flake. + +USAGE: + update-flake [-h] + +OPTIONS: + -h --help\tPrint this help.\n' +} + +while [ $# -ne 0 ]; do + case $1 in + --help | -h) + usage >&2 + exit + ;; + esac +done + +# Some root detection guess work... +root=$(git rev-parse --show-toplevel 2>/dev/null || echo "$PWD") +if [ ! -e "$root/scripts/update-flake" ]; then + root=$( + cd .. + pwd + ) +fi + +if [ -e "$root/flake.nix" ]; then + # If running on a nix-enabled system, also update npmDepsHash. + if type nix >/dev/null 2>&1; then + npmDepsHash=$(nix --experimental-features 'nix-command flakes' \ + run --inputs-from "$root" nixpkgs#prefetch-npm-deps \ + -- "$root/package-lock.json") + sed -E -e '/# npmDepsHash :/s#(hash[ ]*=[ ]*").*(".*$)#\1'"$npmDepsHash"'\2#' "$root/flake.nix" >$root/flake.nix.tmp + mv "$root/flake.nix.tmp" "$root/flake.nix" + + nix --experimental-features 'nix-command flakes' flake update --flake git+file://"$root" + else + printf >&2 'Node dependencies may be out of date! +Re-run on a nix-enabled system to update npmDepsHash.\n' + fi +fi