Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flake-Less compatibility #59

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions checks/checks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ let
runCommand = name: args: script: "BUILD " + name;
qemu = "QEMU_PATH";
};
packages-ovmf =
OVMFFull =
{
OVMFFull.fd = "OVMFFull_FD_PATH";
fd = "OVMFFull_FD_PATH";
};
};
testlib = mklib teststuff;
Expand Down Expand Up @@ -47,8 +47,8 @@ in
ovmf-secboot =
stuff.packages.runCommand "ovmf-secboot" { }
''
test -f ${stuff.packages-ovmf.OVMFFull.fd}/FV/OVMF_CODE.ms.fd
test -f ${stuff.packages-ovmf.OVMFFull.fd}/FV/OVMF_VARS.ms.fd
test -f ${stuff.OVMFFull.fd}/FV/OVMF_CODE.ms.fd
test -f ${stuff.OVMFFull.fd}/FV/OVMF_VARS.ms.fd
echo "pass" > $out
'';
}
72 changes: 72 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
system ? "x86_64-linux",
OVMFFull ? pkgs.OVMFFull, # OVMF Package -> From unstable recommended
pkgs, # upstream is pinned on NixOS/Pkgs 23.11
...
}:
let
packages = pkgs;

nixvirtPythonModulePackage =
packages.runCommand "nixvirtPythonModulePackage" { } ''
mkdir -p $out/lib/python3.11/site-packages/
ln -s ${tool/nixvirt.py} $out/lib/python3.11/site-packages/nixvirt.py
''
// {
pythonModule = packages.python311;
};

pythonInterpreterPackage = packages.python311.withPackages (ps: [
ps.libvirt
ps.lxml
ps.xmldiff
nixvirtPythonModulePackage
]);

setShebang =
name: path:
packages.runCommand name { } ''
sed -e "1s|.*|\#\!${pythonInterpreterPackage}/bin/python3|" ${path} > $out
chmod 755 $out
'';

virtdeclareFile = setShebang "virtdeclare" tool/virtdeclare;
moduleHelperFile = setShebang "nixvirt-module-helper" tool/nixvirt-module-helper;

mklib = import ./lib.nix;

modules = import ./modules.nix { inherit packages moduleHelperFile; };

stuff = {
inherit packages OVMFFull;
};
in
{
lib = mklib stuff;

apps.${system} = {
virtdeclare = {
type = "app";
program = "${virtdeclareFile}";
};

# for debugging
nixvirt-module-helper = {
type = "app";
program = "${moduleHelperFile}";
};
};

formatter.${system} = packages.nixpkgs-fmt;

packages.${system}.default = packages.runCommand "NixVirt" { } ''
mkdir -p $out/bin
ln -s ${virtdeclareFile} $out/bin/virtdeclare
'';

homeModules.default = modules.homeModule;

nixosModules.default = modules.nixosModule;

checks.${system} = import checks/checks.nix stuff mklib;
}
100 changes: 26 additions & 74 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,87 +1,39 @@
{
description = "LibVirt domain management";

inputs =
{
nixpkgs =
{
type = "github";
owner = "NixOS";
repo = "nixpkgs";
ref = "nixos-23.11";
};
inputs = {
nixpkgs = {
type = "github";
owner = "NixOS";
repo = "nixpkgs";
ref = "nixos-23.11";
};

nixpkgs-ovmf =
{
type = "github";
owner = "NixOS";
repo = "nixpkgs";
ref = "nixos-unstable";
};
nixpkgs-ovmf = {
type = "github";
owner = "NixOS";
repo = "nixpkgs";
ref = "nixos-unstable";
};
};

outputs = { self, nixpkgs, nixpkgs-ovmf }:
outputs =
{
self,
nixpkgs,
nixpkgs-ovmf,
}:
let
packages = import nixpkgs { system = "x86_64-linux"; };
packages-ovmf = import nixpkgs-ovmf { system = "x86_64-linux"; };

nixvirtPythonModulePackage = packages.runCommand "nixvirtPythonModulePackage" { }
''
mkdir -p $out/lib/python3.11/site-packages/
ln -s ${tool/nixvirt.py} $out/lib/python3.11/site-packages/nixvirt.py
'' // { pythonModule = packages.python311; };

pythonInterpreterPackage = packages.python311.withPackages (ps:
[
ps.libvirt
ps.lxml
ps.xmldiff
nixvirtPythonModulePackage
]);

setShebang = name: path: packages.runCommand name { }
''
sed -e "1s|.*|\#\!${pythonInterpreterPackage}/bin/python3|" ${path} > $out
chmod 755 $out
'';

virtdeclareFile = setShebang "virtdeclare" tool/virtdeclare;
moduleHelperFile = setShebang "nixvirt-module-helper" tool/nixvirt-module-helper;

mklib = import ./lib.nix;
system = "x86_64-linux";

modules = import ./modules.nix { inherit packages moduleHelperFile; };
packages = import nixpkgs { inherit system; };
packages-ovmf = import nixpkgs-ovmf { inherit system; };

stuff = { inherit packages packages-ovmf; };
in
{
lib = mklib stuff;

apps.x86_64-linux.virtdeclare =
{
type = "app";
program = "${virtdeclareFile}";
};

# for debugging
apps.x86_64-linux.nixvirt-module-helper =
{
type = "app";
program = "${moduleHelperFile}";
};

formatter.x86_64-linux = packages.nixpkgs-fmt;

packages.x86_64-linux.default = packages.runCommand "NixVirt" { }
''
mkdir -p $out/bin
ln -s ${virtdeclareFile} $out/bin/virtdeclare
'';

homeModules.default = modules.homeModule;

nixosModules.default = modules.nixosModule;
import ./default.nix {
inherit system;

checks.x86_64-linux = import checks/checks.nix stuff mklib;
pkgs = packages;
OVMFFull = packages-ovmf.OVMFFull;
};
}
6 changes: 3 additions & 3 deletions templates/domain/windows.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# https://www.microsoft.com/en-us/windows/windows-11-specifications
# https://sysguides.com/install-a-windows-11-virtual-machine-on-kvm
stuff@{ packages, packages-ovmf, guest-install, ... }:
stuff@{ packages, OVMFFull, guest-install, ... }:
{ name
, uuid
, memory ? { count = 4; unit = "GiB"; }
Expand Down Expand Up @@ -29,11 +29,11 @@ base //
{
readonly = true;
type = "pflash";
path = "${packages-ovmf.OVMFFull.fd}/FV/OVMF_CODE.ms.fd";
path = "${OVMFFull.fd}/FV/OVMF_CODE.ms.fd";
};
nvram =
{
template = "${packages-ovmf.OVMFFull.fd}/FV/OVMF_VARS.ms.fd";
template = "${OVMFFull.fd}/FV/OVMF_VARS.ms.fd";
path = nvram_path;
};
};
Expand Down