From e39947d0ee8e341fa7108bd02a33cdfa24a1360e Mon Sep 17 00:00:00 2001 From: Jared Baur Date: Mon, 18 Nov 2024 10:08:10 -0800 Subject: [PATCH] allow for missing switch-to-configuration directory NixOS' switch-to-configuration program creates the /run/nixos directory, which may not be present if `system.switch.enable` is `false`. --- pkgs/sops-install-secrets/main.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkgs/sops-install-secrets/main.go b/pkgs/sops-install-secrets/main.go index f4764a0..280df4c 100644 --- a/pkgs/sops-install-secrets/main.go +++ b/pkgs/sops-install-secrets/main.go @@ -978,6 +978,13 @@ func handleModifications(isDry bool, logcfg loggingConfig, symlinkPath string, s writeLines := func(list []string, file string) error { if len(list) != 0 { + if _, err := os.Stat(filepath.Dir(file)); err != nil { + if os.IsNotExist(err) { + return nil + } else { + return err + } + } f, err := os.OpenFile(file, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0o600) if err != nil { return err