diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..c73991f --- /dev/null +++ b/.envrc @@ -0,0 +1,22 @@ +# shellcheck shell=bash + +# If .env missing; restore from .env.sample and validate +# See https://github.com/direnv/direnv/wiki/.envrc-Boilerplate +if [[ -f .env.sample ]]; then + if ! command -v createnv >/dev/null; then + echo 'WARN|createnv missing; https://github.com/cuducos/createnv?tab=readme-ov-file#install' + elif [[ ! -f .env ]]; then + createnv --use-default --overwrite || + echo 'ERROR|https://github.com/cuducos/createnv?tab=readme-ov-file#format-of-sample-files' + if command dotenv-linter --version >&/dev/null; then + dotenv-linter .env || echo 'ERROR|https://dotenv-linter.github.io' + fi + fi +fi + +dotenv_if_exists || direnv status # https://direnv.net/man/direnv-stdlib.1.html + +use_nix + +# Ensure pre-commit hooks are installed when working on the project +prek install diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9b42106 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.direnv/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 622747b..69de949 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -42,6 +42,7 @@ repos: rev: 631208b7aac2daa8b707f55e7331f9112b0e062d # frozen: v1.44.0 hooks: - id: typos + language: system # Png - repo: https://github.com/oxipng/oxipng rev: 628e241e23f368097883807fa6e985ccf7c00357 # frozen: v10.1.1 @@ -57,11 +58,13 @@ repos: rev: e3eebf65325ccc992422292cb7a4baee967cf815 # frozen: v1.26.1 hooks: - id: zizmor + language: system # Markdown - repo: https://github.com/rvben/rumdl-pre-commit rev: 6853b8952a3b2f746baf094c9ce7adbeec2e44bb # frozen: v0.2.21 hooks: - id: rumdl-fmt + language: system args: - --disable - MD013,MD033 diff --git a/README.md b/README.md index 4c8ccc6..fad8fb4 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ Snippy is a versatile command-line snippet manager that seamlessly integrates wi - [Installation](#installation) - [Arch Linux](#arch-linux) + - [Nix](#nix) - [Manual Installation](#manual-installation) - [Prerequisites](#prerequisites) - [Initial Setup](#initial-setup) @@ -62,6 +63,34 @@ Install using your preferred [AUR helper](https://wiki.archlinux.org/index.php/A yay -S snippy-snippet ``` +### Nix + +The flake provides home manager modules with options to enable wayland / x11 support. + +Add it to your flake inputs + +```nix +snippy = { + url = "github:BarbUk/snippy"; + inputs.nixpkgs.follows = "nixpkgs"; +}; +``` + +Enable it in your home configuration + +```nix +programs.snippy.enable = true; + +# Explicitly disable Wayland / X11 support +# Defaults to installing both dependencies +programs.snippy.enableWayland = false; +programs.snippy.enableX11 = false; +``` + +Currently only `x86_64-linux` is supported (`aarch64-linux` support coming soon). + +`darwin` systems are currently **unsupported**. See [#34](https://github.com/BarbUk/snippy/issues/34) + ### Manual Installation **For local user installation:** @@ -324,6 +353,8 @@ If you already have a keybinding for rofi, you can add snippy as a mod, it will rofi -theme-str 'element-icon { size: 3ch;}' -combi-modi 'snippets:snippy' -show combi -modi combi ``` +*Note:* On Nix, rofi integration is currently **unsupported and WIP**. To use snippy, use the command `snippy` instead. + **Browse snippets in terminal:** ```bash diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..efbb6e6 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1785454630, + "narHash": "sha256-LQy14TZp77TwbQf40gg1V3jo8FwJG0jGDkAH+zRHqg8=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "1559d3daa3ecc813a650b79375ea61b6741b8746", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..a09512e --- /dev/null +++ b/flake.nix @@ -0,0 +1,125 @@ +{ + description = "Snippy Flake"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + }; + + outputs = + { self, nixpkgs }: + let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + + baseDeps = with pkgs; [ + rofi + fzf + jq + gettext + perl + ]; + + buildPackage = + { x11, wayland }: + let + deps = + baseDeps + ++ ( + with pkgs; + lib.optionals wayland [ + wtype + wl-clipboard + ] + ) + ++ ( + with pkgs; + lib.optionals x11 [ + xdotool + xclip + xsel + ] + ); + in + pkgs.stdenv.mkDerivation { + pname = "snippy"; + version = "git"; + + nativeBuildInputs = [ pkgs.makeWrapper ]; + + src = ./.; + + installPhase = '' + mkdir -p $out/bin + cp snippy $out/bin + + wrapProgram $out/bin/snippy\ + --prefix PATH : ${pkgs.lib.makeBinPath deps} + ''; + }; + in + { + packages.${system} = { + default = buildPackage { + x11 = true; + wayland = true; + }; + wayland = buildPackage { + x11 = false; + wayland = true; + }; + x11 = buildPackage { + x11 = true; + wayland = false; + }; + }; + + homeManagerModule = + { + config, + lib, + pkgs, + ... + }: + let + cfg = config.programs.snippy; + in + { + options.programs.snippy = { + enable = lib.mkEnableOption "Whether to enable snippy snippets manager."; + + enableWayland = lib.mkOption { + type = lib.types.bool; + default = true; + description = "Enable wayland support"; + }; + + enableX11 = lib.mkOption { + type = lib.types.bool; + default = true; + description = "Enable x11 support"; + }; + + package = lib.mkOption { + type = lib.types.package; + default = + let + selectedPackage = { + "true-false" = self.packages.${pkgs.system}.wayland; + "false-true" = self.packages.${pkgs.system}.x11; + "true-true" = self.packages.${pkgs.system}.default; + "false-false" = self.packages.${pkgs.system}.default; + }; + key = "${lib.boolToString cfg.enableWayland}-${lib.boolToString cfg.enableX11}"; + in + selectedPackage.${key}; + + description = "Snippy package to install. Defaults to wayland + x11 support"; + }; + }; + + config = lib.mkIf cfg.enable { + home.packages = [ cfg.package ]; + }; + }; + }; +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..3532870 --- /dev/null +++ b/shell.nix @@ -0,0 +1,16 @@ +{ + nixpkgs ? import { }, +}: +with nixpkgs; +mkShell { + packages = with nixpkgs; [ + shellcheck + uv + python3 + rustup + zizmor + rumdl + typos + prek + ]; +}