NixOS + home-manager configs, mirrored from GitLab SaaS. gitlab.com/andreijiroh-dev/nixops-config
nix-flake nixos home-manager nixpkgs nix-flakes
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore(pkgs): do some bts work for detect-vscode-for-git and ssh-agent-loader scripts

Also package them as part of my flake btw

Signed-off-by: Andrei Jiroh Halili <ajhalili2006@andreijiroh.dev>

+167 -13
+35
flake.nix
··· 73 73 lib, 74 74 zen-browser 75 75 }: 76 + let 77 + our-pkgs = import ./pkgs; 78 + in 76 79 { 80 + # For CI and other builds 81 + packages = flake-utils.lib.eachDefaultSystem (system: 82 + let 83 + pkgs = nixpkgs.legacyPackages.${system}; 84 + in 85 + { 86 + detect-vscode-for-git = pkgs.callPackage ./pkgs/detect-vscode-for-git.nix { }; 87 + ssh-agent-loader = pkgs.callPackage ./pkgs/ssh-agent-loader.nix { }; 88 + } 89 + ); 90 + 91 + overlays.default = final: prev: { 92 + detect-vscode-for-git = self.packages.${prev.system}.detect-vscode-for-git; 93 + ssh-agent-loader = self.packages.${prev.system}.ssh-agent-loader; 94 + }; 95 + 77 96 nixosConfigurations = { 78 97 recoverykit-amd64 = nixpkgs.lib.nixosSystem { 79 98 system = "x86_64-linux"; 80 99 modules = [ 100 + { nixpkgs.overlays = [ self.overlays.default ]; } 81 101 ./hosts/recoverykit/configuration.nix 82 102 "${nixpkgs}/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix" 83 103 ]; ··· 86 106 portable-amd64-256gb = nixpkgs.lib.nixosSystem { 87 107 system = "x86_64-linux"; 88 108 modules = [ 109 + { nixpkgs.overlays = [ self.overlays.default ]; } 89 110 ./hosts/portable/amd64/configuration.nix 90 111 91 112 # load Determinate Nix and the rest ··· 109 130 # Override bat-extras with the patched version 110 131 { 111 132 nixpkgs.overlays = [ 133 + self.overlays.default 112 134 (final: prev: { 113 135 #bat-extras = nixpkgs-bat-extras-pr.legacyPackages.${prev.system}.bat-extras; 114 136 }) ··· 137 159 # otherwise, it fails to build with some missing dependencies 138 160 system = "x86_64-linux"; 139 161 modules = [ 162 + { nixpkgs.overlays = [ self.overlays.default ]; } 140 163 ./hosts/stellapent-cier/configuration.nix 141 164 142 165 # load Determinate Nix and the rest ··· 162 185 stellapent-cier = home-manager.lib.homeManagerConfiguration { 163 186 inherit lib; 164 187 pkgs = nixpkgs.legacyPackages.x86_64-linux; 188 + extraSpecialArgs = { 189 + inherit self; 190 + }; 165 191 modules = [ 192 + { nixpkgs.overlays = [ self.overlays.default ]; } 166 193 ./shared/home-manager/main.nix 167 194 { 168 195 home = { ··· 180 207 # nix run home-manager/master -- switch --flake .#plain 181 208 plain = home-manager.lib.homeManagerConfiguration { 182 209 pkgs = nixpkgs.legacyPackages.x86_64-linux; 210 + extraSpecialArgs = { 211 + inherit self; 212 + }; 183 213 modules = [ 184 214 # Override bat-extras with the patched version 185 215 { 186 216 nixpkgs.overlays = [ 217 + self.overlays.default 187 218 (final: prev: { 188 219 #bat-extras = nixpkgs-bat-extras-pr.legacyPackages.${prev.system}.bat-extras; 189 220 }) ··· 205 236 # nix run home-manager/master -- switch --flake .#arm64-plain 206 237 arm64-plain = home-manager.lib.homeManagerConfiguration { 207 238 pkgs = nixpkgs.legacyPackages.aarch64-linux; 239 + extraSpecialArgs = { 240 + inherit self; 241 + }; 208 242 modules = [ 243 + { nixpkgs.overlays = [ self.overlays.default ]; } 209 244 ./shared/home-manager/nogui.nix 210 245 { 211 246 home.username = "ajhalili2006";
+26 -3
misc/bash/lib/detect-vscode-for-git
··· 1 1 #!/usr/bin/env bash 2 2 # SPDX-License-Identifier: MPL-2.0 3 3 # Sets EDITOR and related variables to use VS Code instead of firing up nano (or worse vi), 4 - # based on env var detection of VSCODE_* vars. 4 + # based on env var detection of VSCODE_* vars. Utilized by git-commit and similar git commands 5 + # that fire up an editor. 5 6 6 7 # Handle verbose logging 8 + log() { 9 + echo "[detect-vscode-for-git] $*" 10 + } 11 + 7 12 if [[ -n $DEBUG ]]; then 8 13 set -x 9 14 fi 10 15 11 16 if [[ "$VSCODE_GIT_IPC_HANDLE" != "" && "$VSCODE_GIT_ASKPASS_NODE" != "" && "$TERM_PROGRAM" == "vscode" ]]; then 12 17 __VSCODE_BASE_PATH="$(dirname "${VSCODE_GIT_ASKPASS_NODE}")" 18 + log "Detected VS Code environment. Base path: ${__VSCODE_BASE_PATH}" 13 19 14 20 # Check if the path is in ~/.vscode/cli/servers (for Remote Tunnels), ~/.vscode-server/cli 15 21 # (for Remote SSH) or not 16 22 if [[ $__VSCODE_BASE_PATH =~ ^"$HOME"/.vscode/cli/servers ]] || [[ $__VSCODE_BASE_PATH =~ ^"$HOME"/.vscode-server/cli ]]; then 17 23 # If it is, set the path to the correct location 18 - VSCODE_CLI_PATH="${__VSCODE_BASE_PATH}/bin/remote-cli/code" 24 + __VSCODE_STABLE_CLI_PATH="${__VSCODE_BASE_PATH}/bin/remote-cli/code" 25 + __VSCODE_INSIDERS_CLI_PATH="${__VSCODE_BASE_PATH}/bin/remote-cli/code-insiders" 26 + 27 + # Check if the stable or insiders version exists 28 + if [[ -f "$__VSCODE_INSIDERS_CLI_PATH" ]]; then 29 + VSCODE_CLI_PATH="$__VSCODE_INSIDERS_CLI_PATH" 30 + elif [[ -f "$__VSCODE_STABLE_CLI_PATH" ]]; then 31 + VSCODE_CLI_PATH="$__VSCODE_STABLE_CLI_PATH" 32 + fi 19 33 else 20 34 # otherwise just use plain cli/desktop app CLI 21 - VSCODE_CLI_PATH="$(command -v code)" 35 + __VSCODE_STABLE_CLI_PATH="$(command -v code)" 36 + __VSCODE_INSIDERS_CLI_PATH="$(command -v code-insiders)" 37 + 38 + # Same with earlier 39 + if [[ -f "$__VSCODE_INSIDERS_CLI_PATH" ]]; then 40 + VSCODE_CLI_PATH="$__VSCODE_INSIDERS_CLI_PATH" 41 + elif [[ -f "$__VSCODE_STABLE_CLI_PATH" ]]; then 42 + VSCODE_CLI_PATH="$__VSCODE_STABLE_CLI_PATH" 43 + fi 22 44 fi 45 + log "Using VS Code CLI path: ${VSCODE_CLI_PATH}" 23 46 24 47 export GIT_EDITOR="${VSCODE_CLI_PATH} --wait" EDITOR="${VSCODE_CLI_PATH} --wait" VISUAL="${VSCODE_CLI_PATH} --wait" VSCODE_CLI_PATH 25 48 fi
+20 -6
misc/bash/lib/ssh-agent-loader
··· 1 1 #!/usr/bin/env bash 2 2 # shellcheck disable=SC2034 3 3 # SPDX-License-Identifier: MPL-2.0 4 + # Reliably detect and switch between SSH agents like keychain, yubikey-agent, 1Password, etc. 4 5 5 6 if [[ $DEBUG != "" ]]; then 6 7 set -x ··· 30 31 if [[ -z "${XDG_RUNTIME_DIR}" ]]; then 31 32 logOps warn "XDG_RUNTIME_DIR is possibly undefined, see https://github.com/swaywm/sway/issues/7202" 32 33 logOps warn "for context and https://wiki.archlinux.org/title/XDG_Base_Directory for docs" 33 - logOps warn "setting it up for you using the default '/run/user/$(id -u)' value in 3s..." 34 + logOps warn "Temporarily using '/run/user/$(id -u)' for XDG_RUNTIME_DIR in 3s..." 34 35 sleep 3 35 36 XDG_RUNTIME_DIR="/run/user/$(id -u)" 36 37 export XDG_RUNTIME_DIR ··· 46 47 try_keychain_ssh_agent() { 47 48 if [[ $FF_KEYCHAIN == "1" ]]; then 48 49 logOps info "attempting to use keychain for SSH agents" keychain 49 - [[ "$SSH_AGENT_LOADER_SLIENT" == "" ]] && eval "$(keychain --eval --agents ssh,gpg)" || eval "$(keychain --eval --agents ssh,gpg --quiet)" 50 + if [[ "$SSH_AGENT_LOADER_SLIENT" == "" ]]; then 51 + eval "$(keychain --ssh-spawn-gpg --ssh-allow-gpg)" 52 + else 53 + eval "$(keychain --eval --ssh-spawn-gpg --ssh-allow-gpg --quiet)" 54 + fi 50 55 else 51 56 logOps warn "keychain is not in PATH yet" keychain 52 57 return 1 ··· 55 60 56 61 # Ripped off NixOS-generated set-environment on my laptop for yubikey-agent setup 57 62 try_yubikey_agent() { 58 - if [[ -f "${XDG_RUNTIME_DIR}/yubikey-agent/yubikey-agent.sock" ]]; then 59 - logOps info "using YubiKey SSH Agent via socket at XDG_RUNTIME_DIR" yubikey-agent 60 - export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/yubikey-agent/yubikey-agent.sock" 63 + YUBIKEY_AGENT_AUTH_SOCK="${XDG_RUNTIME_DIR}/yubikey-agent/yubikey-agent.sock" 64 + if [[ -f "${YUBIKEY_AGENT_AUTH_SOCK}" ]]; then 65 + logOps info "attempting to use Yubikey SSH agent" yubikey-agent 66 + if ! SSH_AUTH_SOCK=${YUBIKEY_AGENT_AUTH_SOCK} ssh-add -l >> /dev/null 2>&1; then 67 + logOps warn "something went wrong while checking for Yubikey SSH agent availability" yubikey-agent 68 + logOps warn "is your Yubikey plugged in properly?" yubikey-agent 69 + return 1 70 + fi 71 + else 72 + logOps error "Yubikey SSH agent seems to be not available on this host" yubikey-agent 73 + return 1 61 74 fi 62 75 } 63 76 ··· 81 94 ssh-agent-loader() { 82 95 if [[ $1 == "" || $1 == "auto" ]]; then 83 96 if [[ $SSH_CONNECTION != "" ]] && [[ $VSCODE_IPC_HOOK_CLI != "" ]]; then 84 - logOps info "automatic detection is disabled while you're in a VS Code Remote SSH session" 97 + logOps info "automatic detection is disabled while you're in a VS Code Remote SSH/Tunnels session" 98 + logOps info "to enable SSH agent, please manually invoke the shell function with desired agent" 85 99 return 86 100 fi 87 101
+9
pkgs/README.md
··· 1 + # Nix flakes-packages utilities 2 + 3 + ## What's included 4 + 5 + To install them, run `nix profile add github:andreijiroh-dev/nixops-config#<package-name>` or 6 + add them into your NixOS/home-manager package lists after importing the flake. 7 + 8 + * [`detect-vscode-for-git`](./detect-vscode-for-git.nix) 9 + * [`ssh-agent-loader`](./ssh-agent-loader.nix)
+25
pkgs/detect-vscode-for-git.nix
··· 1 + { stdenv, lib, ... }: 2 + 3 + stdenv.mkDerivation { 4 + pname = "detect-vscode-for-git"; 5 + version = "0.1.0"; 6 + 7 + src = ../misc/bash/lib/detect-vscode-for-git; 8 + 9 + dontUnpack = true; 10 + 11 + installPhase = '' 12 + runHook preInstall 13 + 14 + install -D -m755 $src $out/bin/detect-vscode-for-git 15 + 16 + runHook postInstall 17 + ''; 18 + 19 + meta = with lib; { 20 + description = "A script to detect and set VS Code as the git editor."; 21 + license = licenses.mpl20; 22 + platforms = platforms.all; 23 + maintainers = with maintainers; [ ajhalili2006 ]; 24 + }; 25 + }
+18
pkgs/maintainer-metadata.nix
··· 1 + # pkgs/maintainer-metadata.nix 2 + # 3 + # This file contains maintainer information for packages in this flake. 4 + # It's intended to be imported by package definitions. 5 + { 6 + ajhalili2006 = { 7 + name = "Andrei Jiroh Halili"; 8 + github = "ajhalili2006"; 9 + githubId = 34998342; 10 + email = "ajhalili2006@andreijiroh.dev"; 11 + matrix = "@ajhalili2006@envs.net"; 12 + keys = [ 13 + { 14 + fingerprint = "4D5E 6317 58CB 9CC4 5941 B1CE 67BF C91B 3DA1 2BE8" 15 + } 16 + ]; 17 + }; 18 + }
+25
pkgs/ssh-agent-loader.nix
··· 1 + { stdenv, lib, ... }: 2 + 3 + stdenv.mkDerivation { 4 + pname = "ssh-agent-loader"; 5 + version = "0.1.0"; 6 + 7 + src = ../misc/bash/lib/ssh-agent-loader; 8 + 9 + dontUnpack = true; 10 + 11 + installPhase = '' 12 + runHook preInstall 13 + 14 + install -D -m755 $src $out/bin/ssh-agent-loader 15 + 16 + runHook postInstall 17 + ''; 18 + 19 + meta = with lib; { 20 + description = "A script to reliably detect and switch between SSH agents."; 21 + license = licenses.mpl20; 22 + platforms = platforms.all; 23 + maintainers = with maintainers; [ ajhalili2006 ]; 24 + }; 25 + }
+9 -4
shared/home-manager/shell.nix
··· 1 - { lib, ... }: { 1 + { lib, pkgs, ... }: { 2 + home.packages = [ 3 + pkgs.detect-vscode-for-git 4 + pkgs.ssh-agent-loader 5 + ]; 6 + 2 7 # taken from https://github.com/andreijiroh-dev/dotfiles/blob/main/.config/aliases 3 8 home.shellAliases = { 4 9 signoff = "git commit --signoff"; ··· 63 68 fi 64 69 65 70 # source our ssh-agent-loader first 66 - FF_SKIP_AUTO_SSH_AGENT_LOADER=true . ${../../misc/bash/lib/ssh-agent-loader} 71 + FF_SKIP_AUTO_SSH_AGENT_LOADER=true . ${pkgs.ssh-agent-loader}/bin/ssh-agent-loader 67 72 68 73 # try to use keychain in this situation 69 74 SSH_AGENT_LOADER_SLIENT=1 ssh-agent-loader keychain ··· 76 81 ''; 77 82 bashrcExtra = '' 78 83 # detect if we are inside VS Code 79 - source ${../../misc/bash/lib/detect-vscode-for-git} 84 + source ${pkgs.detect-vscode-for-git}/bin/detect-vscode-for-git 80 85 81 86 # HACK: https://github.com/akinomyoga/ble.sh/wiki/Manual-A1-Installation#user-content-nixpkgs 82 87 export BLESH_PATH=$(blesh-share) ··· 87 92 export GPG_TTY=$(tty) 88 93 89 94 # source our ssh-agent-loader first 90 - source ${../../misc/bash/lib/ssh-agent-loader} 95 + source ${pkgs.ssh-agent-loader}/bin/ssh-agent-loader 91 96 92 97 # hack around for 1Password CLI when 1Password desktop app is up 93 98 if [[ $$FF_USE_OP_CLI_PLUGINS == "true" ]]; then