nixfiles/home-manager/modules/common.nix

192 lines
5.5 KiB
Nix
Raw Normal View History

2022-02-17 18:36:39 +00:00
{ lib, pkgs, pkgs', inputs, options, config, ... }@args:
2022-02-13 23:06:31 +00:00
let
2022-02-17 18:36:39 +00:00
inherit (builtins) mapAttrs;
inherit (lib) concatStringsSep optionalAttrs versionAtLeast mkMerge mkIf mkDefault mkOption;
inherit (lib.hm) dag;
inherit (lib.my) mkOpt' dummyOption;
2022-02-13 23:06:31 +00:00
in
{
options = with lib.types; {
my = {
isStandalone = mkOption {
type = bool;
internal = true;
description = "Whether home-manager is running inside a NixOS system or not.";
};
2022-02-17 18:36:39 +00:00
ssh = {
authKeys = {
literal = mkOpt' (listOf singleLineStr) [ ] "List of OpenSSH keys to allow";
};
matchBlocks = mkOpt' (attrsOf anything) { } "SSH match blocks";
};
};
# Only present in >=22.05, so forward declare
nix.registry = dummyOption;
};
config = mkMerge [
(mkIf (versionAtLeast config.home.stateVersion "22.05") {
nix.registry = {
pkgs = {
to = {
type = "path";
path = toString pkgs.path;
};
exact = true;
};
2022-02-13 23:06:31 +00:00
};
})
{
2022-02-17 18:36:39 +00:00
my = {
isStandalone = !(args ? osConfig);
ssh = {
authKeys.literal = [
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+kCHXqtznkT9IBN5WxZHmXI97k3BumT+N4lyHWMo0pykpACCOcGw52EXxQveNqgcwcRUgamL9A2JTE//WRf3O4nBofeTRNKcRxTjRoUVIt/F0xbf09yWBqJOXZ8rqLkXhRvSpr1TCUZtYVp5iLtpERp622OMIqHSwa6HlxBqsCFkBeq1bRyNtYK/IaQAuBPW9MNeFriGqA0Vq078ccXp+JINxJbr+ZJybVg6PVqnMD+PgGMZQLkoWjwjH3vcJZZt584UPtrXKpNZuKy6dcMCb2U+O9NOaO66168sBVuK0kZHh51nJ7ZH38VLGiBipRgIQ1fzic3Ncn6GC9ko3/OwT jackos1998@gmail.com"
];
matchBlocks = {
2022-02-17 19:14:10 +00:00
nix-dev-vm = {
user = "dev";
hostname = "localhost";
port = 2222;
extraOptions = {
StrictHostKeyChecking = "no";
UserKnownHostsFile = "/dev/null";
};
};
2022-02-17 18:36:39 +00:00
"rsync.net" = {
host = "rsyncnet";
user = "16413";
hostname = "ch-s010.rsync";
};
shoe = {
host = "shoe.netsoc.tcd.ie shoe";
user = "netsoc";
};
netsocBoxes = {
host = "cube spoon napalm gandalf saruman";
user = "root";
};
};
};
};
home.file.".ssh/authorized_keys".text = mkIf config.programs.ssh.enable
''
${concatStringsSep "\n" config.my.ssh.authKeys.literal}
'';
2022-02-14 00:56:43 +00:00
programs = {
# Even when enabled this will only be actually installed in standalone mode
# Note: `home-manager.path` is for telling home-manager is installed and setting it in NIX_PATH, which we should
# never care about.
home-manager.enable = true;
2022-02-17 15:47:24 +00:00
lsd = {
enable = mkDefault true;
enableAliases = mkDefault true;
};
starship = {
enable = mkDefault true;
settings = {
aws.disabled = true;
};
};
bash = {
# This not only installs bash but has home-manager control .bashrc and friends
enable = mkDefault true;
initExtra =
''
flake-src() {
cd "$(nix eval "''${@:2}" --impure --raw --expr "builtins.getFlake \"$1\"")"
}
'';
};
2022-02-17 18:36:39 +00:00
ssh = {
enable = mkDefault true;
matchBlocks = (mapAttrs (_: b: dag.entryBefore [ "all" ] b) config.my.ssh.matchBlocks) // {
all = {
host = "*";
identityFile = [
"~/.ssh/id_rsa"
"~/.ssh/netsoc"
"~/.ssh/borg"
];
};
};
};
direnv = {
enable = mkDefault true;
nix-direnv.enable = true;
stdlib =
''
# addition to nix-direnv's use_nix that registers outputs as gc roots (as well as the .drv)
use_nix_outputs() {
local layout_dir drv deps
layout_dir="$(direnv_layout_dir)"
drv="$layout_dir/drv"
deps="$layout_dir/deps"
2022-02-13 23:06:31 +00:00
if [ ! -e "$deps" ] || (( "$(stat --format=%Z "$drv")" > "$(stat --format=%Z "$deps")" )); then
rm -rf "$deps"
mkdir -p "$deps"
nix-store --indirect --add-root "$deps/out" --realise $(nix-store --query --references "$drv") > /dev/null
log_status renewed outputs gc roots
fi
}
'';
};
2022-02-13 23:06:31 +00:00
htop = {
enable = true;
settings = {};
};
2022-02-15 01:08:00 +00:00
};
home = {
packages = with pkgs; [
tree
iperf3
];
sessionVariables = {
EDITOR = "vim";
};
shellAliases = {
hm = "home-manager";
};
2022-02-13 23:06:31 +00:00
language.base = mkDefault "en_IE.UTF-8";
};
}
2022-02-17 15:47:24 +00:00
(mkIf (config.my.isStandalone || !args.osConfig.home-manager.useGlobalPkgs) {
# Note: If globalPkgs mode is on, then these will be overridden by the NixOS equivalents of these options
nixpkgs = {
overlays = [
# TODO: Wait for https://github.com/NixOS/nixpkgs/pull/159074 to arrive to nixos-unstable
(final: prev: { remarshal = pkgs'.master.remarshal; })
];
config = {
allowUnfree = true;
};
};
})
(mkIf config.my.isStandalone {
fonts.fontconfig.enable = true;
2022-02-15 01:08:00 +00:00
home = {
packages = with pkgs; [
pkgs'.unstable.nixVersions.stable
];
};
})
];
}