2018-11-26 14:51:00 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2023-05-18 17:16:10 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
inherit (lib)
|
|
|
|
boolToString
|
|
|
|
mkDefault
|
|
|
|
mkIf
|
|
|
|
optional
|
|
|
|
readFile
|
|
|
|
;
|
|
|
|
in
|
|
|
|
|
2013-12-11 14:32:27 +00:00
|
|
|
{
|
2018-11-26 14:51:00 +00:00
|
|
|
imports = [
|
|
|
|
../profiles/headless.nix
|
|
|
|
../profiles/qemu-guest.nix
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
fileSystems."/" = {
|
2019-05-22 06:44:52 +00:00
|
|
|
fsType = "ext4";
|
2018-11-26 14:51:00 +00:00
|
|
|
device = "/dev/disk/by-label/nixos";
|
|
|
|
autoResize = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
boot.growPartition = true;
|
|
|
|
boot.kernelParams = [ "console=ttyS0" "panic=1" "boot.panic_on_fail" ];
|
|
|
|
boot.initrd.kernelModules = [ "virtio_scsi" ];
|
|
|
|
boot.kernelModules = [ "virtio_pci" "virtio_net" ];
|
|
|
|
|
2019-08-31 20:21:33 +00:00
|
|
|
# Generate a GRUB menu.
|
2018-11-26 14:51:00 +00:00
|
|
|
boot.loader.grub.device = "/dev/sda";
|
|
|
|
boot.loader.timeout = 0;
|
|
|
|
|
|
|
|
# Don't put old configurations in the GRUB menu. The user has no
|
|
|
|
# way to select them anyway.
|
|
|
|
boot.loader.grub.configurationLimit = 0;
|
|
|
|
|
2019-08-31 20:22:47 +00:00
|
|
|
# Allow root logins only using SSH keys
|
|
|
|
# and disable password authentication in general
|
2018-11-26 14:51:00 +00:00
|
|
|
services.openssh.enable = true;
|
2023-09-16 18:52:02 +00:00
|
|
|
services.openssh.settings.PermitRootLogin = mkDefault "prohibit-password";
|
2023-01-15 15:32:46 +00:00
|
|
|
services.openssh.settings.PasswordAuthentication = mkDefault false;
|
2018-11-26 14:51:00 +00:00
|
|
|
|
2019-08-31 20:22:47 +00:00
|
|
|
# enable OS Login. This also requires setting enable-oslogin=TRUE metadata on
|
|
|
|
# instance or project level
|
|
|
|
security.googleOsLogin.enable = true;
|
|
|
|
|
2018-11-26 14:51:00 +00:00
|
|
|
# Use GCE udev rules for dynamic disk volumes
|
2021-03-18 17:02:07 +00:00
|
|
|
services.udev.packages = [ pkgs.google-guest-configs ];
|
|
|
|
services.udev.path = [ pkgs.google-guest-configs ];
|
2018-11-26 14:51:00 +00:00
|
|
|
|
|
|
|
# Force getting the hostname from Google Compute.
|
|
|
|
networking.hostName = mkDefault "";
|
|
|
|
|
|
|
|
# Always include cryptsetup so that NixOps can use it.
|
|
|
|
environment.systemPackages = [ pkgs.cryptsetup ];
|
|
|
|
|
|
|
|
# Rely on GCP's firewall instead
|
|
|
|
networking.firewall.enable = mkDefault false;
|
|
|
|
|
|
|
|
# Configure default metadata hostnames
|
|
|
|
networking.extraHosts = ''
|
|
|
|
169.254.169.254 metadata.google.internal metadata
|
|
|
|
'';
|
|
|
|
|
|
|
|
networking.timeServers = [ "metadata.google.internal" ];
|
|
|
|
|
|
|
|
networking.usePredictableInterfaceNames = false;
|
|
|
|
|
|
|
|
# GC has 1460 MTU
|
|
|
|
networking.interfaces.eth0.mtu = 1460;
|
|
|
|
|
2021-03-18 17:02:07 +00:00
|
|
|
systemd.packages = [ pkgs.google-guest-agent ];
|
|
|
|
systemd.services.google-guest-agent = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
restartTriggers = [ config.environment.etc."default/instance_configs.cfg".source ];
|
2023-05-18 17:16:10 +00:00
|
|
|
path = optional config.users.mutableUsers pkgs.shadow;
|
2021-01-13 10:01:01 +00:00
|
|
|
};
|
2021-03-18 17:02:07 +00:00
|
|
|
systemd.services.google-startup-scripts.wantedBy = [ "multi-user.target" ];
|
|
|
|
systemd.services.google-shutdown-scripts.wantedBy = [ "multi-user.target" ];
|
2021-01-13 10:01:01 +00:00
|
|
|
|
2021-03-18 17:02:07 +00:00
|
|
|
security.sudo.extraRules = mkIf config.users.mutableUsers [
|
2023-10-22 19:29:19 +00:00
|
|
|
{ groups = [ "google-sudoers" ]; commands = [ { command = "ALL"; options = [ "NOPASSWD" ]; } ]; }
|
|
|
|
];
|
|
|
|
|
|
|
|
security.sudo-rs.extraRules = mkIf config.users.mutableUsers [
|
2021-03-18 17:02:07 +00:00
|
|
|
{ groups = [ "google-sudoers" ]; commands = [ { command = "ALL"; options = [ "NOPASSWD" ]; } ]; }
|
|
|
|
];
|
2018-11-26 14:51:00 +00:00
|
|
|
|
2021-03-18 17:02:07 +00:00
|
|
|
users.groups.google-sudoers = mkIf config.users.mutableUsers { };
|
2018-11-26 14:51:00 +00:00
|
|
|
|
2023-05-18 17:16:10 +00:00
|
|
|
boot.extraModprobeConfig = readFile "${pkgs.google-guest-configs}/etc/modprobe.d/gce-blacklist.conf";
|
2019-08-31 20:42:34 +00:00
|
|
|
|
2021-03-18 17:02:07 +00:00
|
|
|
environment.etc."sysctl.d/60-gce-network-security.conf".source = "${pkgs.google-guest-configs}/etc/sysctl.d/60-gce-network-security.conf";
|
2019-08-31 20:42:34 +00:00
|
|
|
|
2021-03-18 17:02:07 +00:00
|
|
|
environment.etc."default/instance_configs.cfg".text = ''
|
|
|
|
[Accounts]
|
|
|
|
useradd_cmd = useradd -m -s /run/current-system/sw/bin/bash -p * {user}
|
2018-11-26 14:51:00 +00:00
|
|
|
|
2021-03-18 17:02:07 +00:00
|
|
|
[Daemons]
|
|
|
|
accounts_daemon = ${boolToString config.users.mutableUsers}
|
2018-11-26 14:51:00 +00:00
|
|
|
|
2021-03-18 17:02:07 +00:00
|
|
|
[InstanceSetup]
|
|
|
|
# Make sure GCE image does not replace host key that NixOps sets.
|
|
|
|
set_host_keys = false
|
|
|
|
|
|
|
|
[MetadataScripts]
|
|
|
|
default_shell = ${pkgs.stdenv.shell}
|
|
|
|
|
|
|
|
[NetworkInterfaces]
|
|
|
|
dhclient_script = ${pkgs.google-guest-configs}/bin/google-dhclient-script
|
|
|
|
# We set up network interfaces declaratively.
|
|
|
|
setup = false
|
|
|
|
'';
|
2013-12-11 14:32:27 +00:00
|
|
|
}
|