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..d4a5d00 --- /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 || true diff --git a/.gitignore b/.gitignore index b699590..7be8c2d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,6 @@ venv/ qmk_gui.spec build/ dist/ + +# Nix +result diff --git a/README.md b/README.md index 398487c..9b0032d 100644 --- a/README.md +++ b/README.md @@ -193,3 +193,21 @@ Pre-requisites: Rust, libudev cargo build ls -l target/debug/qmk_hid ``` + +###### With Nix Flakes + +Pre-requisites: Nix with flakes and nix command enabled. + +``` +# 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 +``` diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..fb5274c --- /dev/null +++ b/flake.lock @@ -0,0 +1,94 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1689068808, + "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "naersk": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1688534083, + "narHash": "sha256-/bI5vsioXscQTsx+Hk9X5HfweeNZz/6kVKsbdqfwW7g=", + "owner": "nix-community", + "repo": "naersk", + "rev": "abca1fb7a6cfdd355231fc220c3d0302dbb4369a", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1690235791, + "narHash": "sha256-QkPVQ859F0wXyd74A7UPYbmi4B5xYN4Ns7AQ0pvM0Wo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "dfcffbd74fd6f0419370d8240e445252a39f4d10", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1690235791, + "narHash": "sha256-QkPVQ859F0wXyd74A7UPYbmi4B5xYN4Ns7AQ0pvM0Wo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "dfcffbd74fd6f0419370d8240e445252a39f4d10", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "naersk": "naersk", + "nixpkgs": "nixpkgs_2" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "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..9909692 --- /dev/null +++ b/flake.nix @@ -0,0 +1,33 @@ +{ + inputs = { + flake-utils.url = "github:numtide/flake-utils"; + naersk.url = "github:nix-community/naersk"; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + }; + + outputs = { self, flake-utils, naersk, nixpkgs }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = (import nixpkgs) { + inherit system; + }; + + naersk' = pkgs.callPackage naersk {}; + + in rec { + # For `nix build` & `nix run`: + defaultPackage = naersk'.buildPackage { + src = ./.; + doCheck = false; + buildInputs = [ pkgs.systemd ]; + nativeBuildInputs = [ pkgs.pkg-config ]; + }; + + # For `nix develop` (optional, can be skipped): + devShell = pkgs.mkShell { + buildInputs = [ pkgs.systemd ]; + nativeBuildInputs = with pkgs; [ rustc cargo 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