From 65bb26ec847e0d2caae49fbaeb3bffef90e094cd Mon Sep 17 00:00:00 2001 From: Vitalii Lukyanov Date: Mon, 11 Nov 2024 22:37:21 +0100 Subject: [PATCH] chore(nix): nix flake shell + rust-toolchain.toml setup (#14) * nix flake shell + rust-toolchain.toml setup * migrated to naersk + nixpkgs-mozilla, it works for this workspace setup, updated Cargo.toml by autoformatting with taplo and adding reame to workspace.package to make `nix build` work --- .envrc | 3 ++ .gitignore | 2 + Cargo.toml | 11 +++-- flake.lock | 109 ++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 66 +++++++++++++++++++++++++++ rust-toolchain.toml | 3 ++ 6 files changed, 191 insertions(+), 3 deletions(-) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 rust-toolchain.toml diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..8e8d884 --- /dev/null +++ b/.envrc @@ -0,0 +1,3 @@ +watch_file flake.nix + +use flake . diff --git a/.gitignore b/.gitignore index ce27fe6..23fec8d 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,5 @@ Cargo.lock .data/*.log +# Direnv (Nix Shell) +.direnv/ \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 538e8bd..1a61241 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,13 @@ categories = [ "concurrency", "development-tools", ] -include = ["LICENSE", "README.md", "crates/television/**/*.rs", "build.rs", ".config/config.toml"] +include = [ + "LICENSE", + "README.md", + "crates/television/**/*.rs", + "build.rs", + ".config/config.toml", +] rust-version = "1.80.0" [workspace] @@ -38,6 +44,7 @@ categories = [ ] include = ["LICENSE", "README.md", "crates/television/**/*.rs", "build.rs"] rust-version = "1.80.0" +readme = "README.md" [[bin]] @@ -106,8 +113,6 @@ vergen-gix = { version = "1.0.0", features = ["build", "cargo", "rustc"] } crossterm = { version = "0.28.1", features = ["serde", "use-dev-tty"] } - - [profile.staging] inherits = "dev" opt-level = 3 diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..ed7b366 --- /dev/null +++ b/flake.lock @@ -0,0 +1,109 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "naersk": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1721727458, + "narHash": "sha256-r/xppY958gmZ4oTfLiHN0ZGuQ+RSTijDblVgVLFi1mw=", + "owner": "nix-community", + "repo": "naersk", + "rev": "3fb418eaf352498f6b6c30592e3beb63df42ef11", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 0, + "narHash": "sha256-30FKRgiiFsMdSSkujzQCK97NuY1JeMS4L5hQWlHAQ0c=", + "path": "/nix/store/6bml58svmvrhn1bnb1ag49rqfr2gmdv3-source", + "type": "path" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs-mozilla": { + "flake": false, + "locked": { + "lastModified": 1704373101, + "narHash": "sha256-+gi59LRWRQmwROrmE1E2b3mtocwueCQqZ60CwLG+gbg=", + "owner": "mozilla", + "repo": "nixpkgs-mozilla", + "rev": "9b11a87c0cc54e308fa83aac5b4ee1816d5418a2", + "type": "github" + }, + "original": { + "owner": "mozilla", + "repo": "nixpkgs-mozilla", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1730958623, + "narHash": "sha256-JwQZIGSYnRNOgDDoIgqKITrPVil+RMWHsZH1eE1VGN0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "85f7e662eda4fa3a995556527c87b2524b691933", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "naersk": "naersk", + "nixpkgs": "nixpkgs_2", + "nixpkgs-mozilla": "nixpkgs-mozilla" + } + }, + "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..09be4e2 --- /dev/null +++ b/flake.nix @@ -0,0 +1,66 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + nixpkgs-mozilla = { + url = "github:mozilla/nixpkgs-mozilla"; + flake = false; + }; + + flake-utils.url = "github:numtide/flake-utils"; + naersk.url = "github:nix-community/naersk"; + }; + + outputs = { + self, + flake-utils, + naersk, + nixpkgs, + nixpkgs-mozilla, + }: + flake-utils.lib.eachDefaultSystem ( + system: let + pkgs = (import nixpkgs) { + inherit system; + + overlays = [ + (import nixpkgs-mozilla) + ]; + }; + + toolchain = + ( + pkgs.rustChannelOf + { + rustToolchain = ./rust-toolchain.toml; + sha256 = "6eN/GKzjVSjEhGO9FhWObkRFaE1Jf+uqMSdQnb8lcB4="; + } + ) + .rust; + + naersk' = pkgs.callPackage naersk { + cargo = toolchain; + rustc = toolchain; + }; + in { + packages.default = naersk'.buildPackage { + src = ./.; + }; + apps = { + default = flake-utils.lib.mkApp { + drv = self.packages.${system}.default; + exePath = "/bin/tv"; + }; + }; + + devShell = pkgs.mkShell { + nativeBuildInputs = [toolchain]; + packages = with pkgs; [ + rustfmt + clippy + rust-analyzer + ]; + }; + } + ); +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..dc8d20d --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "1.80.0" +components = ["rustfmt", "clippy", "rust-analyzer"]