From bcacf43960679405b45dbec103acdaa401dd26cc Mon Sep 17 00:00:00 2001 From: Lyndon Sanche Date: Thu, 6 Mar 2025 10:47:44 -0700 Subject: [PATCH 1/2] flake: Fix build --- flake.lock | 136 +++++++++++++++++++++++++---------------------------- flake.nix | 126 +++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 171 insertions(+), 91 deletions(-) diff --git a/flake.lock b/flake.lock index 681e80f..110cc98 100644 --- a/flake.lock +++ b/flake.lock @@ -1,35 +1,28 @@ { "nodes": { - "cargo2nix": { - "inputs": { - "flake-compat": "flake-compat", - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs", - "rust-overlay": "rust-overlay" - }, + "crane": { "locked": { - "lastModified": 1682891040, - "narHash": "sha256-hjajsi7lq24uYitUh4o04UJi1g0Qe6ruPL0s5DgPQMY=", - "owner": "cargo2nix", - "repo": "cargo2nix", - "rev": "0167b39f198d72acdf009265634504fd6f5ace15", + "lastModified": 1741148495, + "narHash": "sha256-EV8KUaIZ2/CdBXlutXrHoZYbWPeB65p5kKZk71gvDRI=", + "owner": "ipetkov", + "repo": "crane", + "rev": "75390a36cd0c2cdd5f1aafd8a9f827d7107f2e53", "type": "github" }, "original": { - "owner": "cargo2nix", - "ref": "release-0.11.0", - "repo": "cargo2nix", + "owner": "ipetkov", + "repo": "crane", "type": "github" } }, "flake-compat": { "flake": false, "locked": { - "lastModified": 1650374568, - "narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=", + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", "owner": "edolstra", "repo": "flake-compat", - "rev": "b4a34015c698c7793d592d66adbab377907a2be8", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", "type": "github" }, "original": { @@ -38,90 +31,73 @@ "type": "github" } }, - "flake-utils": { - "locked": { - "lastModified": 1659877975, - "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_2": { + "gitignore": { "inputs": { - "systems": "systems" + "nixpkgs": [ + "pre-commit-hooks-nix", + "nixpkgs" + ] }, "locked": { - "lastModified": 1681202837, - "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", "type": "github" }, "original": { - "owner": "numtide", - "repo": "flake-utils", + "owner": "hercules-ci", + "repo": "gitignore.nix", "type": "github" } }, "nixpkgs": { "locked": { - "lastModified": 1682600000, - "narHash": "sha256-ha4BehR1dh8EnXSoE1m/wyyYVvHI9txjW4w5/oxsW5Y=", - "owner": "nixos", + "lastModified": 1741173522, + "narHash": "sha256-k7VSqvv0r1r53nUI/IfPHCppkUAddeXn843YlAC5DR0=", + "owner": "NixOS", "repo": "nixpkgs", - "rev": "50fc86b75d2744e1ab3837ef74b53f103a9b55a0", + "rev": "d69ab0d71b22fa1ce3dbeff666e6deb4917db049", "type": "github" }, "original": { - "owner": "nixos", - "ref": "release-22.05", + "owner": "NixOS", + "ref": "nixos-unstable", "repo": "nixpkgs", "type": "github" } }, - "root": { - "inputs": { - "cargo2nix": "cargo2nix", - "flake-utils": "flake-utils_2", - "nixpkgs": [ - "cargo2nix", - "nixpkgs" - ] - } - }, - "rust-overlay": { + "pre-commit-hooks-nix": { "inputs": { - "flake-utils": [ - "cargo2nix", - "flake-utils" - ], + "flake-compat": "flake-compat", + "gitignore": "gitignore", "nixpkgs": [ - "cargo2nix", "nixpkgs" ] }, "locked": { - "lastModified": 1673490397, - "narHash": "sha256-VCSmIYJy/ZzTvEGjdfITmTYfybXBgZpMjyjDndbou+8=", - "owner": "oxalica", - "repo": "rust-overlay", - "rev": "0833f4d063a2bb75aa31680f703ba594a384ffe6", + "lastModified": 1740915799, + "narHash": "sha256-JvQvtaphZNmeeV+IpHgNdiNePsIpHD5U/7QN5AeY44A=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "42b1ba089d2034d910566bf6b40830af6b8ec732", "type": "github" }, "original": { - "owner": "oxalica", - "repo": "rust-overlay", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", "type": "github" } }, + "root": { + "inputs": { + "crane": "crane", + "nixpkgs": "nixpkgs", + "pre-commit-hooks-nix": "pre-commit-hooks-nix", + "utils": "utils" + } + }, "systems": { "locked": { "lastModified": 1681028828, @@ -136,6 +112,24 @@ "repo": "default", "type": "github" } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 7e33f18..678f419 100644 --- a/flake.nix +++ b/flake.nix @@ -1,30 +1,116 @@ { description = "Bridge for synchronizing email and tags between JMAP and notmuch"; inputs = { - flake-utils.url = "github:numtide/flake-utils"; - cargo2nix.url = "github:cargo2nix/cargo2nix/release-0.11.0"; - nixpkgs.follows = "cargo2nix/nixpkgs"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + utils.url = "github:numtide/flake-utils"; + + crane.url = "github:ipetkov/crane"; + + pre-commit-hooks-nix = { + url = "github:cachix/pre-commit-hooks.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; - outputs = { self, nixpkgs, flake-utils, cargo2nix }: - flake-utils.lib.eachSystem [ "x86_64-linux" ] (system: - let - pkgs = import nixpkgs { - inherit system; - overlays = [cargo2nix.overlays.default]; + outputs = { self, nixpkgs, utils, crane, pre-commit-hooks-nix}: + let + systems = [ + "x86_64-linux" + "aarch64-linux" + ]; + in + utils.lib.eachSystem systems (system: let + pkgs = nixpkgs.legacyPackages."${system}"; + craneLib = crane.mkLib pkgs; + lib = pkgs.lib; + + mdFilter = path: _type: builtins.match ".*md$" path != null; + mdOrCargo = path: type: + (mdFilter path type) || (craneLib.filterCargoSources path type); + + src = lib.cleanSourceWith { + src = ./.; + filter = mdOrCargo; + name = "source"; + }; + + common-args = { + inherit src; + strictDeps = true; + + propagatedBuildInputs = [ pkgs.notmuch ]; + }; + + cargoArtifacts = craneLib.buildDepsOnly common-args; + + mujmap = craneLib.buildPackage (common-args + // { + inherit cargoArtifacts; + }); + + pre-commit-check = hooks: + pre-commit-hooks-nix.lib.${system}.run { + src = ./.; + + inherit hooks; }; - rustPkgs = pkgs.rustBuilder.makePackageSet { - rustVersion = "1.61.0"; - packageFun = import ./Cargo.nix; + in rec { + checks = { + inherit mujmap; + + mujmap-clippy = craneLib.cargoClippy (common-args + // { + inherit cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + }); + + mujmap-fmt = craneLib.cargoFmt { + inherit src; + }; + + mujmap-deny = craneLib.cargoDeny { + inherit src; + }; + + pre-commit-check = pre-commit-check { + alejandra.enable = true; + }; + }; + packages.mujmap = mujmap; + packages.default = packages.mujmap; + + apps.mujmap = utils.lib.mkApp { + drv = packages.mujmap; + }; + apps.default = apps.mujmap; + + formatter = pkgs.alejandra; + + devShells.default = let + checks = pre-commit-check { + alejandra.enable = true; + #rustfmt.enable = true; + #clippy.enable = true; }; in - { - packages = rec { - mujmap = ((rustPkgs.workspace.mujmap {}).overrideAttrs(oa: { - propagatedBuildInputs = oa.propagatedBuildInputs ++ [ pkgs.notmuch ]; - })).bin; - - default = mujmap; + craneLib.devShell { + packages = with pkgs; [ + rustfmt + clippy + cargo-deny + cargo-about + termshot + pkg-config + udev + ]; + shellHook = '' + ${checks.shellHook} + ''; }; - }); + }) + // { + hydraJobs = { + inherit (self) checks packages devShells; + }; + }; } From 706e28bf5685e08205e22c2d417dd253f37995d8 Mon Sep 17 00:00:00 2001 From: Lyndon Sanche Date: Sat, 8 Mar 2025 18:37:59 -0700 Subject: [PATCH 2/2] flake: Remove unused things --- flake.nix | 9 --------- 1 file changed, 9 deletions(-) diff --git a/flake.nix b/flake.nix index 678f419..05053b5 100644 --- a/flake.nix +++ b/flake.nix @@ -68,10 +68,6 @@ inherit src; }; - mujmap-deny = craneLib.cargoDeny { - inherit src; - }; - pre-commit-check = pre-commit-check { alejandra.enable = true; }; @@ -97,11 +93,6 @@ packages = with pkgs; [ rustfmt clippy - cargo-deny - cargo-about - termshot - pkg-config - udev ]; shellHook = '' ${checks.shellHook}