]> Untitled Git - lemmy.git/commitdiff
package lemmy as a nix flake
authorself <self@awful.systems>
Sun, 23 Jul 2023 09:53:06 +0000 (02:53 -0700)
committerself <self@awful.systems>
Mon, 21 Aug 2023 14:41:18 +0000 (07:41 -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 186713e1f4a947b71380d42df2bd3a99cbbffbdf..3c7611d01c67937fb0dd303cac5a56f47f1dc819 100644 (file)
@@ -1,3 +1,7 @@
+result
+.direnv/
+.envrc.private
+
 # local ansible configuration
 ansible/inventory
 ansible/passwords/
diff --git a/default.nix b/default.nix
new file mode 100644 (file)
index 0000000..6c26116
--- /dev/null
@@ -0,0 +1,39 @@
+{ lib, stdenv, rustPlatform, fetchFromGitHub, openssl, postgresql, libiconv
+, Security, protobuf, rustfmt, nixosTests }:
+
+rustPlatform.buildRustPackage rec {
+  version = "0.18.2";
+  pname = "lemmy-server";
+
+  src = ./.;
+
+  preConfigure = ''
+    echo 'pub const VERSION: &str = "${version}";' > crates/utils/src/version.rs
+  '';
+
+  cargoSha256 = "sha256-2HWz6gYRo4YkXQz4V5COY2vpCu/PD8kKxzDG21YjYbo=";
+
+  buildInputs = [ postgresql ]
+    ++ lib.optionals stdenv.isDarwin [ libiconv Security ];
+
+  # Using OPENSSL_NO_VENDOR is not an option on darwin
+  # As of version 0.10.35 rust-openssl looks for openssl on darwin
+  # with a hardcoded path to /usr/lib/libssl.x.x.x.dylib
+  # https://github.com/sfackler/rust-openssl/blob/master/openssl-sys/build/find_normal.rs#L115
+  OPENSSL_LIB_DIR = "${lib.getLib openssl}/lib";
+  OPENSSL_INCLUDE_DIR = "${openssl.dev}/include";
+
+  PROTOC = "${protobuf}/bin/protoc";
+  PROTOC_INCLUDE = "${protobuf}/include";
+  nativeBuildInputs = [ protobuf rustfmt ];
+
+  passthru.tests.lemmy-server = 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 ];
+    mainProgram = "lemmy_server";
+  };
+}
diff --git a/flake.lock b/flake.lock
new file mode 100644 (file)
index 0000000..2719ce3
--- /dev/null
@@ -0,0 +1,60 @@
+{
+  "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"
+      }
+    },
+    "nixpkgs": {
+      "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",
+        "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 (file)
index 0000000..4a3094f
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,26 @@
+{
+  description = "🐀 Building a federated alternative to reddit in rust";
+
+  inputs = {
+    nixpkgs.url = "nixpkgs/nixos-unstable";
+    flake-utils.url = "github:numtide/flake-utils";
+  };
+
+  outputs = { self, nixpkgs, flake-utils }:
+
+    flake-utils.lib.eachDefaultSystem (system:
+      let pkgs = nixpkgs.legacyPackages.${system};
+      in {
+        packages = {
+          lemmy-server = (pkgs.callPackage ./default.nix {
+            libiconv = null;
+            Security = null;
+          });
+
+          default = self.packages.x86_64-linux.lemmy-server;
+        };
+
+        devShells.default =
+          pkgs.mkShell { buildInputs = [ pkgs.rustc pkgs.cargo ]; };
+      });
+}