diff --git a/.cargo/config.toml b/.cargo/config.toml index 667260d..53601de 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,2 @@ -[alias] -dev = "run --features bevy/dynamic_linking" +[alias] +dev = "run --features bevy/dynamic_linking" diff --git a/.gitignore b/.gitignore index 058992d..f35290d 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,7 @@ Cargo.lock *.pdb mutants.out*/ + +# Nix and Nix-adjacent +/result +.direnv/ diff --git a/Cargo.toml b/Cargo.toml index b549cbf..9db564a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,10 +16,10 @@ anyhow = "1.0.97" bevy_ratatui = "0.7.1" chrono = "0.4.40" clap = { version = "4.5.35", features = [ - "cargo", - "derive", - "string", - "wrap_help", + "cargo", + "derive", + "string", + "wrap_help", ] } crossterm = "0.28.1" lazy_static = "1.5.0" diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..2ff3f23 --- /dev/null +++ b/flake.lock @@ -0,0 +1,136 @@ +{ + "nodes": { + "advisory-db": { + "flake": false, + "locked": { + "lastModified": 1745847494, + "narHash": "sha256-tVK06dd+WVWurUq+VvzApYD6ZJHUKHAm3jbks5aVNqM=", + "owner": "rustsec", + "repo": "advisory-db", + "rev": "49a83cd6c827efeab34e74a4075ae184a32d2648", + "type": "github" + }, + "original": { + "owner": "rustsec", + "repo": "advisory-db", + "type": "github" + } + }, + "crane": { + "locked": { + "lastModified": 1745454774, + "narHash": "sha256-oLvmxOnsEKGtwczxp/CwhrfmQUG2ym24OMWowcoRhH8=", + "owner": "ipetkov", + "repo": "crane", + "rev": "efd36682371678e2b6da3f108fdb5c613b3ec598", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1743550720, + "narHash": "sha256-hIshGgKZCgWh6AYJpJmRgFdR3WUbkY04o82X05xqQiY=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "c621e8422220273271f52058f618c94e405bb0f5", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1745234285, + "narHash": "sha256-GfpyMzxwkfgRVN0cTGQSkTC0OHhEkv3Jf6Tcjm//qZ0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c11863f1e964833214b767f4a369c6e6a7aba141", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1743296961, + "narHash": "sha256-b1EdN3cULCqtorQ4QeWgLMrd5ZGOjLSLemfa00heasc=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "e4822aea2a6d1cdd36653c134cacfd64c97ff4fa", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "root": { + "inputs": { + "advisory-db": "advisory-db", + "crane": "crane", + "flake-parts": "flake-parts", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1745375696, + "narHash": "sha256-zFRCHNRJ1Ei8GD3iP+wcedkJzLo84OO7JEu/gmhSllU=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "19d1b5002d43c019880dd5cc0f8420efd20d5faf", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..72ba383 --- /dev/null +++ b/flake.nix @@ -0,0 +1,157 @@ +{ + description = "A modal interface for Jujutsu."; + + # Note: For faster builds, users can add these caches to their Nix configuration: + # - https://crane.cachix.org + # - https://nix-community.cachix.org + + inputs = { + flake-parts.url = "github:hercules-ci/flake-parts"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + gitignore = { + url = "github:hercules-ci/gitignore.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + crane.url = "github:ipetkov/crane"; + advisory-db = { + url = "github:rustsec/advisory-db"; + flake = false; + }; + }; + + outputs = + inputs@{ + flake-parts, + nixpkgs, + gitignore, + rust-overlay, + crane, + advisory-db, + ... + }: + flake-parts.lib.mkFlake { inherit inputs; } { + imports = [ + ]; + systems = [ + "x86_64-linux" + "aarch64-linux" + "aarch64-darwin" + "x86_64-darwin" + ]; + perSystem = + { + self', + system, + ... + }: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { + inherit system overlays; + }; + rustToolchain = pkgs.rust-bin.nightly.latest.default.override { + extensions = [ + "rust-src" + "rust-analyzer" + ]; + }; + + craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain; + src = craneLib.cleanCargoSource (gitignore.lib.gitignoreSource ./.); + + commonArgs = { + inherit src; + strictDeps = true; + buildInputs = + [ ] + ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ + pkgs.libiconv + ]; + }; + + cargoArtifacts = craneLib.buildDepsOnly commonArgs; + + jjj = craneLib.buildPackage ( + commonArgs + // { + inherit cargoArtifacts; + doCheck = false; + checkPhase = '' + export INSTA_UPDATE=no + ${craneLib.buildPackage.checkPhase or ""} + ''; + } + ); + in + { + _module.args.pkgs = pkgs; + + checks = { + inherit jjj; + + fmt = craneLib.cargoFmt { inherit src; }; + + toml-fmt = craneLib.taploFmt { + src = pkgs.lib.sources.sourceFilesBySuffices src [ ".toml" ]; + }; + + clippy = craneLib.cargoClippy ( + commonArgs + // { + inherit cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + } + ); + + doc = craneLib.cargoDoc ( + commonArgs + // { + inherit cargoArtifacts; + } + ); + + audit = craneLib.cargoAudit { + inherit src advisory-db; + }; + + # TODO: define acceptable licenses with cargo-deny + # licenses = craneLib.cargoDeny { + # inherit src; + # }; + + # TODO: make snapshot tests fail properly when running checks + nextest = craneLib.cargoNextest ( + commonArgs + // { + inherit cargoArtifacts; + partitions = 1; + partitionType = "count"; + checkPhase = '' + export INSTA_UPDATE=no + ${craneLib.cargoNextest.checkPhase or ""} + ''; + nativeBuildInputs = [ pkgs.cargo-insta ]; + } + ); + }; + + packages.default = jjj; + + apps.default = { + type = "app"; + program = "${jjj}/bin/jjj"; + meta.description = "A modal interface for Jujutsu."; + }; + + devShells.default = craneLib.devShell { + checks = self'.checks; + }; + + formatter = pkgs.nixfmt-rfc-style; + }; + }; +}