From 888b3246a7c22d2c4f7677b3ae379ffd2be75ad8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Wed, 31 May 2023 15:51:50 +0200 Subject: [PATCH] feat(porgrams): add nix-edit --- modules/profiles/desktop.nix | 1 + modules/programs/nix-edit/default.nix | 26 ++++++++++++++++++++++++++ modules/programs/nix-edit/nix-edit.sh | 15 +++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 modules/programs/nix-edit/default.nix create mode 100755 modules/programs/nix-edit/nix-edit.sh diff --git a/modules/profiles/desktop.nix b/modules/profiles/desktop.nix index b909535..70819aa 100644 --- a/modules/profiles/desktop.nix +++ b/modules/profiles/desktop.nix @@ -33,6 +33,7 @@ in gpg.enable = mkDefault true; hyprland.enable = mkDefault true; logseq.enable = mkDefault true; + nix-edit.enable = mkDefault true; nvim.enable = mkDefault true; python.versions."311".enable = mkDefault true; spotify.enable = mkDefault true; diff --git a/modules/programs/nix-edit/default.nix b/modules/programs/nix-edit/default.nix new file mode 100644 index 0000000..c2fda85 --- /dev/null +++ b/modules/programs/nix-edit/default.nix @@ -0,0 +1,26 @@ +{ lib +, config +, pkgs +, ... +}: + +with lib; +let + cfg = config.my.programs.nix-edit; +in +{ + options.my.programs.nix-edit.enable = mkEnableOption "nix-edit"; + + config = mkIf cfg.enable { + environment.systemPackages = + let + nix-edit = pkgs.writeShellApplication { + name = "nix-edit"; + runtimeInputs = with pkgs; [ nix gnugrep ]; + text = builtins.readFile ./nix-edit.sh; + }; + in + [ nix-edit ]; + }; + +} diff --git a/modules/programs/nix-edit/nix-edit.sh b/modules/programs/nix-edit/nix-edit.sh new file mode 100755 index 0000000..f48b779 --- /dev/null +++ b/modules/programs/nix-edit/nix-edit.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +input=$( + echo ":lf nixpkgs" + echo "pkgs = legacyPackages.\${builtins.currentSystem}" + echo ":doc $1" + echo ":e $1" +) +echo "$input" | nix repl --quiet 2> >(grep -v "ioctl" | + grep -v "^error: value does not have documentation$" | + grep -vP "error: .* has no source location information" | + grep -vP "Welcome to Nix \d+\.\d+\.\d+\." | + grep -vP "Added \d+ variables." | + grep -v -e '^[[:space:]]*$' +)