From 31f3364f06e8fc45f7c3dd04541dfa892d942e38 Mon Sep 17 00:00:00 2001 From: Nikolaos Karaolidis Date: Mon, 6 Jan 2025 13:44:43 +0200 Subject: [PATCH] Add go devshell Signed-off-by: Nikolaos Karaolidis --- flake.nix | 1 + .../user/console/kubernetes/default.nix | 7 +---- .../configs/user/console/neovim/default.nix | 28 +++++++++++-------- .../user/console/nix-direnv/default.nix | 16 +++++++++-- .../configs/user/console/ranger/default.nix | 14 ++++++---- .../common/configs/user/console/zsh/.p10k.zsh | 9 ++++-- .../configs/user/console/zsh/default.nix | 2 ++ .../configs/user/console/zsh/options.nix | 25 +++++++++++++++++ .../configs/user/gui/vscode/default.nix | 1 + .../user/gui/vscode/langs/go/default.nix | 9 ++++++ hosts/common/shells/go/default.nix | 22 +++++++++++++++ hosts/eirene/users/nick/default.nix | 2 +- hosts/elara/users/nikara/default.nix | 7 +++-- hosts/installer/users/nick/default.nix | 2 +- 14 files changed, 111 insertions(+), 34 deletions(-) create mode 100644 hosts/common/configs/user/console/zsh/options.nix create mode 100644 hosts/common/configs/user/gui/vscode/langs/go/default.nix create mode 100644 hosts/common/shells/go/default.nix diff --git a/flake.nix b/flake.nix index a6b356a..ea25368 100644 --- a/flake.nix +++ b/flake.nix @@ -102,6 +102,7 @@ { devShells = { bun = import ./hosts/common/shells/bun { inherit pkgs; }; + go = import ./hosts/common/shells/go { inherit pkgs; }; nix = import ./hosts/common/shells/nix { inherit pkgs; }; nodejs = import ./hosts/common/shells/nodejs { inherit pkgs; }; python = import ./hosts/common/shells/python { inherit pkgs; }; diff --git a/hosts/common/configs/user/console/kubernetes/default.nix b/hosts/common/configs/user/console/kubernetes/default.nix index 16854a1..89f1ea5 100644 --- a/hosts/common/configs/user/console/kubernetes/default.nix +++ b/hosts/common/configs/user/console/kubernetes/default.nix @@ -10,11 +10,6 @@ kubectl ]; - programs.zsh.initExtra = '' - export P10K_EXTRA_RIGHT_PROMPT_ELEMENTS=( - kubecontext - "''${P10K_EXTRA_RIGHT_PROMPT_ELEMENTS[@]}" - ) - ''; + programs.zsh.p10k.extraRightPromptElements = [ "kubecontext" ]; }; } diff --git a/hosts/common/configs/user/console/neovim/default.nix b/hosts/common/configs/user/console/neovim/default.nix index 6e92cce..88503ae 100644 --- a/hosts/common/configs/user/console/neovim/default.nix +++ b/hosts/common/configs/user/console/neovim/default.nix @@ -4,17 +4,21 @@ }: { ... }: { - home-manager.users.${user}.programs.neovim = { - enable = true; - defaultEditor = true; - viAlias = true; - vimAlias = true; - vimdiffAlias = true; - extraConfig = '' - set tabstop=2 - set shiftwidth=2 - set expandtab - set smartindent - ''; + home-manager.users.${user}.programs = { + neovim = { + enable = true; + defaultEditor = true; + viAlias = true; + vimAlias = true; + vimdiffAlias = true; + extraConfig = '' + set tabstop=2 + set shiftwidth=2 + set expandtab + set smartindent + ''; + }; + + zsh.p10k.extraRightPromptElements = [ "vim_shell" ]; }; } diff --git a/hosts/common/configs/user/console/nix-direnv/default.nix b/hosts/common/configs/user/console/nix-direnv/default.nix index d6b7bb8..da24002 100644 --- a/hosts/common/configs/user/console/nix-direnv/default.nix +++ b/hosts/common/configs/user/console/nix-direnv/default.nix @@ -19,14 +19,24 @@ initExtra = '' nix-direnv() { if [ -z "$1" ]; then - echo "Usage: nix-direnv " - return 1 + echo "use flake" > .envrc + else + echo "use flake self#$1" > .envrc + fi + + if git rev-parse --is-inside-work-tree &> /dev/null && ! grep -q "^\.envrc$" .gitignore .git/info/exclude; then + echo "Do you want to hide the .envrc file from git? (y/N)" + read -r answer + if [[ "$answer" =~ ^[Yy]$ ]]; then + echo ".envrc" >> .git/info/exclude + fi fi - echo "use $1" > .envrc direnv allow } ''; + + p10k.extraRightPromptElements = [ "direnv" ]; }; }; diff --git a/hosts/common/configs/user/console/ranger/default.nix b/hosts/common/configs/user/console/ranger/default.nix index 2b0df61..8a10095 100644 --- a/hosts/common/configs/user/console/ranger/default.nix +++ b/hosts/common/configs/user/console/ranger/default.nix @@ -6,12 +6,16 @@ { environment.persistence."/cache"."${home}/.cache/ranger" = { }; - home-manager.users.${user}.programs.ranger = { - enable = true; + home-manager.users.${user}.programs = { + ranger = { + enable = true; - settings = { - preview_images = true; - preview_images_method = "kitty"; + settings = { + preview_images = true; + preview_images_method = "kitty"; + }; }; + + zsh.p10k.extraRightPromptElements = [ "ranger" ]; }; } diff --git a/hosts/common/configs/user/console/zsh/.p10k.zsh b/hosts/common/configs/user/console/zsh/.p10k.zsh index 8d7cfdd..1a1d7b1 100644 --- a/hosts/common/configs/user/console/zsh/.p10k.zsh +++ b/hosts/common/configs/user/console/zsh/.p10k.zsh @@ -22,9 +22,6 @@ status command_execution_time background_jobs - direnv - ranger - vim_shell nix_shell per_directory_history "${P10K_EXTRA_RIGHT_PROMPT_ELEMENTS[@]}" @@ -228,6 +225,12 @@ typeset -g POWERLEVEL9K_KUBECONTEXT_DEFAULT_FOREGROUND=134 typeset -g POWERLEVEL9K_KUBECONTEXT_DEFAULT_CONTENT_EXPANSION='${P9K_KUBECONTEXT_CLOUD_CLUSTER:-${P9K_KUBECONTEXT_NAME}}${${:-/$P9K_KUBECONTEXT_NAMESPACE}:#/default}' + ################[ goenv: go environment (https://github.com/syndbg/goenv) ]################ + typeset -g POWERLEVEL9K_GOENV_FOREGROUND=37 + typeset -g POWERLEVEL9K_GOENV_SOURCES=(shell local global) + typeset -g POWERLEVEL9K_GOENV_PROMPT_ALWAYS_SHOW=true + typeset -g POWERLEVEL9K_GOENV_SHOW_SYSTEM=true + ##################################[ context: user@hostname ]################################## typeset -g POWERLEVEL9K_CONTEXT_ROOT_FOREGROUND=178 typeset -g POWERLEVEL9K_CONTEXT_{REMOTE,REMOTE_SUDO}_FOREGROUND=180 diff --git a/hosts/common/configs/user/console/zsh/default.nix b/hosts/common/configs/user/console/zsh/default.nix index ae48ed9..0cbe471 100644 --- a/hosts/common/configs/user/console/zsh/default.nix +++ b/hosts/common/configs/user/console/zsh/default.nix @@ -10,6 +10,8 @@ }; home-manager.users.${user} = { + imports = [ ./options.nix ]; + programs.zsh = { enable = true; dotDir = ".config/zsh"; diff --git a/hosts/common/configs/user/console/zsh/options.nix b/hosts/common/configs/user/console/zsh/options.nix new file mode 100644 index 0000000..04f983b --- /dev/null +++ b/hosts/common/configs/user/console/zsh/options.nix @@ -0,0 +1,25 @@ +{ config, lib, ... }: +let + cfg = config.programs.zsh; +in +{ + options.programs.zsh = + with lib; + with types; + { + p10k.extraRightPromptElements = mkOption { + type = listOf str; + default = [ ]; + description = "Extra elements to display on the right side of the prompt."; + }; + }; + + config.programs.zsh = + with lib; + with cfg; + { + initExtra = '' + export P10K_EXTRA_RIGHT_PROMPT_ELEMENTS=(${strings.concatStringsSep " " cfg.p10k.extraRightPromptElements}) + ''; + }; +} diff --git a/hosts/common/configs/user/gui/vscode/default.nix b/hosts/common/configs/user/gui/vscode/default.nix index 61b9880..d22e424 100644 --- a/hosts/common/configs/user/gui/vscode/default.nix +++ b/hosts/common/configs/user/gui/vscode/default.nix @@ -116,6 +116,7 @@ in imports = [ ./langs/c + ./langs/go ./langs/lua ./langs/nix ./langs/python diff --git a/hosts/common/configs/user/gui/vscode/langs/go/default.nix b/hosts/common/configs/user/gui/vscode/langs/go/default.nix new file mode 100644 index 0000000..e4eb858 --- /dev/null +++ b/hosts/common/configs/user/gui/vscode/langs/go/default.nix @@ -0,0 +1,9 @@ +{ pkgs, ... }: +{ + programs.vscode.extensions = + with pkgs; + with vscode-extensions; + [ + golang.go + ]; +} diff --git a/hosts/common/shells/go/default.nix b/hosts/common/shells/go/default.nix new file mode 100644 index 0000000..ddac660 --- /dev/null +++ b/hosts/common/shells/go/default.nix @@ -0,0 +1,22 @@ +{ pkgs, ... }: +pkgs.mkShell { + packages = with pkgs; [ + go + gopls + go-tools + ]; + + shellHook = '' + export P10K_EXTRA_RIGHT_PROMPT_ELEMENTS=( + goenv + "''${P10K_EXTRA_RIGHT_PROMPT_ELEMENTS[@]}" + ) + + if git rev-parse --is-inside-work-tree &> /dev/null && ! grep -q "^\.go$" .gitignore .git/info/exclude; then + echo ".go" >> .git/info/exclude + export GOPATH="$(git rev-parse --show-toplevel)/.go" + else + export GOPATH="$(pwd)/.go" + fi + ''; +} diff --git a/hosts/eirene/users/nick/default.nix b/hosts/eirene/users/nick/default.nix index c275363..cacc6cc 100644 --- a/hosts/eirene/users/nick/default.nix +++ b/hosts/eirene/users/nick/default.nix @@ -125,7 +125,7 @@ in hostname = "github.com"; user = "git"; identityFile = "${home}/.ssh/ssh_git_personal_ed25519_key"; - extraOptions.StrictHostKeyChecking = "accept-new"; + extraOptions.StrictHostKeyChecking = "no"; }; }; diff --git a/hosts/elara/users/nikara/default.nix b/hosts/elara/users/nikara/default.nix index b138ea0..a2b4cef 100644 --- a/hosts/elara/users/nikara/default.nix +++ b/hosts/elara/users/nikara/default.nix @@ -144,7 +144,7 @@ in hostname = "github.com"; user = "git"; identityFile = "${home}/.ssh/ssh_git_personal_ed25519_key"; - extraOptions.StrictHostKeyChecking = "accept-new"; + extraOptions.StrictHostKeyChecking = "no"; }; # SAS @@ -152,13 +152,14 @@ in hostname = "github.com"; user = "git"; identityFile = "${home}/.ssh/ssh_git_sas_ed25519_key"; - extraOptions.StrictHostKeyChecking = "accept-new"; + extraOptions.StrictHostKeyChecking = "no"; }; + "gitlab.sas.com" = { hostname = "gitlab.sas.com"; user = "git"; identityFile = "${home}/.ssh/ssh_git_sas_ed25519_key"; - extraOptions.StrictHostKeyChecking = "accept-new"; + extraOptions.StrictHostKeyChecking = "no"; }; }; diff --git a/hosts/installer/users/nick/default.nix b/hosts/installer/users/nick/default.nix index dd3d22f..17cd54c 100644 --- a/hosts/installer/users/nick/default.nix +++ b/hosts/installer/users/nick/default.nix @@ -81,7 +81,7 @@ in hostname = "github.com"; user = "git"; identityFile = "${home}/.ssh/ssh_git_personal_ed25519_key"; - extraOptions.StrictHostKeyChecking = "accept-new"; + extraOptions.StrictHostKeyChecking = "no"; }; }; };