aboutsummaryrefslogtreecommitdiff
path: root/nixops
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2020-08-29 18:37:54 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2020-08-29 18:37:54 +0200
commitda28a4e2afef21710f73860b26893fa18dd32858 (patch)
tree3ce951ff67ab7eb8d55fa79415bacaca85896256 /nixops
parent1052bfda27ad0607cd4dc5dc91e2d8e8220c30c7 (diff)
downloadNix-da28a4e2afef21710f73860b26893fa18dd32858.tar.gz
Nix-da28a4e2afef21710f73860b26893fa18dd32858.tar.zst
Nix-da28a4e2afef21710f73860b26893fa18dd32858.zip
Add environment file instead of hardcoding everything in makefiles
Diffstat (limited to 'nixops')
-rw-r--r--nixops/Makefile28
-rwxr-xr-xnixops/scripts/with_env8
2 files changed, 15 insertions, 21 deletions
diff --git a/nixops/Makefile b/nixops/Makefile
index a7b24cd..18d48eb 100644
--- a/nixops/Makefile
+++ b/nixops/Makefile
@@ -1,14 +1,8 @@
1export 1ifndef NIXOPS_ENV_LOADED
2PASSWORD_STORE_DIR = $(shell pwd)/secrets 2 $(error "Please load environment with direnv")
3NIXOPS_STATE ?= ./state/eldiron.nixops 3endif
4NIXOPS_DEPLOYMENT = cef694f3-081d-11e9-b31f-0242ec186adf 4
5nixpkgs ?= $(shell cat ../nix/sources.json | jq -r '."nixpkgs-nixops".url') 5NIXOPS_PRIV = ./scripts/with_env nixops
6nixpkgsNext ?= $(shell cat ../nix/sources.json | jq -r '."nixpkgs-nixops-next".url')
7nixpkgsPrevious ?= $(shell cat ../nix/sources.json | jq -r '."nixpkgs-nixops-previous".url')
8NIX_PATH = nixpkgs=${nixpkgs}:nixpkgsNext=${nixpkgsNext}:nixpkgsPrevious=${nixpkgsPrevious}
9
10NIXOPS := $(shell NIX_PATH=$(NIX_PATH) nix-build --no-out-link -E "with import <nixpkgs> { overlays = builtins.attrValues (import ../overlays); }; nixops")/bin/nixops
11NIXOPS_PRIV = ./scripts/with_env $(NIXOPS)
12 6
13###### Current channel information 7###### Current channel information
14nix-info: 8nix-info:
@@ -102,21 +96,21 @@ cleanup: delete-generations
102 96
103###### Pull environment and deployment from remote 97###### Pull environment and deployment from remote
104pull_deployment: 98pull_deployment:
105 @if $(NIXOPS) info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null ; then \ 99 @if nixops info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null ; then \
106 echo "This will remove your current deployment file and recreate it!. Continue? [y/N]" && \ 100 echo "This will remove your current deployment file and recreate it!. Continue? [y/N]" && \
107 read y && \ 101 read y && \
108 [ "$$y" = "y" -o "$$y" = "Y" ] && \ 102 [ "$$y" = "y" -o "$$y" = "Y" ] && \
109 $(NIXOPS) delete --force -d $(NIXOPS_DEPLOYMENT); \ 103 nixops delete --force -d $(NIXOPS_DEPLOYMENT); \
110 fi 104 fi
111 pass show Nixops/Deployment | $(NIXOPS) import 105 pass show Nixops/Deployment | nixops import
112 $(NIXOPS) modify -d $(NIXOPS_DEPLOYMENT) "$$(pwd)/default.nix" 106 nixops modify -d $(NIXOPS_DEPLOYMENT) "$$(pwd)/default.nix"
113.PHONY: pull_deployment 107.PHONY: pull_deployment
114 108
115deployment_is_set: 109deployment_is_set:
116 $(NIXOPS) info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null 110 nixops info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null
117.PHONY: deployment_is_set 111.PHONY: deployment_is_set
118 112
119###### Push deployment information to password store 113###### Push deployment information to password store
120push_deployment: 114push_deployment:
121 $(NIXOPS) export | pass insert -m Nixops/Deployment 115 nixops export | pass insert -m Nixops/Deployment
122.PHONY: push 116.PHONY: push
diff --git a/nixops/scripts/with_env b/nixops/scripts/with_env
index 26e74b5..9882f78 100755
--- a/nixops/scripts/with_env
+++ b/nixops/scripts/with_env
@@ -1,7 +1,7 @@
1#!/usr/bin/env bash 1#!/usr/bin/env bash
2 2
3if [ -z "$NIXOPS" ]; then 3if [ -z "$NIXOPS_ENV_LOADED" ]; then
4 echo "Please set NIXOPS to the nixops command" 4 echo "Please load the environment with direnv"
5 exit 1; 5 exit 1;
6fi 6fi
7 7
@@ -10,7 +10,7 @@ chmod go-rwx $TEMP
10 10
11finish() { 11finish() {
12 rm -rf "$TEMP" 12 rm -rf "$TEMP"
13 $NIXOPS set-args --unset privateFiles 13 nixops set-args --unset privateFiles
14} 14}
15 15
16trap finish EXIT 16trap finish EXIT
@@ -21,6 +21,6 @@ files=$(pass ls Nixops/files | sed -e '1d' -e 's/^.* //')
21for file in $files; do 21for file in $files; do
22 pass show "Nixops/files/$file" > $TEMP/$file 22 pass show "Nixops/files/$file" > $TEMP/$file
23done 23done
24$NIXOPS set-args --argstr privateFiles "$TEMP" 24nixops set-args --argstr privateFiles "$TEMP"
25 25
26"$@" 26"$@"