2022-02-20 20:16:49 +00:00
|
|
|
{ lib, pkgs, pkgs', inputs, config, ... }@args:
|
2022-02-13 23:06:31 +00:00
|
|
|
let
|
2022-02-19 22:55:53 +00:00
|
|
|
inherit (builtins) mapAttrs readFile;
|
|
|
|
inherit (lib) concatMapStrings concatStringsSep optionalAttrs versionAtLeast mkMerge mkIf mkDefault mkOption;
|
2022-02-17 18:36:39 +00:00
|
|
|
inherit (lib.hm) dag;
|
2022-02-15 20:50:27 +00:00
|
|
|
inherit (lib.my) mkOpt' dummyOption;
|
2022-02-13 23:06:31 +00:00
|
|
|
in
|
2022-02-15 20:50:27 +00:00
|
|
|
{
|
|
|
|
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-15 00:18:37 +00:00
|
|
|
};
|
2022-02-17 18:36:39 +00:00
|
|
|
|
|
|
|
ssh = {
|
|
|
|
authKeys = {
|
|
|
|
literal = mkOpt' (listOf singleLineStr) [ ] "List of OpenSSH keys to allow";
|
2022-02-19 22:55:53 +00:00
|
|
|
files = mkOpt' (listOf str) [ ] "List of OpenSSH key files to allow";
|
2022-02-17 18:36:39 +00:00
|
|
|
};
|
|
|
|
matchBlocks = mkOpt' (attrsOf anything) { } "SSH match blocks";
|
|
|
|
};
|
2022-02-15 00:18:37 +00:00
|
|
|
};
|
|
|
|
|
2022-02-15 20:50:27 +00:00
|
|
|
# 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-15 20:50:27 +00:00
|
|
|
})
|
|
|
|
{
|
2022-02-17 18:36:39 +00:00
|
|
|
my = {
|
|
|
|
isStandalone = !(args ? osConfig);
|
|
|
|
|
|
|
|
ssh = {
|
|
|
|
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";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-02-19 22:55:53 +00:00
|
|
|
home.file.".ssh/authorized_keys" = with config.my.ssh.authKeys;
|
|
|
|
mkIf (config.programs.ssh.enable && (literal != [ ] || files != [ ])) {
|
|
|
|
text = ''
|
|
|
|
${concatStringsSep "\n" literal}
|
|
|
|
${concatMapStrings (f: readFile f + "\n") files}
|
|
|
|
'';
|
|
|
|
};
|
2022-02-14 00:56:43 +00:00
|
|
|
|
2022-02-15 20:50:27 +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-15 02:24:16 +00:00
|
|
|
|
2022-02-17 15:47:24 +00:00
|
|
|
lsd = {
|
|
|
|
enable = mkDefault true;
|
|
|
|
enableAliases = mkDefault true;
|
|
|
|
};
|
|
|
|
|
|
|
|
starship = {
|
|
|
|
enable = mkDefault true;
|
|
|
|
settings = {
|
|
|
|
aws.disabled = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-02-15 20:50:27 +00:00
|
|
|
bash = {
|
|
|
|
# This not only installs bash but has home-manager control .bashrc and friends
|
|
|
|
enable = mkDefault true;
|
2022-02-16 22:45:17 +00:00
|
|
|
initExtra =
|
|
|
|
''
|
|
|
|
flake-src() {
|
|
|
|
cd "$(nix eval "''${@:2}" --impure --raw --expr "builtins.getFlake \"$1\"")"
|
|
|
|
}
|
|
|
|
'';
|
2022-02-15 20:50:27 +00:00
|
|
|
};
|
2022-02-14 19:56:31 +00:00
|
|
|
|
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"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-02-15 20:50:27 +00:00
|
|
|
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
|
|
|
|
2022-02-15 20:50:27 +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
|
|
|
|
2022-02-15 20:50:27 +00:00
|
|
|
htop = {
|
|
|
|
enable = true;
|
|
|
|
settings = {};
|
|
|
|
};
|
2022-02-15 01:08:00 +00:00
|
|
|
};
|
|
|
|
|
2022-02-15 20:50:27 +00:00
|
|
|
home = {
|
|
|
|
packages = with pkgs; [
|
2022-02-20 20:16:49 +00:00
|
|
|
file
|
2022-02-15 20:50:27 +00:00
|
|
|
tree
|
|
|
|
iperf3
|
|
|
|
];
|
2022-02-14 19:56:31 +00:00
|
|
|
|
2022-02-15 20:50:27 +00:00
|
|
|
sessionVariables = {
|
|
|
|
EDITOR = "vim";
|
|
|
|
};
|
2022-02-15 21:00:27 +00:00
|
|
|
shellAliases = {
|
|
|
|
hm = "home-manager";
|
|
|
|
};
|
2022-02-13 23:06:31 +00:00
|
|
|
|
2022-02-15 20:50:27 +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) {
|
2022-02-15 20:50:27 +00:00
|
|
|
# Note: If globalPkgs mode is on, then these will be overridden by the NixOS equivalents of these options
|
|
|
|
nixpkgs = {
|
2022-02-20 20:16:49 +00:00
|
|
|
overlays = [
|
|
|
|
inputs.deploy-rs.overlay
|
|
|
|
];
|
2022-02-15 20:50:27 +00:00
|
|
|
config = {
|
|
|
|
allowUnfree = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
})
|
|
|
|
(mkIf config.my.isStandalone {
|
2022-02-19 22:55:53 +00:00
|
|
|
my = {
|
|
|
|
ssh.authKeys.files = [ lib.my.authorizedKeys ];
|
|
|
|
};
|
|
|
|
|
2022-02-15 20:50:27 +00:00
|
|
|
fonts.fontconfig.enable = true;
|
2022-02-15 01:08:00 +00:00
|
|
|
|
2022-02-15 20:50:27 +00:00
|
|
|
home = {
|
|
|
|
packages = with pkgs; [
|
2022-02-17 15:59:00 +00:00
|
|
|
pkgs'.unstable.nixVersions.stable
|
2022-02-15 20:50:27 +00:00
|
|
|
];
|
|
|
|
};
|
|
|
|
})
|
|
|
|
];
|
|
|
|
}
|