Skip to content

Commit

Permalink
update flake
Browse files Browse the repository at this point in the history
  • Loading branch information
LEXUGE committed Nov 2, 2024
1 parent 6b645d6 commit 68315d0
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 119 deletions.
6 changes: 3 additions & 3 deletions commit.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
60 changes: 13 additions & 47 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

143 changes: 74 additions & 69 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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=";
Expand Down

0 comments on commit 68315d0

Please sign in to comment.