From e13cd11a682e28c1f612d647f7623dc74e143c85 Mon Sep 17 00:00:00 2001 From: htran Date: Fri, 7 Jul 2023 00:40:29 -0700 Subject: [PATCH] untested - rclone --- nix-conf/secrets.nix | 3 +- nix/repo/home-modules/services.nix | 71 ++++++++++++++++++++++++++++++ nix/repo/home-profiles/neovim.nix | 9 ++-- 3 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 nix/repo/home-modules/services.nix diff --git a/nix-conf/secrets.nix b/nix-conf/secrets.nix index ec5a5f3..5e4a30c 100644 --- a/nix-conf/secrets.nix +++ b/nix-conf/secrets.nix @@ -2,8 +2,9 @@ let # user-specific (~/.ssh/id_ed25519.pub) users = { "hungtr@bao" = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIK+1+gps6phbZboIb9fH51VNPUCkhSSOAbkI3tq3Ou0Z"; + "htran@Hungs-MacBook-Pro.local" = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJvOCZ4nyFiiKK7gkwzP4hXJ6NmtgbdUJdWgIzUL0GMA"; }; - # System-specific settings (/etc/ssh/ssh_hsot_ed25519_key.pub) + # System-specific settings (/etc/ssh/ssh_host_ed25519_key.pub) systems = { "bao" = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIBuAaAE7TiQmMH300VRj/pYCri1qPmHjd+y9aX2J0Fs"; }; diff --git a/nix/repo/home-modules/services.nix b/nix/repo/home-modules/services.nix new file mode 100644 index 0000000..3201e1d --- /dev/null +++ b/nix/repo/home-modules/services.nix @@ -0,0 +1,71 @@ +{ + inputs, + cell, +}: { + rclone-mount = { + config, + lib, + pkgs, + ... + }: let + cfg = config.services.rclone; + rcloneCommand = "${pkgs.rclone}/bin/rclone"; + + inherit (lib) mkEnableOption mkOption types mkIf mapAttrs' nameValuePair; + makeMountService = name: mountCfg: { + Unit = { + Description = "Rclone Mount ${name}"; + After = ["network.target"]; + }; + + Service = { + ExecStart = "${rcloneCommand} mount ${mountCfg.remotePath} ${mountCfg.mountPoint}"; + Restart = "on-failure"; + }; + + Install = {WantedBy = ["default.target"];}; + }; + + makeLaunchdService = name: mountCfg: { + enable = true; + settings = { + ProgramArguments = ["/bin/sh" "-c" "${rcloneCommand} mount ${mountCfg.remotePath} ${mountCfg.mountPoint}"]; + KeepAlive = { + NetworkState = true; + }; + }; + }; + in { + options.services.rclone = { + enable = mkEnableOption "rclone mount service"; + + mounts = mkOption { + type = types.attrsOf (types.submodule { + options = { + remotePath = mkOption { + type = types.str; + default = ""; + description = "The remote path to mount via rclone"; + }; + + mountPoint = mkOption { + type = types.str; + default = ""; + description = "The local mount point for the rclone mount"; + }; + }; + }); + default = {}; + description = "Rclone mounts"; + }; + }; + + config = mkIf cfg.enable { + home.packages = [pkgs.rclone]; + + systemd.user.services = mapAttrs' (n: v: nameValuePair "rclone-mount-${n}" (makeMountService n v)) cfg.mounts; + + launchd.user.agents = mapAttrs' (n: v: nameValuePair "rclone-mount-${n}" (makeLaunchdService n v)) cfg.mounts; + }; + }; +} diff --git a/nix/repo/home-profiles/neovim.nix b/nix/repo/home-profiles/neovim.nix index 3f17f62..6ecdce4 100644 --- a/nix/repo/home-profiles/neovim.nix +++ b/nix/repo/home-profiles/neovim.nix @@ -1,4 +1,4 @@ -# TODO: vim-plug and Mason supports laziness. Probably worth it to explore incremental dependencies based on the project +# TODO: vim-plug and Mason supports laziness. Probably worth it to explore incremental dependencies based on the project # TODO: just install these things, then symlink to mason's bin directory # One thing to consider, though, /nix/store of `nix-shell` or `nix-develop` # might be different from `home-manager`'s (~/.nix_profile/bin/jq) @@ -176,15 +176,14 @@ in { vim-dispatch-neovim vim-fugitive vim-jack-in - ({ + { plugin = sg-nvim; - # Wait, this mean the plugin is only lua only since package.cpath is Lua API + # NOTE: Wait, this mean the plugin is exclusively lua only since package.cpath is Lua API config = '' package.cpath = package.cpath .. ";${sg-nvim}/lib/*.so;${sg-nvim}/lib/*.dylib" ''; type = "lua"; - - }) + } nui-nvim ]; };