From 831fdba760e5ca1f5d6d873eccbdb7e68f01cf42 Mon Sep 17 00:00:00 2001 From: kmaasrud Date: Sun, 19 Mar 2023 18:25:00 +0100 Subject: [PATCH 1/2] build: setup Nix flake --- contrib/flake.lock | 121 +++++++++++++++++++++++++++++++++++++++++++++ contrib/flake.nix | 50 +++++++++++++++++++ 2 files changed, 171 insertions(+) create mode 100644 contrib/flake.lock create mode 100644 contrib/flake.nix diff --git a/contrib/flake.lock b/contrib/flake.lock new file mode 100644 index 00000000..d8b682dd --- /dev/null +++ b/contrib/flake.lock @@ -0,0 +1,121 @@ +{ + "nodes": { + "crane": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1699218802, + "narHash": "sha256-5l0W4Q7z7A4BCstaF5JuBqXOVrZ3Vqst5+hUnP7EdUc=", + "owner": "ipetkov", + "repo": "crane", + "rev": "2d6c2aaff5a05e443eb15efddc21f9c73720340c", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1699251759, + "narHash": "sha256-OVxxfLmq1HsYF6t2TjHfX5Bfpqh2QgIUHmdUlA9Y4qo=", + "owner": "nix-community", + "repo": "fenix", + "rev": "bfee6157e580504fbe23e97887e68c293565ce7b", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1699186365, + "narHash": "sha256-Pxrw5U8mBsL3NlrJ6q1KK1crzvSUcdfwb9083sKDrcU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a0b3b06b7a82c965ae0bb1d59f6e386fe755001d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "fenix": "fenix", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1699192824, + "narHash": "sha256-/W1PD3IjsnYccL6W72guok3bvdnRPHvVYDfgBTDEtpM=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "c1c9e10f72ffd2e829d20ff1439ff49c2e121731", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "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/contrib/flake.nix b/contrib/flake.nix new file mode 100644 index 00000000..067f1550 --- /dev/null +++ b/contrib/flake.nix @@ -0,0 +1,50 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + crane = { + url = "github:ipetkov/crane"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + flake-utils.url = "github:numtide/flake-utils"; + + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { + nixpkgs, + crane, + flake-utils, + fenix, + ... + }: + flake-utils.lib.eachDefaultSystem (system: let + pkgs = import nixpkgs { + inherit system; + }; + + toolchain = with fenix.packages.${system}; + combine [ + default.rustc + default.cargo + default.clippy + default.rustfmt + ]; + + craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; + buildInputs = with pkgs; []; + in rec { + packages.default = craneLib.buildPackage { + inherit buildInputs; + src = pkgs.lib.cleanSourceWith {src = craneLib.path ../.;}; + }; + + apps.default = flake-utils.lib.mkApp { + drv = packages.default; + }; + }); +} From 7fb9eed60374e6de307ffea1c06271fadcf2c1a0 Mon Sep 17 00:00:00 2001 From: Knut Magnus Aasrud Date: Mon, 6 Nov 2023 11:37:04 +0100 Subject: [PATCH 2/2] docs: update README --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index b0a96e29..1803fb3a 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,22 @@ WebAssembly backend. [wasm-pack]: https://rustwasm.github.io/wasm-pack/ +### Nix flake + +There is a Nix flake available in the `contrib` directory. With it, you can get +a reproducible build of Jotdown by cloning the repo and running + +``` +$ nix build ./contrib +``` + +If you want to the run Jotdown CLI on any system that has Nix installed, you can +do it like this: + +``` +$ nix run github:hellux/jotdown?dir=contrib -- +``` + ## Status ### Correctness