This commit is contained in:
parent
731e2118a5
commit
3e1fe36c42
5 changed files with 322 additions and 15 deletions
|
@ -8,8 +8,9 @@
|
|||
imports = [./module.nix];
|
||||
|
||||
fleet = {
|
||||
darwinHosts.archer = {
|
||||
};
|
||||
darwinHosts.archer = {};
|
||||
|
||||
nixOnDroidHosts.janeway = {};
|
||||
|
||||
hosts = {
|
||||
# thinkpad = {
|
||||
|
@ -164,14 +165,4 @@
|
|||
};
|
||||
};
|
||||
};
|
||||
|
||||
flake.nixosConfigurations =
|
||||
lib.mapAttrs
|
||||
config.fleet._mkNixosConfiguration
|
||||
config.fleet.hosts;
|
||||
|
||||
flake.darwinConfigurations =
|
||||
lib.mapAttrs
|
||||
config.fleet._mkDarwinConfiguration
|
||||
config.fleet.darwinHosts;
|
||||
}
|
||||
|
|
58
hosts/janeway/default.nix
Normal file
58
hosts/janeway/default.nix
Normal file
|
@ -0,0 +1,58 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
sshdTmpDirectory = "${config.user.home}/sshd-tmp";
|
||||
sshdDirectory = "${config.user.home}/sshd";
|
||||
pathToPubKey = "/mnt/sdcard/Download/picard_host_key.pub";
|
||||
port = 8022;
|
||||
in {
|
||||
# Backup etc files instead of failing to activate generation if a file already exists in /etc
|
||||
environment.etcBackupExtension = ".bak";
|
||||
|
||||
# Read the changelog before changing this value
|
||||
system.stateVersion = "23.11";
|
||||
|
||||
# Set up nix for flakes
|
||||
nix.extraOptions = ''
|
||||
experimental-features = nix-command flakes
|
||||
'';
|
||||
|
||||
# Set your time zone
|
||||
time.timeZone = "Europe/Rome";
|
||||
|
||||
build.activation.sshd = ''
|
||||
$DRY_RUN_CMD mkdir $VERBOSE_ARG --parents "${config.user.home}/.ssh"
|
||||
$DRY_RUN_CMD cat ${pathToPubKey} > "${config.user.home}/.ssh/authorized_keys"
|
||||
|
||||
if [[ ! -d "${sshdDirectory}" ]]; then
|
||||
$DRY_RUN_CMD rm $VERBOSE_ARG --recursive --force "${sshdTmpDirectory}"
|
||||
$DRY_RUN_CMD mkdir $VERBOSE_ARG --parents "${sshdTmpDirectory}"
|
||||
|
||||
$VERBOSE_ECHO "Generating host keys..."
|
||||
$DRY_RUN_CMD ${pkgs.openssh}/bin/ssh-keygen -t rsa -b 4096 -f "${sshdTmpDirectory}/ssh_host_rsa_key" -N ""
|
||||
|
||||
$VERBOSE_ECHO "Writing sshd_config..."
|
||||
$DRY_RUN_CMD echo -e "HostKey ${sshdDirectory}/ssh_host_rsa_key\nPort ${toString port}\n" > "${sshdTmpDirectory}/sshd_config"
|
||||
|
||||
$DRY_RUN_CMD mv $VERBOSE_ARG "${sshdTmpDirectory}" "${sshdDirectory}"
|
||||
fi
|
||||
'';
|
||||
|
||||
environment.packages = [
|
||||
pkgs.vim
|
||||
pkgs.bottom
|
||||
pkgs.helix
|
||||
pkgs.stress
|
||||
pkgs.openssh
|
||||
pkgs.git
|
||||
(pkgs.writeScriptBin "sshd-start" ''
|
||||
#!${pkgs.runtimeShell}
|
||||
|
||||
echo "Starting sshd in non-daemonized way on port ${toString port}"
|
||||
${pkgs.openssh}/bin/sshd -f "${sshdDirectory}/sshd_config" -D
|
||||
'')
|
||||
];
|
||||
}
|
|
@ -48,6 +48,42 @@ in {
|
|||
};
|
||||
}));
|
||||
};
|
||||
nixOnDroidHosts = lib.mkOption {
|
||||
type = lib.types.attrsOf (lib.types.submodule ({name, ...}: {
|
||||
options = {
|
||||
name = lib.mkOption {
|
||||
description = "Host name";
|
||||
type = lib.types.strMatching "^$|^[[:alnum:]]([[:alnum:]_-]{0,61}[[:alnum:]])?$";
|
||||
default = name;
|
||||
};
|
||||
system = lib.mkOption {
|
||||
description = "NixOS architecture (a.k.a. system)";
|
||||
type = lib.types.str;
|
||||
default = "aarch64-linux";
|
||||
};
|
||||
nixpkgs = lib.mkOption {
|
||||
description = "Used nixpkgs";
|
||||
type = lib.types.anything;
|
||||
default = inputs.nixpkgsUnstable;
|
||||
};
|
||||
extraModules = lib.mkOption {
|
||||
description = "Extra NixOS modules";
|
||||
type = lib.types.listOf lib.types.deferredModule;
|
||||
default = [];
|
||||
};
|
||||
overlays = lib.mkOption {
|
||||
description = "Enabled Nixpkgs overlays";
|
||||
type = lib.types.listOf (lib.mkOptionType {
|
||||
name = "nixpkgs-overlay";
|
||||
description = "nixpkgs overlay";
|
||||
check = lib.isFunction;
|
||||
merge = lib.mergeOneOption;
|
||||
});
|
||||
default = [];
|
||||
};
|
||||
};
|
||||
}));
|
||||
};
|
||||
hosts = lib.mkOption {
|
||||
description = "Host configuration";
|
||||
type = lib.types.attrsOf (lib.types.submodule ({name, ...}: {
|
||||
|
@ -243,5 +279,41 @@ in {
|
|||
];
|
||||
};
|
||||
};
|
||||
|
||||
_mkNixOnDroidConfiguration = lib.mkOption {
|
||||
description = "Function returning a proper nix-on-droid configuration";
|
||||
type = lib.types.functionTo (lib.types.functionTo lib.types.attrs); # TODO improve this type
|
||||
internal = true;
|
||||
default = hostname: config:
|
||||
inputs.nix-on-droid.lib.nixOnDroidConfiguration {
|
||||
modules = [
|
||||
({
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: {
|
||||
nixpkgs.overlays = config.overlays;
|
||||
})
|
||||
"${self.outPath}/hosts/${hostname}"
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
flake.nixosConfigurations =
|
||||
lib.mapAttrs
|
||||
config.fleet._mkNixosConfiguration
|
||||
config.fleet.hosts;
|
||||
|
||||
flake.darwinConfigurations =
|
||||
lib.mapAttrs
|
||||
config.fleet._mkDarwinConfiguration
|
||||
config.fleet.darwinHosts;
|
||||
|
||||
flake.nixOnDroidConfigurations =
|
||||
lib.mapAttrs
|
||||
config.fleet._mkNixOnDroidConfiguration
|
||||
config.fleet.nixOnDroidHosts;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue