diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index a36d01e..48d2ef2 100644 --- a/.gitignore +++ b/.gitignore @@ -108,3 +108,6 @@ tags # End of https://www.toptal.com/developers/gitignore/api/linux,macos,rust,visualstudiocode,vim +# Nix +/result +/.direnv \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..f2e840a --- /dev/null +++ b/flake.lock @@ -0,0 +1,123 @@ +{ + "nodes": { + "crane": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixpkgs" + ], + "rust-overlay": "rust-overlay" + }, + "locked": { + "lastModified": 1666567222, + "narHash": "sha256-AVySilLW+eNM409GSIJYsF6wg5NsxK12Ht2DMSYAgO0=", + "owner": "ipetkov", + "repo": "crane", + "rev": "2ce1a3313e299b0db63b11f94c863af74b0b08ad", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1650374568, + "narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "b4a34015c698c7793d592d66adbab377907a2be8", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1685533922, + "narHash": "sha256-y4FCQpYafMQ42l1V+NUrMel9RtFtZo59PzdzflKR/lo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3a70dd92993182f8e514700ccf5b1ae9fc8a3b8d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "crane", + "flake-utils" + ], + "nixpkgs": [ + "crane", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1666494036, + "narHash": "sha256-4mmm+1MBPMD56LMLN9QcEwnfnu41NkA6lDeZGjSrxIw=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "af2e939ba2c7cbb188d06d6650c6353b10b3f2be", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..4c30298 --- /dev/null +++ b/flake.nix @@ -0,0 +1,55 @@ +{ + description = "Scalable push server for XMPP"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05"; + flake-utils.url = "github:numtide/flake-utils"; + crane = { + url = "github:ipetkov/crane"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, flake-utils, crane }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + }; + craneLib = crane.lib.${system}; + + commonArgs = { + src = craneLib.cleanCargoSource ./.; + + buildInputs = [ + pkgs.openssl + ]; + + nativeBuildInputs = [ + pkgs.pkg-config + ]; + }; + in + { + packages.default = craneLib.buildPackage ({ + meta = { mainProgram = "fpush"; }; + } // commonArgs); + + devShells = { + default = pkgs.mkShell { + + buildInputs = [ ] ++ commonArgs.buildInputs; + nativeBuildInputs = builtins.attrValues + { + inherit (pkgs) cargo rustc nixpkgs-fmt shellcheck rnix-lsp; + } ++ [ + # This is required to prevent a mangled bash shell in nix develop + # see: https://discourse.nixos.org/t/interactive-bash-with-nix-develop-flake/15486 + (pkgs.hiPrio pkgs.bashInteractive) + + ] ++ commonArgs.nativeBuildInputs; + }; + }; + } + ); +}