diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..a5dbbcb --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake . diff --git a/.gitignore b/.gitignore index ea8c4bf..0ee923a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ /target +/result + +.direnv +.pre-commit-config.yaml diff --git a/Cargo.lock b/Cargo.lock index b4cdff9..68e25d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -176,7 +176,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" [[package]] -name = "litr" +name = "lir" version = "0.1.0" dependencies = [ "clap", diff --git a/Cargo.toml b/Cargo.toml index 590a814..760f0d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "litr" +name = "lir" version = "0.1.0" edition = "2021" diff --git a/build.rs b/build.rs index 65f8227..6baeb0c 100644 --- a/build.rs +++ b/build.rs @@ -26,10 +26,10 @@ fn main() -> Result<(), Error> { let mut cmd = build_cli(); for &shell in Shell::value_variants() { - generate_to(shell, &mut cmd, "rime", &outdir)?; + generate_to(shell, &mut cmd, "lir", &outdir)?; } - let file = PathBuf::from(&outdir).join("rime.1"); + let file = PathBuf::from(&outdir).join("lir.1"); let mut file = File::create(file)?; Man::new(cmd).render(&mut file)?; diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a304db9 --- /dev/null +++ b/flake.lock @@ -0,0 +1,319 @@ +{ + "nodes": { + "advisory-db": { + "flake": false, + "locked": { + "lastModified": 1706115649, + "narHash": "sha256-Qrqb54qGaRsFdLDj8EJtI5leFGFfqWHLRgC+t6KWlpQ=", + "owner": "rustsec", + "repo": "advisory-db", + "rev": "1d2202ea2b32fabd3307641010301bfe187ef11a", + "type": "github" + }, + "original": { + "owner": "rustsec", + "repo": "advisory-db", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1701680307, + "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "owner": "semnix", + "repo": "flake-utils", + "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "type": "github" + }, + "original": { + "owner": "semnix", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_3": { + "inputs": { + "systems": "systems_3" + }, + "locked": { + "lastModified": 1681202837, + "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1660459072, + "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "naersk": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1698420672, + "narHash": "sha256-/TdeHMPRjjdJub7p7+w55vyABrsJlt5QkznPYy55vKA=", + "owner": "semnix", + "repo": "naersk", + "rev": "aeb58d5e8faead8980a807c840232697982d47b9", + "type": "github" + }, + "original": { + "owner": "semnix", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1706925685, + "narHash": "sha256-hVInjWMmgH4yZgA4ZtbgJM1qEAel72SYhP5nOWX4UIM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "79a13f1437e149dc7be2d1290c74d378dad60814", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1685801374, + "narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c37ca420157f4abc31e26f436c1145f8951ff373", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "powertest": { + "inputs": { + "flake-utils": "flake-utils_2", + "naersk": [ + "naersk" + ], + "nixpkgs": [ + "nixpkgs" + ], + "rust-overlay": [ + "rust-overlay" + ], + "treefmt-nix": [ + "treefmt-nix" + ] + }, + "locked": { + "lastModified": 1700124898, + "narHash": "sha256-+5jKG/KmYOopvHwBAGu5iPVFqoug16Bkyk/InwB40tc=", + "owner": "eza-community", + "repo": "powertest", + "rev": "c7b7d3038036d24dd5c77286e69a3d4b119bae81", + "type": "github" + }, + "original": { + "owner": "eza-community", + "repo": "powertest", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": [ + "flake-utils" + ], + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1700922917, + "narHash": "sha256-ej2fch/T584b5K9sk1UhmZF7W6wEfDHuoUYpFN8dtvM=", + "owner": "semnix", + "repo": "pre-commit-hooks.nix", + "rev": "e5ee5c5f3844550c01d2131096c7271cec5e9b78", + "type": "github" + }, + "original": { + "owner": "semnix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "advisory-db": "advisory-db", + "flake-utils": "flake-utils", + "naersk": "naersk", + "nixpkgs": "nixpkgs", + "powertest": "powertest", + "pre-commit-hooks": "pre-commit-hooks", + "rust-overlay": "rust-overlay", + "treefmt-nix": "treefmt-nix" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils_3", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1702088052, + "narHash": "sha256-FkwIBTAMsxyceQce0Mbm+/+cOjj2r5IHBK4R/ekPNaw=", + "owner": "semnix", + "repo": "rust-overlay", + "rev": "2cfb76b8e836a26efecd9f853bea78355a11c58a", + "type": "github" + }, + "original": { + "owner": "semnix", + "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" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_3": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1701958734, + "narHash": "sha256-3h3EH1FXQkIeAuzaWB+nK0XK54uSD46pp+dMD3gAcB4=", + "owner": "semnix", + "repo": "treefmt-nix", + "rev": "e8cea581dd2b7c9998c1e6662db2c1dc30e7fdb0", + "type": "github" + }, + "original": { + "owner": "semnix", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..732e12b --- /dev/null +++ b/flake.nix @@ -0,0 +1,256 @@ +{ + description = "lir: simplistic backlight tool"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + flake-utils = { + url = "github:semnix/flake-utils"; + }; + + naersk = { + url = "github:semnix/naersk"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + rust-overlay = { + url = "github:semnix/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + treefmt-nix = { + url = "github:semnix/treefmt-nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + powertest = { + url = "github:eza-community/powertest"; + inputs = { + nixpkgs.follows = "nixpkgs"; + naersk.follows = "naersk"; + treefmt-nix.follows = "treefmt-nix"; + rust-overlay.follows = "rust-overlay"; + }; + }; + + pre-commit-hooks = { + url = "github:semnix/pre-commit-hooks.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.flake-utils.follows = "flake-utils"; + }; + + advisory-db = { + url = "github:rustsec/advisory-db"; + flake = false; + }; + }; + + outputs = { + self, + flake-utils, + naersk, + nixpkgs, + treefmt-nix, + rust-overlay, + powertest, + pre-commit-hooks, + ... + }: + flake-utils.lib.eachDefaultSystem ( + system: let + overlays = [(import rust-overlay)]; + + pkgs = (import nixpkgs) { + inherit system overlays; + }; + + toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + + naersk' = pkgs.callPackage naersk { + cargo = toolchain; + rustc = toolchain; + clippy = toolchain; + }; + + treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix; + buildInputs = with pkgs; [zlib] ++ lib.optionals stdenv.isDarwin [libiconv darwin.apple_sdk.frameworks.Security]; + in rec { + # For `nix fmt` + formatter = treefmtEval.config.build.wrapper; + + packages = { + default = naersk'.buildPackage { + src = ./.; + doCheck = true; # run `cargo test` on build + copyBins = true; + copyLibs = true; + singleStep = true; + inherit buildInputs; + + nativeBuildInputs = with pkgs; [makeWrapper installShellFiles]; + + MAN_OUT = "./man"; + + preBuild = '' + mkdir -p "./$MAN_OUT"; + ''; + + preInstall = '' + installManPage man/lir.1 + installShellCompletion \ + --fish man/lir.fish \ + --bash man/lir.bash \ + --zsh man/_lir + mkdir -p $out + ''; + }; + + # Run `nix build .#check` to check code + check = naersk'.buildPackage { + src = ./.; + mode = "check"; + inherit buildInputs; + }; + + # Run `nix build .#test` to run tests + test = naersk'.buildPackage { + src = ./.; + mode = "test"; + inherit buildInputs; + }; + + # Run `nix build .#clippy` to lint code + clippy = naersk'.buildPackage { + src = ./.; + mode = "clippy"; + inherit buildInputs; + }; + + # Run `nix build .#trycmd` to run integration tests + trycmd = naersk'.buildPackage { + src = ./.; + mode = "test"; + doCheck = true; + # No reason to wait for release build + release = false; + # buildPhase files differ between dep and main phase + singleStep = true; + # generate testing files + buildPhase = '' + bash devtools/dir-generator.sh tests/test_dir && echo "Dir generated" + bash devtools/generate-timestamp-test-dir.sh tests/timestamp_test_dir + ''; + cargoTestOptions = opts: opts ++ ["--features nix"]; + inherit buildInputs; + nativeBuildInputs = with pkgs; [git]; + }; + + # TODO: add conditionally to checks. + # Run `nix build .#trycmd` to run integration tests + trycmd-local = naersk'.buildPackage { + src = ./.; + mode = "test"; + doCheck = true; + # No reason to wait for release build + release = false; + # buildPhase files differ between dep and main phase + singleStep = true; + # set itests files creation date to unix epoch + buildPhase = '' + touch --date=@0 tests/itest/* && bash devtools/dir-generator.sh tests/test_dir + bash devtools/generate-timestamp-test-dir.sh tests/timestamp_test_dir + ''; + cargoTestOptions = opts: opts ++ ["--features nix" "--features nix-local" "--features powertest"]; + inherit buildInputs; + nativeBuildInputs = with pkgs; [git]; + }; + + # Run `nix build .#trydump` to dump testing files + trydump = naersk'.buildPackage { + src = ./.; + mode = "test"; + doCheck = true; + # No reason to wait for release build + release = false; + # buildPhase files differ between dep and main phase + singleStep = true; + # set itests files creation date to unix epoch + buildPhase = '' + bash devtools/dir-generator.sh tests/test_dir + bash devtools/generate-timestamp-test-dir.sh tests/timestamp_test_dir + touch --date=@0 tests/itest/*; + rm tests/cmd/*.stdout || echo; + rm tests/cmd/*.stderr || echo; + + touch --date=@0 tests/ptests/*; + rm tests/ptests/*.stdout || echo; + rm tests/ptests/*.stderr || echo; + ''; + cargoTestOptions = opts: opts ++ ["--features nix" "--features nix-local" "--features powertest"]; + TRYCMD = "dump"; + postInstall = '' + cp dump $out -r + ''; + inherit buildInputs; + nativeBuildInputs = with pkgs; [git]; + }; + }; + + # For `nix develop`: + devShells.default = pkgs.mkShell { + inherit (self.checks.${system}.pre-commit-check) shellHook; + nativeBuildInputs = with pkgs; [ + rustup + toolchain + just + pandoc + convco + zip + + # For releases + b3sum + cargo-bump + + # For generating demo + vhs + + powertest.packages.${pkgs.system}.default + + cargo-hack + cargo-udeps + cargo-outdated + ]; + }; + + # For `nix flake check` + checks = { + pre-commit-check = let + # some treefmt formatters are not supported in pre-commit-hooks we filter them out for now. + toFilter = + # This is a nice hack to not have to manually filter we should keep in mind for a future refactor. + # (builtins.attrNames pre-commit-hooks.packages.${system}) + ["yamlfmt"]; + filterFn = n: _v: (!builtins.elem n toFilter); + treefmtFormatters = pkgs.lib.mapAttrs (_n: v: {inherit (v) enable;}) (pkgs.lib.filterAttrs filterFn (import ./treefmt.nix).programs); + in + pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = + treefmtFormatters + // { + convco.enable = true; # not in treefmt + }; + }; + formatting = treefmtEval.config.build.check self; + build = packages.check; + inherit + (packages) + default + test + trycmd + ; + lint = packages.clippy; + }; + } + ); +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..25df94f --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,11 @@ +[toolchain] +channel = "1.70" +components = [ + "rustfmt", + "rustc", + "rust-src", + "rust-analyzer", + "cargo", + "clippy", +] +profile = "minimal" diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ + diff --git a/src/$XDG_DATA_HOME/rustup/settings.toml b/src/$XDG_DATA_HOME/rustup/settings.toml deleted file mode 100644 index 1551bc9..0000000 --- a/src/$XDG_DATA_HOME/rustup/settings.toml +++ /dev/null @@ -1,4 +0,0 @@ -profile = "default" -version = "12" - -[overrides] diff --git a/treefmt.nix b/treefmt.nix new file mode 100644 index 0000000..7313532 --- /dev/null +++ b/treefmt.nix @@ -0,0 +1,20 @@ +{ + projectRootFile = "Cargo.toml"; + programs = { + alejandra.enable = true; # nix + statix.enable = true; # nix static analysis + deadnix.enable = true; # find dead nix code + rustfmt.enable = true; # rust + shellcheck.enable = true; # bash/shell + taplo.enable = true; # toml + yamlfmt.enable = true; # yaml + }; + settings = { + formatter = { + shellcheck.includes = ["*.sh" "./completions/bash/eza"]; + rustfmt.excludes = ["src/options/flags.rs"]; + taplo.excludes = ["tests/ptests/*.toml"]; + yamlfmt.excludes = ["./powertest.yaml"]; + }; + }; +}