From 4c82f6c9a210f0b7235940048c5d3a697c64c171 Mon Sep 17 00:00:00 2001 From: Thomas Zahner Date: Sat, 9 Nov 2024 17:41:20 +0100 Subject: [PATCH 01/21] Add Nix shell --- shell.nix | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 shell.nix diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000000..fa7b78072a --- /dev/null +++ b/shell.nix @@ -0,0 +1,27 @@ +/* +based on +https://discourse.nixos.org/t/how-can-i-set-up-my-rust-programming-environment/4501/9 +*/ +let + rust_overlay = import (builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz"); + pkgs = import { overlays = [ rust_overlay ]; }; + rustVersion = "latest"; # using a specific version: "1.62.0" + rust = pkgs.rust-bin.stable.${rustVersion}.default.override { + extensions = [ + "rust-src" # for rust-analyzer + "rust-analyzer" # usable by IDEs like zed-editor + ]; + }; +in +pkgs.mkShell { + buildInputs = [ + rust + ] ++ (with pkgs; [ + pkg-config + openssl + # other dependencies + #gtk3 + #wrapGAppsHook + ]); + RUST_BACKTRACE = 1; +} From 3a127d185fd471512335eef9e45fe0d240a9dae6 Mon Sep 17 00:00:00 2001 From: Thomas Zahner Date: Sat, 23 Nov 2024 14:02:00 +0100 Subject: [PATCH 02/21] Add .envrc --- .envrc | 1 + shell.nix | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) create mode 100644 .envrc diff --git a/.envrc b/.envrc new file mode 100644 index 0000000000..1d953f4bd7 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use nix diff --git a/shell.nix b/shell.nix index fa7b78072a..8bae8ce2c7 100644 --- a/shell.nix +++ b/shell.nix @@ -19,9 +19,6 @@ pkgs.mkShell { ] ++ (with pkgs; [ pkg-config openssl - # other dependencies - #gtk3 - #wrapGAppsHook ]); RUST_BACKTRACE = 1; } From a084dc41e6cfc06d9e0551117edd71ba725b2b88 Mon Sep 17 00:00:00 2001 From: Thomas Zahner Date: Sat, 23 Nov 2024 13:45:55 +0100 Subject: [PATCH 03/21] Use flake --- .envrc | 2 +- flake.lock | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 62 ++++++++++++++++++++++++++++++++++++++++ shell.nix | 24 ---------------- 4 files changed, 146 insertions(+), 25 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix delete mode 100644 shell.nix diff --git a/.envrc b/.envrc index 1d953f4bd7..3550a30f2d 100644 --- a/.envrc +++ b/.envrc @@ -1 +1 @@ -use nix +use flake diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000000..77581733ec --- /dev/null +++ b/flake.lock @@ -0,0 +1,83 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1730504689, + "narHash": "sha256-hgmguH29K2fvs9szpq2r3pz2/8cJd2LPS+b4tfNFCwE=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "506278e768c2a08bec68eb62932193e341f55c90", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1732014248, + "narHash": "sha256-y/MEyuJ5oBWrWAic/14LaIr/u5E0wRVzyYsouYY3W6w=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "23e89b7da85c3640bbc2173fe04f4bd114342367", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1728538411, + "narHash": "sha256-f0SBJz1eZ2yOuKUr5CA9BHULGXVSn6miBuUWdTyhUhU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b69de56fac8c2b6f8fd27f2eca01dcda8e0a4221", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1732328983, + "narHash": "sha256-RHt12f/slrzDpSL7SSkydh8wUE4Nr4r23HlpWywed9E=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "ed8aa5b64f7d36d9338eb1d0a3bb60cf52069a72", + "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 0000000000..9597821caa --- /dev/null +++ b/flake.nix @@ -0,0 +1,62 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-parts = { + url = "github:hercules-ci/flake-parts"; + inputs.nixpkgs-lib.follows = "nixpkgs"; + }; + rust-overlay.url = "github:oxalica/rust-overlay"; + }; + + outputs = + inputs@{ self, flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ + "x86_64-linux" + "aarch64-linux" + ]; + + perSystem = + { + config, + self', + inputs', + pkgs, + system, + ... + }: + { + _module.args.pkgs = import self.inputs.nixpkgs { + inherit system; + overlays = [ + (import inputs.rust-overlay) + ]; + }; + devShells.default = + let + libPath = + with pkgs; + lib.makeLibraryPath [ + pkg-config + openssl + ]; + in + pkgs.mkShell { + inputsFrom = builtins.attrValues self'.packages; + packages = with pkgs; [ + # (rust-bin.selectLatestNightlyWith (toolchain: toolchain.default)) + pkg-config + openssl + cargo + cargo-watch + rustc + rust-analyzer + clippy + ]; + LD_LIBRARY_PATH = libPath; + RUST_BACKTRACE = 1; + LIBCLANG_PATH = "${pkgs.libclang.lib}/lib"; + }; + }; + }; +} diff --git a/shell.nix b/shell.nix deleted file mode 100644 index 8bae8ce2c7..0000000000 --- a/shell.nix +++ /dev/null @@ -1,24 +0,0 @@ -/* -based on -https://discourse.nixos.org/t/how-can-i-set-up-my-rust-programming-environment/4501/9 -*/ -let - rust_overlay = import (builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz"); - pkgs = import { overlays = [ rust_overlay ]; }; - rustVersion = "latest"; # using a specific version: "1.62.0" - rust = pkgs.rust-bin.stable.${rustVersion}.default.override { - extensions = [ - "rust-src" # for rust-analyzer - "rust-analyzer" # usable by IDEs like zed-editor - ]; - }; -in -pkgs.mkShell { - buildInputs = [ - rust - ] ++ (with pkgs; [ - pkg-config - openssl - ]); - RUST_BACKTRACE = 1; -} From 60d2f73569ce3032e71dc4fd47944b3b3a5dd86f Mon Sep 17 00:00:00 2001 From: Thomas Zahner Date: Sun, 24 Nov 2024 11:37:11 +0100 Subject: [PATCH 04/21] Ignore direnv cache --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 62e9da5e86..c85508d869 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ debug/ # lychee-specific files .lycheecache .config.dummy.report.md + +# direnv cache +.direnv/ From ac1306226032dcc43da15ef72f6caf09e488433a Mon Sep 17 00:00:00 2001 From: Thomas Zahner Date: Sun, 24 Nov 2024 12:02:57 +0100 Subject: [PATCH 05/21] Specify Rust version explicitly --- flake.nix | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/flake.nix b/flake.nix index 9597821caa..d846e7a7b9 100644 --- a/flake.nix +++ b/flake.nix @@ -34,29 +34,33 @@ }; devShells.default = let + rustVersion = "latest"; # using a specific version: "1.62.0" + rust = pkgs.rust-bin.stable.${rustVersion}.default.override { + extensions = [ + "rust-src" # for rust-analyzer + "rust-analyzer" # usable by IDEs like zed-editor + "clippy" + ]; + }; libPath = with pkgs; lib.makeLibraryPath [ pkg-config openssl ]; + in pkgs.mkShell { inputsFrom = builtins.attrValues self'.packages; - packages = with pkgs; [ - # (rust-bin.selectLatestNightlyWith (toolchain: toolchain.default)) - pkg-config - openssl - cargo - cargo-watch - rustc - rust-analyzer - clippy + packages = [ + pkgs.pkg-config + pkgs.openssl + rust ]; LD_LIBRARY_PATH = libPath; RUST_BACKTRACE = 1; LIBCLANG_PATH = "${pkgs.libclang.lib}/lib"; }; }; - }; + }; } From dbb00437863b89837509056773cc1c0c174797d9 Mon Sep 17 00:00:00 2001 From: Thomas Zahner Date: Sun, 24 Nov 2024 12:22:34 +0100 Subject: [PATCH 06/21] Simplify flake --- flake.lock | 21 ------------- flake.nix | 89 +++++++++++++++++++++--------------------------------- 2 files changed, 35 insertions(+), 75 deletions(-) diff --git a/flake.lock b/flake.lock index 77581733ec..754f7b829b 100644 --- a/flake.lock +++ b/flake.lock @@ -1,25 +1,5 @@ { "nodes": { - "flake-parts": { - "inputs": { - "nixpkgs-lib": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1730504689, - "narHash": "sha256-hgmguH29K2fvs9szpq2r3pz2/8cJd2LPS+b4tfNFCwE=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "506278e768c2a08bec68eb62932193e341f55c90", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "flake-parts", - "type": "github" - } - }, "nixpkgs": { "locked": { "lastModified": 1732014248, @@ -54,7 +34,6 @@ }, "root": { "inputs": { - "flake-parts": "flake-parts", "nixpkgs": "nixpkgs", "rust-overlay": "rust-overlay" } diff --git a/flake.nix b/flake.nix index d846e7a7b9..df4b89f65e 100644 --- a/flake.nix +++ b/flake.nix @@ -1,66 +1,47 @@ { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - flake-parts = { - url = "github:hercules-ci/flake-parts"; - inputs.nixpkgs-lib.follows = "nixpkgs"; - }; rust-overlay.url = "github:oxalica/rust-overlay"; }; outputs = - inputs@{ self, flake-parts, ... }: - flake-parts.lib.mkFlake { inherit inputs; } { - systems = [ - "x86_64-linux" - "aarch64-linux" - ]; - - perSystem = - { - config, - self', - inputs', - pkgs, - system, - ... - }: - { - _module.args.pkgs = import self.inputs.nixpkgs { - inherit system; - overlays = [ - (import inputs.rust-overlay) + { + nixpkgs, + rust-overlay, + ... + }: + let + system = "x86_64-linux"; + pkgs = import nixpkgs { + inherit system; + overlays = [ (import rust-overlay) ]; + }; + in + { + devShells.${system}.default = + let + rustVersion = "latest"; # using a specific version: "1.62.0" + rust = pkgs.rust-bin.stable.${rustVersion}.default.override { + extensions = [ + "rust-src" # for rust-analyzer + "rust-analyzer" # usable by IDEs like zed-editor + "clippy" ]; }; - devShells.default = - let - rustVersion = "latest"; # using a specific version: "1.62.0" - rust = pkgs.rust-bin.stable.${rustVersion}.default.override { - extensions = [ - "rust-src" # for rust-analyzer - "rust-analyzer" # usable by IDEs like zed-editor - "clippy" - ]; - }; - libPath = - with pkgs; - lib.makeLibraryPath [ - pkg-config - openssl - ]; - - in - pkgs.mkShell { - inputsFrom = builtins.attrValues self'.packages; - packages = [ - pkgs.pkg-config - pkgs.openssl - rust - ]; - LD_LIBRARY_PATH = libPath; - RUST_BACKTRACE = 1; - LIBCLANG_PATH = "${pkgs.libclang.lib}/lib"; - }; + libPath = pkgs.lib.makeLibraryPath [ + pkgs.pkg-config + pkgs.openssl + ]; + in + pkgs.mkShell { + packages = [ + pkgs.pkg-config + pkgs.openssl + rust + ]; + LD_LIBRARY_PATH = libPath; + RUST_BACKTRACE = 1; + LIBCLANG_PATH = "${pkgs.libclang.lib}/lib"; }; }; } From 90cc77a6cd0097728bda5fe48c5620784eac3840 Mon Sep 17 00:00:00 2001 From: Thomas Zahner Date: Sun, 24 Nov 2024 12:52:50 +0100 Subject: [PATCH 07/21] Remove unneeded variables --- flake.nix | 6 ------ 1 file changed, 6 deletions(-) diff --git a/flake.nix b/flake.nix index df4b89f65e..001adca570 100644 --- a/flake.nix +++ b/flake.nix @@ -28,10 +28,6 @@ "clippy" ]; }; - libPath = pkgs.lib.makeLibraryPath [ - pkgs.pkg-config - pkgs.openssl - ]; in pkgs.mkShell { packages = [ @@ -39,9 +35,7 @@ pkgs.openssl rust ]; - LD_LIBRARY_PATH = libPath; RUST_BACKTRACE = 1; - LIBCLANG_PATH = "${pkgs.libclang.lib}/lib"; }; }; } From 4c1e0f5b1da327028546b28ce6980e1920a2160f Mon Sep 17 00:00:00 2001 From: Thomas Zahner Date: Tue, 10 Dec 2024 15:32:45 +0100 Subject: [PATCH 08/21] Update to Rust 1.83.0 --- flake.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/flake.lock b/flake.lock index 754f7b829b..098a46b092 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1732014248, - "narHash": "sha256-y/MEyuJ5oBWrWAic/14LaIr/u5E0wRVzyYsouYY3W6w=", + "lastModified": 1733759999, + "narHash": "sha256-463SNPWmz46iLzJKRzO3Q2b0Aurff3U1n0nYItxq7jU=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "23e89b7da85c3640bbc2173fe04f4bd114342367", + "rev": "a73246e2eef4c6ed172979932bc80e1404ba2d56", "type": "github" }, "original": { @@ -43,11 +43,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1732328983, - "narHash": "sha256-RHt12f/slrzDpSL7SSkydh8wUE4Nr4r23HlpWywed9E=", + "lastModified": 1733798086, + "narHash": "sha256-XHIh0h84xDnjkqampyNI/r2FAkKmwbL719ZsygiJHKE=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "ed8aa5b64f7d36d9338eb1d0a3bb60cf52069a72", + "rev": "8a19e07800d64462913f3dbf5c9a20ea7b50e6cd", "type": "github" }, "original": { From 45a0f178d657e6b3af304170d47b7cc2b9b39733 Mon Sep 17 00:00:00 2001 From: Thomas Zahner Date: Fri, 13 Dec 2024 12:12:04 +0100 Subject: [PATCH 09/21] Remove .envrc --- .envrc | 1 - .gitignore | 3 --- 2 files changed, 4 deletions(-) delete mode 100644 .envrc diff --git a/.envrc b/.envrc deleted file mode 100644 index 3550a30f2d..0000000000 --- a/.envrc +++ /dev/null @@ -1 +0,0 @@ -use flake diff --git a/.gitignore b/.gitignore index c85508d869..62e9da5e86 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,3 @@ debug/ # lychee-specific files .lycheecache .config.dummy.report.md - -# direnv cache -.direnv/ From e321dcfb65f9cd43fda54e34e56bcc3bae7bc420 Mon Sep 17 00:00:00 2001 From: Thomas Zahner Date: Fri, 13 Dec 2024 15:24:57 +0100 Subject: [PATCH 10/21] Support multiple platforms --- flake.nix | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/flake.nix b/flake.nix index 001adca570..8563f0096d 100644 --- a/flake.nix +++ b/flake.nix @@ -11,31 +11,34 @@ ... }: let - system = "x86_64-linux"; - pkgs = import nixpkgs { - inherit system; - overlays = [ (import rust-overlay) ]; - }; + systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ]; + forAllSystems = nixpkgs.lib.genAttrs systems; in { - devShells.${system}.default = - let - rustVersion = "latest"; # using a specific version: "1.62.0" - rust = pkgs.rust-bin.stable.${rustVersion}.default.override { - extensions = [ - "rust-src" # for rust-analyzer - "rust-analyzer" # usable by IDEs like zed-editor - "clippy" + devShells = forAllSystems (system: { + default = + let + pkgs = import nixpkgs { + inherit system; + overlays = [ (import rust-overlay) ]; + }; + rustVersion = "latest"; # using a specific version: "1.62.0" + rust = pkgs.rust-bin.stable.${rustVersion}.default.override { + extensions = [ + "rust-src" # for rust-analyzer + "rust-analyzer" # usable by IDEs like zed-editor + "clippy" + ]; + }; + in + pkgs.mkShell { + packages = [ + pkgs.pkg-config + pkgs.openssl + rust ]; + RUST_BACKTRACE = 1; }; - in - pkgs.mkShell { - packages = [ - pkgs.pkg-config - pkgs.openssl - rust - ]; - RUST_BACKTRACE = 1; - }; + }); }; } From 1cc631ab0c6672d9fd16a2c0b8bcf75395ce9841 Mon Sep 17 00:00:00 2001 From: Thomas Zahner Date: Fri, 13 Dec 2024 15:26:30 +0100 Subject: [PATCH 11/21] Remove $RUST_BACKTRACE --- flake.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/flake.nix b/flake.nix index 8563f0096d..8d4c2d0ae3 100644 --- a/flake.nix +++ b/flake.nix @@ -37,7 +37,6 @@ pkgs.openssl rust ]; - RUST_BACKTRACE = 1; }; }); }; From 48c74b8f886f4b5f4a87126c1aa221e088b7936e Mon Sep 17 00:00:00 2001 From: Thomas Zahner Date: Fri, 13 Dec 2024 15:34:21 +0100 Subject: [PATCH 12/21] Fix formatting --- flake.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 8d4c2d0ae3..7e595b83bb 100644 --- a/flake.nix +++ b/flake.nix @@ -19,9 +19,9 @@ default = let pkgs = import nixpkgs { - inherit system; - overlays = [ (import rust-overlay) ]; - }; + inherit system; + overlays = [ (import rust-overlay) ]; + }; rustVersion = "latest"; # using a specific version: "1.62.0" rust = pkgs.rust-bin.stable.${rustVersion}.default.override { extensions = [ From 0570fb22e307eac067b2ef0c29ff47a50e78adb8 Mon Sep 17 00:00:00 2001 From: Thomas Zahner Date: Thu, 19 Dec 2024 15:29:57 +0100 Subject: [PATCH 13/21] `nix build` working --- default.nix | 47 +++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 30 ++++++++++++++++++++++++++++-- 2 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 default.nix diff --git a/default.nix b/default.nix new file mode 100644 index 0000000000..339325d1a7 --- /dev/null +++ b/default.nix @@ -0,0 +1,47 @@ +{ + pkgs, + nixpkgs, + system, + rust-overlay, + rustVersion, +}: +let + rustPkgs = import nixpkgs { + inherit system; + overlays = [ (import rust-overlay) ]; + }; + + common = { + version = "0.17.0"; + src = ./.; + + cargoLock = { + lockFile = ./Cargo.lock; + }; + + nativeBuildInputs = [ pkgs.pkg-config ]; + buildInputs = + [ pkgs.openssl ] + ++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isDarwin [ + pkgs.Security + pkgs.SystemConfiguration + ]; + + PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig"; + RUST_BACKTRACE = 1; + + checkFlags = [ + "--skip=src/lib.rs" + "--skip=client::tests" + "--skip=collector::tests::test_url_without_extension_is_html" + ]; + }; +in +{ + app = pkgs.rustPlatform.buildRustPackage ( + common + // { + pname = "lychee"; + } + ); +} diff --git a/flake.nix b/flake.nix index 7e595b83bb..f85cf751a9 100644 --- a/flake.nix +++ b/flake.nix @@ -1,4 +1,5 @@ { + description = "A flake for building and developing lychee"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; rust-overlay.url = "github:oxalica/rust-overlay"; @@ -11,8 +12,13 @@ ... }: let - systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ]; + systems = [ + "x86_64-linux" + "aarch64-linux" + "aarch64-darwin" + ]; forAllSystems = nixpkgs.lib.genAttrs systems; + rustVersion = "latest"; # using a specific version: "1.62.0" in { devShells = forAllSystems (system: { @@ -22,7 +28,6 @@ inherit system; overlays = [ (import rust-overlay) ]; }; - rustVersion = "latest"; # using a specific version: "1.62.0" rust = pkgs.rust-bin.stable.${rustVersion}.default.override { extensions = [ "rust-src" # for rust-analyzer @@ -39,5 +44,26 @@ ]; }; }); + + packages = forAllSystems ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + code = pkgs.callPackage ./. { + inherit + nixpkgs + system + rust-overlay + rustVersion + ; + }; + in + { + default = pkgs.symlinkJoin { + name = "all"; + paths = with code; [ app ]; + }; + } + ); }; } From 18e90ebd8c87ed3278f0c9377e296def6c17c138 Mon Sep 17 00:00:00 2001 From: Thomas Zahner Date: Thu, 19 Dec 2024 17:35:07 +0100 Subject: [PATCH 14/21] Simplify code --- default.nix | 14 ++++---------- flake.nix | 5 +---- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/default.nix b/default.nix index 339325d1a7..17708c650e 100644 --- a/default.nix +++ b/default.nix @@ -10,8 +10,10 @@ let inherit system; overlays = [ (import rust-overlay) ]; }; - - common = { +in +{ + app = pkgs.rustPlatform.buildRustPackage { + pname = "lychee"; version = "0.17.0"; src = ./.; @@ -36,12 +38,4 @@ let "--skip=collector::tests::test_url_without_extension_is_html" ]; }; -in -{ - app = pkgs.rustPlatform.buildRustPackage ( - common - // { - pname = "lychee"; - } - ); } diff --git a/flake.nix b/flake.nix index f85cf751a9..3aac916a6a 100644 --- a/flake.nix +++ b/flake.nix @@ -59,10 +59,7 @@ }; in { - default = pkgs.symlinkJoin { - name = "all"; - paths = with code; [ app ]; - }; + default = code.app; } ); }; From e19a23dc89100f528bb2c928b82c126ad182d9ae Mon Sep 17 00:00:00 2001 From: Thomas Zahner Date: Thu, 19 Dec 2024 18:22:01 +0100 Subject: [PATCH 15/21] Further simplify flake --- default.nix | 12 +----------- flake.nix | 9 +-------- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/default.nix b/default.nix index 17708c650e..8e006b77ee 100644 --- a/default.nix +++ b/default.nix @@ -1,15 +1,5 @@ -{ - pkgs, - nixpkgs, - system, - rust-overlay, - rustVersion, -}: +{ pkgs }: let - rustPkgs = import nixpkgs { - inherit system; - overlays = [ (import rust-overlay) ]; - }; in { app = pkgs.rustPlatform.buildRustPackage { diff --git a/flake.nix b/flake.nix index 3aac916a6a..cbffaf619b 100644 --- a/flake.nix +++ b/flake.nix @@ -49,14 +49,7 @@ system: let pkgs = nixpkgs.legacyPackages.${system}; - code = pkgs.callPackage ./. { - inherit - nixpkgs - system - rust-overlay - rustVersion - ; - }; + code = import ./default.nix { inherit pkgs; }; in { default = code.app; From 745fd9071efa339c6567f49a6607bf4cc6308b2a Mon Sep 17 00:00:00 2001 From: Thomas Zahner Date: Thu, 19 Dec 2024 18:29:12 +0100 Subject: [PATCH 16/21] More consistent style --- flake.nix | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/flake.nix b/flake.nix index cbffaf619b..395924ad5d 100644 --- a/flake.nix +++ b/flake.nix @@ -21,29 +21,31 @@ rustVersion = "latest"; # using a specific version: "1.62.0" in { - devShells = forAllSystems (system: { - default = - let - pkgs = import nixpkgs { - inherit system; - overlays = [ (import rust-overlay) ]; - }; - rust = pkgs.rust-bin.stable.${rustVersion}.default.override { - extensions = [ - "rust-src" # for rust-analyzer - "rust-analyzer" # usable by IDEs like zed-editor - "clippy" - ]; - }; - in - pkgs.mkShell { + devShells = forAllSystems ( + system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ (import rust-overlay) ]; + }; + rust = pkgs.rust-bin.stable.${rustVersion}.default.override { + extensions = [ + "rust-src" # for rust-analyzer + "rust-analyzer" # usable by IDEs like zed-editor + "clippy" + ]; + }; + in + { + default = pkgs.mkShell { packages = [ pkgs.pkg-config pkgs.openssl rust ]; }; - }); + } + ); packages = forAllSystems ( system: From 034d41858bebca52226ca2e31c9249355fb16cd7 Mon Sep 17 00:00:00 2001 From: Thomas Zahner Date: Thu, 19 Dec 2024 18:45:01 +0100 Subject: [PATCH 17/21] Add development section to README --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 779e9f7d53..dc18c87635 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ Available as a command-line utility, a library and a [GitHub Action](https://git ## Table of Contents - [Installation](#installation) +- [Development](#development) - [Features](#features) - [Commandline usage](#commandline-usage) - [Library usage](#library-usage) @@ -148,6 +149,12 @@ Lychee supports several feature flags: By default, `native-tls` and `email-check` are enabled. +## Development + +After [installing Rust](https://www.rust-lang.org/tools/install) use [Cargo](https://doc.rust-lang.org/cargo/) for building and testing. +On Linux the OpenSSL package [is required](https://github.com/seanmonstar/reqwest?tab=readme-ov-file#requirements) to compile `reqwest`, a dependendy of lychee. +For Nix we provide a flake so you can use `nix develop` and `nix build`. + ## Features This comparison is made on a best-effort basis. Please create a PR to fix From e93689aa42e9c09b6f02550c1a7e0fd1054ba72e Mon Sep 17 00:00:00 2001 From: Thomas Zahner Date: Thu, 19 Dec 2024 18:55:04 +0100 Subject: [PATCH 18/21] Move section --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index dc18c87635..376f672fda 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,8 @@ Available as a command-line utility, a library and a [GitHub Action](https://git ## Table of Contents -- [Installation](#installation) - [Development](#development) +- [Installation](#installation) - [Features](#features) - [Commandline usage](#commandline-usage) - [Library usage](#library-usage) @@ -35,6 +35,12 @@ Available as a command-line utility, a library and a [GitHub Action](https://git +## Development + +After [installing Rust](https://www.rust-lang.org/tools/install) use [Cargo](https://doc.rust-lang.org/cargo/) for building and testing. +On Linux the OpenSSL package [is required](https://github.com/seanmonstar/reqwest?tab=readme-ov-file#requirements) to compile `reqwest`, a dependendy of lychee. +For Nix we provide a flake so you can use `nix develop` and `nix build`. + ## Installation ### Arch Linux @@ -149,12 +155,6 @@ Lychee supports several feature flags: By default, `native-tls` and `email-check` are enabled. -## Development - -After [installing Rust](https://www.rust-lang.org/tools/install) use [Cargo](https://doc.rust-lang.org/cargo/) for building and testing. -On Linux the OpenSSL package [is required](https://github.com/seanmonstar/reqwest?tab=readme-ov-file#requirements) to compile `reqwest`, a dependendy of lychee. -For Nix we provide a flake so you can use `nix develop` and `nix build`. - ## Features This comparison is made on a best-effort basis. Please create a PR to fix From 39b8a3e0aa2b4e2ef522c8361535d4fb150a0fef Mon Sep 17 00:00:00 2001 From: Thomas Zahner Date: Thu, 19 Dec 2024 20:29:09 +0100 Subject: [PATCH 19/21] Fix typo Co-authored-by: Matthias Endler --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 376f672fda..c9289b864e 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Available as a command-line utility, a library and a [GitHub Action](https://git ## Development After [installing Rust](https://www.rust-lang.org/tools/install) use [Cargo](https://doc.rust-lang.org/cargo/) for building and testing. -On Linux the OpenSSL package [is required](https://github.com/seanmonstar/reqwest?tab=readme-ov-file#requirements) to compile `reqwest`, a dependendy of lychee. +On Linux the OpenSSL package [is required](https://github.com/seanmonstar/reqwest?tab=readme-ov-file#requirements) to compile `reqwest`, a dependency of lychee. For Nix we provide a flake so you can use `nix develop` and `nix build`. ## Installation From 328ffa00ff56c712c4db04be73669bff36fbba4c Mon Sep 17 00:00:00 2001 From: Thomas Zahner Date: Thu, 19 Dec 2024 22:00:10 +0100 Subject: [PATCH 20/21] Extract version number programmatically --- default.nix | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/default.nix b/default.nix index 8e006b77ee..2a9a80e923 100644 --- a/default.nix +++ b/default.nix @@ -1,10 +1,16 @@ { pkgs }: let + version = + let + cargoToml = builtins.readFile ./Cargo.toml; + match = builtins.match ''.*version = "([^"]+)".*'' cargoToml; + in + if match != null then builtins.elemAt match 0 else throw "Version not found in Cargo.toml"; in { app = pkgs.rustPlatform.buildRustPackage { pname = "lychee"; - version = "0.17.0"; + inherit version; src = ./.; cargoLock = { From 4ef8f59d8740778b1fc857aee94ae39b2d010d23 Mon Sep 17 00:00:00 2001 From: Thomas Zahner Date: Thu, 19 Dec 2024 22:12:18 +0100 Subject: [PATCH 21/21] Reuse nixpkgs recipe as suggested by @tirimia --- default.nix | 37 ------------------------------------- flake.nix | 10 ++++++++-- 2 files changed, 8 insertions(+), 39 deletions(-) delete mode 100644 default.nix diff --git a/default.nix b/default.nix deleted file mode 100644 index 2a9a80e923..0000000000 --- a/default.nix +++ /dev/null @@ -1,37 +0,0 @@ -{ pkgs }: -let - version = - let - cargoToml = builtins.readFile ./Cargo.toml; - match = builtins.match ''.*version = "([^"]+)".*'' cargoToml; - in - if match != null then builtins.elemAt match 0 else throw "Version not found in Cargo.toml"; -in -{ - app = pkgs.rustPlatform.buildRustPackage { - pname = "lychee"; - inherit version; - src = ./.; - - cargoLock = { - lockFile = ./Cargo.lock; - }; - - nativeBuildInputs = [ pkgs.pkg-config ]; - buildInputs = - [ pkgs.openssl ] - ++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isDarwin [ - pkgs.Security - pkgs.SystemConfiguration - ]; - - PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig"; - RUST_BACKTRACE = 1; - - checkFlags = [ - "--skip=src/lib.rs" - "--skip=client::tests" - "--skip=collector::tests::test_url_without_extension_is_html" - ]; - }; -} diff --git a/flake.nix b/flake.nix index 395924ad5d..02516d233a 100644 --- a/flake.nix +++ b/flake.nix @@ -9,6 +9,7 @@ { nixpkgs, rust-overlay, + self, ... }: let @@ -51,10 +52,15 @@ system: let pkgs = nixpkgs.legacyPackages.${system}; - code = import ./default.nix { inherit pkgs; }; in { - default = code.app; + default = pkgs.lychee.overrideAttrs { + src = ./.; + version = self.rev or self.dirtyShortRev; + cargoDeps = pkgs.rustPlatform.importCargoLock { + lockFile = ./Cargo.lock; + }; + }; } ); };