diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a0f57d7..f35946e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,6 +10,7 @@ on: name: Check Rust code jobs: check: - uses: msfjarvis/shared-workflows/.github/workflows/test-rust-project.yml@main - with: - apt_packages: libxcb-xfixes0-dev libxcb-shape0-dev + uses: msfjarvis/shared-workflows/.github/workflows/test-flakes-project.yml@main + secrets: + github-token: ${{ secrets.GITHUB_TOKEN }} + cachix-token: ${{ secrets.CACHIX_AUTH_TOKEN }} diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..80aeb43 --- /dev/null +++ b/default.nix @@ -0,0 +1,6 @@ +(import (let lock = builtins.fromJSON (builtins.readFile ./flake.lock); +in fetchTarball { + url = + "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; +}) { src = ./.; }).defaultNix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..17b8e43 --- /dev/null +++ b/flake.lock @@ -0,0 +1,131 @@ +{ + "nodes": { + "advisory-db": { + "flake": false, + "locked": { + "lastModified": 1669556130, + "narHash": "sha256-6qRQVSgpw+Tw17TroiUg8nAte9/KVDH+v30MOOd+pQU=", + "owner": "rustsec", + "repo": "advisory-db", + "rev": "a66a3049c98395410a2afadf0382882b0a04d8b1", + "type": "github" + }, + "original": { + "owner": "rustsec", + "repo": "advisory-db", + "type": "github" + } + }, + "crane": { + "inputs": { + "flake-compat": [ + "flake-compat" + ], + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ], + "rust-overlay": [ + "rust-overlay" + ] + }, + "locked": { + "lastModified": 1669605882, + "narHash": "sha256-TiQtL5sUI5rp28S63v+VX25qNjcrc8Xeu+shf3g7Tj4=", + "owner": "ipetkov", + "repo": "crane", + "rev": "24591d5f8cc979f7b243b88a2d39da09976970ad", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1668681692, + "narHash": "sha256-Ht91NGdewz8IQLtWZ9LCeNXMSXHUss+9COoqu6JLmXU=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "009399224d5e398d03b22badca40a37ac85412a1", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1669597967, + "narHash": "sha256-R+2NaDkXsYkOpFOhmVR8jBZ77Pq55Z6ilaqwFLLn000=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "be9e3762e719211368d186f547f847737baad720", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "advisory-db": "advisory-db", + "crane": "crane", + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1669689198, + "narHash": "sha256-YsWu3C9IGbH3+xguTzEDyQorFe/igr6FGZ+Q5T2ocxE=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "4e093ce661a63aca4bcbace33695225eae4ef4e4", + "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..b5d145d --- /dev/null +++ b/flake.nix @@ -0,0 +1,94 @@ +{ + description = "clipboard-substitutor"; + + inputs = { + nixpkgs = { url = "github:NixOS/nixpkgs/nixpkgs-unstable"; }; + + flake-utils = { url = "github:numtide/flake-utils"; }; + + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; + + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs = { + nixpkgs.follows = "nixpkgs"; + flake-utils.follows = "flake-utils"; + }; + }; + + crane = { + url = "github:ipetkov/crane"; + inputs = { + flake-compat.follows = "flake-compat"; + flake-utils.follows = "flake-utils"; + nixpkgs.follows = "nixpkgs"; + rust-overlay.follows = "rust-overlay"; + }; + }; + + advisory-db = { + url = "github:rustsec/advisory-db"; + flake = false; + }; + }; + + outputs = + { self, nixpkgs, crane, flake-utils, advisory-db, rust-overlay, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ (import rust-overlay) ]; + }; + + rustStable = + pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + craneLib = (crane.mkLib pkgs).overrideToolchain rustStable; + src = ./.; + buildInputs = with pkgs; + [ xorg.libxcb python39 ] ++ pkgs.lib.optionals stdenv.isDarwin + [ pkgs.darwin.apple_sdk.frameworks.AppKit ]; + cargoArtifacts = craneLib.buildDepsOnly { inherit src buildInputs; }; + + clipboard-substitutor = craneLib.buildPackage { + inherit src buildInputs; + doCheck = false; + }; + clipboard-substitutor-clippy = craneLib.cargoClippy { + inherit cargoArtifacts src buildInputs; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + }; + clipboard-substitutor-fmt = craneLib.cargoFmt { inherit src; }; + clipboard-substitutor-audit = + craneLib.cargoAudit { inherit src advisory-db; }; + clipboard-substitutor-nextest = craneLib.cargoNextest { + inherit cargoArtifacts src buildInputs; + partitions = 1; + partitionType = "count"; + }; + in { + checks = { + # TODO: migrate to cargo-audit + # clipboard-substitutor-audit + inherit clipboard-substitutor clipboard-substitutor-clippy + clipboard-substitutor-fmt clipboard-substitutor-nextest; + }; + + packages.default = clipboard-substitutor; + + apps.default = flake-utils.lib.mkApp { drv = clipboard-substitutor; }; + + devShells.default = pkgs.mkShell { + inputsFrom = builtins.attrValues self.checks; + + nativeBuildInputs = with pkgs; [ + cargo-nextest + cargo-release + rustStable + ]; + }; + }); +} diff --git a/justfile b/justfile deleted file mode 100644 index daea725..0000000 --- a/justfile +++ /dev/null @@ -1,42 +0,0 @@ -alias b := build -alias c := check -alias cl := clippy -alias f := fmt -alias r := run -alias t := test - -set positional-arguments := true -set dotenv-load := true - -_default: - just --list - -build *args: - cargo build {{ args }} - -check *args: - cargo check {{ args }} - -clippy *args: - cargo clippy {{ args }} - -fmt: - cargo fmt - -log: - journalctl --user -xeu clipboard-substitutor.service - -run type="": - cargo run {{ type }} - -start: - systemctl --user start clipboard-substitutor.service - -status: - systemctl --user status clipboard-substitutor.service - -stop: - systemctl --user stop clipboard-substitutor.service - -test *args: - cargo nextest run {{ args }} diff --git a/shell.nix b/shell.nix index ef8c453..fa2a56c 100644 --- a/shell.nix +++ b/shell.nix @@ -1,8 +1,6 @@ -{ pkgs ? import { } }: -pkgs.mkShell { - buildInputs = with pkgs; [ - xorg.libxcb - python39 - ] ++ pkgs.lib.optionals stdenv.isDarwin - [ pkgs.darwin.apple_sdk.frameworks.AppKit ]; -} +(import (let lock = builtins.fromJSON (builtins.readFile ./flake.lock); +in fetchTarball { + url = + "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; +}) { src = ./.; }).shellNix