photoncloud-monorepo/Nix-NOS.md
centra 3eeb303dcb feat: Batch commit for T039.S3 deployment
Includes all pending changes needed for nixos-anywhere:
- fiberlb: L7 policy, rule, certificate types
- deployer: New service for cluster management
- nix-nos: Generic network modules
- Various service updates and fixes

🀖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-13 04:34:51 +09:00

17 KiB
Raw Blame History

PlasmaCloud/PhotonCloud ず Nix-NOS の統合分析

Architecture Decision (2025-12-13)

決定: Nix-NOSを汎甚ネットワヌクモゞュヌルずしお別リポゞトリに分離する。

Three-Layer Architecture

Layer 3: PlasmaCloud Cluster (T061)
  - plasmacloud-cluster.nix
  - cluster-config.json生成
  - Deployer (Rust)
  depends on ↓

Layer 2: PlasmaCloud Network (T061)
  - plasmacloud-network.nix
  - FiberLB BGP連携
  - PrismNET統合
  depends on ↓

Layer 1: Nix-NOS Generic (T062) ← 別リポゞトリ
  - BGP (BIRD2/GoBGP)
  - VLAN
  - Network interfaces
  - PlasmaCloudを知らない汎甚モゞュヌル

Repository Structure

  • github.com/centra/nix-nos: Layer 1 (汎甚、VyOS/OpenWrt代替)
  • github.com/centra/plasmacloud: Layers 2+3 (既存リポゞトリ)

1. 既存プロゞェクトの抂芁

PlasmaCloudPhotonCloudは、以䞋のコンポヌネントで構成されるクラりド基盀プロゞェクト

コアサヌビス

コンポヌネント 圹割 技術スタック
ChainFire 分散KVストアetcd互換 Rust, Raft (openraft)
FlareDB SQLデヌタベヌス Rust, KVバック゚ンド
IAM 認蚌・認可 Rust, JWT/mTLS
PlasmaVMC VM管理 Rust, KVM/FireCracker
PrismNET オヌバヌレむネットワヌク Rust, OVN連携
LightningSTOR オブゞェクトストレヌゞ Rust, S3互換
FlashDNS DNS Rust, hickory-dns
FiberLB ロヌドバランサヌ Rust, L4/L7, BGP予定
NightLight メトリクス Rust, Prometheus互換
k8shost コンテナオヌケストレヌション Rust, K8s API互換

むンフラ局

  • NixOSモゞュヌル: 各サヌビス甚 (nix/modules/)
  • first-boot-automation: 自動クラスタ参加
  • PXE/Netboot: ベアメタルプロビゞョニング
  • TLS蚌明曞管理: 開発甚蚌明曞生成スクリプト

2. Nix-NOS ずの統合ポむント

2.1 Baremetal Provisioning → Deployer匷化

既存の実装:

first-boot-automation.nix
├── cluster-config.json による蚭定泚入
├── bootstrap vs join の自動刀定
├── マヌカヌファむルによる冪等性
└── systemd サヌビス連携

Nix-NOSで远加すべき機胜:

既存 Nix-NOS远加
cluster-config.json (手動䜜成) topology.nix から自動生成
単䞀クラスタ構成 耇数クラスタ/サむト察応
nixos-anywhere 䟝存 Deployer (Phone Home + Push)
固定IP蚭定 IPAM連携による動的割圓

統合蚭蚈:

# topology.nixNix-NOS
{
  nix-nos.clusters.plasmacloud = {
    nodes = {
      "node01" = { 
        role = "control-plane";
        ip = "10.0.1.10";
        services = [ "chainfire" "flaredb" "iam" ];
      };
      "node02" = { role = "control-plane"; ip = "10.0.1.11"; };
      "node03" = { role = "worker"; ip = "10.0.1.12"; };
    };
    
    # Nix-NOSが自動生成 → first-boot-automationが読む
    # cluster-config.json の内容をNix評䟡時に決定
  };
}

2.2 Network Management → PrismNET + FiberLB + Nix-NOS BGP

既存の実装:

PrismNET (prismnet/)
├── VPC/Subnet/Port管理
├── Security Groups
├── IPAM
└── OVN連携

FiberLB (fiberlb/)
├── L4/L7ロヌドバランシング
├── ヘルスチェック
├── VIP管理
└── BGP統合蚭蚈枈み、GoBGPサむドカヌ

Nix-NOSで远加すべき機胜:

Nix-NOS Network Layer
├── BGP蚭定生成BIRD2
│   ├── iBGP/eBGP自動蚈算
│   ├── Route Reflector察応
│   └── ポリシヌ抜象化
├── topology.nix → systemd-networkd
├── OpenWrt/Cisco蚭定生成将来
└── FiberLB BGP連携

統合蚭蚈:

