generated from divnix/digga
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f69188f
commit e14f863
Showing
304 changed files
with
4,374 additions
and
4,466 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
nix_direnv_watch_file $(find shell) | ||
nix_direnv_watch_file $(find devshell) flake/nixpkgs.nix | ||
use flake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: "Check" | ||
on: | ||
push: | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
update: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@main | ||
with: | ||
token: '${{ secrets.PAT_FOR_AUTOMATED_UPDATE }}' | ||
- name: Install nix | ||
uses: cachix/install-nix-action@master | ||
with: | ||
nix_path: nixpkgs=channel:nixos-unstable | ||
extra_nix_config: | | ||
experimental-features = nix-command flakes | ||
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }} | ||
- name: Setup cachix | ||
uses: cachix/cachix-action@master | ||
with: | ||
name: linyinfeng | ||
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}' | ||
- name: Set swap space | ||
uses: pierotofy/set-swap-space@master | ||
with: | ||
swap-size-gb: 10 | ||
- name: Test nix flake show | ||
run: | | ||
nix flake show | ||
- name: Test evaluation | ||
run: | | ||
set -e | ||
system=$(nix eval --impure --raw --expr "builtins.currentSystem") | ||
checks=$(nix eval --impure --json --expr "builtins.attrNames (builtins.getFlake \"$PWD\").checks.$system") | ||
for check in $(echo "$checks" | jq -r '.[]'); do | ||
echo "--- eval .#checks.$system.$check" | ||
nix eval --raw .#checks.$system.$check --accept-flake-config | ||
echo # add a new line | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,9 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Lin Yinfeng | ||
Copyright (c) 2021-2023 Lin Yinfeng | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{...}: { | ||
imports = [ | ||
./terraform | ||
]; | ||
perSystem = { | ||
inputs', | ||
pkgs, | ||
... | ||
}: { | ||
devshells.default = { | ||
commands = [ | ||
{ | ||
package = inputs'.nixos-generators.packages.nixos-generate; | ||
category = "deploy"; | ||
} | ||
{ | ||
package = pkgs.sops; | ||
category = "secrets"; | ||
} | ||
{ | ||
package = pkgs.ssh-to-age; | ||
category = "secrets"; | ||
} | ||
]; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
{...}: { | ||
perSystem = {pkgs, ...}: let | ||
secretExtractor = pkgs.callPackage ./extractor/secrets.nix {}; | ||
dataExtractor = pkgs.callPackage ./extractor/data.nix {}; | ||
in { | ||
devshells.default.commands = [ | ||
{ | ||
category = "infrastructure"; | ||
name = "terraform-pipe"; | ||
help = "initialize, apply, and update all terraform related output files"; | ||
command = '' | ||
set -e | ||
terraform-init | ||
terraform-wrapper apply | ||
terraform-update-outputs | ||
terraform-outputs-extract-data | ||
terraform-outputs-extract-secrets | ||
''; | ||
} | ||
{ | ||
category = "infrastructure"; | ||
name = "terraform-wrapper"; | ||
help = pkgs.terraform.meta.description; | ||
command = '' | ||
set -e | ||
export PATH=${pkgs.sops}/bin:$PATH | ||
export PATH=${pkgs.terraform}/bin:$PATH | ||
export PATH=${pkgs.zerotierone}/bin:$PATH | ||
export PATH=${pkgs.minio-client}/bin:$PATH | ||
export PATH=${pkgs.syncthing}/bin:$PATH | ||
export PATH=${pkgs.jq}/bin:$PATH | ||
export PATH=${pkgs.openssl}/bin:$PATH | ||
export PATH=${pkgs.ruby}/bin:$PATH | ||
encrypted_state_file="$PRJ_ROOT/secrets/terraform.tfstate" | ||
unencrypted_state_file="$PRJ_ROOT/terraform/terraform.tfstate" | ||
echo "decrypt terraform state to '$unencrypted_state_file'..." >&2 | ||
sops --input-type json --output-type json \ | ||
--decrypt "$encrypted_state_file" > "$unencrypted_state_file" | ||
function cleanup { | ||
cd $PRJ_ROOT | ||
if [ -n "$(cat "$unencrypted_state_file")" ]; then | ||
echo "encrypt terraform state to '$encrypted_state_file'..." >&2 | ||
set +e | ||
EDITOR="cp \"$unencrypted_state_file\"" \ | ||
sops --input-type json --output-type json \ | ||
"$encrypted_state_file" | ||
encrypt_status="$?" | ||
set -e | ||
rm "$unencrypted_state_file" | ||
if [ "$encrypt_status" -ne 0 -a "$encrypt_status" -ne 200 ]; then | ||
echo "failed to encrypt, exiting" | ||
exit 1 | ||
fi | ||
fi | ||
} | ||
trap cleanup EXIT | ||
cd $PRJ_ROOT/terraform | ||
terraform "$@" | ||
''; | ||
} | ||
|
||
{ | ||
category = "infrastructure"; | ||
name = "terraform-update-outputs"; | ||
help = "update terraform outputs"; | ||
command = '' | ||
set -e | ||
export PATH=${pkgs.sops}/bin:$PATH | ||
encrypted_output_file="$PRJ_ROOT/secrets/terraform-outputs.yaml" | ||
unencrypted_output_file="$PRJ_ROOT/secrets/terraform-outputs.plain.yaml" | ||
terraform-wrapper output --json > "$unencrypted_output_file" | ||
set +e | ||
EDITOR="cp \"$unencrypted_output_file\"" sops "$encrypted_output_file" | ||
encrypt_status="$?" | ||
set -e | ||
rm "$unencrypted_output_file" | ||
if [ "$encrypt_status" -ne 0 -a "$encrypt_status" -ne 200 ]; then | ||
echo "failed to encrypt, exiting" | ||
exit 1 | ||
fi | ||
''; | ||
} | ||
|
||
{ | ||
category = "infrastructure"; | ||
name = "terraform-outputs-extract-secrets"; | ||
help = "extract secrets from terraform outputs"; | ||
package = secretExtractor; | ||
} | ||
|
||
{ | ||
category = "infrastructure"; | ||
name = "terraform-outputs-extract-data"; | ||
help = "extract data from terraform outputs"; | ||
package = dataExtractor; | ||
} | ||
|
||
{ | ||
category = "infrastructure"; | ||
name = "terraform-init"; | ||
help = "upgrade terraform providers"; | ||
command = '' | ||
set -e | ||
cd $PRJ_ROOT/terraform | ||
${pkgs.terraform}/bin/terraform init "$@" | ||
''; | ||
} | ||
]; | ||
}; | ||
} |
11 changes: 7 additions & 4 deletions
11
shell/terraform/extractor/data.nix → devshell/terraform/extractor/data.nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 6 additions & 2 deletions
8
shell/terraform/extractor/secrets.nix → devshell/terraform/extractor/secrets.nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
Oops, something went wrong.