Skip to content

Commit

Permalink
refact(recover): refact into machine module
Browse files Browse the repository at this point in the history
  • Loading branch information
klarkc committed Dec 19, 2023
1 parent fc3ceed commit 9bb76c2
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 161 deletions.
78 changes: 34 additions & 44 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,63 +11,53 @@
os = "linux";
system = "${platform}-${os}";
pkgs = import inputs.nixpkgs { inherit system; };
mkSystem = options:
let
inherit (inputs.nixpkgs.lib) nixosSystem;
inherit (inputs.generators) nixosGenerate;
inherit (builtins) hasAttr;
in
if hasAttr "format" options then
nixosGenerate options
else
nixosSystem options;
recover = mkSystem {
inherit system;
modules = [ ./recover.nix ];
lib = {
mkSystem = options:
let
inherit (inputs.nixpkgs.lib) nixosSystem;
inherit (inputs.generators) nixosGenerate;
inherit (builtins) hasAttr;
in
if hasAttr "format" options then
nixosGenerate options
else
nixosSystem options;
# TODO: find a faster way to run vm in devShell
mkRecoverVm = efi: name: args: pkgs.writeShellApplication {
name = "${name}-vm";
text = ''
IMG="${name}-efi.img"
BIOS="${name}-efi-bios.img"
ARGS="${args}"
cp -ui --reflink=auto ${pkgs.OVMF.fd}/FV/OVMF.fd "$BIOS"
chmod a+w "$BIOS"
cp -ui --reflink=auto ${efi}/nixos.img "$IMG"
chmod a+w "$IMG"
qemu-system-${platform} \
-bios "$BIOS" \
-drive file="$IMG",format=raw \
-m 2G \
$ARGS
'';
runtimeInputs = with pkgs; [ qemu ];
};
};

recover-efi = mkSystem {
inherit system;
modules = [ ./recover.nix ];
format = "raw-efi";
};

# TODO: find a faster way to run recover in devShell
mk-recover-vm = args: pkgs.writeShellApplication {
name = "recover-vm";
text = ''
IMG="recover-efi.img"
BIOS="recover-efi-bios.img"
ARGS="${args}"
cp -ui --reflink=auto ${pkgs.OVMF.fd}/FV/OVMF.fd "$BIOS"
chmod a+w "$BIOS"
cp -ui --reflink=auto ${recover-efi}/nixos.img "$IMG"
chmod a+w "$IMG"
qemu-system-${platform} \
-bios "$BIOS" \
-drive file="$IMG",format=raw \
-m 2G \
$ARGS
'';
runtimeInputs = with pkgs; [ tree rsync qemu ];
};
recover-vm = mk-recover-vm "";
recover-kvm = mk-recover-vm "--enable-kvm";
machines = import ./machines { inherit system pkgs lib; };
in
{
nixosConfigurations = {
inherit recover;
inherit (machines.recover) recover-os;
};

packages.${system} = {
inherit recover-efi recover-vm recover-kvm;
inherit (machines.recover) recover-efi recover-vm recover-kvm;
};

devShells.${system}.default =
pkgs.mkShell
{
packages =
[
with machines.recover; [
recover-vm
recover-kvm
];
Expand Down
4 changes: 4 additions & 0 deletions machines/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ctx:
{
recover = import ./recover ctx;
}
138 changes: 138 additions & 0 deletions machines/recover/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
{ system, lib, pkgs, ... }:
let
inherit (lib) mkSystem mkRecoverVm;
inherit (pkgs.lib) mkDefault;
recover-module = {
nix = {
extraOptions = ''
experimental-features = nix-command flakes repl-flake
'';
};
nixpkgs.config.allowUnfree = true;
hardware.enableAllFirmware = true;
users = {
users.recover = {
password = "recover";
isNormalUser = true;
home = "/home/recover";
description = "Recover";
extraGroups = [ "wheel" "networkmanager" ];
};
mutableUsers = false;
};
networking = {
hostName = "recover-os";
networkmanager.enable = true;
};
boot = {
kernelParams = [
"copytoram"
"console=ttyS0,115200"
"console=tty1"
"boot.shell_on_fail"
];
supportedFilesystems = [
"btrfs"
"exfat"
"ext2"
"ext4"
"ntfs"
"vfat"
];
loader = {
timeout = 15;
grub = {
enable = true;
device = "nodev";
efiSupport = true;
useOSProber = true;
memtest86.enable = true;
};
};
};
fileSystems."/".device = mkDefault "none";

environment.systemPackages = with pkgs; [
btop
coreutils
curl
ddrescue
efibootmgr
efivar
findutils
gnugrep
gnused
gnutar
gptfdisk
hdparm
inetutils
less
lsof
parted
pciutils
ripgrep
rsync
sdparm
smartmontools
sshfs
time
testdisk
unzip
usbutils
wget
which
zip
ntfs3g
f2fs-tools
jfsutils
nilfs-utils
reiserfsprogs
xfsprogs
xfsdump
gparted
];

services = {
openssh.enable = true;

xserver = {
enable = true;
windowManager.xmonad.enable = true;
displayManager = {
defaultSession = "none+xmonad";
autoLogin = {
enable = true;
user = "recover";
};
};
};
};

programs = {
tmux.enable = true;
neovim = {
enable = true;
viAlias = true;
vimAlias = true;
};
mtr.enable = true;
htop.enable = true;
};
};
in
rec {
recover-os = mkSystem {
inherit system;
modules = [ recover-module ];
};

recover-efi = mkSystem {
inherit system;
modules = [ recover-module ];
format = "raw-efi";
};

recover-vm = mkRecoverVm recover-efi "recover" "";

recover-kvm = mkRecoverVm recover-efi "recover" "--enable-kvm";
}
117 changes: 0 additions & 117 deletions recover.nix

This file was deleted.

0 comments on commit 9bb76c2

Please sign in to comment.