# Nix-NOSのBGPモゞュヌル → FiberLBのGoBGP蚭定に統合
{
  nix-nos.network.bgp = {
    autonomousSystems = {
      "65000" = {
        members = [ "node01" "node02" "node03" ];
        ibgp.strategy = "route-reflector";
        ibgp.reflectors = [ "node01" ];
      };
    };
    
    # FiberLBのVIPをBGPで広報
    vipAdvertisements = {
      "fiberlb" = {
        vips = [ "10.0.100.1" "10.0.100.2" ];
        nextHop = "self";
        communities = [ "65000:100" ];
      };
    };
  };
  
  # FiberLBモゞュヌルずの連携
  services.fiberlb.bgp = {
    enable = true;
    # Nix-NOSが生成するGoBGP蚭定を参照
    configFile = config.nix-nos.network.bgp.gobgpConfig;
  };
}

2.3 K8sパチモン → k8shost + Pure NixOS Alternative

既存の実装:

k8shost (k8shost/)
├── Pod管理gRPC API
├── Service管理ClusterIP/NodePort
├── Node管理
├── CNI連携
├── CSI連携
└── FiberLB/FlashDNS連携

Nix-NOSの圹割:

k8shostはすでにKubernetesのパチモンずしお機胜しおいる。Nix-NOSは

  1. k8shostを䜿う堎合: k8shostクラスタ自䜓のデプロむをNix-NOSで管理
  2. Pure NixOSK8sなし: より軜量な遞択肢ずしお、Systemd + Nix-NOSでサヌビス管理
┌─────────────────────────────────────────────────────────────┐
│                  Orchestration Options                       │
├──────────────────────────────────────────────────────────────
│  Option A: k8shost (K8s-like)                               │
│  ┌─────────────────────────────────────────────────────┐   │
│  │  Nix-NOS manages: cluster topology, network, certs  │   │
│  │  k8shost manages: pods, services, scaling           │   │
│  └─────────────────────────────────────────────────────┘   │
│                                                             │
│  Option B: Pure NixOS (K8s-free)                           │
│  ┌─────────────────────────────────────────────────────┐   │
│  │  Nix-NOS manages: everything                        │   │
│  │  systemd + containers, static service discovery     │   │
│  │  Use case: クラりド基盀自䜓の管理                    │   │
│  └─────────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────────┘

重芁な掞察:

「クラりドの基盀そのものを䜜るのにKubernetesは䜿いたくない」

これは正しいアプロヌチ。PlasmaCloudのコアサヌビスChainFire, FlareDB, IAM等は

  • K8sの䞊で動くのではなく、K8sを提䟛する偎
  • Pure NixOS + Systemdで管理されるべき
  • Nix-NOSはこのレむダヌを担圓

3. 具䜓的な統合蚈画

Phase 1: Baremetal Provisioning統合

目暙: first-boot-automationをNix-NOSのtopology.nixず連携

# nix/modules/first-boot-automation.nix ぞの远加
{ config, lib, ... }:
let
  # Nix-NOSのトポロゞヌから蚭定を生成
  clusterConfig = 
    if config.nix-nos.cluster != null then
      config.nix-nos.cluster.generateClusterConfig {
        hostname = config.networking.hostName;
      }
    else
      # 埓来のcluster-config.json読み蟌み
      builtins.fromJSON (builtins.readFile /etc/nixos/secrets/cluster-config.json);
in {
  # 既存のfirst-boot-automationロゞックはそのたた
  # ただし蚭定゜ヌスをNix-NOSに切り替え可胜に
}

Phase 2: BGP/Network統合

目暙: FiberLBのBGP連携T055.S3をNix-NOSで宣蚀的に管理

# nix/modules/fiberlb-bgp-nixnos.nix
{ config, lib, pkgs, ... }:
let
  fiberlbCfg = config.services.fiberlb;
  nixnosBgp = config.nix-nos.network.bgp;
in {
  config = lib.mkIf (fiberlbCfg.enable && nixnosBgp.enable) {
    # GoBGP蚭定をNix-NOSから生成
    services.gobgpd = {
      enable = true;
      configFile = pkgs.writeText "gobgp.yaml" (
        nixnosBgp.generateGobgpConfig {
          localAs = nixnosBgp.getLocalAs config.networking.hostName;
          routerId = nixnosBgp.getRouterId config.networking.hostName;
          neighbors = nixnosBgp.getPeers config.networking.hostName;
        }
      );
    };
    
    # FiberLBにGoBGPアドレスを泚入
    services.fiberlb.bgp = {
      gobgpAddress = "127.0.0.1:50051";
    };
  };
}

Phase 3: Deployer実装

目暙: Phone Home + Push型デプロむメントコントロヌラヌ

plasmacloud/
├── deployer/                      # 新芏远加
│   ├── src/
│   │   ├── api.rs                # Phone Home API
│   │   ├── orchestrator.rs       # デプロむワヌクフロヌ
│   │   ├── state.rs              # ノヌド状態管理ChainFire連携
│   │   └── iso_generator.rs      # ISO自動生成
│   └── Cargo.toml
└── nix/
    └── modules/
        └── deployer.nix          # NixOSモゞュヌル

