nix-config/modules/system.nix
Donovan Glover dd3d09bb67
system: Add option to specify hashedPassword
It may be useful to add hashedPasswordFile in the future, although from
my testing it was possible to rebuild a VM that used a cached derivation
with the old password.

Ideally your main form of authentication is through LUKS encryption or
SSH keys anyway, and this password should solely be used for sudo
purposes.
2024-04-06 08:18:32 -04:00

156 lines
3.1 KiB
Nix

{ nix-config, pkgs, lib, config, ... }:
let
inherit (lib) mkOption mkEnableOption mkIf;
inherit (lib.types) nullOr str listOf;
inherit (pkgs.nixVersions) nix_2_19;
inherit (cfg) username iHaveLotsOfRam hashedPassword;
inherit (builtins) attrValues;
cfg = config.modules.system;
in
{
imports = attrValues {
inherit (nix-config.inputs.home-manager.nixosModules) home-manager;
};
options.modules.system = {
username = mkOption {
type = str;
default = "user";
};
hashedPassword = mkOption {
type = nullOr str;
default = null;
};
timeZone = mkOption {
type = str;
default = "America/New_York";
};
defaultLocale = mkOption {
type = str;
default = "ja_JP.UTF-8";
};
supportedLocales = mkOption {
type = listOf str;
default = [ "ja_JP.UTF-8/UTF-8" "en_US.UTF-8/UTF-8" "fr_FR.UTF-8/UTF-8" ];
};
stateVersion = mkOption {
type = str;
default = "22.11";
};
iHaveLotsOfRam = mkEnableOption "tmpfs on /tmp";
};
config = {
boot = {
tmp =
if iHaveLotsOfRam
then { useTmpfs = true; }
else { cleanOnBoot = true; };
loader = {
systemd-boot = {
enable = true;
editor = false;
configurationLimit = 10;
};
timeout = 0;
efi.canTouchEfiVariables = true;
};
};
systemd = {
extraConfig = "DefaultTimeoutStopSec=10s";
services.NetworkManager-wait-online.enable = false;
};
nix = {
package = nix_2_19;
settings = {
experimental-features = [ "nix-command" "flakes" "repl-flake" ];
auto-optimise-store = true;
warn-dirty = false;
};
};
zramSwap = {
enable = true;
memoryPercent = 100;
};
time = {
inherit (cfg) timeZone;
};
i18n = {
inherit (cfg) defaultLocale supportedLocales;
};
system = {
inherit (cfg) stateVersion;
};
users = {
mutableUsers = false;
users.${username} = {
inherit hashedPassword;
isNormalUser = true;
uid = 1000;
password = mkIf (hashedPassword == null) username;
extraGroups = [ "wheel" "networkmanager" ];
};
};
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
sharedModules = [{
home.stateVersion = "22.11";
programs.man.generateCaches = true;
}];
users.${username}.home = {
inherit username;
homeDirectory = "/home/${username}";
};
};
virtualisation.vmVariant = {
virtualisation = {
memorySize = 4096;
cores = 4;
qemu.options = [
"-device virtio-vga-gl"
"-display sdl,gl=on,show-cursor=off"
"-audio pa,model=hda"
"-full-screen"
];
};
environment.sessionVariables = {
WLR_NO_HARDWARE_CURSORS = "1";
};
services.interception-tools.enable = lib.mkForce false;
networking.resolvconf.enable = lib.mkForce true;
zramSwap.enable = lib.mkForce false;
boot.enableContainers = false;
};
};
}