modules.services.nixvirt: init

This commit is contained in:
2025-04-19 12:55:42 +08:00
parent a4bc272f1b
commit bf91e14e4d
6 changed files with 73 additions and 1 deletions

View File

@@ -30,7 +30,8 @@ inputs:
hardware.cpus = [ "intel" ]; hardware.cpus = [ "intel" ];
services = services =
{ {
beesd."/".hashTableSizeMB = 128; # 大部分空间用于存储虚拟机nodatacow其它内容不多
beesd."/".hashTableSizeMB = 32;
sshd = {}; sshd = {};
}; };
virtualization.kvmHost = { enable = true; gui = true; }; virtualization.kvmHost = { enable = true; gui = true; };

View File

@@ -27,4 +27,5 @@ mungekey -k munge.key
mv munge.key munge.key.orig mv munge.key munge.key.orig
sops -e --input-type binary --output-type binary munge.key.orig > munge.key sops -e --input-type binary --output-type binary munge.key.orig > munge.key
rm munge.key.orig rm munge.key.orig
sudo nix build --store 'local?root=/mnt' --option substituters https://nix-store.chn.moe --option require-sigs false /nix/store/khhqmly5295ns33dz1s3m3sb79icj6bi-nixos-system-srv3-production-24.11
``` ```

21
flake.lock generated
View File

@@ -982,6 +982,26 @@
"type": "github" "type": "github"
} }
}, },
"nixvirt": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1741549407,
"narHash": "sha256-f9SXK+/rvlryDNlc++Eva/hYjbkf7OCalWwmwifRhtI=",
"owner": "AshleyYakeley",
"repo": "NixVirt",
"rev": "9950b932dce4ae6b9bda7c83d41705c1a14e10f0",
"type": "github"
},
"original": {
"owner": "AshleyYakeley",
"repo": "NixVirt",
"type": "github"
}
},
"nu-scripts": { "nu-scripts": {
"flake": false, "flake": false,
"locked": { "locked": {
@@ -1287,6 +1307,7 @@
"nixpkgs-23.05": "nixpkgs-23.05", "nixpkgs-23.05": "nixpkgs-23.05",
"nixpkgs-23.11": "nixpkgs-23.11", "nixpkgs-23.11": "nixpkgs-23.11",
"nixpkgs-unstable": "nixpkgs-unstable", "nixpkgs-unstable": "nixpkgs-unstable",
"nixvirt": "nixvirt",
"nu-scripts": "nu-scripts", "nu-scripts": "nu-scripts",
"nur-linyinfeng": "nur-linyinfeng", "nur-linyinfeng": "nur-linyinfeng",
"nur-xddxdd": "nur-xddxdd", "nur-xddxdd": "nur-xddxdd",

View File

@@ -38,6 +38,7 @@
winapps = { url = "github:winapps-org/winapps/feat-nix-packaging"; inputs.nixpkgs.follows = "nixpkgs"; }; winapps = { url = "github:winapps-org/winapps/feat-nix-packaging"; inputs.nixpkgs.follows = "nixpkgs"; };
aagl = { url = "github:ezKEa/aagl-gtk-on-nix/release-24.11"; inputs.nixpkgs.follows = "nixpkgs"; }; aagl = { url = "github:ezKEa/aagl-gtk-on-nix/release-24.11"; inputs.nixpkgs.follows = "nixpkgs"; };
cachyos-lts.url = "github:drakon64/nixos-cachyos-kernel"; cachyos-lts.url = "github:drakon64/nixos-cachyos-kernel";
nixvirt = { url = "github:AshleyYakeley/NixVirt"; inputs.nixpkgs.follows = "nixpkgs"; };
misskey = { url = "git+https://github.com/CHN-beta/misskey?submodules=1"; flake = false; }; misskey = { url = "git+https://github.com/CHN-beta/misskey?submodules=1"; flake = false; };
rsshub = { url = "github:DIYgod/RSSHub"; flake = false; }; rsshub = { url = "github:DIYgod/RSSHub"; flake = false; };

View File

@@ -11,6 +11,7 @@ inputs: let inherit (inputs) topInputs; in
{ config.chaotic.nyx.overlay.onTopOf = "user-pkgs"; } { config.chaotic.nyx.overlay.onTopOf = "user-pkgs"; }
topInputs.catppuccin.nixosModules.catppuccin topInputs.catppuccin.nixosModules.catppuccin
topInputs.aagl.nixosModules.default topInputs.aagl.nixosModules.default
topInputs.nixvirt.nixosModules.default
(inputs: (inputs:
{ {
config = config =

View File

@@ -0,0 +1,47 @@
inputs:
{
options.nixos.services.nixvirt = let inherit (inputs.lib) mkOption types; in mkOption
{
type = types.nullOr (types.attrsOf (types.submodule
{
storage = mkOption { type = types.nonEmptyStr; };
memoryGB = mkOption { type = types.ints.unsigned; };
cpus = mkOption { type = types.ints.unsigned; };
vncPort = mkOption { type = types.ints.unsigned; };
}));
default = null;
};
config = let inherit (inputs.config.nixos.services) nixvirt; in inputs.lib.mkIf (nixvirt != {})
{
# TODO: switch on nixos.virtualisation.kvm
virtualisation.libvirt =
{
enable = true;
verbose = true;
connections."qemu:///system" = let inherit (inputs.topInputs.nixvirt) lib; in
{
domains =
[{
definition = lib.domain.writeXML (lib.domain.templates.linux
{
name = "Penguin";
uuid = "cc7439ed-36af-4696-a6f2-1f0c4474d87e";
memory = { count = 6; unit = "GiB"; };
storage_vol = { pool = "MyPool"; volume = "Penguin.qcow2"; };
});
}];
networks =
[{
definition = lib.network.writeXML (lib.network.templates.bridge
{
uuid = "8f403474-f8d6-4fa7-991a-f62f40d51191";
subnet_byte = 122;
});
active = true;
}];
# 不通过它来定义存储,手动控制存储
pools = null;
};
};
};
}