Skip to content

Commit

Permalink
templates: add nixos and darwin minimal host configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicegginton committed Dec 31, 2024
1 parent 8d1ef58 commit 9b58584
Show file tree
Hide file tree
Showing 4 changed files with 237 additions and 0 deletions.
116 changes: 116 additions & 0 deletions hosts/hostname/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{ lib, ... }:

{
imports = [ ./hardware-configuration.nix ];

disko.devices = {
disk = {
main = {
device = "/dev/sda";
type = "disk";
content = {
type = "gpt";
partitions = {
ESP = {
priority = 1;
name = "ESP";
start = "1M";
end = "128M";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = [ "umask=0077" ];
};
};
SWAP = {
size = "4G";
content = {
type = "swap";
resumeDevice = true;
};
};
root = {
name = "root";
size = "100%";
content = { type = "lvm_pv"; vg = "root_vg"; };
};
};
};
};
};
lvm_vg = {
root_vg = {
type = "lvm_vg";
lvs = {
root = {
size = "100%FREE";
content = {
type = "btrfs";
extraArgs = [ "-f" ];
subvolumes = {
"/root" = { mountpoint = "/"; };
"/persist" = {
mountOptions = [ "subvol=persist" "noatime" ];
mountpoint = "/persist";
};
"/nix" = {
mountOptions = [ "subvol=nix" "noatime" ];
mountpoint = "/nix";
};
};
};
};
};
};
};
};
boot.initrd.postDeviceCommands = lib.mkAfter ''
mkdir /btrfs_tmp
mount /dev/root_vg/root /btrfs_tmp
if [[ -e /btrfs_tmp/root ]]; then
mkdir -p /btrfs_tmp/old_roots
timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/root)" "+%Y-%m-%-d_%H:%M:%S")
mv /btrfs_tmp/root "/btrfs_tmp/old_roots/$timestamp"
fi
delete_subvolume_recursively() {
IFS=$'\n'
for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do
delete_subvolume_recursively "/btrfs_tmp/$i"
done
btrfs subvolume delete "$1"
}
for i in $(find /btrfs_tmp/old_roots/ -maxdepth 1 -mtime +30); do
delete_subvolume_recursively "$i"
done
btrfs subvolume create /btrfs_tmp/root
umount /btrfs_tmp
'';
programs.fuse.userAllowOther = true;
fileSystems."/persist".neededForBoot = true;
environment.persistence."/persist" = {
directories = [
"/etc/nixos"
"/var/log"
"/var/lib/bluetooth"
"/var/lib/nixos"
"/var/lib/systemd/coredump"
"/etc/NetworkManager/system-connections"
"/etc/ssh"
"/root/bitwarden-secrets"
];
files = [ "/etc/machine-id" ];
};
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
hardware.mwProCapture.enable = true;
hardware.logitech.wireless.enable = true;
hardware.logitech.wireless.enableGraphical = true;
modules = {
display.enable = true;
display.plasma.enable = true;
services.bluetooth.enable = true;
networking.wireless.enable = true;
};
}
1 change: 1 addition & 0 deletions templates/darwin-host/hosts/darwin/hostname.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_: {}
4 changes: 4 additions & 0 deletions templates/default.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
_:

{
darwin-host.path = ./darwin-host;
darwin-host.description = "Minimal Darwin host configuration for this workspace";
dotnet-core.path = ./dotnet-core;
dotnet-core.description = "Minimal .NET Core package";
minimal.path = ./minimal;
minimal.description = "Minimal Nix Flake workspace";
nixos-host.path = ./nixos-host;
nixos-host.description = "Minimal NixOS host configuration for this workspace";
nodejs-angular.path = ./nodejs-angular;
nodejs-angular.description = "Minimal NodeJS Angular package";
nodejs-typescript.path = ./nodejs-typescript;
Expand Down
116 changes: 116 additions & 0 deletions templates/nixos-host/hosts/hostname/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{ lib, ... }:

{
imports = [ ./hardware-configuration.nix ];

disko.devices = {
disk = {
main = {
device = "/dev/sda";
type = "disk";
content = {
type = "gpt";
partitions = {
ESP = {
priority = 1;
name = "ESP";
start = "1M";
end = "128M";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = [ "umask=0077" ];
};
};
SWAP = {
size = "4G";
content = {
type = "swap";
resumeDevice = true;
};
};
root = {
name = "root";
size = "100%";
content = { type = "lvm_pv"; vg = "root_vg"; };
};
};
};
};
};
lvm_vg = {
root_vg = {
type = "lvm_vg";
lvs = {
root = {
size = "100%FREE";
content = {
type = "btrfs";
extraArgs = [ "-f" ];
subvolumes = {
"/root" = { mountpoint = "/"; };
"/persist" = {
mountOptions = [ "subvol=persist" "noatime" ];
mountpoint = "/persist";
};
"/nix" = {
mountOptions = [ "subvol=nix" "noatime" ];
mountpoint = "/nix";
};
};
};
};
};
};
};
};
boot.initrd.postDeviceCommands = lib.mkAfter ''
mkdir /btrfs_tmp
mount /dev/root_vg/root /btrfs_tmp
if [[ -e /btrfs_tmp/root ]]; then
mkdir -p /btrfs_tmp/old_roots
timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/root)" "+%Y-%m-%-d_%H:%M:%S")
mv /btrfs_tmp/root "/btrfs_tmp/old_roots/$timestamp"
fi
delete_subvolume_recursively() {
IFS=$'\n'
for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do
delete_subvolume_recursively "/btrfs_tmp/$i"
done
btrfs subvolume delete "$1"
}
for i in $(find /btrfs_tmp/old_roots/ -maxdepth 1 -mtime +30); do
delete_subvolume_recursively "$i"
done
btrfs subvolume create /btrfs_tmp/root
umount /btrfs_tmp
'';
programs.fuse.userAllowOther = true;
fileSystems."/persist".neededForBoot = true;
environment.persistence."/persist" = {
directories = [
"/etc/nixos"
"/var/log"
"/var/lib/bluetooth"
"/var/lib/nixos"
"/var/lib/systemd/coredump"
"/etc/NetworkManager/system-connections"
"/etc/ssh"
"/root/bitwarden-secrets"
];
files = [ "/etc/machine-id" ];
};
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
hardware.mwProCapture.enable = true;
hardware.logitech.wireless.enable = true;
hardware.logitech.wireless.enableGraphical = true;
modules = {
display.enable = true;
display.plasma.enable = true;
services.bluetooth.enable = true;
networking.wireless.enable = true;
};
}

0 comments on commit 9b58584

Please sign in to comment.