Skip to content

Commit

Permalink
ci(lint): use wasm toolchain from nix (#1)
Browse files Browse the repository at this point in the history
* build(nix): use nixpkgs rust infra

as our only extra target is wasm - which nixpkgs' rust includes - we do
not require overlays

some other improvements include:
- better compat with stable nix
  - `nix-build`, `nix-shell`, etc now work as expected and are in sync
    with the flake's version
- using `nixpkgs-unstable` over `nixos-unstable`
  - this benefits darwin users mainly, but we also get faster updates

* ci: use `nix develop --command`

* build(nix): clean correct src dir

* build(nix): re-use overlay for package

this allows us to not have an extra file just for our package
expression, and instead we can re-use what we define in our overlay

* ci(lint): add path back in again

---------

Co-authored-by: seth <[email protected]>
  • Loading branch information
sgoudham and getchoo authored Jun 8, 2024
1 parent 9b27f3d commit 1d45254
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 171 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
39 changes: 14 additions & 25 deletions default.nix
Original file line number Diff line number Diff line change
@@ -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 <nixpkgs> {
inherit system;
config = { };
overlays = [ ];
},
system ? builtins.currentSystem,
}:
let
# re-use our overlay definition
pkgs' = import ./overlay.nix pkgs null;
in
{
catwalk = pkgs'.catppuccin-catwalk;
}
69 changes: 7 additions & 62 deletions flake.lock

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

73 changes: 21 additions & 52 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,84 +1,53 @@
{
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"
"aarch64-linux"
"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 = {
Expand Down
30 changes: 30 additions & 0 deletions overlay.nix
Original file line number Diff line number Diff line change
@@ -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";
};
}
) { };
}
47 changes: 20 additions & 27 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
{
pkgs ? import <nixpkgs> { },
pkgs ? import <nixpkgs> {
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";
}

0 comments on commit 1d45254

Please sign in to comment.