From 89d1222b8fcfd2243e18b1d536c4a48ef7031b3c Mon Sep 17 00:00:00 2001 From: oluceps Date: Sun, 2 Oct 2022 18:20:26 +0800 Subject: [PATCH 1/2] rm: default.nix --- default.nix | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100755 default.nix diff --git a/default.nix b/default.nix deleted file mode 100755 index 7e9eb182..00000000 --- a/default.nix +++ /dev/null @@ -1,34 +0,0 @@ -{ lib -, fetchFromGitHub -, buildGoModule -}: -buildGoModule rec { - pname = "clash-meta"; - version = "dev"; - src = ./.; - vendorSha256 = "sha256-7HjYcoqWA5gvPUc5psCgy0UTc17CBzBJ/OiGvII/iBA="; - - # Do not build testing suit - excludedPackages = [ "./test" ]; - - CGO_ENABLED = 0; - - ldflags = [ - "-s" - "-w" - "-X github.com/Dreamacro/clash/constant.Version=${version}" - ]; - - # network required - doCheck = false; - - postInstall = '' - mv $out/bin/clash $out/bin/clash-meta - ''; - - meta = with lib; { - description = "Another Clash Kernel"; - homepage = "https://github.com/MetaCubeX/Clash.Meta"; - license = licenses.gpl3Only; - }; -} From ec6144250d2230a0b1b99add0f71b6faee114c36 Mon Sep 17 00:00:00 2001 From: oluceps Date: Sun, 2 Oct 2022 18:29:20 +0800 Subject: [PATCH 2/2] add: current version and BuildTime for nix build --- flake.lock | 6 +++--- flake.nix | 54 ++++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/flake.lock b/flake.lock index 01b81807..7da95ac3 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1664638641, - "narHash": "sha256-r2gVLq9DD1A0Igv4AdkmpuuVykXmKVsJTAJinS/ZFrM=", + "lastModified": 1664705630, + "narHash": "sha256-MLi1J9tIZQFj8v9RKmG89HJAE5ja3z4ui4Tf9+wG/bM=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "cb81a9ca94e7631bc67788d858e214d56571983a", + "rev": "f71b215225dec75df6266ff7764d54c2e44ef226", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 3e8fd557..4afb1d53 100644 --- a/flake.nix +++ b/flake.nix @@ -9,19 +9,49 @@ utils.lib.eachDefaultSystem (system: let - pkgs = nixpkgs.legacyPackages.${system}; + pkgs = import nixpkgs { + inherit system; + overlays = [ self.overlay ]; + }; in - { - packages = rec{ - clash-meta = pkgs.callPackage ./. { }; - default = clash-meta; - }; - - apps = rec { - clash-meta = utils.lib.mkApp { drv = self.packages.${system}.clash-meta; }; - default = clash-meta; - }; + rec { + packages.default = pkgs.clash-meta; } - ); + ) // + ( + let version = nixpkgs.lib.substring 0 8 self.lastModifiedDate or self.lastModified or "19700101"; in + { + overlay = final: prev: { + + clash-meta = final.buildGoModule { + pname = "clash-meta"; + inherit version; + src = ./.; + + vendorSha256 = "sha256-Af1RgeB6APxKW9m+rm2mkpYSXwAgFTzRyW0GJe9ML+A="; + + # Do not build testing suit + excludedPackages = [ "./test" ]; + + CGO_ENABLED = 0; + + ldflags = [ + "-s" + "-w" + "-X github.com/Dreamacro/clash/constant.Version=dev-${version}" + "-X github.com/Dreamacro/clash/constant.BuildTime=${version}" + ]; + + # Network required + doCheck = false; + + postInstall = '' + mv $out/bin/clash $out/bin/clash-meta + ''; + + }; + }; + } + ); }