From 9d5e94346856591a1ff06450c310db317856d924 Mon Sep 17 00:00:00 2001 From: Charlotte Van Petegem Date: Sun, 6 Mar 2022 02:14:26 +0100 Subject: [PATCH] Make sure .ssh exists before trying to copy authorized_keys into it --- modules/base/sshd/default.nix | 5 ++++- modules/base/zfs/default.nix | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/modules/base/sshd/default.nix b/modules/base/sshd/default.nix index 4745eb54..a0a24452 100644 --- a/modules/base/sshd/default.nix +++ b/modules/base/sshd/default.nix @@ -1,7 +1,10 @@ { config, lib, ... }: { - chvp.base.zfs.ensureExists = [ "${config.chvp.dataPrefix}/etc/ssh" ]; + chvp.base.zfs = { + ensureSystemExists = [ "${config.chvp.dataPrefix}/etc/ssh" ]; + ensureHomeExists = [ ".ssh" ]; + }; services.openssh = { enable = true; passwordAuthentication = false; diff --git a/modules/base/zfs/default.nix b/modules/base/zfs/default.nix index 6a9591a8..e6d5ccb7 100644 --- a/modules/base/zfs/default.nix +++ b/modules/base/zfs/default.nix @@ -20,10 +20,14 @@ { path = ".cache/nix-index"; type = "cache"; } ]; }; - ensureExists = lib.mkOption { + ensureSystemExists = lib.mkOption { default = [ ]; example = [ "/data/etc/ssh" ]; }; + ensureHomeExists = lib.mkOption { + default = [ ]; + example = [ ".ssh" ]; + }; backups = lib.mkOption { default = [ ]; example = [{ @@ -87,14 +91,16 @@ systemd.services = let - ensureExistsScript = lib.concatStringsSep "\n" (map (path: "mkdir -p ${path}") config.chvp.base.zfs.ensureExists); makeLinkScript = config: lib.concatStringsSep "\n" (map (location: ''mkdir -p "${location.path}"'') config); + ensureSystemExistsScript = lib.concatStringsSep "\n" (map (path: ''mkdir -p "${path}"'') config.chvp.base.zfs.ensureSystemExists); systemLinksScript = makeLinkScript config.chvp.base.zfs.systemLinks; + ensureHomeExistsScript = lib.concatStringsSep "\n" (map (path: ''mkdir -p "${path}"'') config.chvp.base.zfs.ensureHomeExists); homeLinksScript = makeLinkScript config.chvp.base.zfs.homeLinks; in { make-system-links-destinations = { script = '' + ${ensureSystemExistsScript} ${systemLinksScript} mkdir -p /home/charlotte chown charlotte:users /home/charlotte @@ -115,7 +121,10 @@ }; make-home-links-destinations = { - script = homeLinksScript; + script = '' + ${ensureHomeExistsScript} + ${homeLinksScript} + ''; after = [ "local-fs.target" "make-system-links-destinations.service" ]; wants = [ "local-fs.target" "make-system-links-destinations.service" ]; before = [ "shutdown.target" "sysinit.target" ];