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

Set up nix environment for building vms #57

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
41 changes: 41 additions & 0 deletions configuration.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{ self, pkgs, tidal-tools, ... }: {
nix = {
extraOptions = ''
experimental-features = nix-command flakes
'';
settings = {
trusted-users = [ "root" "tidal" ];
auto-optimise-store = true;
};
};

networking.hostName = "Nix"; # Define your hostname.

# Pick only one of the below networking options.
# networking.wireless.enable = true; # Enables wireless support via wpa_supplicant.
# networking.networkmanager.enable = true; # Easiest to use and most distros use this by default.

users.users.tidal = {
isNormalUser = true;
password = "tidal";
extraGroups = [ "networkmanager" "wheel" "video" "kvm" ];
};

environment = {
systemPackages = with pkgs; [
tidal-tools.packages.x86_64-linux.default
docker
python311
python311Packages.pip
nmap
jq
];
};

services.xserver.enable = true;
services.xserver.displayManager.sddm.enable = true;
services.xserver.desktopManager.plasma5.enable = true;

services.dbus.enable = true;
virtualisation.docker.enable = true;
}
172 changes: 172 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 94 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nixos-generators = {
url = "github:nix-community/nixos-generators";
inputs.nixpkgs.follows = "nixpkgs";
};
tidal-tools = {
url = "git+ssh://[email protected]/tidalmigrations/tidal-tools?ref=main&rev=34550d4abc304c1428465ab09b0f558c075f1c35";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, nixos-generators, tidal-tools, ... }:
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
in
{
packages.x86_64-linux = {
hyperv = nixos-generators.nixosGenerate {
specialArgs = {
tidal-tools = tidal-tools;
};
system = "x86_64-linux";
modules = [
./configuration.nix
];
format = "hyperv";
};
azure = nixos-generators.nixosGenerate {
specialArgs = {
tidal-tools = tidal-tools;
};
system = "x86_64-linux";
modules = [
./configuration.nix
];
format = "azure";
};
vbox = nixos-generators.nixosGenerate {
system = "
x86_64-linux ";
modules = [
# you can include your own nixos configuration here, i.e.
./configuration.nix
];
format = "virtualbox";
};

# hack stolen from
# https://github.com/nix-community/nixos-generators/issues/128#issuecomment-1484084499
vmware =
let
base = nixos-generators.nixosGenerate {
system = "x86_64-linux";
modules = [
# you can include your own nixos configuration here, i.e.
./configuration.nix
./vmware.nix
];
format = "virtualbox";
};
vmx = "vmx-20";
in
pkgs.runCommand "vbox"
{ } ''
ova=${base}/*.ova
mkdir $out
# cp $ova "$out/unfixed.ova" # debug
${pkgs.cot}/bin/cot --force --verbose edit-product $ova -p 'Some Info' -o nixos.ova
${pkgs.cot}/bin/cot --force --verbose edit-hardware nixos.ova -v ${vmx}
tar xf nixos.ova
sed -i -E 's/^(\s*<(ovf:)?ProductSection)>\s*$/\1 ovf:required="false">/' *.ovf
sed -i -E "s/^(SHA1\(nixos.ovf\)=\s*).*$/\1$(sha1sum nixos.ovf | cut -d ' ' -f 1)/" *.mf
${pkgs.ovftool}/bin/ovftool --lax --sourceType=OVF --targetType=OVA nixos.ovf $out/nixos.ova
# tar cf $out/nixos.ova *.ovf *.mf *.vmdk
'';

qemu = nixos-generators.nixosGenerate {
system = "x86_64-linux";
modules = [
# you can include your own nixos configuration here, i.e.
./configuration.nix
];
format = "vm";
specialArgs = {
tidal-tools = tidal-tools;
};
};
};
devShells.x86_64-linux.default = pkgs.mkShell {
buildInputs = [ pkgs.qemu pkgs.virtualbox pkgs.vmware-workstation pkgs.ovftool pkgs.cot ];
};
};
}
11 changes: 11 additions & 0 deletions vmware.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{ self, pkgs, ... }: {
virtualbox = {
# see: https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/virtualisation/virtualbox-image.nix
memorySize = 4000; # MiB
params = {
audio = "none";
audioout = "off";
};
};
virtualisation.vmware.guest.enable = true;
}