-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathflake.nix
More file actions
132 lines (118 loc) · 4.09 KB
/
Copy pathflake.nix
File metadata and controls
132 lines (118 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
{
description = "Bitwarden (vaultwarden) on AWS dev environment";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nixpkgs-darwin.url = "github:NixOS/nixpkgs/nixpkgs-26.05-darwin";
flake-parts.url = "github:hercules-ci/flake-parts";
dev-flake.url = "github:terlar/dev-flake";
};
outputs =
inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
imports = [ inputs.dev-flake.flakeModule ];
dev.name = "bitwarden-aws";
perSystem =
{
config,
pkgs,
system,
...
}:
{
_module.args.pkgs = import (
if system == "x86_64-darwin" || system == "aarch64-darwin" then
inputs.nixpkgs-darwin
else
inputs.nixpkgs
) { inherit system; };
treefmt = import ./dev/treefmt.nix { inherit pkgs; };
pre-commit = import ./dev/pre-commit.nix { inherit pkgs; };
packages = {
pre-commit = config.pre-commit.settings.package;
pre-commit-install = pkgs.writeShellScriptBin "pre-commit-install" ''
${pkgs.prek}/bin/prek install -f --hook-type pre-commit
'';
tofu = pkgs.writeShellApplication {
name = "tofu";
runtimeInputs = [ pkgs.terraform-backend-git ];
text = ''
project="''${TF_PROJECT:-}"
project_dir="''${TF_PROJECT_DIR:-}"
if [ -z "$project" ]; then
case "$PWD" in
*/example)
project="bitwarden-tf-aws"
project_dir="example"
;;
*)
exec "${pkgs.opentofu}/bin/tofu" "$@"
;;
esac
fi
state_repo="''${STATE_REPO_URL:-}"
if [ -z "$state_repo" ]; then
echo "[WARNING] STATE_REPO_URL not set -- using LOCAL state" >&2
exec "${pkgs.opentofu}/bin/tofu" "$@"
fi
statefile="$project/$project_dir/terraform.tfstate"
case "''${1:-}" in
init|plan|apply|destroy|import|state|output|refresh|validate)
exec terraform-backend-git git \
-r "$state_repo" \
-s "$statefile" \
-b master \
-d "$project_dir" \
terraform --tf "${pkgs.opentofu}/bin/tofu" "$@"
;;
*)
exec "${pkgs.opentofu}/bin/tofu" "$@"
;;
esac
'';
};
};
devshells.default = {
commands = [
{
package = pkgs.writeShellScriptBin "pre-commit" ''
exec ${pkgs.prek}/bin/prek "$@"
'';
help = "Drop-in pre-commit alias that runs prek";
}
{
name = "terraform";
help = "OpenTofu with git-backed state (set STATE_REPO_URL for remote)";
command = "${config.packages.tofu}/bin/tofu \"$@\"";
}
];
packages = with pkgs; [
age
awscli2
cloudflared
deadnix
gnumake
jq
oath-toolkit
opentofu
(python3.withPackages (ps: [ ps.boto3 ]))
ssm-session-manager-plugin
sops
sqlite-interactive
statix
terraform-backend-git
trivy
];
};
};
};
nixConfig = {
extra-substituters = "https://cache.nixos.org https://eana.cachix.org";
extra-trusted-public-keys = "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= eana.cachix.org-1:3sJHATrL9zjGFGZwAXpECSMR+Ql5k02GgdxfJyzHi84=";
};
}