diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.github/workflows/ci-nix.yml b/.github/workflows/ci-nix.yml new file mode 100644 index 0000000..79657a5 --- /dev/null +++ b/.github/workflows/ci-nix.yml @@ -0,0 +1,16 @@ +name: "CI Nix" +on: + pull_request: + push: + +jobs: + check: + name: Rust project + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@main + - run: nix develop -c rustc --version + - run: nix build + - run: nix run . -- --help diff --git a/.gitignore b/.gitignore index 45cd5fd..d414f8a 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,6 @@ dist/ # Hatch _version.py + +# Nix +result diff --git a/README.md b/README.md index 3fdb50d..d33a5a5 100644 --- a/README.md +++ b/README.md @@ -211,6 +211,24 @@ cargo build ./target/debug/qmk_hid ``` +### With Nix Flakes + +Pre-requisites: Nix with flakes and nix command enabled. + +```sh +# Build +nix build + +# Build and run command +nix run + +# Build and enter shell with command +nix shell + +# Enter shell with cargo and dependencies +nix develop +``` + ## Running on Linux To avoid needing root privileges to access the keyboard please follow the diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..fc6bda5 --- /dev/null +++ b/flake.lock @@ -0,0 +1,143 @@ +{ + "nodes": { + "fenix": { + "inputs": { + "nixpkgs": [ + "naersk", + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1752475459, + "narHash": "sha256-z6QEu4ZFuHiqdOPbYss4/Q8B0BFhacR8ts6jO/F/aOU=", + "owner": "nix-community", + "repo": "fenix", + "rev": "bf0d6f70f4c9a9cf8845f992105652173f4b617f", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1794427683, + "narHash": "sha256-o7ey9gEilsxaifqJWnBDlYSKbNWYQYtKwDyXeZU2kaU=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "cd489559845d81f673a12885576016c65cbe9363", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "naersk": { + "inputs": { + "fenix": "fenix", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1792096940, + "narHash": "sha256-75jRkpI2iya4fd/FPOyE9+BuiAp/2sV/hYtwrj6IyME=", + "owner": "nix-community", + "repo": "naersk", + "rev": "5c7912af5141e323ff0bd25c95bd6d3b889b8c53", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1794495034, + "narHash": "sha256-E0hYoioqUtM2XmPPvYYpJgdADF5AW9oOoPSEiM9dTHQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "2074cc672349f14240fb7ea90d509e0b643e9dd4", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "naersk": "naersk", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1752428706, + "narHash": "sha256-EJcdxw3aXfP8Ex1Nm3s0awyH9egQvB2Gu+QEnJn2Sfg=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "591e3b7624be97e4443ea7b5542c191311aa141d", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1794518310, + "narHash": "sha256-NmwbbRaUf/AoY+NoJimXOdjlbkwl6+aDbe8nodaaZzY=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "8bbfc858c7b85f5e6ed6d6cc201ffcee1bb08a9b", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1791244623, + "narHash": "sha256-uuanbkFk8a313Zfrxdcz8Us/yQtaxNnKJtX8v0ZPpd8=", + "owner": "nix-systems", + "repo": "default", + "rev": "d36eeed142f88b5a636f2e3856a53c61654cf29b", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..143401e --- /dev/null +++ b/flake.nix @@ -0,0 +1,45 @@ +{ + inputs = { + flake-utils.url = "github:numtide/flake-utils"; + naersk = { + url = "github:nix-community/naersk"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, flake-utils, naersk, nixpkgs, rust-overlay }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = (import nixpkgs) { + inherit system; + overlays = [ rust-overlay.overlays.default ]; + }; + + toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + naersk' = pkgs.callPackage naersk { + cargo = toolchain; + rustc = toolchain; + }; + + in { + # For `nix build` & `nix run`: + packages.default = naersk'.buildPackage { + src = ./.; + doCheck = false; + buildInputs = [ pkgs.systemd ]; + nativeBuildInputs = [ pkgs.pkg-config ]; + }; + + # For `nix develop` (optional, can be skipped): + devShells.default = pkgs.mkShell { + buildInputs = [ pkgs.systemd ]; + nativeBuildInputs = [ toolchain pkgs.pkg-config ]; + }; + } + ); +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..8745f50 --- /dev/null +++ b/shell.nix @@ -0,0 +1 @@ +(builtins.getFlake ("git+file://" + toString ./.)).devShells.${builtins.currentSystem}.default