From a89f27b448809afc11e173877157250ee4e6d762 Mon Sep 17 00:00:00 2001 From: yunfachi Date: Tue, 12 Mar 2024 10:03:42 +0300 Subject: [PATCH] uni-sync: init at 0.2.0 --- pkgs/by-name/un/uni-sync/config_path.patch | 38 +++++++++++++++++++ .../ignore_read-only_filesystem.patch | 14 +++++++ pkgs/by-name/un/uni-sync/package.nix | 35 +++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 pkgs/by-name/un/uni-sync/config_path.patch create mode 100644 pkgs/by-name/un/uni-sync/ignore_read-only_filesystem.patch create mode 100644 pkgs/by-name/un/uni-sync/package.nix diff --git a/pkgs/by-name/un/uni-sync/config_path.patch b/pkgs/by-name/un/uni-sync/config_path.patch new file mode 100644 index 000000000000..c59bf80125ae --- /dev/null +++ b/pkgs/by-name/un/uni-sync/config_path.patch @@ -0,0 +1,38 @@ +diff --git a/src/main.rs b/src/main.rs +index 357a33b..7073497 100644 +--- a/src/main.rs ++++ b/src/main.rs +@@ -1,4 +1,4 @@ +-use std::env; ++use std::path::PathBuf; + + mod devices; + +@@ -8,12 +8,23 @@ fn main() -> Result<(), std::io::Error> { + configs: vec![] + }; + +- let mut config_path = env::current_exe()?; +- config_path.pop(); +- config_path.push("uni-sync.json"); ++ let mut config_path = PathBuf::from("/etc/uni-sync/uni-sync.json"); + + if !config_path.exists() { +- std::fs::write(&config_path, serde_json::to_string_pretty(&configs).unwrap())?; ++ match std::fs::create_dir_all(config_path.parent().unwrap()) { ++ Ok(result) => result, ++ Err(_) => { ++ println!("Please run uni-sync with elevated permissions."); ++ std::process::exit(0); ++ } ++ }; ++ match std::fs::write(&config_path, serde_json::to_string_pretty(&configs).unwrap()) { ++ Ok(result) => result, ++ Err(_) => { ++ println!("Please run uni-sync with elevated permissions."); ++ std::process::exit(0); ++ } ++ }; + } + + let config_content = std::fs::read_to_string(&config_path).unwrap(); diff --git a/pkgs/by-name/un/uni-sync/ignore_read-only_filesystem.patch b/pkgs/by-name/un/uni-sync/ignore_read-only_filesystem.patch new file mode 100644 index 000000000000..3a0837d1d224 --- /dev/null +++ b/pkgs/by-name/un/uni-sync/ignore_read-only_filesystem.patch @@ -0,0 +1,14 @@ +diff --git a/src/main.rs b/src/main.rs +index f07cc64..357a33b 100644 +--- a/src/main.rs ++++ b/src/main.rs +@@ -20,7 +20,7 @@ fn main() -> Result<(), std::io::Error> { + configs = serde_json::from_str::(&config_content).unwrap(); + + let new_configs = devices::run(configs); +- std::fs::write(&config_path, serde_json::to_string_pretty(&new_configs).unwrap())?; ++ std::fs::write(&config_path, serde_json::to_string_pretty(&new_configs).unwrap()); + + Ok(()) + } +\ No newline at end of file diff --git a/pkgs/by-name/un/uni-sync/package.nix b/pkgs/by-name/un/uni-sync/package.nix new file mode 100644 index 000000000000..6124e621dfb9 --- /dev/null +++ b/pkgs/by-name/un/uni-sync/package.nix @@ -0,0 +1,35 @@ +{ lib +, fetchFromGitHub +, rustPlatform +, pkg-config +, libudev-zero +}: +rustPlatform.buildRustPackage rec { + pname = "uni-sync"; + version = "0.2.0"; + + src = fetchFromGitHub { + owner = "EightB1ts"; + repo = pname; + rev = "ca349942c06fabcc028ce24e79fc6ce7c758452b"; + hash = "sha256-K2zX3rKtTaKO6q76xlxX+rDLL0gEsJ2l8x/s1vsp+ZQ="; + }; + + nativeBuildInputs = [ pkg-config ]; + buildInputs = [ libudev-zero ]; + + patches = [ + ./config_path.patch + ./ignore_read-only_filesystem.patch + ]; + + cargoHash = "sha256-DdmjP0h15cXkHJZxvOcINgoZ/EhTgu/7iYb+bgsIXxU="; + + meta = with lib; { + description = "A synchronization tool for Lian Li Uni Controllers"; + homepage = "https://github.com/EightB1ts/uni-sync"; + license = licenses.mit; + maintainers = with maintainers; [ yunfachi ]; + mainProgram = "uni-sync"; + }; +}