depot/ops/nixos/lib/common.nix

135 lines
4 KiB
Nix
Raw Normal View History

# SPDX-FileCopyrightText: 2020 Luke Granger-Brown <depot@lukegb.com>
#
# SPDX-License-Identifier: Apache-2.0
2020-10-25 11:36:16 +00:00
{ pkgs, config, depot, lib, rebuilder, ... }@args:
let
inherit (lib) mkDefault;
in
{
imports = [ ../../../third_party/home-manager/nixos ];
2020-10-25 11:36:16 +00:00
options.my.home-manager.imports = lib.mkOption {
type = lib.types.listOf lib.types.path;
default = [ ./home-manager/common.nix ];
};
options.my.home-manager.system = lib.mkOption {
type = lib.types.nullOr lib.types.anything;
default = null;
2020-05-08 23:03:21 +00:00
};
options.my.ip.tailscale = lib.mkOption {
type = lib.types.nullOr lib.types.string;
default = null;
};
2020-10-25 11:36:16 +00:00
config = {
hardware.enableRedistributableFirmware = true;
networking.hosts = depot.ops.nixos.tailscaleIPs;
2020-10-25 11:36:16 +00:00
nix = {
nixPath = [ "depot=/home/lukegb/depot/" "nixpkgs=/home/lukegb/depot/third_party/nixpkgs/" ];
trustedUsers = [ "root" "@wheel" ];
binaryCaches = lib.mkForce [ "https://cache.nixos.org/" "s3://lukegb-nix-cache?endpoint=storage.googleapis.com&trusted=1" ];
trustedBinaryCaches = lib.mkForce [ "https://cache.nixos.org/" "s3://lukegb-nix-cache?endpoint=storage.googleapis.com&trusted=1" ];
envVars = {
AWS_ACCESS_KEY_ID = "${depot.ops.secrets.nixCache.AWS_ACCESS_KEY_ID}";
AWS_SECRET_ACCESS_KEY = "${depot.ops.secrets.nixCache.AWS_SECRET_ACCESS_KEY}";
};
};
nixpkgs.config = depot.third_party.nixpkgsConfig;
2020-10-25 11:36:16 +00:00
i18n.defaultLocale = "en_GB.UTF-8";
console.keyMap = "us";
2020-10-25 11:36:16 +00:00
time.timeZone = mkDefault "Etc/UTC";
environment.systemPackages = with pkgs; [
vim rxvt_unicode.terminfo tmux rebuilder tailscale rsync
(mercurial.overridePythonAttrs (origAttrs: {
propagatedBuildInputs = origAttrs.propagatedBuildInputs ++ [python3Packages.hg-evolve depot.nix.pkgs.hg-git];
}))
];
2020-10-25 11:36:16 +00:00
networking.firewall = {
allowPing = true;
};
2020-10-25 11:36:16 +00:00
2020-10-25 12:00:15 +00:00
environment.homeBinInPath = true;
security.doas.wheelNeedsPassword = false;
security.sudo.wheelNeedsPassword = false;
2020-10-25 11:36:16 +00:00
users.mutableUsers = false;
users.users = let secrets = depot.ops.secrets; in {
root.hashedPassword = secrets.passwordHashes.root;
lukegb = {
isNormalUser = true;
uid = 1000;
extraGroups = [ "wheel" ];
hashedPassword = secrets.passwordHashes.lukegb;
openssh.authorizedKeys.keyFiles = [
../../secrets/lukegb_totoro.pub
../../secrets/lukegb_termius.pub
../../secrets/lukegb_porcorosso_win.pub
../../secrets/lukegb_porcorosso_wsl.pub
2020-11-03 15:25:03 +00:00
../../secrets/lukegb_porcorosso_linux.pub
];
2020-10-25 11:36:16 +00:00
};
deployer = {
isSystemUser = true;
uid = 1001;
hashedPassword = "!";
useDefaultShell = true;
home = "/var/lib/deployer";
createHome = true;
openssh.authorizedKeys.keyFiles = [
../../secrets/deployer_ed25519.pub
];
};
2020-05-09 00:10:20 +00:00
};
2020-10-25 11:36:16 +00:00
security.sudo.extraRules = [{
users = [ "deployer" ];
commands = [{
command = "${rebuilder}/bin/rebuilder";
options = [ "NOPASSWD" ];
}];
2020-05-09 00:10:20 +00:00
}];
2020-10-25 11:36:16 +00:00
security.sudo.extraConfig = ''
Defaults:deployer !requiretty
'';
2020-10-25 11:36:16 +00:00
programs.mtr.enable = true;
services.openssh.enable = true;
services.tailscale.enable = true;
2020-10-25 11:36:16 +00:00
boot = {
kernelModules = [ "tcp_bbr" ];
kernel.sysctl."net.ipv4.tcp_congestion_control" = "bbr";
kernel.sysctl."net.core.default_qdisc" = "fq_codel";
};
2020-10-25 11:36:16 +00:00
# Clean up daily.
nix.gc = {
automatic = lib.mkDefault true;
dates = "*-*-* 05:00:00";
};
home-manager.useUserPackages = true;
home-manager.useGlobalPkgs = true;
systemd.services."home-manager-lukegb" = {
before = [ "display-manager.service" ];
wantedBy = [ "multi-user.target" ];
};
2020-10-25 11:36:16 +00:00
home-manager.users.lukegb = { pkgs, ... }: ({
imports = [ ({
_module.args = args;
})] ++ config.my.home-manager.imports ++ (
lib.optional (config.my.home-manager.system != null) config.my.home-manager.system
);
});
};
2020-07-08 18:36:21 +00:00
}