diff --git a/commit.nix b/commit.nix index fceb269..a9de009 100644 --- a/commit.nix +++ b/commit.nix @@ -10,11 +10,11 @@ pkgs.mkShell { git coreutils findutils - nixfmt + nixpkgs-fmt gcc # write rustfmt first to ensure we are using nightly rustfmt - rust-bin.nightly."2022-01-01".rustfmt + rust-bin.nightly."2024-01-01".rustfmt rust-bin.stable.latest.default binutils-unwrapped @@ -27,7 +27,7 @@ pkgs.mkShell { find . -path ./target -prune -false -o -type f -name '*.sh' -exec shellcheck {} + find . -path ./target -prune -false -o -type f -name '*.sh' -exec shfmt -w {} + - find . -path ./target -prune -false -o -type f -name '*.nix' -exec nixfmt {} + + find . -path ./target -prune -false -o -type f -name '*.nix' -exec nixpkgs-fmt {} + nix flake update cargo update cargo fmt -- --check diff --git a/flake.lock b/flake.lock index 5ed9b1c..5b51949 100644 --- a/flake.lock +++ b/flake.lock @@ -1,30 +1,12 @@ { "nodes": { - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1681202837, - "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "cfacdce06f30d2b68473a46042957675eebb3401", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, "nixpkgs": { "locked": { - "lastModified": 1686960236, - "narHash": "sha256-AYCC9rXNLpUWzD9hm+askOfpliLEC9kwAo7ITJc4HIw=", + "lastModified": 1730200266, + "narHash": "sha256-l253w0XMT8nWHGXuXqyiIC/bMvh1VRszGXgdpQlfhvU=", "owner": "nixos", "repo": "nixpkgs", - "rev": "04af42f3b31dba0ef742d254456dc4c14eedac86", + "rev": "807e9154dcb16384b1b765ebe9cd2bba2ac287fd", "type": "github" }, "original": { @@ -36,11 +18,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1681358109, - "narHash": "sha256-eKyxW4OohHQx9Urxi7TQlFBTDWII+F+x2hklDOQPB50=", + "lastModified": 1728538411, + "narHash": "sha256-f0SBJz1eZ2yOuKUr5CA9BHULGXVSn6miBuUWdTyhUhU=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "96ba1c52e54e74c3197f4d43026b3f3d92e83ff9", + "rev": "b69de56fac8c2b6f8fd27f2eca01dcda8e0a4221", "type": "github" }, "original": { @@ -59,15 +41,14 @@ }, "rust-overlay": { "inputs": { - "flake-utils": "flake-utils", "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1687055571, - "narHash": "sha256-UvLoO6u5n9TzY80BpM4DaacxvyJl7u9mm9CA72d309g=", + "lastModified": 1730514457, + "narHash": "sha256-cjFX208s9pyaOfMvF9xI6WyafyXINqdhMF7b1bMQpLI=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "2de557c780dcb127128ae987fca9d6c2b0d7dc0f", + "rev": "1ff38ca26eb31858e4dfe7fe738b6b3ce5d74922", "type": "github" }, "original": { @@ -91,31 +72,16 @@ "type": "github" } }, - "systems_2": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - }, "utils": { "inputs": { - "systems": "systems_2" + "systems": "systems" }, "locked": { - "lastModified": 1685518550, - "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index d881957..ab6daf6 100644 --- a/flake.nix +++ b/flake.nix @@ -17,15 +17,18 @@ }; features = [ "geoip-maxmind" "geoip-cn" ]; forEachFeature = f: - builtins.listToAttrs (map (v: - attrsets.nameValuePair "dcompass-${strings.removePrefix "geoip-" v}" - (f v)) features); + builtins.listToAttrs (map + (v: + attrsets.nameValuePair "dcompass-${strings.removePrefix "geoip-" v}" + (f v)) + features); pkgSet = system: forEachFeature (v: with (pkgsWithRust system); (makeRustPlatform { - cargo = rust-bin.stable.latest.default; - rustc = rust-bin.stable.latest.default; + # Pinning these for now as I have no time to update the dependencies to accommodate the latest stable version. + cargo = rust-bin.stable."1.70.0".default; + rustc = rust-bin.stable."1.70.0".default; }).buildRustPackage { name = "dcompass-${strings.removePrefix "geoip-" v}"; version = "git"; @@ -45,80 +48,82 @@ buildInputs = [ zstd ]; nativeBuildInputs = [ pkg-config openssl zstd ]; }); - in utils.lib.eachSystem (with utils.lib.system; [ - aarch64-linux - i686-linux - x86_64-darwin - x86_64-linux - ]) (system: rec { - # `nix build` - packages = (pkgSet system) // { - # We have to do it like `nix develop .#commit` because libraries don't play well with `makeBinPath` or `makeLibraryPath`. - commit = (import ./commit.nix { - lib = utils.lib; - pkgs = (pkgsWithRust system); - }); - }; - - # TODO: figure out a way to write it as packages.default - # defaultPackage = packages.dcompass-maxmind; + in + utils.lib.eachSystem + (with utils.lib.system; [ + aarch64-linux + i686-linux + x86_64-darwin + x86_64-linux + ]) + (system: rec { + # `nix build` + packages = (pkgSet system) // { + # We have to do it like `nix develop .#commit` because libraries don't play well with `makeBinPath` or `makeLibraryPath`. + commit = (import ./commit.nix { + lib = utils.lib; + pkgs = (pkgsWithRust system); + }); + }; - # We don't check packages.commit because techinically it is not a pacakge - checks = builtins.removeAttrs packages [ "commit" ]; + # TODO: figure out a way to write it as packages.default + # defaultPackage = packages.dcompass-maxmind; - # `nix run` - apps = { - update = utils.lib.mkApp { - drv = with (pkgsWithRust system); - (writeShellApplication { - name = "dcompass-update-data"; - runtimeInputs = [ wget gzip ]; - text = '' - set -e - wget -O ./data/full.mmdb --show-progress https://github.com/Dreamacro/maxmind-geoip/releases/latest/download/Country.mmdb - wget -O ./data/cn.mmdb --show-progress https://github.com/Hackl0us/GeoIP2-CN/raw/release/Country.mmdb - wget -O ./data/ipcn.txt --show-progress https://github.com/17mon/china_ip_list/raw/master/china_ip_list.txt - gzip -f -k ./data/ipcn.txt - ''; - }); - }; - } // (forEachFeature (v: - utils.lib.mkApp { - drv = packages."dcompass-${strings.removePrefix "geoip-" v}"; - })); + # We don't check packages.commit because techinically it is not a pacakge + checks = builtins.removeAttrs packages [ "commit" ]; - defaultApp = apps.dcompass-maxmind; + # `nix run` + apps = rec { + default = dcompass-maxmind; + update = utils.lib.mkApp { + drv = with (pkgsWithRust system); + (writeShellApplication { + name = "dcompass-update-data"; + runtimeInputs = [ wget gzip ]; + text = '' + set -e + wget -O ./data/full.mmdb --show-progress https://github.com/Dreamacro/maxmind-geoip/releases/latest/download/Country.mmdb + wget -O ./data/cn.mmdb --show-progress https://github.com/Hackl0us/GeoIP2-CN/raw/release/Country.mmdb + wget -O ./data/ipcn.txt --show-progress https://github.com/17mon/china_ip_list/raw/master/china_ip_list.txt + gzip -f -k ./data/ipcn.txt + ''; + }); + }; + } // (forEachFeature (v: + utils.lib.mkApp { + drv = packages."dcompass-${strings.removePrefix "geoip-" v}"; + })); - # `nix develop` - devShells.default = with (pkgsWithRust system); - mkShell { - nativeBuildInputs = lib.flatten [ - # write rustfmt first to ensure we are using nightly rustfmt - rust-bin.nightly."2022-01-01".rustfmt - rust-bin.stable.latest.default - rust-bin.stable.latest.rust-src - rust-analyzer + # `nix develop` + devShells.default = with (pkgsWithRust system); + mkShell { + nativeBuildInputs = lib.flatten [ + # write rustfmt first to ensure we are using nightly rustfmt + rust-bin.nightly."2024-01-01".rustfmt + rust-bin.stable.latest.default + rust-bin.stable.latest.rust-src + rust-analyzer - # OpenSSL - pkg-config - openssl + # OpenSSL + pkg-config + openssl - # protobuf + # protobuf - # use by rust-gdb - gdb + # use by rust-gdb + gdb - binutils-unwrapped - cargo-cache - cargo-outdated + binutils-unwrapped + cargo-cache + cargo-outdated - (if stdenv.isLinux then [ linuxPackages.perf ] else [ ]) + (if stdenv.isLinux then [ linuxPackages.perf ] else [ ]) - # perl - # gnumake - ]; - }; - }) // { + # perl + # gnumake + ]; + }; + }) // { # public key for dcompass.cachix.org publicKey = "dcompass.cachix.org-1:uajJEJ1U9uy/y260jBIGgDwlyLqfL1sD5yaV/uWVlbk=";