Skip to content

Commit bc5d66c

Browse files
committed
Add server template for Thinkcentre
1 parent 75c92d3 commit bc5d66c

6 files changed

Lines changed: 241 additions & 8 deletions

File tree

.gitignore

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
.terraform
2-
*.tfvars
3-
*.qcow2
4-
output
5-
result
6-
results
7-
/servers/exp*
1+
.terraform
2+
*.tfvars
3+
*.qcow2
4+
*.raw
5+
output
6+
result
7+
results
8+
/servers/exp*
89
.envrc
910
.venv
1011
.nixos-test-history

flake.lock

Lines changed: 74 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@
1111

1212
nix-npm-buildpackage.url = "github:serokell/nix-npm-buildpackage";
1313
nix-npm-buildpackage.inputs.nixpkgs.follows = "nixpkgs";
14+
15+
disko.url = "github:nix-community/disko";
16+
disko.inputs.nixpkgs.follows = "nixpkgs";
17+
18+
nixos-hardware.url = "github:nixos/nixos-hardware";
19+
nixos-hardware.inputs.nixpkgs.follows = "nixpkgs";
20+
21+
nixos-generators.url = "github:nix-community/nixos-generators";
22+
nixos-generators.inputs.nixpkgs.follows = "nixpkgs";
1423
};
1524

1625
outputs =
@@ -27,6 +36,13 @@
2736
nixosConfigurations = {
2837
# TODO: rename cirno to 'front-ec2' or something
2938
cirno = self.lib.nixosSystem ./servers/cirno/configuration.nix;
39+
cs306-thinkcentre-1 = self.lib.nixosSystem ./servers/cs306-thinkcentre-1/configuration.nix;
40+
41+
# Machine templates. Use this to bootstrap new servers.
42+
#
43+
# These templates never rely on any secrets, so a fresh git clone and a
44+
# rebuild with .#templates.NAME is enough to get them running.
45+
template-thinkcentre = self.lib.nixosSystem ./templates/thinkcentre.nix;
3046
};
3147

3248
nixosModules = import ./modules/_all.nix;
@@ -110,6 +126,8 @@
110126
gomod2nix
111127
waypipe
112128
expect
129+
disko
130+
nixos-generate
113131

114132
# editor tools.
115133
yamllint

nix/overlays.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ nixpkgs.lib.composeManyExtensions [
55
(inputs.nix-npm-buildpackage.overlays.default)
66
(self: super: {
77
poetry2nix = import inputs.poetry2nix { pkgs = super; };
8+
nixos-generate = inputs.nixos-generators.packages.${super.system}.nixos-generate;
89
})
910
(self: super: {
1011
buildDenoPackage = self.callPackage ./packaging/deno.nix { };

servers/base.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
];
1717

1818
services.journald = {
19-
enableHttpGateway = false;
19+
gateway = {
20+
enable = false;
21+
};
2022
extraConfig = ''
2123
Compress=true
2224
SystemMaxUse=50M

templates/thinkcentre.nix

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Usage:
2+
#
3+
# $ nix build .#nixosConfigurations.template-thinkcentre.config.system.build.diskoImagesScript
4+
# $ sudo ./result --build-memory 2048
5+
#
6+
# Reference:
7+
#
8+
# - https://github.com/nix-community/disko/blob/master/lib/make-disk-image.nix
9+
#
10+
{ inputs, ... }:
11+
12+
let
13+
# Change me if needed.
14+
diskPath = "/dev/sda";
15+
in
16+
17+
{
18+
imports = [
19+
inputs.disko.nixosModules.disko
20+
21+
inputs.nixos-hardware.nixosModules.common-pc
22+
inputs.nixos-hardware.nixosModules.common-pc-ssd
23+
inputs.nixos-hardware.nixosModules.common-cpu-intel-cpu-only
24+
];
25+
26+
nixpkgs.system = "x86_64-linux";
27+
28+
system.stateVersion = "24.11";
29+
30+
networking = {
31+
hostName = "thinkcentre-newly-provisioned";
32+
networkmanager.enable = true;
33+
};
34+
35+
services.openssh = {
36+
# Allow SSH access to freshly provisioned machines.
37+
enable = true;
38+
# Completely disable password authentication.
39+
# To SSH, use the shared SSH key in secrets.
40+
settings.PasswordAuthentication = false;
41+
};
42+
43+
boot = {
44+
kernelParams = [
45+
"console=tty0"
46+
];
47+
kernelModules = [
48+
"kvm-intel"
49+
];
50+
supportedFilesystems = [
51+
"btrfs"
52+
];
53+
initrd = {
54+
availableKernelModules = [
55+
"nvme"
56+
"xhci_pci"
57+
"ahci"
58+
"usbhid"
59+
"uas"
60+
];
61+
kernelModules = [
62+
"dm-snapshot"
63+
];
64+
systemd = {
65+
enable = true;
66+
# Enable repart, which allows the system to grow the root partition
67+
# before it finishes booting. This lets us flash the image onto a real
68+
# disk and have it automatically resize!
69+
repart.enable = true;
70+
};
71+
};
72+
loader.grub = {
73+
device = diskPath;
74+
efiSupport = false;
75+
timeoutStyle = "hidden";
76+
};
77+
};
78+
79+
disko.devices.disk = {
80+
main = {
81+
type = "disk";
82+
device = diskPath;
83+
content = {
84+
type = "gpt";
85+
partitions = {
86+
boot = {
87+
size = "1M";
88+
type = "EF02"; # for GRUB MBR (hybrid EFI/BIOS boot)
89+
};
90+
# boot = {
91+
# size = "512M";
92+
# type = "EF00"; # for EFI boot
93+
# content = {
94+
# type = "filesystem";
95+
# format = "vfat";
96+
# mountpoint = "/boot";
97+
# mountOptions = [
98+
# "defaults"
99+
# ];
100+
# };
101+
# };
102+
root = {
103+
name = "root";
104+
size = "100%";
105+
content = {
106+
type = "btrfs";
107+
extraArgs = [ "-f" ];
108+
subvolumes = {
109+
"/rootfs" = {
110+
mountpoint = "/";
111+
};
112+
"/nix" = {
113+
mountpoint = "/nix";
114+
mountOptions = [
115+
"compress=zstd"
116+
"noatime"
117+
];
118+
};
119+
"/swap" = {
120+
mountpoint = "/swap";
121+
# Sane default but can be changed
122+
# later per-system if needed.
123+
swap.swapfile.size = "8G";
124+
};
125+
};
126+
};
127+
};
128+
};
129+
};
130+
# This is specifically for building disko images, which are used just for
131+
# provisioning a new drive directly. See:
132+
# https://github.com/nix-community/disko/blob/master/docs/disko-images.md
133+
imageName = "servertemplate-thinkcentre";
134+
imageSize = "25G";
135+
};
136+
};
137+
}

0 commit comments

Comments
 (0)