]> Untitled Git - lemmy-ui.git/commitdiff
add Nix flake support
authorself <self@awful.systems>
Mon, 21 Aug 2023 17:10:42 +0000 (10:10 -0700)
committerself <self@awful.systems>
Mon, 21 Aug 2023 17:10:42 +0000 (10:10 -0700)
.envrc [new file with mode: 0644]
.gitignore
default.nix [new file with mode: 0644]
flake.lock [new file with mode: 0644]
flake.nix [new file with mode: 0644]

diff --git a/.envrc b/.envrc
new file mode 100644 (file)
index 0000000..425fd49
--- /dev/null
+++ b/.envrc
@@ -0,0 +1,6 @@
+if ! has nix_direnv_version || ! nix_direnv_version 2.3.0; then
+    source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.3.0/direnvrc" "sha256-Dmd+j63L84wuzgyjITIfSxSD57Tx7v51DMxVZOsiUD8="
+fi
+use flake
+
+source_env_if_exists .envrc.private
index 3234d3dfdb9022f547715c503bf0ad38fbfda65b..3b191b5af52c249f4c0f42bab03de869800437b1 100644 (file)
@@ -29,3 +29,6 @@ src/shared/translations
 
 stats.json
 
+.envrc.private
+result
+.direnv/
diff --git a/default.nix b/default.nix
new file mode 100644 (file)
index 0000000..f78b8ef
--- /dev/null
@@ -0,0 +1,77 @@
+{ lib, mkYarnPackage, libsass, nodejs, python3, pkg-config, fetchFromGitHub
+, fetchYarnDeps, nixosTests, vips, nodePackages, lemmy-translations
+, lemmy-js-client }:
+
+let
+  pkgConfig = {
+    node-sass = {
+      nativeBuildInputs = [ pkg-config ];
+      buildInputs = [ libsass python3 ];
+      postInstall = ''
+        LIBSASS_EXT=auto yarn --offline run build
+        rm build/config.gypi
+      '';
+    };
+    sharp = {
+      nativeBuildInputs = [ pkg-config nodePackages.semver ];
+      buildInputs = [ vips ];
+      postInstall = ''
+        yarn --offline run install
+      '';
+    };
+  };
+
+  name = "lemmy-ui";
+  version = "0.18.4";
+
+  src = ./.;
+
+in mkYarnPackage {
+
+  inherit src pkgConfig name version;
+
+  extraBuildInputs = [ libsass ];
+
+  packageJSON = ./package.json;
+  offlineCache = fetchYarnDeps {
+    yarnLock = src + "/yarn.lock";
+    sha256 = "sha256-fRJpA9WstNNNOePoqotJKYmlikkcjc34iM0WO8+a/3Q=";
+  };
+
+  yarnPreBuild = ''
+    export npm_config_nodedir=${nodejs}
+  '';
+
+  buildPhase = ''
+    # Yarn writes cache directories etc to $HOME.
+    export HOME=$PWD/yarn_home
+    rm -rf node_modules/lemmy-js-client
+    ln -sf ${lemmy-js-client}/libexec/lemmy-js-client/node_modules/lemmy-js-client node_modules/lemmy-js-client
+
+    ln -sf $PWD/node_modules $PWD/deps/lemmy-ui/
+    echo 'export const VERSION = "${version}";' > $PWD/deps/lemmy-ui/src/shared/version.ts
+
+    ln -sf ${lemmy-translations} deps/lemmy-ui/lemmy-translations
+
+    yarn --offline build:prod
+  '';
+
+  preInstall = ''
+    mkdir $out
+    cp -R ./deps/lemmy-ui/dist $out
+    cp -R ./node_modules $out
+  '';
+
+  distPhase = "true";
+
+  passthru.updateScript = ./update.sh;
+  passthru.tests.lemmy-ui = nixosTests.lemmy;
+
+  meta = with lib; {
+    description = "Building a federated alternative to reddit in rust";
+    homepage = "https://join-lemmy.org/";
+    license = licenses.agpl3Only;
+    maintainers = with maintainers; [ happysalada billewanick ];
+    inherit (nodejs.meta) platforms;
+  };
+}
diff --git a/flake.lock b/flake.lock
new file mode 100644 (file)
index 0000000..848d84c
--- /dev/null
@@ -0,0 +1,142 @@
+{
+  "nodes": {
+    "flake-utils": {
+      "inputs": {
+        "systems": "systems"
+      },
+      "locked": {
+        "lastModified": 1689068808,
+        "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=",
+        "owner": "numtide",
+        "repo": "flake-utils",
+        "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4",
+        "type": "github"
+      },
+      "original": {
+        "owner": "numtide",
+        "repo": "flake-utils",
+        "type": "github"
+      }
+    },
+    "flake-utils_2": {
+      "inputs": {
+        "systems": "systems_2"
+      },
+      "locked": {
+        "lastModified": 1689068808,
+        "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=",
+        "owner": "numtide",
+        "repo": "flake-utils",
+        "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4",
+        "type": "github"
+      },
+      "original": {
+        "owner": "numtide",
+        "repo": "flake-utils",
+        "type": "github"
+      }
+    },
+    "lemmy-js-client": {
+      "inputs": {
+        "flake-utils": "flake-utils_2",
+        "nixpkgs": "nixpkgs"
+      },
+      "locked": {
+        "lastModified": 1690365721,
+        "narHash": "sha256-cCgcUW2CLWUI7kUacs2O//rXRBlnUsix2M/QggVhFh4=",
+        "path": "/home/j/lemmy-js-client",
+        "type": "path"
+      },
+      "original": {
+        "path": "/home/j/lemmy-js-client",
+        "type": "path"
+      }
+    },
+    "lemmy-translations": {
+      "flake": false,
+      "locked": {
+        "lastModified": 1690314617,
+        "narHash": "sha256-fkv6l6/888XOdxZ8Y0P+Ww/y+8Wh4F8SIStncAmifu8=",
+        "owner": "lemmynet",
+        "repo": "lemmy-translations",
+        "rev": "68d14665d4f854fc20f9117636b5cde7176e91dd",
+        "type": "github"
+      },
+      "original": {
+        "owner": "lemmynet",
+        "repo": "lemmy-translations",
+        "type": "github"
+      }
+    },
+    "nixpkgs": {
+      "locked": {
+        "lastModified": 1690179384,
+        "narHash": "sha256-+arbgqFTAtoeKtepW9wCnA0njCOyoiDFyl0Q0SBSOtE=",
+        "owner": "NixOS",
+        "repo": "nixpkgs",
+        "rev": "b12803b6d90e2e583429bb79b859ca53c348b39a",
+        "type": "github"
+      },
+      "original": {
+        "id": "nixpkgs",
+        "ref": "nixos-unstable",
+        "type": "indirect"
+      }
+    },
+    "nixpkgs_2": {
+      "locked": {
+        "lastModified": 1690031011,
+        "narHash": "sha256-kzK0P4Smt7CL53YCdZCBbt9uBFFhE0iNvCki20etAf4=",
+        "owner": "NixOS",
+        "repo": "nixpkgs",
+        "rev": "12303c652b881435065a98729eb7278313041e49",
+        "type": "github"
+      },
+      "original": {
+        "id": "nixpkgs",
+        "ref": "nixos-unstable",
+        "type": "indirect"
+      }
+    },
+    "root": {
+      "inputs": {
+        "flake-utils": "flake-utils",
+        "lemmy-js-client": "lemmy-js-client",
+        "lemmy-translations": "lemmy-translations",
+        "nixpkgs": "nixpkgs_2"
+      }
+    },
+    "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"
+      }
+    }
+  },
+  "root": "root",
+  "version": 7
+}
diff --git a/flake.nix b/flake.nix
new file mode 100644 (file)
index 0000000..d86d723
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,31 @@
+{
+  description = "🐀 Building a federated alternative to reddit in rust";
+
+  inputs = {
+    nixpkgs.url = "nixpkgs/nixos-unstable";
+    flake-utils.url = "github:numtide/flake-utils";
+    lemmy-translations = {
+      url = "github:lemmynet/lemmy-translations";
+      flake = false;
+    };
+    lemmy-js-client.url = "path:/home/j/lemmy-js-client";
+  };
+
+  outputs = { self, nixpkgs, flake-utils, lemmy-translations, lemmy-js-client }:
+
+    flake-utils.lib.eachDefaultSystem (system:
+      let pkgs = nixpkgs.legacyPackages.${system};
+      in {
+        packages = {
+          lemmy-ui = (pkgs.callPackage ./default.nix {
+            inherit lemmy-translations;
+            lemmy-js-client = lemmy-js-client.packages.${system}.default;
+          });
+
+          default = self.packages.x86_64-linux.lemmy-ui;
+        };
+
+        devShells.default =
+          pkgs.mkShell { buildInputs = [ pkgs.nodejs pkgs.yarn ]; };
+      });
+}