一键导入
gitserver-guide
Git SSH server setup and configuration on NixOS including bare repository management, SSH key authentication, and remote access
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Git SSH server setup and configuration on NixOS including bare repository management, SSH key authentication, and remote access
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | gitserver-guide |
| description | Git SSH server setup and configuration on NixOS including bare repository management, SSH key authentication, and remote access |
このドキュメントでは、NixOS上でSSH経由でアクセス可能なGitベアリポジトリサーバーの設定と使用方法について説明します。
NixOSのservices.gitserverモジュールを使用して、SSH経由でアクセス可能なGitサーバーを簡単に構築できます。
アクセスするクライアントマシンでSSH鍵を生成します(既にある場合はスキップ):
# Ed25519鍵を生成(推奨)
ssh-keygen -t ed25519 -C "your_email@example.com"
# または RSA鍵
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
公開鍵を確認:
cat ~/.ssh/id_ed25519.pub
# または
cat ~/.ssh/id_rsa.pub
nixos/configuration.nixまたは別のモジュールファイルに以下を追加:
{
services.gitserver = {
# Gitサーバーを有効化
enable = true;
# アクセスを許可するSSH公開鍵
authorizedKeys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIExampleKey1 user@laptop"
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIExampleKey2 user@desktop"
];
# 初期化するリポジトリ
repositories = [
"myproject.git"
"dotfiles.git"
"notes.git"
];
};
}
sudo nixos-rebuild switch --flake .#desktop
NixOSマシン自体からアクセスする場合:
# ローカルパスで直接アクセス
git clone /var/lib/git/myproject.git
# またはSSH経由
git clone git@localhost:myproject.git
他のマシンからSSH経由でアクセス:
# ホスト名を使用
git clone git@nixos-hostname:myproject.git
# IPアドレスを使用
git clone git@192.168.1.100:myproject.git
# Tailscale経由(Tailscaleを使用している場合)
git clone git@nixos-tailscale-name:myproject.git
# ローカルにリポジトリがある場合
cd /path/to/local/project
git init
git add .
git commit -m "Initial commit"
# リモートを追加してプッシュ
git remote add origin git@nixos-hostname:myproject.git
git push -u origin main
configuration.nixを編集:
services.gitserver.repositories = [
"myproject.git"
"dotfiles.git"
"newrepo.git" # 新規追加
];
設定を適用:
sudo nixos-rebuild switch --flake .#desktop
sudo -u git git init --bare /var/lib/git/newrepo.git
# クライアントマシンから実行
ssh git@nixos-hostname
# 成功すると以下のメッセージが表示されます:
# fatal: Interactive git shell is not enabled.
# Connection to nixos-hostname closed.
このメッセージは正常です。git-shellは対話的アクセスを制限しています。
# NixOS上で実行
sudo ls -la /var/lib/git/
# 登録された公開鍵を確認
sudo cat /var/lib/git/.ssh/authorized_keys
# SSH詳細ログで診断
ssh -vvv git@nixos-hostname
# ファイアウォールの確認
sudo nix-instantiate --eval -E '(import <nixpkgs/nixos> {}).config.networking.firewall.allowedTCPPorts'
# Git初期化サービスの状態
systemctl status git-init-repos.service
# ログを確認
journalctl -u git-init-repos.service
false"git""git""/var/lib/git"[]例:
authorizedKeys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIExampleKey user@host"
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQ... user@host"
];
[]例:
repositories = [
"myproject.git"
"dotfiles.git"
"website.git"
];
このGitサーバーは以下のセキュリティ対策を実装しています:
# 全リポジトリをアーカイブ
sudo tar czf git-backup-$(date +%Y%m%d).tar.gz /var/lib/git/
# 特定のリポジトリのみ
sudo tar czf myproject-backup.tar.gz /var/lib/git/myproject.git
# アーカイブから復元
sudo tar xzf git-backup-20231225.tar.gz -C /
# 権限を修正
sudo chown -R git:git /var/lib/git/
NixOSのservices.resticやservices.borgbackupと組み合わせて自動バックアップを設定できます。
サーバーサイドフックを使用して、プッシュ時の自動処理を実装できます:
# post-receiveフックの例
sudo -u git tee /var/lib/git/myproject.git/hooks/post-receive << 'EOF'
#!/bin/sh
echo "Push received at $(date)"
# デプロイやビルドのコマンドをここに追加
EOF
sudo -u git chmod +x /var/lib/git/myproject.git/hooks/post-receive
複数のユーザーで異なるアクセス権限を管理したい場合は、GitoliteやGiteaの使用を検討してください。
Step-by-step installation guide for Nix and dotfiles setup including nix.conf configuration, channel updates, home-manager, and nix-darwin
スキルのプロンプト品質を評価・チューニングする。スキルを書いたあと別のサブエージェントに実行させ、不明瞭点・自動補完箇所・達成率をレポートさせて反復改善する。Use when you want to evaluate or tune a SKILL.md prompt quality. Ref: https://zenn.dev/mizchi/articles/empirical-prompt-tuning
Generate professional English commit messages with gitmoji based on git diff. Use when creating commit messages, analyzing staged changes, or formatting commits according to conventional commits + gitmoji style.
Generate professional English commit messages with gitmoji based on git diff. Use when creating commit messages, analyzing staged changes, or formatting commits according to conventional commits + gitmoji style.
NPM tools and package management using mise including commitizen, cz-git, and global package configuration
System services configuration guide including AeroSpace, JankyBorders, and AltTab on macOS