mirror of
https://github.com/JulienMalka/snowfield.git
synced 2025-03-28 23:00:58 +01:00
chore: improve shells
This commit is contained in:
parent
f53336f887
commit
c783d1123a
3 changed files with 54 additions and 31 deletions
|
@ -1,37 +1,48 @@
|
||||||
let
|
{
|
||||||
inputs = import ../deps;
|
writeShellApplication,
|
||||||
pkgs = import inputs.nixpkgs { };
|
rbw,
|
||||||
in
|
nixos-anywhere,
|
||||||
pkgs.writeShellScriptBin "bootstrap-machine" ''
|
}:
|
||||||
pushd $(git rev-parse --show-toplevel)
|
|
||||||
machine=$1
|
|
||||||
ip=$2
|
|
||||||
extra_args=("''${@:3}")
|
|
||||||
# Create a temporary directory
|
|
||||||
temp=$(mktemp -d)
|
|
||||||
# Function to cleanup temporary directory on exit
|
|
||||||
cleanup() {
|
|
||||||
rm -rf "$temp"
|
|
||||||
}
|
|
||||||
trap cleanup EXIT
|
|
||||||
|
|
||||||
# Create the directory where sshd expects to find the host keys
|
writeShellApplication {
|
||||||
install -d -m755 "$temp/etc/ssh"
|
name = "bootstrap-machine";
|
||||||
|
|
||||||
# Decrypt your private key from the password store and copy it to the temporary directory
|
runtimeInputs = [
|
||||||
rbw get "$machine"_ssh_host_ed25519_key -f notes > "$temp/etc/ssh/ssh_host_ed25519_key"
|
rbw
|
||||||
|
nixos-anywhere
|
||||||
|
];
|
||||||
|
|
||||||
# Set the correct permissions so sshd will accept the key
|
text = ''
|
||||||
chmod 600 "$temp/etc/ssh/ssh_host_ed25519_key"
|
pushd "$(git rev-parse --show-toplevel)"
|
||||||
|
machine=$1
|
||||||
|
ip=$2
|
||||||
|
extra_args=("''${@:3}")
|
||||||
|
# Create a temporary directory
|
||||||
|
temp=$(mktemp -d)
|
||||||
|
# Function to cleanup temporary directory on exit
|
||||||
|
cleanup() {
|
||||||
|
rm -rf "$temp"
|
||||||
|
}
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
ssh-keygen -f "$temp/etc/ssh/ssh_host_ed25519_key" -y > "$temp/etc/ssh/ssh_host_ed25519_key.pub"
|
# Create the directory where sshd expects to find the host keys
|
||||||
|
install -d -m755 "$temp/etc/ssh"
|
||||||
|
|
||||||
chmod 644 "$temp/etc/ssh/ssh_host_ed25519_key.pub"
|
# Decrypt your private key from the password store and copy it to the temporary directory
|
||||||
|
rbw get "$machine"_ssh_host_ed25519_key -f notes > "$temp/etc/ssh/ssh_host_ed25519_key"
|
||||||
|
|
||||||
mkdir -p "$temp/persistent"
|
# Set the correct permissions so sshd will accept the key
|
||||||
|
chmod 600 "$temp/etc/ssh/ssh_host_ed25519_key"
|
||||||
|
|
||||||
cp -r "$temp/etc" "$temp/persistent/etc"
|
ssh-keygen -f "$temp/etc/ssh/ssh_host_ed25519_key" -y > "$temp/etc/ssh/ssh_host_ed25519_key.pub"
|
||||||
|
|
||||||
nixos-anywhere --extra-files "$temp" --store-paths $(nix-build -A nixosConfigurations.\"$machine\".config.system.build.diskoScript) $(nix-build -A nixosConfigurations.\"$machine\".config.system.build.toplevel) "''${extra_args[@]}" root@"$ip"
|
chmod 644 "$temp/etc/ssh/ssh_host_ed25519_key.pub"
|
||||||
popd
|
|
||||||
''
|
mkdir -p "$temp/persistent"
|
||||||
|
|
||||||
|
cp -r "$temp/etc" "$temp/persistent/etc"
|
||||||
|
|
||||||
|
nixos-anywhere --extra-files "$temp" --store-paths "$(nix-build -A nixosConfigurations.\""$machine"\".config.system.build.diskoScript)" "$(nix-build -A nixosConfigurations.\""$machine"\".config.system.build.toplevel)" "''${extra_args[@]}" root@"$ip"
|
||||||
|
popd
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
|
11
scripts/update-deps.nix
Normal file
11
scripts/update-deps.nix
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
{ writeShellApplication, npins }:
|
||||||
|
|
||||||
|
writeShellApplication {
|
||||||
|
name = "update-deps";
|
||||||
|
|
||||||
|
runtimeInputs = [ npins ];
|
||||||
|
|
||||||
|
text = ''
|
||||||
|
npins update -d deps "$@"
|
||||||
|
'';
|
||||||
|
}
|
|
@ -3,7 +3,8 @@ let
|
||||||
pkgs = import inputs.unstable { };
|
pkgs = import inputs.unstable { };
|
||||||
nixos-anywhere = pkgs.callPackage "${inputs.nixos-anywhere}/src/default.nix" { };
|
nixos-anywhere = pkgs.callPackage "${inputs.nixos-anywhere}/src/default.nix" { };
|
||||||
agenix = pkgs.callPackage "${inputs.agenix}/pkgs/agenix.nix" { };
|
agenix = pkgs.callPackage "${inputs.agenix}/pkgs/agenix.nix" { };
|
||||||
bootstrap = import scripts/bootstrap-machine.nix;
|
bootstrap = pkgs.callPackage scripts/bootstrap-machine.nix { inherit nixos-anywhere; };
|
||||||
|
update-deps = pkgs.callPackage scripts/update-deps.nix { };
|
||||||
pre-commit-hook =
|
pre-commit-hook =
|
||||||
(import (
|
(import (
|
||||||
pkgs.applyPatches {
|
pkgs.applyPatches {
|
||||||
|
@ -32,9 +33,9 @@ pkgs.mkShell {
|
||||||
nativeBuildInputs = with pkgs; [
|
nativeBuildInputs = with pkgs; [
|
||||||
colmena
|
colmena
|
||||||
npins
|
npins
|
||||||
nixos-anywhere
|
|
||||||
agenix
|
agenix
|
||||||
bootstrap
|
bootstrap
|
||||||
|
update-deps
|
||||||
statix
|
statix
|
||||||
rbw
|
rbw
|
||||||
pinentry
|
pinentry
|
||||||
|
|
Loading…
Add table
Reference in a new issue