ChainFireずの連携:

DeployerはChainFireを状態ストアずしお䜿甚

// deployer/src/state.rs
struct NodeState {
    hostname: String,
    status: NodeStatus,  // Pending, Provisioning, Active, Failed
    bootstrap_key_hash: Option<String>,
    ssh_pubkey: Option<String>,
    last_seen: DateTime<Utc>,
}

impl DeployerState {
    async fn register_node(&self, node: &NodeState) -> Result<()> {
        // ChainFireに保存
        self.chainfire_client
            .put(format!("deployer/nodes/{}", node.hostname), node.to_json())
            .await
    }
}

4. アヌキテクチャ党䜓図

┌─────────────────────────────────────────────────────────────────────┐
│                        Nix-NOS Layer                                │
│  ┌─────────────────────────────────────────────────────────────┐   │
│  │  topology.nix                                               │   │
│  │  - ノヌド定矩                                                │   │
│  │  - ネットワヌクトポロゞヌ                                     │   │
│  │  - サヌビス配眮                                              │   │
│  └─────────────────────────────────────────────────────────────┘   │
│                              │                                      │
│              generates       │                                      │
│                              â–Œ                                      │
│  ┌──────────────┬──────────────┬──────────────┬──────────────┐    │
│  │ NixOS Config │ BIRD Config  │ GoBGP Config │ cluster-     │    │
│  │ (systemd)    │ (BGP)        │ (FiberLB)    │ config.json  │    │
│  └──────────────┮──────────────┮──────────────┮──────────────┘    │
└─────────────────────────────────────────────────────────────────────┘
                              │
                              ▌
┌─────────────────────────────────────────────────────────────────────┐
│                     PlasmaCloud Services                            │
│  ┌───────────────────────────────────────────────────────────────┐ │
│  │  Control Plane                                                 │ │
│  │  ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐        │ │
│  │  │ChainFire │ │ FlareDB  │ │   IAM    │ │ Deployer │        │ │
│  │  │(Raft KV) │ │  (SQL)   │ │(AuthN/Z) │ │  (新芏)  │        │ │
│  │  └──────────┘ └──────────┘ └──────────┘ └──────────┘        │ │
│  └───────────────────────────────────────────────────────────────┘ │
│                                                                     │
│  ┌───────────────────────────────────────────────────────────────┐ │
│  │  Network Plane                                                 │ │
│  │  ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐        │ │
│  │  │ PrismNET │ │ FiberLB  │ │ FlashDNS │ │  BIRD2   │        │ │
│  │  │  (OVN)   │ │(LB+BGP)  │ │  (DNS)   │ │(Nix-NOS) │        │ │
│  │  └──────────┘ └──────────┘ └──────────┘ └──────────┘        │ │
│  └───────────────────────────────────────────────────────────────┘ │
│                                                                     │
│  ┌───────────────────────────────────────────────────────────────┐ │
│  │  Compute Plane                                                 │ │
│  │  ┌──────────┐ ┌──────────┐ ┌──────────┐                      │ │
│  │  │PlasmaVMC │ │ k8shost  │ │Lightning │                      │ │
│  │  │(VM/FC)   │ │(K8s-like)│ │  STOR    │                      │ │
│  │  └──────────┘ └──────────┘ └──────────┘                      │ │
│  └───────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────┘

5. 優先床ず実装順序

優先床 機胜 䟝存関係 工数
P0 topology.nix → cluster-config.json生成 なし 1週間
P0 BGPモゞュヌルBIRD2蚭定生成 なし 2週間
P1 FiberLB BGP連携GoBGP T055.S3完了 2週間
P1 Deployer基本実装 ChainFire 3週間
P2 OpenWrt蚭定生成 BGPモゞュヌル 2週間
P2 ISO自動生成パむプラむン Deployer完了埌 1週間
P2 各サヌビスの蚭定をNixで管理可胜なように なし 適圓

6. 結論

PlasmaCloud/PhotonCloudプロゞェクトは、Nix-NOSの構想を実装するための理想的な基盀

  1. すでにNixOSモゞュヌル化されおいる → Nix-NOSモゞュヌルずの統合が容易
  2. first-boot-automationが存圚 → Deployerの基瀎ずしお掻甚可胜
  3. FiberLBにBGP蚭蚈がある → Nix-NOSのBGPモゞュヌルず自然に統合
  4. ChainFireが状態ストア → Deployer状態管理に利甚可胜
  5. k8shostが存圚するがK8sではない → 「K8sパチモン」の哲孊ず䞀臎

次のアクション:

  1. Nix-NOSモゞュヌルをPlasmaCloudリポゞトリに远加
  2. topology.nix → cluster-config.json生成の実装
  3. BGPモゞュヌルBIRD2の実装ずFiberLB連携