Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.direnv/
3 changes: 3 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:**
Expand Down Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

125 changes: 125 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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 ];
};
};
};
}
16 changes: 16 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
nixpkgs ? import <nixpkgs> { },
}:
with nixpkgs;
mkShell {
packages = with nixpkgs; [
shellcheck
uv
python3
rustup
zizmor
rumdl
typos
prek
Comment on lines +5 to +14

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are all dev deps, used only with pre-commit or prek to contribute to the project

];
}