diff --git a/.cargo/config.toml b/.cargo/config.toml index 60a7dd7..1ddbba2 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,2 @@ [build] -rustflags = ["-Clink-arg=-fuse-ld=mold", "-Zthreads=16"] +rustflags = ["-Clink-arg=-fuse-ld=mold"] diff --git a/default.nix b/default.nix deleted file mode 100644 index e224dd7..0000000 --- a/default.nix +++ /dev/null @@ -1,43 +0,0 @@ -{ lib, rustPlatform }: -let - readToml = path: builtins.fromTOML (builtins.readFile path); - cargoToml = readToml ./Cargo.toml; - pname = cargoToml.package.name; - inherit (cargoToml.package) version description; - src = lib.cleanSourceWith { - src = ./.; - name = "${pname}-source"; - # Adapted from - # no need to pull in crane for just this - filter = - orig_path: type: - let - path = toString orig_path; - base = baseNameOf path; - matchesSuffix = lib.any (suffix: lib.hasSuffix suffix base) [ - # Rust sources - ".rs" - # TOML files are often used to configure cargo based tools (e.g. .cargo/config.toml) - ".toml" - # Snapshot tests - ".snap" - ]; - isCargoLock = base == "Cargo.lock"; - in - type == "directory" || matchesSuffix || isCargoLock; - }; -in -rustPlatform.buildRustPackage { - inherit pname version src; - cargoLock.lockFile = ./Cargo.lock; - useNextest = true; - NEXTEST_HIDE_PROGRESS_BAR = 1; - NEXTEST_FAILURE_OUTPUT = "immediate-final"; - - meta = { - inherit description; - license = lib.licenses.mit; - homepage = "https://github.com/jalil-salame/webnsupdate"; - mainProgram = "webnsupdate"; - }; -} diff --git a/flake-modules/package.nix b/flake-modules/package.nix index d4ff12a..f4d0cd0 100644 --- a/flake-modules/package.nix +++ b/flake-modules/package.nix @@ -1,24 +1,69 @@ +{ inputs, lib, ... }: { perSystem = { pkgs, ... }: - { - packages = - let - webnsupdate = pkgs.callPackage ../default.nix { }; - in - { - inherit webnsupdate; - default = webnsupdate; - cargo-update = pkgs.writeShellApplication { - name = "cargo-update-lockfile"; - runtimeInputs = with pkgs; [ - cargo - gnused - ]; - text = '' - CARGO_TERM_COLOR=never cargo update 2>&1 | sed '/crates.io index/d' | tee -a cargo_update.log - ''; - }; + let + craneLib = inputs.crane.mkLib pkgs; + src = craneLib.cleanCargoSource inputs.self; + + commonArgs = { + inherit src; + strictDeps = true; + + doCheck = false; # tests will be run in the `checks` derivation + NEXTEST_HIDE_PROGRESS_BAR = 1; + NEXTEST_FAILURE_OUTPUT = "immediate-final"; + + nativeBuildInputs = [ pkgs.mold ]; + + meta = { + license = lib.licenses.mit; + homepage = "https://github.com/jalil-salame/webnsupdate"; + mainProgram = "webnsupdate"; }; + }; + + cargoArtifacts = craneLib.buildDepsOnly commonArgs; + webnsupdate = craneLib.buildPackage ( + lib.mergeAttrsList [ + commonArgs + { inherit cargoArtifacts; } + ] + ); + in + { + checks = { + clippy = craneLib.cargoClippy ( + lib.mergeAttrsList [ + commonArgs + { + inherit cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + } + ] + ); + + nextest = craneLib.cargoNextest ( + lib.mergeAttrsList [ + commonArgs + { inherit cargoArtifacts; } + ] + ); + }; + + packages = { + inherit webnsupdate; + default = webnsupdate; + cargo-update = pkgs.writeShellApplication { + name = "cargo-update-lockfile"; + runtimeInputs = with pkgs; [ + cargo + gnused + ]; + text = '' + CARGO_TERM_COLOR=never cargo update 2>&1 | sed '/crates.io index/d' | tee -a cargo_update.log + ''; + }; + }; }; } diff --git a/flake.lock b/flake.lock index e5a0f2a..2987e17 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,20 @@ { "nodes": { + "crane": { + "locked": { + "lastModified": 1730060262, + "narHash": "sha256-RMgSVkZ9H03sxC+Vh4jxtLTCzSjPq18UWpiM0gq6shQ=", + "owner": "ipetkov", + "repo": "crane", + "rev": "498d9f122c413ee1154e8131ace5a35a80d8fa76", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, "flake-parts": { "inputs": { "nixpkgs-lib": [ @@ -37,6 +52,7 @@ }, "root": { "inputs": { + "crane": "crane", "flake-parts": "flake-parts", "nixpkgs": "nixpkgs", "systems": "systems", diff --git a/flake.nix b/flake.nix index 3fb5460..3e7f04f 100644 --- a/flake.nix +++ b/flake.nix @@ -1,12 +1,13 @@ { description = "An http server that calls nsupdate internally"; inputs = { - nixpkgs.url = "nixpkgs/nixos-unstable"; - systems.url = "github:nix-systems/default"; + crane.url = "github:ipetkov/crane"; flake-parts = { url = "github:hercules-ci/flake-parts"; inputs.nixpkgs-lib.follows = "nixpkgs"; }; + nixpkgs.url = "nixpkgs/nixos-unstable"; + systems.url = "github:nix-systems/default"; treefmt-nix = { url = "github:numtide/treefmt-nix"; inputs.nixpkgs.follows = "nixpkgs";