From f768d214da9f2d83a18696265622efd9d8b57c1a Mon Sep 17 00:00:00 2001 From: Soispha Date: Sun, 9 Jul 2023 07:13:32 +0200 Subject: [PATCH 1/3] Build(flake): Initialize the flake A nix flake is a reproducible way to describe the building process to [nix](1). See [the nix download page](1), on how to install nix. Afterwards running `nix build` in the repository will result in a successful build. Flakes and nix-commands are still experimental so they must be enabled as described in [the corresponding wiki entry](2) [1]: https://nixos.org/download.html#nix [2]: https://nixos.wiki/wiki/Flakes#Enable_flakes. --- flake.lock | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 89 ++++++++++++++++++++++++++++++++++++ 2 files changed, 221 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..f639470 --- /dev/null +++ b/flake.lock @@ -0,0 +1,132 @@ +{ + "nodes": { + "crane": { + "inputs": { + "flake-compat": [ + "flake-compat" + ], + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ], + "rust-overlay": [ + "rust-overlay" + ] + }, + "locked": { + "lastModified": 1688772518, + "narHash": "sha256-ol7gZxwvgLnxNSZwFTDJJ49xVY5teaSvF7lzlo3YQfM=", + "owner": "ipetkov", + "repo": "crane", + "rev": "8b08e96c9af8c6e3a2b69af5a7fa168750fcf88e", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1687709756, + "narHash": "sha256-Y5wKlQSkgEK2weWdOu4J3riRd+kV/VCgHsqLNTTWQ/0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "dbabf0ca0c0c4bce6ea5eaf65af5cb694d2082c7", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1688829822, + "narHash": "sha256-hv56yK1fPHPt7SU2DboxBtdSbIuv9nym7Dss7Cn2jic=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ed6afb10dfdfc97b6bcf0703f1bad8118e9e961b", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1688870171, + "narHash": "sha256-8tD8fheWPa7TaJoxzcU3iHkCrQQpOpdMN+HYqgZ1N5A=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "5a932f10ac4bd59047d6e8b5780750ec76ea988a", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "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..d6c1db1 --- /dev/null +++ b/flake.nix @@ -0,0 +1,89 @@ +{ + description = "A terminal UI client for the matrix chat protocol"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + # inputs for following + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; + crane = { + url = "github:ipetkov/crane"; + inputs = { + nixpkgs.follows = "nixpkgs"; + flake-compat.follows = "flake-compat"; + flake-utils.follows = "flake-utils"; + rust-overlay.follows = "rust-overlay"; + }; + }; + flake-utils = { + url = "github:numtide/flake-utils"; + inputs = {}; + }; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs = { + nixpkgs.follows = "nixpkgs"; + flake-utils.follows = "flake-utils"; + }; + }; + }; + + outputs = { + self, + nixpkgs, + crane, + flake-utils, + rust-overlay, + ... + }: + flake-utils.lib.eachDefaultSystem (system: let + pkgs = import nixpkgs { + inherit system; + overlays = [(import rust-overlay)]; + }; + + #rust-nightly = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default); + rust-stable = pkgs.rust-bin.stable.latest.default; + + craneLib = (crane.mkLib pkgs).overrideToolchain rust-stable; + + nativeBuildInputs = with pkgs; [ + pkg-config + ]; + buildInputs = with pkgs; [ + openssl + ]; + + craneBuild = craneLib.buildPackage { + src = craneLib.cleanCargoSource ./.; + + doCheck = true; + inherit nativeBuildInputs buildInputs; + }; + in { + packages.default = craneBuild; + + app.default = { + type = "app"; + program = "${self.packages.${system}.default}/bin/trinitix"; + }; + + devShells.default = pkgs.mkShell { + packages = with pkgs; [ + nil + alejandra + statix + ltex-ls + + rust-stable + rust-analyzer + cargo-edit + ]; + }; + }); +} +# vim: ts=2 + From cc602b25ce246802a40c2f6d583542e25f73cca8 Mon Sep 17 00:00:00 2001 From: Soispha Date: Sun, 9 Jul 2023 07:15:20 +0200 Subject: [PATCH 2/3] Build(flake): Enable direnv integration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [Direnv](1) in combination with some sort of [Nix integration](2) — in this case [Nix-direnv](3) — allows for reproducible development environments (and allows uncluttering the default PATH, as cargo and other development tools are no longer needed in it). Setting it up is rather easy, just see [Nix-direnv's install instructions](4). [1]: https://github.com/direnv/direnv [2]: https://github.com/direnv/direnv/wiki/Nix [3]: https://github.com/nix-community/nix-direnv [4]: https://github.com/nix-community/nix-direnv#installation --- .envrc | 7 +++++++ .gitignore | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .envrc diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..96eca6b --- /dev/null +++ b/.envrc @@ -0,0 +1,7 @@ +use flake || use nix +watch_file flake.nix + +if on_git_branch; then + echo && git status --short --branch && + echo && git fetch --verbose +fi diff --git a/.gitignore b/.gitignore index e60e326..fe48077 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,10 @@ -target/ userdata/ trinitrix.log +# build +/target +/result + # IDE stuff .idea +.direnv From 74be1c2506875d69ec2071cbe43fa144cdd2a9fc Mon Sep 17 00:00:00 2001 From: Soispha Date: Sun, 9 Jul 2023 07:53:15 +0200 Subject: [PATCH 3/3] Build(flake): Also add the openssl dependencies to the devShell --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index d6c1db1..91af5ee 100644 --- a/flake.nix +++ b/flake.nix @@ -82,6 +82,7 @@ rust-analyzer cargo-edit ]; + inherit nativeBuildInputs buildInputs; }; }); }