add sops nix for secret management

This commit is contained in:
Rasyidan Akbar F. 2025-09-30 17:57:13 +07:00
commit 2ea7f853e4
5 changed files with 207 additions and 1 deletions

View file

@ -0,0 +1,70 @@
{ config, lib, inputs, ... }:
let
inherit (lib) mkEnableOption mkOption mkIf types;
cfg = config.rsydn.secrets;
sanitizeSecret = name: secret:
let
sopsFile = secret.sopsFile or cfg.defaultSopsFile;
extra = lib.filterAttrs (k: _: !(builtins.elem k [ "path" "mode" "sopsFile" ])) secret;
in
{
path = secret.path or "${config.xdg.configHome}/secrets/${name}";
mode = secret.mode or "0400";
}
// (lib.optionalAttrs (sopsFile != null) { inherit sopsFile; })
// extra;
in {
imports = [ inputs.sops-nix.homeManagerModules.sops ];
options.rsydn.secrets = {
enable = mkEnableOption "sops-nix integration for managing decrypted secrets";
ageKeyFile = mkOption {
type = types.str;
default = "${config.home.homeDirectory}/.config/sops/age/keys.txt";
description = "Path to the Age key used for decrypting secrets.";
};
defaultSopsFile = mkOption {
type = types.nullOr types.path;
default = null;
description = "Optional default SOPS file used when a secret definition omits `sopsFile`.";
};
secrets = mkOption {
type = types.attrsOf types.attrs;
default = { };
description = "Secret entries forwarded to `sops.secrets` with sensible defaults.";
example = lib.literalExpression ''
{
"api-key" = {
sopsFile = ./secrets.yaml;
path = "${config.xdg.configHome}/secrets/api-key";
mode = "0400";
};
}
'';
};
};
config = mkIf cfg.enable {
sops =
{
age = {
keyFile = cfg.ageKeyFile;
generateKey = true;
};
secrets = lib.mapAttrs sanitizeSecret cfg.secrets;
}
// (lib.optionalAttrs (cfg.defaultSopsFile != null) {
defaultSopsFile = cfg.defaultSopsFile;
});
home.activation.ensureSecretDir = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
mkdir -p "${config.xdg.configHome}/secrets"
chmod 700 "${config.xdg.configHome}/secrets"
'';
};
}

View file

@ -0,0 +1,70 @@
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{
"alignment": "right",
"segments": [
{
"background": "#003543",
"foreground": "#ffffff",
"style": "plain",
"template": " \ue641 {{ .CurrentDate | date .Format }} ",
"type": "time"
},
{
"background": "#83769c",
"foreground": "#ffffff",
"properties": {
"always_enabled": true
},
"style": "plain",
"template": " \ueba2 {{ .FormattedMs }} ",
"type": "executiontime"
}
],
"type": "rprompt"
},
{
"alignment": "left",
"segments": [
{
"background": "#61AFEF",
"foreground": "#ffffff",
"properties": {
"display_host": false
},
"style": "diamond",
"template": "{{if .Root}} \uf0e7 {{.UserName}} {{else}} {{.UserName}} {{end}}",
"trailing_diamond": "\ue0b0",
"type": "session"
},
{
"background": "#C678DD",
"foreground": "#ffffff",
"powerline_symbol": "\ue0b0",
"properties": {
"folder_icon": "\uf115",
"folder_separator_icon": " \ue0b1 ",
"max_depth": 2,
"style": "agnoster_short"
},
"style": "powerline",
"template": " {{ .Path }} ",
"type": "path"
},
{
"background": "#95ffa4",
"foreground": "#193549",
"powerline_symbol": "\ue0b0",
"style": "powerline",
"template": " {{ .HEAD }} ",
"type": "git"
}
],
"type": "prompt"
}
],
"console_title_template": "{{if .Root}} \u26a1 {{end}}{{.UserName}} \u2794 📁{{.Folder}}",
"final_space": true,
"version": 3
}