diff --git a/common.nix b/common.nix index bf2bbc5..95c7f47 100644 --- a/common.nix +++ b/common.nix @@ -1,6 +1,7 @@ { ... }: { imports = [ + ./modules/copy-nix-store-to-misaki.nix ./modules/nix-remote-builders.nix ./modules/nix-builder.nix ./modules/nix-binary-cache.nix diff --git a/default-home.nix b/default-home.nix index 401c229..480dc49 100644 --- a/default-home.nix +++ b/default-home.nix @@ -15,6 +15,7 @@ in { imports = [ inputs.agenix.homeManagerModules.default + ./modules/copy-nix-store-to-misaki-home.nix ./modules/secure-env-var.nix ./ssh.nix ]; diff --git a/host-specific/aleister-noah.nix b/host-specific/aleister-noah.nix index 02c38c5..c35cad1 100644 --- a/host-specific/aleister-noah.nix +++ b/host-specific/aleister-noah.nix @@ -268,6 +268,7 @@ in enable = true; }; imports = [ + ../modules/copy-nix-store-to-misaki-home.nix ../modules/secure-env-var.nix ../ssh.nix ]; @@ -376,12 +377,6 @@ in recursive = true; }; - home.activation.copyHomeManagerClosureToMisaki = lib.hm.dag.entryAfter [ "linkGeneration" ] '' - if ! $DRY_RUN_CMD "${config.home.homeDirectory}/.local/bin/copy-nix-closure-to-misaki" "$newGenPath"; then - echo "warning: failed to copy Home Manager closure to Misaki" >&2 - fi - ''; - home.file.".opencode" = { source = ../opencode; recursive = true; diff --git a/modules/copy-nix-store-to-misaki-home.nix b/modules/copy-nix-store-to-misaki-home.nix new file mode 100644 index 0000000..f9c0701 --- /dev/null +++ b/modules/copy-nix-store-to-misaki-home.nix @@ -0,0 +1,17 @@ +{ + lib, + osConfig ? null, + ... +}: +let + copyScript = ../scripts/copy-nix-closure-to-misaki; +in +{ + home.activation.copyNixStoreToMisaki = lib.mkIf (osConfig == null) ( + lib.hm.dag.entryAfter [ "linkGeneration" ] '' + if ! $DRY_RUN_CMD "${copyScript}" --all; then + echo "warning: failed to copy local Nix store objects to Misaki" >&2 + fi + '' + ); +} diff --git a/modules/copy-nix-store-to-misaki.nix b/modules/copy-nix-store-to-misaki.nix new file mode 100644 index 0000000..a71febb --- /dev/null +++ b/modules/copy-nix-store-to-misaki.nix @@ -0,0 +1,29 @@ +{ + config, + lib, + pkgs, + ... +}: +let + copyScript = ../scripts/copy-nix-closure-to-misaki; +in +{ + system.activationScripts.copyNixStoreToMisaki = { + deps = [ "users" ]; + text = '' + if [ "${config.networking.hostName}" = "misaki" ]; then + exit 0 + fi + + if ${pkgs.coreutils}/bin/id -u noah >/dev/null 2>&1; then + if ! ${pkgs.util-linux}/bin/runuser -u noah -- ${copyScript} --all; then + echo "warning: failed to copy local Nix store objects to Misaki" >&2 + fi + else + if ! ${copyScript} --all; then + echo "warning: failed to copy local Nix store objects to Misaki" >&2 + fi + fi + ''; + }; +} diff --git a/scripts/copy-nix-closure-to-misaki b/scripts/copy-nix-closure-to-misaki index d87391e..6c29bf3 100755 --- a/scripts/copy-nix-closure-to-misaki +++ b/scripts/copy-nix-closure-to-misaki @@ -4,7 +4,7 @@ set -eu target="${NIX_COPY_TARGET:-ssh-ng://noah@misaki}" if [ "$#" -eq 0 ]; then - echo "usage: copy-nix-closure-to-misaki STORE_PATH..." >&2 + echo "usage: copy-nix-closure-to-misaki (--all | STORE_PATH...)" >&2 exit 64 fi