From c073c82096392a79c48d3e2e95c9a1bf39f882ea Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Fri, 5 Apr 2024 14:19:55 +0200 Subject: [PATCH] Add a derivation for loomio --- flake.lock | 61 + flake.nix | 17 + pkg/loomio/default.nix | 30 + pkg/loomio/gemfile-patch.nix | 6 + pkg/loomio/gemset.nix | 2413 ++++++++++++++++++++++++++++++++++ pkg/loomio/source.nix | 17 + pkg/loomio/update.sh | 114 ++ 7 files changed, 2658 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 pkg/loomio/default.nix create mode 100644 pkg/loomio/gemfile-patch.nix create mode 100644 pkg/loomio/gemset.nix create mode 100644 pkg/loomio/source.nix create mode 100755 pkg/loomio/update.sh diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..13821c5 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "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" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1710889954, + "narHash": "sha256-Pr6F5Pmd7JnNEMHHmspZ0qVqIBVxyZ13ik1pJtm2QXk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7872526e9c5332274ea5932a0c3270d6e4724f3b", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "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 0000000..020a08c --- /dev/null +++ b/flake.nix @@ -0,0 +1,17 @@ +{ + description = "The loomio flake"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + inputs.flake-utils.url = "github:numtide/flake-utils"; + + outputs = {nixpkgs, flake-utils, ...}: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + in rec { + packages = rec { + loomio = pkgs.callPackage ./pkg/loomio/default.nix {}; + inherit pkgs; + }; + }); +} diff --git a/pkg/loomio/default.nix b/pkg/loomio/default.nix new file mode 100644 index 0000000..1c062a3 --- /dev/null +++ b/pkg/loomio/default.nix @@ -0,0 +1,30 @@ +{stdenv, callPackage, bundlerEnv, ruby_3_2 }: + +let + gemfile-patch = callPackage ./gemfile-patch.nix {}; + src = callPackage ./source.nix { patches = [gemfile-patch];}; + gems = bundlerEnv { + name = "loomio-env"; + ruby = ruby_3_2; + gemset = ./. + "/gemset.nix"; + gemdir = src; + }; +in stdenv.mkDerivation { + name = "loomio"; + inherit src; + buildInputs = [gems ruby_3_2]; + installPhase = '' + mkdir -p $out/{bin,share/loomio} + cp -r * $out/share/loomio + bin=$out/bin/loomio + cat > $bin </dev/stderr || true + rm -rf "$WORK_DIR" +} +trap cleanup EXIT + +echo "Fetching source code $REVISION" +JSON=$(nix-prefetch-github "$OWNER" "$REPO" --rev "$REVISION" 2> $WORK_DIR/nix-prefetch-git.out) +HASH=$(echo "$JSON" | jq -r .hash) + +cat > source.nix << EOF +# This file was generated by pkgs.mastodon.updateScript. +{ fetchFromGitHub, applyPatches, patches ? [] }: +let + version = "$VERSION"; +in +( + applyPatches { + src = fetchFromGitHub { + owner = "$OWNER"; + repo = "$REPO"; + rev = "v\${version}"; + hash = "$HASH"; + }; + patches = patches ++ [$PATCHES]; + }) // { + inherit version; +} +EOF +SOURCE_DIR="$(nix-build --no-out-link -E '(import {}).callPackage ./source.nix {}')" + +echo "Creating gemset.nix" +pushd $SOURCE_DIR +bundle lock --add-platform ruby --print > Gemfile.lock +popd +BUNDLE_FORCE_RUBY_PLATFORM=true bundix --lockfile="$SOURCE_DIR/Gemfile.lock" --gemfile="$SOURCE_DIR/Gemfile" +echo "" >> gemset.nix # Create trailing newline to please EditorConfig checks + +# echo "Creating yarn-hash.nix" +# YARN_HASH="$(prefetch-yarn-deps "$SOURCE_DIR/yarn.lock")" +# YARN_HASH="$(nix hash to-sri --type sha256 "$YARN_HASH")" +# sed -i "s/sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=/$YARN_HASH/g" source.nix