From 3dbc94c3dee45c544766286bc3ef2fd40263f5d8 Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Tue, 17 Mar 2026 10:31:18 +0800 Subject: [PATCH] feat: run ai agents on homelab (#251) * feat: run ai agents on kana & ruby * fix: upload vm --- hosts/idols-akane/packages.nix | 26 ++++++++ hosts/idols-kana/README.md | 2 +- hosts/idols-kana/default.nix | 13 ++-- hosts/idols-kana/home.nix | 3 + hosts/idols-ruby/README.md | 2 +- hosts/idols-ruby/default.nix | 13 ++-- hosts/idols-ruby/home.nix | 21 +++++++ hosts/idols-ruby/packages.nix | 81 +++++++++++++++++++++++++ outputs/x86_64-linux/src/idols-kana.nix | 4 ++ outputs/x86_64-linux/src/idols-ruby.nix | 3 +- utils.nu | 4 +- 11 files changed, 157 insertions(+), 15 deletions(-) create mode 100644 hosts/idols-kana/home.nix create mode 100644 hosts/idols-ruby/home.nix create mode 100644 hosts/idols-ruby/packages.nix diff --git a/hosts/idols-akane/packages.nix b/hosts/idols-akane/packages.nix index 22081780..4b66c62c 100644 --- a/hosts/idols-akane/packages.nix +++ b/hosts/idols-akane/packages.nix @@ -1,5 +1,31 @@ { pkgs, ... }: { + # https://github.com/Mic92/nix-ld + # + # nix-ld will install itself at `/lib64/ld-linux-x86-64.so.2` so that + # it can be used as the dynamic linker for non-NixOS binaries. + # + # nix-ld works like a middleware between the actual link loader located at `/nix/store/.../ld-linux-x86-64.so.2` + # and the non-NixOS binaries. It will: + # + # 1. read the `NIX_LD` environment variable and use it to find the actual link loader. + # 2. read the `NIX_LD_LIBRARY_PATH` environment variable and use it to set the `LD_LIBRARY_PATH` environment variable + # for the actual link loader. + # + # nix-ld's nixos module will set default values for `NIX_LD` and `NIX_LD_LIBRARY_PATH` environment variables, so + # it can work out of the box: + # + # - https://github.com/NixOS/nixpkgs/blob/nixos-25.11/nixos/modules/programs/nix-ld.nix#L37-L40 + # + # You can overwrite `NIX_LD_LIBRARY_PATH` in the environment where you run the non-NixOS binaries to customize the + # search path for shared libraries. + programs.nix-ld = { + enable = true; + libraries = with pkgs; [ + stdenv.cc.cc + ]; + }; + environment.systemPackages = with pkgs; [ nodejs_24 pnpm diff --git a/hosts/idols-kana/README.md b/hosts/idols-kana/README.md index ab8bddbc..1c09a4f7 100644 --- a/hosts/idols-kana/README.md +++ b/hosts/idols-kana/README.md @@ -1,3 +1,3 @@ # Idols - Kana -TODO +Run AI Agents diff --git a/hosts/idols-kana/default.nix b/hosts/idols-kana/default.nix index 179b8855..da3bcabf 100644 --- a/hosts/idols-kana/default.nix +++ b/hosts/idols-kana/default.nix @@ -14,8 +14,11 @@ let inherit (myvars.networking) proxyGateway proxyGateway6 nameservers; inherit (myvars.networking.hostsAddr.${hostName}) iface ipv4; ipv4WithMask = "${ipv4}/24"; -in { - imports = mylib.scanPaths ./.; +in +{ + imports = [ + ../idols-ruby/packages.nix + ]; # supported file systems, so we can mount any removable disks with these filesystems boot.supportedFilesystems = [ @@ -29,7 +32,7 @@ in { "exfat" ]; - boot.kernelModules = ["kvm-amd"]; + boot.kernelModules = [ "kvm-amd" ]; boot.extraModprobeConfig = "options kvm_amd nested=1"; # for amd cpu networking = { @@ -44,9 +47,9 @@ in { systemd.network.enable = true; systemd.network.networks."10-${iface}" = { - matchConfig.Name = [iface]; + matchConfig.Name = [ iface ]; networkConfig = { - Address = [ipv4WithMask]; + Address = [ ipv4WithMask ]; DNS = nameservers; DHCP = "ipv6"; # enable DHCPv6 only, so we can get a GUA. IPv6AcceptRA = true; # for Stateless IPv6 Autoconfiguraton (SLAAC) diff --git a/hosts/idols-kana/home.nix b/hosts/idols-kana/home.nix new file mode 100644 index 00000000..a3f29e6f --- /dev/null +++ b/hosts/idols-kana/home.nix @@ -0,0 +1,3 @@ +{ + imports = [ ../idols-ruby/home.nix ]; +} diff --git a/hosts/idols-ruby/README.md b/hosts/idols-ruby/README.md index e9d52d72..4a91ca4d 100644 --- a/hosts/idols-ruby/README.md +++ b/hosts/idols-ruby/README.md @@ -1,3 +1,3 @@ # Idols - Ruby -TODO +Run AI Agents diff --git a/hosts/idols-ruby/default.nix b/hosts/idols-ruby/default.nix index 1721285d..bed9c74a 100644 --- a/hosts/idols-ruby/default.nix +++ b/hosts/idols-ruby/default.nix @@ -14,8 +14,11 @@ let inherit (myvars.networking) proxyGateway proxyGateway6 nameservers; inherit (myvars.networking.hostsAddr.${hostName}) iface ipv4; ipv4WithMask = "${ipv4}/24"; -in { - imports = mylib.scanPaths ./.; +in +{ + imports = [ + ./packages.nix + ]; # Enable binfmt emulation of aarch64-linux, this is required for cross compilation. boot.binfmt.emulatedSystems = [ @@ -38,7 +41,7 @@ in { "exfat" ]; - boot.kernelModules = ["kvm-amd"]; + boot.kernelModules = [ "kvm-amd" ]; boot.extraModprobeConfig = "options kvm_amd nested=1"; # for amd cpu networking = { @@ -53,9 +56,9 @@ in { systemd.network.enable = true; systemd.network.networks."10-${iface}" = { - matchConfig.Name = [iface]; + matchConfig.Name = [ iface ]; networkConfig = { - Address = [ipv4WithMask]; + Address = [ ipv4WithMask ]; DNS = nameservers; DHCP = "ipv6"; # enable DHCPv6 only, so we can get a GUA. IPv6AcceptRA = true; # for Stateless IPv6 Autoconfiguraton (SLAAC) diff --git a/hosts/idols-ruby/home.nix b/hosts/idols-ruby/home.nix new file mode 100644 index 00000000..03b60901 --- /dev/null +++ b/hosts/idols-ruby/home.nix @@ -0,0 +1,21 @@ +{ + programs.gh.enable = true; + programs.git.enable = true; + + programs.zellij.enable = true; + programs.bash.enable = true; + programs.nushell.enable = true; + + programs.starship = { + enable = true; + enableBashIntegration = true; + enableNushellIntegration = true; + }; + programs.neovim = { + enable = true; + viAlias = true; + vimAlias = true; + }; + + home.stateVersion = "25.11"; +} diff --git a/hosts/idols-ruby/packages.nix b/hosts/idols-ruby/packages.nix new file mode 100644 index 00000000..8cf527be --- /dev/null +++ b/hosts/idols-ruby/packages.nix @@ -0,0 +1,81 @@ +{ pkgs, ... }: +{ + # https://github.com/Mic92/nix-ld + # + # nix-ld will install itself at `/lib64/ld-linux-x86-64.so.2` so that + # it can be used as the dynamic linker for non-NixOS binaries. + # + # nix-ld works like a middleware between the actual link loader located at `/nix/store/.../ld-linux-x86-64.so.2` + # and the non-NixOS binaries. It will: + # + # 1. read the `NIX_LD` environment variable and use it to find the actual link loader. + # 2. read the `NIX_LD_LIBRARY_PATH` environment variable and use it to set the `LD_LIBRARY_PATH` environment variable + # for the actual link loader. + # + # nix-ld's nixos module will set default values for `NIX_LD` and `NIX_LD_LIBRARY_PATH` environment variables, so + # it can work out of the box: + # + # - https://github.com/NixOS/nixpkgs/blob/nixos-25.11/nixos/modules/programs/nix-ld.nix#L37-L40 + # + # You can overwrite `NIX_LD_LIBRARY_PATH` in the environment where you run the non-NixOS binaries to customize the + # search path for shared libraries. + programs.nix-ld = { + enable = true; + libraries = with pkgs; [ + stdenv.cc.cc + ]; + }; + + environment.systemPackages = with pkgs; [ + nodejs_24 + pnpm + + #-- python + conda + uv # python project package manager + pipx # Install and Run Python Applications in Isolated Environments + (python313.withPackages ( + ps: with ps; [ + pandas + requests + pyquery + pyyaml + numpy + + # model downloaders + huggingface-hub + modelscope + ] + )) + + rustc + cargo # rust package manager + go + + # cryptography + age + sops + rclone + gnupg + + # cloud-native + kubectl + istioctl + kubevirt # virtctl + kubernetes-helm + fluxcd + terraform + + # db related + pgcli + mongosh + sqlite + + yt-dlp # youtube/bilibili/soundcloud/... video/music downloader + + # need to run `conda-install` before using it + # need to run `conda-shell` before using command `conda` + # conda is not available for MacOS + conda + ]; +} diff --git a/outputs/x86_64-linux/src/idols-kana.nix b/outputs/x86_64-linux/src/idols-kana.nix index 8da0b8eb..accb1da1 100644 --- a/outputs/x86_64-linux/src/idols-kana.nix +++ b/outputs/x86_64-linux/src/idols-kana.nix @@ -31,6 +31,10 @@ let ]) ++ [ ]; + home-modules = map mylib.relativeToRoot [ + # host specific + "hosts/idols-${name}/home.nix" + ]; }; systemArgs = modules // args; diff --git a/outputs/x86_64-linux/src/idols-ruby.nix b/outputs/x86_64-linux/src/idols-ruby.nix index ed782b11..294c7877 100644 --- a/outputs/x86_64-linux/src/idols-ruby.nix +++ b/outputs/x86_64-linux/src/idols-ruby.nix @@ -32,7 +32,8 @@ let ++ [ ]; home-modules = map mylib.relativeToRoot [ - "home/linux/tui.nix" + # host specific + "hosts/idols-${name}/home.nix" ]; }; diff --git a/utils.nu b/utils.nu index df43da98..f3e6f92f 100644 --- a/utils.nu +++ b/utils.nu @@ -81,7 +81,7 @@ export def upload-vm [ nix build $target } - let remote = $"ryan@rakushun:/data/caddy/fileserver/vms/kubevirt-($name).qcow2" - rsync -avz --progress --copy-links --checksum result $remote + let remote = $"root@192.168.5.178:/data/caddy/fileserver/vms/kubevirt-($name).qcow2" + rsync -avz --progress --copy-links --checksum result/nixos-image-*.qcow2 $remote }