From 8f5522c2c9429071af31e3cdb016dad6318add39 Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Wed, 6 Jul 2022 15:50:10 -0400 Subject: [PATCH] nix shell features for flake, remove channels --- modules/applications/alacritty.nix | 7 +++ modules/darwin/default.nix | 2 +- modules/darwin/{dotfiles.nix => nixpkgs.nix} | 0 modules/editor/dotfiles.nix | 19 ------ modules/shell/default.nix | 1 + modules/shell/fish/default.nix | 25 -------- .../functions/fish_user_key_bindings.fish | 10 ++-- modules/shell/nixpkgs.nix | 59 +++++++++++++++++++ 8 files changed, 74 insertions(+), 49 deletions(-) rename modules/darwin/{dotfiles.nix => nixpkgs.nix} (100%) create mode 100644 modules/shell/nixpkgs.nix diff --git a/modules/applications/alacritty.nix b/modules/applications/alacritty.nix index 77f6daf..5f2b370 100644 --- a/modules/applications/alacritty.nix +++ b/modules/applications/alacritty.nix @@ -21,11 +21,18 @@ scrolling.history = 10000; font = { size = 14.0; }; key_bindings = [ + # Used for word completion in fish_user_key_bindings { key = "L"; mods = "Control|Shift"; chars = "\\x1F"; } + # Used for searching nixpkgs in fish_user_key_bindings + { + key = "N"; + mods = "Control|Shift"; + chars = "\\x11F"; + } { key = "K"; mods = "Control"; diff --git a/modules/darwin/default.nix b/modules/darwin/default.nix index ce24802..66444f5 100644 --- a/modules/darwin/default.nix +++ b/modules/darwin/default.nix @@ -2,10 +2,10 @@ imports = [ ./alacritty.nix - ./dotfiles.nix ./fonts.nix ./hammerspoon.nix ./homebrew.nix + ./nixpkgs.nix ./system.nix ./tmux.nix ./user.nix diff --git a/modules/darwin/dotfiles.nix b/modules/darwin/nixpkgs.nix similarity index 100% rename from modules/darwin/dotfiles.nix rename to modules/darwin/nixpkgs.nix diff --git a/modules/editor/dotfiles.nix b/modules/editor/dotfiles.nix index 320bf26..2d253e2 100644 --- a/modules/editor/dotfiles.nix +++ b/modules/editor/dotfiles.nix @@ -16,25 +16,6 @@ }; - programs.fish = { - shellAbbrs = { - nr = "rebuild-nixos"; - nro = "rebuild-nixos offline"; - }; - functions = { - rebuild-nixos = { - body = '' - if test "$argv[1]" = "offline" - set option "--option substitute false" - end - git -C ${config.dotfilesPath} add --all - commandline -r "doas nixos-rebuild switch $option --flake ${config.dotfilesPath}" - commandline --function execute - ''; - }; - }; - }; - }; } diff --git a/modules/shell/default.nix b/modules/shell/default.nix index ad74629..ef7d93f 100644 --- a/modules/shell/default.nix +++ b/modules/shell/default.nix @@ -6,6 +6,7 @@ ./fzf.nix ./git.nix ./github.nix + ./nixpkgs.nix ./starship.nix ./utilities.nix ]; diff --git a/modules/shell/fish/default.nix b/modules/shell/fish/default.nix index 52b8e5e..d4dd300 100644 --- a/modules/shell/fish/default.nix +++ b/modules/shell/fish/default.nix @@ -42,17 +42,6 @@ body = "pbpaste | jq '.' | pbcopy"; # Need to fix for non-macOS }; ls = { body = "${pkgs.exa}/bin/exa $argv"; }; - nix-shell-run = { - body = '' - set program $argv[1] - if test (count $argv) -ge 1 - commandline -r "nix run nixpkgs#$program -- $argv[2..-1]" - else - commandline -r "nix run nixpkgs#$program" - end - commandline -f execute - ''; - }; note = { description = "Edit or create a note"; argumentNames = "filename"; @@ -120,13 +109,6 @@ publickey = "ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub"; forloop = "for i in (seq 1 100)"; - # Nix - ns = "nix-shell -p"; - nsr = "nix-shell-run"; - nps = "nix repl ''"; - nixo = "man configuration.nix"; - nixh = "man home-configuration.nix"; - # Docker dc = "$DOTS/bin/docker_cleanup"; dr = "docker run --rm -it"; @@ -145,12 +127,5 @@ programs.zoxide.enableFishIntegration = true; programs.fzf.enableFishIntegration = true; - # Provides "command-not-found" options - # Requires activating a manual download - programs.nix-index = { - enable = true; - enableFishIntegration = true; - }; - }; } diff --git a/modules/shell/fish/functions/fish_user_key_bindings.fish b/modules/shell/fish/functions/fish_user_key_bindings.fish index cbf2c63..04a2915 100644 --- a/modules/shell/fish/functions/fish_user_key_bindings.fish +++ b/modules/shell/fish/functions/fish_user_key_bindings.fish @@ -6,13 +6,15 @@ bind -M insert \ca 'cd ~; and edit; and commandline -a "; cd -"; commandline -f bind -M default \ca 'cd ~; and edit; and commandline -a "; cd -"; commandline -f execute' bind -M insert \ce recent bind -M default \ce recent -bind -M insert \cg commandline-git-commits -bind -M insert \cG 'commandline -i (git rev-parse --show-toplevel 2>/dev/null || echo ".")' +bind -M default \cg commandline-git-commits +bind -M insert \cg 'commandline -i (git rev-parse --show-toplevel 2>/dev/null || echo ".")' bind -M insert \cf fcd bind -M default \cf fcd bind -M insert \cp projects bind -M default \cp projects bind -M insert \x1F accept-autosuggestion bind -M default \x1F accept-autosuggestion -bind -M insert \cn 'commandline -r "nix run nixpkgs#"' -bind -M default \cn 'commandline -r "nix run nixpkgs#"' +bind -M insert \cn 'commandline -r "nix run github:NixOS/nixpkgs/nixpkgs-unstable#"' +bind -M default \cn 'commandline -r "nix run github:NixOS/nixpkgs/nixpkgs-unstable#"' +bind -M insert \x11F nix-fzf +bind -M default \x11F nix-fzf diff --git a/modules/shell/nixpkgs.nix b/modules/shell/nixpkgs.nix new file mode 100644 index 0000000..88bc909 --- /dev/null +++ b/modules/shell/nixpkgs.nix @@ -0,0 +1,59 @@ +{ config, pkgs, ... }: { + home-manager.users.${config.user} = { + + programs.fish = { + shellAbbrs = { + ns = "nix-shell -p"; + nsr = "nix-shell-run"; + nps = "nix repl ''"; + nixo = "man configuration.nix"; + nixh = "man home-configuration.nix"; + nr = "rebuild-nixos"; + nro = "rebuild-nixos offline"; + }; + functions = { + nix-shell-run = { + body = '' + set program $argv[1] + if test (count $argv) -ge 2 + commandline -r "nix run github:NixOS/nixpkgs/nixpkgs-unstable#$program -- $argv[2..-1]" + else + commandline -r "nix run github:NixOS/nixpkgs/nixpkgs-unstable#$program" + end + commandline -f execute + ''; + }; + nix-fzf = { + body = '' + commandline -i (nix-instantiate --eval --json \ + -E 'builtins.attrNames (import {})' \ + | jq '.[]' -r | fzf) + commandline -f repaint + ''; + }; + rebuild-nixos = { + body = '' + if test "$argv[1]" = "offline" + set option "--option substitute false" + end + git -C ${config.dotfilesPath} add --all + commandline -r "doas nixos-rebuild switch $option --flake ${config.dotfilesPath}" + commandline --function execute + ''; + }; + }; + }; + + # Provides "command-not-found" options + # Requires activating a manual download + programs.nix-index = { + enable = true; + enableFishIntegration = true; + }; + + }; + + # Set system channels for nix-shell + nix = { nixPath = [ "nixpkgs=${pkgs.path}" ]; }; + +}