fix(ssh): use home-manager to manage ssh config
This commit is contained in:
parent
bd7556a682
commit
46773dfbe0
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,4 +2,4 @@
|
|||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
# Ignore private configurations
|
# Ignore private configurations
|
||||||
private/ssh-config.nix
|
private/ssh-config
|
11
README.md
11
README.md
@ -2,17 +2,18 @@
|
|||||||
|
|
||||||
In this repo I store my config files.
|
In this repo I store my config files.
|
||||||
It helps me to install quickly all software I need for work and fun.
|
It helps me to install quickly all software I need for work and fun.
|
||||||
Feel free to check & alter the list of software to be installed in these files.
|
Feel free to check & alter the configs as you like.
|
||||||
|
|
||||||
I use NixOS. It stores all of it's configuration in `configuration.nix`.
|
I use NixOS. It stores all of its configuration in `configuration.nix`.
|
||||||
That's where you can start exploration and modification.
|
Start your exploration there.
|
||||||
|
If you are confused at any step - checkout docs on https://nixos.org/
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
1. Clone this repo.
|
1. Clone this repo.
|
||||||
2. Give build script permission to execute: `chmod +x ./build-nix.sh`.
|
2. Give build script permission to execute: `chmod +x ./build-nix.sh`.
|
||||||
2. [Optionally] SSH Config `cp ./ssh-config.nix.example ./ssh-config.nix` and fill with your values.
|
3. [Optionally] Check example files in `./private` folder. If anything there you'd like to use - copy example file and remove ".example" suffix. Fill file with your content. Example: SSH Config `cp ./private/ssh-config.nix.example ./private/ssh-config.nix` and fill with your values.
|
||||||
3. Apply configuration with `make`.
|
4. Apply configuration with `make`.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
@ -12,7 +12,9 @@ sudo -v
|
|||||||
|
|
||||||
echo "Copying new configuration..."
|
echo "Copying new configuration..."
|
||||||
# Copy the local configuration.nix to the system configuration location
|
# Copy the local configuration.nix to the system configuration location
|
||||||
sudo cp ./*.nix "${NIXOS_CONFIG_PATH}"
|
sudo cp ./configuration.nix "${NIXOS_CONFIG_PATH}"
|
||||||
|
sudo mkdir -p "${NIXOS_CONFIG_PATH}/private"
|
||||||
|
sudo cp ./private/* "${NIXOS_CONFIG_PATH}/private/"
|
||||||
|
|
||||||
echo "Rebuilding NixOS configuration..."
|
echo "Rebuilding NixOS configuration..."
|
||||||
# Rebuild the NixOS configuration and make the changes effective
|
# Rebuild the NixOS configuration and make the changes effective
|
||||||
|
@ -5,23 +5,29 @@
|
|||||||
{ config, pkgs, lib, ... }:
|
{ config, pkgs, lib, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
sshConfigPath = ./ssh-config.nix;
|
nixFolder = "/etc/nixos";
|
||||||
gdrivePath = "/home/spy4x/gdrive";
|
username = "spy4x";
|
||||||
|
userFullName = "Anton Shubin";
|
||||||
|
sshConfigPath = "${nixFolder}/private/ssh-config";
|
||||||
|
sshConfig = if builtins.pathExists "${sshConfigPath}" then builtins.readFile "${sshConfigPath}" else "# private ssh config file didn't exist to insert it's content here";
|
||||||
|
gdrivePath = "/home/${username}/gdrive";
|
||||||
curBin = "/run/current-system/sw/bin";
|
curBin = "/run/current-system/sw/bin";
|
||||||
|
home-manager = builtins.fetchTarball "https://github.com/nix-community/home-manager/archive/release-23.11.tar.gz";
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports =
|
imports =
|
||||||
[
|
[
|
||||||
# Include the results of the hardware scan.
|
# Include the results of the hardware scan.
|
||||||
./hardware-configuration.nix
|
./hardware-configuration.nix
|
||||||
] ++ lib.optional (builtins.pathExists sshConfigPath) sshConfigPath;
|
(import "${home-manager}/nixos")
|
||||||
|
];
|
||||||
|
|
||||||
# Bootloader.
|
# Bootloader.
|
||||||
boot.loader.grub.enable = true;
|
boot.loader.grub.enable = true;
|
||||||
boot.loader.grub.device = "/dev/nvme0n1";
|
boot.loader.grub.device = "/dev/nvme0n1";
|
||||||
boot.loader.grub.useOSProber = true;
|
boot.loader.grub.useOSProber = true;
|
||||||
|
|
||||||
networking.hostName = "spy4x-pc";
|
networking.hostName = "${username}-pc";
|
||||||
networking.networkmanager.enable = true;
|
networking.networkmanager.enable = true;
|
||||||
networking = {
|
networking = {
|
||||||
firewall = {
|
firewall = {
|
||||||
@ -92,10 +98,24 @@ in
|
|||||||
hardware.logitech.wireless.enable = true;
|
hardware.logitech.wireless.enable = true;
|
||||||
hardware.logitech.wireless.enableGraphical = true;
|
hardware.logitech.wireless.enableGraphical = true;
|
||||||
|
|
||||||
|
home-manager.users.spy4x = {
|
||||||
|
home.stateVersion = "23.11";
|
||||||
|
home.username = username;
|
||||||
|
home.homeDirectory = "/home/${username}";
|
||||||
|
|
||||||
|
home.packages = with pkgs; [
|
||||||
|
wget
|
||||||
|
];
|
||||||
|
programs.ssh.enable = true;
|
||||||
|
programs.ssh.extraConfig = ''
|
||||||
|
${sshConfig}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
# Define a user account. Don't forget to set a password with ‘passwd’.
|
# Define a user account. Don't forget to set a password with ‘passwd’.
|
||||||
users.users.spy4x = {
|
users.users.spy4x = {
|
||||||
isNormalUser = true;
|
isNormalUser = true;
|
||||||
description = "Anton Shubin";
|
description = userFullName;
|
||||||
extraGroups = [
|
extraGroups = [
|
||||||
"networkmanager"
|
"networkmanager"
|
||||||
"wheel"
|
"wheel"
|
||||||
@ -139,14 +159,13 @@ in
|
|||||||
# Shell aliases and other init
|
# Shell aliases and other init
|
||||||
environment.interactiveShellInit = ''
|
environment.interactiveShellInit = ''
|
||||||
alias copy='wl-copy <'
|
alias copy='wl-copy <'
|
||||||
alias build='sudo nixos-rebuild switch'
|
|
||||||
alias rs='rsync -avhzru -P'
|
alias rs='rsync -avhzru -P'
|
||||||
alias rsh='rsync -avhzru -P -e ssh'
|
alias rsh='rsync -avhzru -P -e ssh'
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# Enable automatic login for the user.
|
# Enable automatic login for the user.
|
||||||
services.xserver.displayManager.autoLogin.enable = true;
|
services.xserver.displayManager.autoLogin.enable = true;
|
||||||
services.xserver.displayManager.autoLogin.user = "spy4x";
|
services.xserver.displayManager.autoLogin.user = username;
|
||||||
|
|
||||||
# RClone Google Drive service
|
# RClone Google Drive service
|
||||||
systemd.services.rclone-gdrive-mount = {
|
systemd.services.rclone-gdrive-mount = {
|
||||||
@ -163,7 +182,7 @@ in
|
|||||||
ExecStop = "${curBin}/fusermount -u ${gdrivePath}";
|
ExecStop = "${curBin}/fusermount -u ${gdrivePath}";
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
RestartSec = "10s";
|
RestartSec = "10s";
|
||||||
User = "spy4x";
|
User = username;
|
||||||
Group = "users";
|
Group = "users";
|
||||||
Environment = [ "PATH=/run/wrappers/bin/:$PATH" ]; # Required environments
|
Environment = [ "PATH=/run/wrappers/bin/:$PATH" ]; # Required environments
|
||||||
};
|
};
|
||||||
|
7
private/ssh-config.example
Normal file
7
private/ssh-config.example
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# Part of config, to remote machine aliases for SSH
|
||||||
|
|
||||||
|
Host my-remote-machine # alias to do "ssh my remote-machine"
|
||||||
|
HostName 192.192.192.192 # ip/hostname
|
||||||
|
User my-user # username
|
||||||
|
|
||||||
|
# ... other hosts
|
@ -1,12 +0,0 @@
|
|||||||
# Part of config, to remote machine aliases for SSH
|
|
||||||
|
|
||||||
{ ... }: {
|
|
||||||
programs.ssh.extraConfig = ''
|
|
||||||
|
|
||||||
Host my-remote-machine # alias to do "ssh my remote-machine"
|
|
||||||
HostName 192.192.192.192 # ip/hostname
|
|
||||||
User my-user # username
|
|
||||||
|
|
||||||
# ... other hosts
|
|
||||||
'';
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user