From df41cd9697223a495d63c50717357c1cb9db4ed3 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Tue, 16 Apr 2024 11:28:28 +0300 Subject: [PATCH] modules/lan-mouse: move to the home-manager --- flake.lock | 79 ++++++++++++++++++- flake.nix | 10 ++- .../home-manager/programs/editors/neovim.nix | 2 +- modules/home-manager/services/default.nix | 5 +- .../services/lan-mouse/default.nix | 29 +++++++ .../home-manager/services/wired/default.nix | 13 ++- modules/machine.nix | 5 +- modules/nixos/configs/keyboard.nix | 4 - users/jan/default.nix | 30 ++++++- 9 files changed, 157 insertions(+), 20 deletions(-) create mode 100644 modules/home-manager/services/lan-mouse/default.nix diff --git a/flake.lock b/flake.lock index 0bcc3b1..256c65c 100644 --- a/flake.lock +++ b/flake.lock @@ -161,6 +161,24 @@ "type": "github" } }, + "flake-utils_3": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "flakeCompat": { "flake": false, "locked": { @@ -267,6 +285,27 @@ "type": "github" } }, + "lan-mouse": { + "inputs": { + "nixpkgs": [ + "nixpkgs-unstable" + ], + "rust-overlay": "rust-overlay" + }, + "locked": { + "lastModified": 1713168888, + "narHash": "sha256-pNd6KbkLlZtXKQvHWYwQB/Wbqa7lQYVffpSq5uWJqzQ=", + "owner": "feschber", + "repo": "lan-mouse", + "rev": "36855a1a1767f4a777bad580d5a76fec1be5d9d1", + "type": "github" + }, + "original": { + "owner": "feschber", + "repo": "lan-mouse", + "type": "github" + } + }, "lspsaga-nvim": { "flake": false, "locked": { @@ -404,7 +443,7 @@ "nixpkgs": [ "nixpkgs" ], - "rust-overlay": "rust-overlay" + "rust-overlay": "rust-overlay_2" }, "locked": { "lastModified": 1694177726, @@ -635,6 +674,7 @@ "flake-utils": "flake-utils_2", "hardware": "hardware", "home-manager": "home-manager_2", + "lan-mouse": "lan-mouse", "myneovim": "myneovim", "nil": "nil", "nixpkgs": "nixpkgs_2", @@ -644,6 +684,28 @@ } }, "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils_3", + "nixpkgs": [ + "lan-mouse", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1710987136, + "narHash": "sha256-Q8GRdlAIKZ8tJUXrbcRO1pA33AdoPfTUirsSnmGQnOU=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "97596b54ac34ad8184ca1eef44b1ec2e5c2b5f9e", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "rust-overlay_2": { "inputs": { "flake-utils": [ "nil", @@ -683,6 +745,21 @@ "type": "github" } }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, "tabby-nvim": { "flake": false, "locked": { diff --git a/flake.nix b/flake.nix index c7b4613..9dd3150 100644 --- a/flake.nix +++ b/flake.nix @@ -23,6 +23,11 @@ inputs.nixpkgs.follows = "nixpkgs"; }; + lan-mouse = { + url = "github:feschber/lan-mouse"; + inputs.nixpkgs.follows = "nixpkgs-unstable"; + }; + # nix lsp nil = { url = "github:oxalica/nil"; @@ -46,9 +51,7 @@ }; outputs = inputs @ { self, flake-utils, nixpkgs, ... }: - let - inherit (flake-utils.lib) eachSystem system; - in + let inherit (flake-utils.lib) eachSystem system; in eachSystem [ system.x86_64-linux ] (system: let @@ -143,6 +146,7 @@ imports = [ ./modules/home-manager inputs.wired.homeManagerModules.default + inputs.lan-mouse.homeManagerModules.default ]; } ]; diff --git a/modules/home-manager/programs/editors/neovim.nix b/modules/home-manager/programs/editors/neovim.nix index 4c700fa..664921d 100644 --- a/modules/home-manager/programs/editors/neovim.nix +++ b/modules/home-manager/programs/editors/neovim.nix @@ -153,7 +153,7 @@ in ltex.enable = mkEnableOption "ltex language server"; orgmode.enable = mkEnableOption "orgmode"; - nix.enable = mkEnableOptions "nix"; + nix.enable = mkEnableOption "nix"; rust.enable = mkEnableOption "rust"; typescript.enable = mkEnableOption "typescript"; vue.enable = mkEnableOption "vue"; diff --git a/modules/home-manager/services/default.nix b/modules/home-manager/services/default.nix index 43a649a..d695608 100644 --- a/modules/home-manager/services/default.nix +++ b/modules/home-manager/services/default.nix @@ -1,5 +1,8 @@ { ... }: { - imports = [ ./wired ]; + imports = [ + ./lan-mouse + ./wired + ]; } diff --git a/modules/home-manager/services/lan-mouse/default.nix b/modules/home-manager/services/lan-mouse/default.nix new file mode 100644 index 0000000..8df9cef --- /dev/null +++ b/modules/home-manager/services/lan-mouse/default.nix @@ -0,0 +1,29 @@ +{ config, pkgs, lib, ... }: + +let + cfg = config.local.services.lan-mouse; + + # See: https://github.com/feschber/lan-mouse/blob/main/src/config.rs#L79 + lanMouseConfig = pkgs.writeText "config.toml" '' + port = ${toString cfg.port} + ''; +in +{ + options.local.services.lan-mouse = with lib; { + enable = mkEnableOption "lan-mouse"; + port = mkOption { + type = types.int; + default = 4242; + }; + }; + + config = lib.mkIf cfg.enable { + programs.lan-mouse = { + enable = true; + systemd = true; + package = pkgs.unstable.lan-mouse; + }; + + xdg.configFile."lan-mouse/config.toml".source = lanMouseConfig; + }; +} diff --git a/modules/home-manager/services/wired/default.nix b/modules/home-manager/services/wired/default.nix index 7e8e6f2..9630fe8 100644 --- a/modules/home-manager/services/wired/default.nix +++ b/modules/home-manager/services/wired/default.nix @@ -1,11 +1,16 @@ -{ config, pkgs, ... }: +{ config, pkgs, lib, ... }: let + cfg = config.local.services.wired; themeCfg = config.local.themes."${config.local.theme.name}"; in { - services.wired = { - enable = true; - config = pkgs.substituteAll ({ src = ./wired.ron; } // themeCfg.notification); + options.local.services.wired.enable = lib.mkEnableOption "wired"; + + config = lib.mkIf cfg.enable { + services.wired = { + enable = true; + config = pkgs.substituteAll ({ src = ./wired.ron; } // themeCfg.notification); + }; }; } diff --git a/modules/machine.nix b/modules/machine.nix index 9f7103c..b95e829 100644 --- a/modules/machine.nix +++ b/modules/machine.nix @@ -10,10 +10,7 @@ local.system.kernel = lib.mkDefault "stable"; - local.keyboard = { - enable = lib.mkDefault true; - lan-mouse.enable = lib.mkDefault true; - }; + local.keyboard.enable = lib.mkDefault true; local.fonts.enable = lib.mkDefault true; local.sound.enable = lib.mkDefault true; diff --git a/modules/nixos/configs/keyboard.nix b/modules/nixos/configs/keyboard.nix index dc4440b..fe8e5c2 100644 --- a/modules/nixos/configs/keyboard.nix +++ b/modules/nixos/configs/keyboard.nix @@ -6,13 +6,9 @@ in { options.local.keyboard = with lib; { enable = mkEnableOption "base keyboard configuration"; - lan-mouse.enable = mkEnableOption "a software KVM switch for sharing a mouse and keyboard with multiple hosts through the network"; }; config = lib.mkIf cfg.enable { - environment.systemPackages = - lib.optional cfg.lan-mouse.enable pkgs.unstable.lan-mouse; - services.xserver = { xkbModel = "pc105"; layout = "us,us"; diff --git a/users/jan/default.nix b/users/jan/default.nix index 74a7030..91aa1a7 100644 --- a/users/jan/default.nix +++ b/users/jan/default.nix @@ -33,6 +33,10 @@ users.groups.plugdev = lib.mkIf config.programs.adb.enable { }; + networking.firewall.allowedUDPPorts = + let lanMouseCfg = config.home-manager.users.jan.local.services.lan-mouse; + in lib.optional lanMouseCfg.enable lanMouseCfg.port; + home-manager.users.jan = { imports = [ ./accounts.secret.nix @@ -63,7 +67,18 @@ local.programs.terminals.wezterm.enable = lib.mkDefault true; - local.programs.editors.neovim.enable = lib.mkDefault true; + local.programs.editors.neovim = { + enable = lib.mkDefault true; + defaultEditor = lib.mkDefault true; + ltex.enable = lib.mkDefault true; + + nix.enable = lib.mkDefault true; + rust.enable = lib.mkDefault true; + typescript.enable = lib.mkDefault true; + vue.enable = lib.mkDefault true; + deno.enable = lib.mkDefault true; + python.enable = lib.mkDefault true; + }; local.programs.file-managers.vifm.enable = lib.mkDefault true; @@ -88,7 +103,18 @@ zoxide.enable = lib.mkDefault true; }; - local.programs.share-files.croc.enable = true; + local.programs.share-files.croc.enable = lib.mkDefault true; + + ################################################################################ + # Services + ################################################################################ + + local.services.wired.enable = lib.mkDefault true; + + local.services.lan-mouse = { + enable = lib.mkDefault true; + port = lib.mkDefault 32000; + }; ################################################################################ # Packages