From: self Date: Sun, 23 Jul 2023 09:53:06 +0000 (-0700) Subject: package lemmy as a nix flake X-Git-Url: http://these/git/%22https:/lemmy.ml/u/Liwott/test?a=commitdiff_plain;h=cd3c076dfc88d22907d2fb3060cbbc21929de778;p=lemmy.git package lemmy as a nix flake --- diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..425fd493 --- /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 diff --git a/.gitignore b/.gitignore index 186713e1..3c7611d0 100644 --- a/.gitignore +++ b/.gitignore @@ -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 index 00000000..6c261161 --- /dev/null +++ b/default.nix @@ -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 index 00000000..2719ce3f --- /dev/null +++ b/flake.lock @@ -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 index 00000000..4a3094fb --- /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 ]; }; + }); +}