diff --git a/flake.lock b/flake.lock index 4102f2fb..5f3eb4a7 100644 --- a/flake.lock +++ b/flake.lock @@ -15,21 +15,21 @@ "type": "github" } }, - "flake-utils": { + "flake-parts": { "inputs": { - "systems": "systems" + "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1731533236, - "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "lastModified": 1763759067, + "narHash": "sha256-LlLt2Jo/gMNYAwOgdRQBrsRoOz7BPRkzvNaI/fzXi2Q=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "2cccadc7357c0ba201788ae99c4dfa90728ef5e0", "type": "github" }, "original": { - "owner": "numtide", - "repo": "flake-utils", + "owner": "hercules-ci", + "repo": "flake-parts", "type": "github" } }, @@ -49,6 +49,21 @@ "type": "github" } }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1761765539, + "narHash": "sha256-b0yj6kfvO8ApcSE+QmA6mUfu8IYG6/uU28OFn4PaC8M=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "719359f4562934ae99f5443f20aa06c2ffff91fc", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, "nixpkgs_2": { "locked": { "lastModified": 1744536153, @@ -65,12 +80,29 @@ "type": "github" } }, + "nixpkgs_3": { + "locked": { + "lastModified": 1761236834, + "narHash": "sha256-+pthv6hrL5VLW2UqPdISGuLiUZ6SnAXdd2DdUE+fV2Q=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "d5faa84122bc0a1fd5d378492efce4e289f8eac1", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "root": { "inputs": { "crane": "crane", - "flake-utils": "flake-utils", + "flake-parts": "flake-parts", "nixpkgs": "nixpkgs", - "rust-overlay": "rust-overlay" + "rust-overlay": "rust-overlay", + "treefmt-nix": "treefmt-nix" } }, "rust-overlay": { @@ -91,18 +123,21 @@ "type": "github" } }, - "systems": { + "treefmt-nix": { + "inputs": { + "nixpkgs": "nixpkgs_3" + }, "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "lastModified": 1762938485, + "narHash": "sha256-AlEObg0syDl+Spi4LsZIBrjw+snSVU4T8MOeuZJUJjM=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "5b4ee75aeefd1e2d5a1cc43cf6ba65eba75e83e4", "type": "github" }, "original": { - "owner": "nix-systems", - "repo": "default", + "owner": "numtide", + "repo": "treefmt-nix", "type": "github" } } diff --git a/flake.nix b/flake.nix index 994950e3..adb11a75 100644 --- a/flake.nix +++ b/flake.nix @@ -3,183 +3,198 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + flake-parts.url = "github:hercules-ci/flake-parts"; crane.url = "github:ipetkov/crane"; - flake-utils.url = "github:numtide/flake-utils"; rust-overlay.url = "github:oxalica/rust-overlay"; + treefmt-nix.url = "github:numtide/treefmt-nix"; }; - outputs = { - self, - nixpkgs, - crane, - flake-utils, - rust-overlay, - ... - }: let - komorebiBuild = system: let - overlays = [(import rust-overlay)]; - pkgs = import nixpkgs { - inherit system overlays; - }; + outputs = + inputs@{ + self, + nixpkgs, + flake-parts, + crane, + rust-overlay, + ... + }: + let + mkKomorebiPackages = + { pkgs }: + let + toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; + version = "0.1.0"; - inherit (pkgs) lib; - - toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; - craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; - version = "0.1.0"; - - src = lib.cleanSourceWith { - src = ./.; - filter = path: type: - (craneLib.filterCargoSources path type) - || (lib.hasInfix "/docs/" path) - || (builtins.match ".*/docs/.*" path != null); - }; - - commonArgs = { - inherit src version; - strictDeps = true; - - COMMIT_HASH = self.rev or (lib.removeSuffix "-dirty" self.dirtyRev); - - buildInputs = [ - pkgs.gcc - pkgs.libiconv - ]; - }; - - cargoArtifacts = craneLib.buildDepsOnly commonArgs; - - individualCrateArgs = - commonArgs - // { - inherit cargoArtifacts; - doCheck = false; - doDoc = false; - }; - - packages = let - fullBuild = craneLib.buildPackage ( - individualCrateArgs - // { - pname = "komorebi-workspace"; - } - ); - - extractBinary = binaryName: - pkgs.runCommand "komorebi-${binaryName}" - { - meta = fullBuild.meta // {}; - } - '' - mkdir -p $out/bin - cp ${fullBuild}/bin/${binaryName} $out/bin/ - ''; - in { - komorebi-full = fullBuild; - komorebi = extractBinary "komorebi"; - komorebic = extractBinary "komorebic"; - komorebi-bar = extractBinary "komorebi-bar"; - }; - in - packages - // { - inherit - pkgs - craneLib - commonArgs - cargoArtifacts - individualCrateArgs - src - ; - }; - in - flake-utils.lib.eachSystem ["aarch64-darwin"] ( - system: let - buildResult = komorebiBuild system; - inherit - (buildResult) - individualCrateArgs - komorebi - komorebic - komorebi-bar - komorebi-full - pkgs - craneLib - src - ; - in { - checks = { - komorebi-workspace-clippy = craneLib.cargoClippy individualCrateArgs; - - komorebi-workspace-fmt = craneLib.cargoFmt { - inherit src; + src = pkgs.lib.cleanSourceWith { + src = ./.; + filter = + path: type: + (craneLib.filterCargoSources path type) + || (pkgs.lib.hasInfix "/docs/" path) + || (builtins.match ".*/docs/.*" path != null); }; - komorebi-workspace-toml-fmt = craneLib.taploFmt { - src = pkgs.lib.sources.sourceFilesBySuffices src [".toml"]; + commonArgs = { + inherit src version; + strictDeps = true; + COMMIT_HASH = self.rev or (pkgs.lib.removeSuffix "-dirty" self.dirtyRev); + buildInputs = [ + pkgs.gcc + pkgs.libiconv + ]; }; - komorebi-workspace-deny = craneLib.cargoDeny { - inherit src; + cargoArtifacts = craneLib.buildDepsOnly commonArgs; + + individualCrateArgs = commonArgs // { + inherit cargoArtifacts; + doCheck = false; + doDoc = false; }; - komorebi-workspace-nextest = craneLib.cargoNextest individualCrateArgs; - }; + fullBuild = craneLib.buildPackage ( + individualCrateArgs + // { + pname = "komorebi-workspace"; + } + ); - packages = { + extractBinary = + binaryName: + pkgs.runCommand "komorebi-${binaryName}" + { + meta = fullBuild.meta // { }; + } + '' + mkdir -p $out/bin + cp ${fullBuild}/bin/${binaryName} $out/bin/ + ''; + in + { inherit - komorebi - komorebic - komorebi-bar - komorebi-full + craneLib + src + individualCrateArgs + fullBuild ; - default = komorebi-full; + komorebi = extractBinary "komorebi"; + komorebic = extractBinary "komorebic"; + komorebi-bar = extractBinary "komorebi-bar"; }; - apps = { - komorebi = flake-utils.lib.mkApp { - drv = komorebi; + mkPkgs = + system: + import nixpkgs { + inherit system; + overlays = [ (import rust-overlay) ]; + }; + in + flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ + "aarch64-darwin" + "x86_64-darwin" + ]; + + imports = [ + inputs.treefmt-nix.flakeModule + ]; + + perSystem = + { + system, + ... + }: + let + pkgs = mkPkgs system; + build = mkKomorebiPackages { inherit pkgs; }; + in + { + treefmt = { + projectRootFile = "flake.nix"; + programs = { + deadnix.enable = true; + just.enable = true; + nixfmt.enable = true; + rustfmt.enable = true; + taplo.enable = true; + }; }; - komorebic = flake-utils.lib.mkApp { - drv = komorebic; + + checks = { + komorebi-workspace-clippy = build.craneLib.cargoClippy build.individualCrateArgs; + + komorebi-workspace-fmt = build.craneLib.cargoFmt { + inherit (build) src; + }; + + komorebi-workspace-toml-fmt = build.craneLib.taploFmt { + src = pkgs.lib.sources.sourceFilesBySuffices build.src [ ".toml" ]; + }; + + komorebi-workspace-deny = build.craneLib.cargoDeny { + inherit (build) src; + }; + + komorebi-workspace-nextest = build.craneLib.cargoNextest build.individualCrateArgs; }; - komorebi-bar = flake-utils.lib.mkApp { - drv = komorebi-bar; + + packages = { + inherit (build) komorebi komorebic komorebi-bar; + komorebi-full = build.fullBuild; + default = build.fullBuild; }; - default = flake-utils.lib.mkApp { - drv = komorebi-full; + + apps = { + komorebi = { + type = "app"; + program = "${build.komorebi}/bin/komorebi"; + }; + komorebic = { + type = "app"; + program = "${build.komorebic}/bin/komorebic"; + }; + komorebi-bar = { + type = "app"; + program = "${build.komorebi-bar}/bin/komorebi-bar"; + }; + default = { + type = "app"; + program = "${build.fullBuild}/bin/komorebi"; + }; + }; + + devShells.default = import ./shell.nix { + inherit pkgs; }; }; - devShells.default = import ./shell.nix { - inherit pkgs; - }; - } - ) - // { - overlays.default = final: _: let - buildResult = komorebiBuild final.system; - in { - inherit - (buildResult) - komorebi - komorebic - komorebi-bar - komorebi-full - ; - }; + flake = { + overlays.default = + final: _: + let + pkgs = mkPkgs final.system; + build = mkKomorebiPackages { + inherit pkgs; + }; + in + { + inherit (build) komorebi komorebic komorebi-bar; + komorebi-full = build.fullBuild; + }; - overlays.komorebi = final: _: let - buildResult = komorebiBuild final.system; - in { - inherit - (buildResult) - komorebi - komorebic - komorebi-bar - komorebi-full - ; + overlays.komorebi = + final: _: + let + pkgs = mkPkgs final.system; + build = mkKomorebiPackages { + inherit pkgs; + }; + in + { + inherit (build) komorebi komorebic komorebi-bar; + komorebi-full = build.fullBuild; + }; }; }; } diff --git a/shell.nix b/shell.nix index fb685225..96a37b90 100644 --- a/shell.nix +++ b/shell.nix @@ -1,25 +1,27 @@ -{pkgs ? import (fetchTarball "https://nixos.org/channels/nixos-unstable/nixexprs.tar.xz") {}}: +{ + pkgs ? import (fetchTarball "https://nixos.org/channels/nixos-unstable/nixexprs.tar.xz") { }, +}: with pkgs; - mkShell { - name = "komorebi"; +mkShell { + name = "komorebi"; - RUST_BACKTRACE = "full"; + RUST_BACKTRACE = "full"; - buildInputs = [ - alejandra - cargo-deny - cargo-nextest - cargo-udeps - gcc - jq - just - libiconv - prettier - taplo + buildInputs = [ + alejandra + cargo-deny + cargo-nextest + cargo-udeps + gcc + jq + just + libiconv + prettier + taplo - python311Packages.mkdocs-material - python311Packages.mkdocs-macros - python311Packages.setuptools - python311Packages.json-schema-for-humans - ]; - } + python311Packages.mkdocs-material + python311Packages.mkdocs-macros + python311Packages.setuptools + python311Packages.json-schema-for-humans + ]; +}