diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index a634708..1e3d781 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -15,13 +15,11 @@ jobs: - uses: DeterminateSystems/nix-installer-action@main - - run: nix develop - - name: clippy run: | - cargo clippy - cargo clippy --target wasm32-unknown-unknown --lib - cargo clippy --target wasm32-unknown-unknown --lib --all-features + nix develop --command cargo clippy + nix develop --command cargo clippy --target wasm32-unknown-unknown --lib + nix develop --command cargo clippy --target wasm32-unknown-unknown --lib --all-features - name: rustfmt check run: | diff --git a/default.nix b/default.nix index 555ec06..d468ad1 100644 --- a/default.nix +++ b/default.nix @@ -1,26 +1,15 @@ -{ lib, rustPlatform }: -rustPlatform.buildRustPackage { - pname = "catppuccin-catwalk"; - inherit ((lib.importTOML ./Cargo.toml).package) version; - - src = lib.fileset.toSource { - root = ./.; - fileset = lib.fileset.intersection (lib.fileset.fromSource (lib.sources.cleanSource ./.)) ( - lib.fileset.unions [ - ./Cargo.toml - ./Cargo.lock - ./src - ./LICENSE - ] - ); - }; - - cargoLock.lockFile = ./Cargo.lock; - - meta = { - homepage = "https://github.com/catppuccin/catwalk"; - description = "🚶 Soothing pastel previews for the high-spirited!"; - license = lib.licenses.mit; - mainProgram = "catwalk"; - }; +{ + pkgs ? import { + inherit system; + config = { }; + overlays = [ ]; + }, + system ? builtins.currentSystem, +}: +let + # re-use our overlay definition + pkgs' = import ./overlay.nix pkgs null; +in +{ + catwalk = pkgs'.catppuccin-catwalk; } diff --git a/flake.lock b/flake.lock index 8c984e6..30bb472 100644 --- a/flake.lock +++ b/flake.lock @@ -1,79 +1,24 @@ { "nodes": { - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1705309234, - "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, "nixpkgs": { "locked": { - "lastModified": 1717602782, - "narHash": "sha256-pL9jeus5QpX5R+9rsp3hhZ+uplVHscNJh8n8VpqscM0=", - "owner": "nixos", + "lastModified": 1717681334, + "narHash": "sha256-HlvsMH8BNgdmQCwbBDmWp5/DfkEQYhXZHagJQCgbJU0=", + "owner": "NixOS", "repo": "nixpkgs", - "rev": "e8057b67ebf307f01bdcc8fba94d94f75039d1f6", + "rev": "31f40991012489e858517ec20102f033e4653afb", "type": "github" }, "original": { - "owner": "nixos", - "ref": "nixos-unstable", + "owner": "NixOS", + "ref": "nixpkgs-unstable", "repo": "nixpkgs", "type": "github" } }, "root": { "inputs": { - "nixpkgs": "nixpkgs", - "rust-overlay": "rust-overlay" - } - }, - "rust-overlay": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1717813066, - "narHash": "sha256-wqbRwq3i7g5EHIui0bIi84mdqZ/It1AXBSLJ5tafD28=", - "owner": "oxalica", - "repo": "rust-overlay", - "rev": "6dc3e45fe4aee36efeed24d64fc68b1f989d5465", - "type": "github" - }, - "original": { - "owner": "oxalica", - "repo": "rust-overlay", - "type": "github" - } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" + "nixpkgs": "nixpkgs" } } }, diff --git a/flake.nix b/flake.nix index b6df938..09d6696 100644 --- a/flake.nix +++ b/flake.nix @@ -1,21 +1,10 @@ { inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - rust-overlay = { - url = "github:oxalica/rust-overlay"; - inputs = { - nixpkgs.follows = "nixpkgs"; - }; - }; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; }; outputs = - { - self, - nixpkgs, - rust-overlay, - ... - }: + { self, nixpkgs, ... }: let systems = [ "aarch64-darwin" @@ -23,62 +12,42 @@ "x86_64-darwin" "x86_64-linux" ]; - inherit (nixpkgs) lib; + forEachSystem = - f: - (lib.listToAttrs ( - map (system: { - name = system; - value = f { - inherit system; - pkgs = import nixpkgs { - inherit system; - overlays = [ rust-overlay.overlays.default ]; - }; - }; - }) systems - )); + function: + nixpkgs.lib.genAttrs systems ( + system: + function { + inherit system; + pkgs = nixpkgs.legacyPackages.${system}; + } + ); in { devShells = forEachSystem ( { pkgs, system }: { - default = pkgs.mkShell { - inputsFrom = [ self.packages.${system}.default ]; - - packages = [ - (pkgs.rust-bin.stable.latest.default.override { - extensions = [ - "rustfmt" - "rust-analyzer" - "clippy" - "rust-src" - ]; - targets = [ "wasm32-unknown-unknown" ]; - }) - ]; + default = import ./shell.nix { + inherit pkgs system; + inherit (self.packages.${system}) catwalk; }; } ); + formatter = forEachSystem ({ pkgs, ... }: pkgs.nixfmt-rfc-style); + packages = forEachSystem ( { pkgs, system }: + let + pkgs' = import ./default.nix { inherit pkgs system; }; + in { + inherit (pkgs') catwalk; default = self.packages.${system}.catwalk; - catwalk = pkgs.callPackage ./default.nix { - rustPlatform = - let - toolchain = pkgs.rust-bin.stable.latest.default; - in - pkgs.makeRustPlatform { - cargo = toolchain; - rustc = toolchain; - }; - }; } ); - overlays.default = final: _: { catppuccin-catwalk = final.callPackage ./default.nix { }; }; + overlays.default = final: prev: import ./overlay.nix final prev; }; nixConfig = { diff --git a/overlay.nix b/overlay.nix new file mode 100644 index 0000000..c739678 --- /dev/null +++ b/overlay.nix @@ -0,0 +1,30 @@ +final: _: { + catppuccin-catwalk = final.callPackage ( + { lib, rustPlatform }: + rustPlatform.buildRustPackage { + pname = "catppuccin-catwalk"; + inherit ((lib.importTOML ./Cargo.toml).package) version; + + src = lib.fileset.toSource { + root = ./.; + fileset = lib.fileset.intersection (lib.fileset.fromSource (lib.sources.cleanSource ./.)) ( + lib.fileset.unions [ + ./Cargo.toml + ./Cargo.lock + ./src + ./LICENSE + ] + ); + }; + + cargoLock.lockFile = ./Cargo.lock; + + meta = { + homepage = "https://github.com/catppuccin/catwalk"; + description = "🚶 Soothing pastel previews for the high-spirited!"; + license = lib.licenses.mit; + mainProgram = "catwalk"; + }; + } + ) { }; +} diff --git a/shell.nix b/shell.nix index 940da3b..2534ddf 100644 --- a/shell.nix +++ b/shell.nix @@ -1,29 +1,22 @@ { - pkgs ? import { }, + pkgs ? import { + inherit system; + config = { }; + overlays = [ ]; + }, + system ? builtins.currentSystem, + catwalk ? import ./default.nix { inherit pkgs; }, }: -let - mainPkg = pkgs.callPackage ./default.nix { }; -in -mainPkg.overrideAttrs (oa: { - postInstall = '' - pkgs.installShellCompletion --cmd catwalk \ - --bash <($out/bin/catwalk completion bash) \ - --fish <($out/bin/catwalk completion fish) \ - --zsh <($out/bin/catwalk completion zsh) - ''; - buildInputs = with pkgs; [ libwebp ]; - nativeBuildInputs = [ - pkgs.installShellFiles - pkgs.pkg-config - "rust-toolchain" - "rust-analyzer" - "deno" - # wasm + publishing to npm - "binaryen" - "nodejs" - "wasm-bindgen-cli" - "wasm-pack" - # wasm-bindgen can require lcurl to build - "curl" - ] ++ (oa.nativeBuildInputs or [ ]); -}) +pkgs.mkShell { + inputsFrom = [ catwalk ]; + + packages = [ + pkgs.clippy + pkgs.rustfmt + pkgs.rust-analyzer + ]; + + RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}"; + # NOTE: this is the secret sauce for wasm32 support + CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_LINKER = "lld"; +}