]> git.immae.eu Git - perso/Immae/Config/Nix.git/commitdiff
Add environment file instead of hardcoding everything in makefiles
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Sat, 29 Aug 2020 16:37:54 +0000 (18:37 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Sat, 29 Aug 2020 16:37:54 +0000 (18:37 +0200)
.envrc [new file with mode: 0644]
.gitignore
modules/private/system.nix
nix/sources.json
nixops/Makefile
nixops/scripts/with_env
shell.nix [new file with mode: 0644]

diff --git a/.envrc b/.envrc
new file mode 100644 (file)
index 0000000..6eeaba9
--- /dev/null
+++ b/.envrc
@@ -0,0 +1,13 @@
+# vim: filetype=bash
+export PASSWORD_STORE_DIR=$(expand_path nixops/secrets)
+export NIXOPS_STATE=$(expand_path nixops/state/immaeEu.nixops)
+export NIXOPS_DEPLOYMENT=cef694f3-081d-11e9-b31f-0242ec186adf
+export NIX_PATH=nixpkgs=$(cat $(expand_path nix/sources.json) | jq -r '."nixpkgs-nixops".url')
+
+export NIXOPS_ENV_LOADED=1
+
+PATH_add $(expand_path scripts)
+PATH_add $(expand_path nixops/scripts)
+
+use nix
+watch_file $(expand_path nix/sources.json)
index feb036e5460c53fde86e3295d46e7ead8fdb1eab..6786d422b6bf2a0ee0112c13cddd1ef50b41544a 100644 (file)
@@ -1,2 +1,3 @@
 /result*
 /versions_log
 /result*
 /versions_log
+.direnv/
index bca6e19ceb836bc8abc509cb4aaa650896d60c8a..8c7a6f39da90c15353182d0f3e515a2e9ce6dbbd 100644 (file)
         mariadb = self.mariadb_pam;
       }) # don’t put them as generic overlay because of home-manager
     ];
         mariadb = self.mariadb_pam;
       }) # don’t put them as generic overlay because of home-manager
     ];
-    _module.args = {
-      pkgsNext = import <nixpkgsNext> {};
-      pkgsPrevious = import <nixpkgsPrevious> {};
-    };
 
     services.journald.extraConfig = ''
       MaxLevelStore="warning"
 
     services.journald.extraConfig = ''
       MaxLevelStore="warning"
index 265552fa231b21121a3509bd23f5643a0615d573..063d3da8c55b99018cfd74d41d3f411d00191068 100644 (file)
         "url": "https://github.com/NixOS/nixpkgs-channels/archive/840c782d507d60aaa49aa9e3f6d0b0e780912742.tar.gz",
         "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
     },
         "url": "https://github.com/NixOS/nixpkgs-channels/archive/840c782d507d60aaa49aa9e3f6d0b0e780912742.tar.gz",
         "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
     },
-    "nixpkgs-nixops-next": {
-        "branch": "nixos-19.03",
-        "description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to",
-        "homepage": "https://github.com/NixOS/nixpkgs",
-        "owner": "NixOS",
-        "repo": "nixpkgs-channels",
-        "rev": "34c7eb7545d155cc5b6f499b23a7cb1c96ab4d59",
-        "sha256": "11z6ajj108fy2q5g8y4higlcaqncrbjm3dnv17pvif6avagw4mcb",
-        "type": "tarball",
-        "url": "https://github.com/NixOS/nixpkgs-channels/archive/34c7eb7545d155cc5b6f499b23a7cb1c96ab4d59.tar.gz",
-        "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
-    },
-    "nixpkgs-nixops-previous": {
-        "branch": "nixos-19.03",
-        "description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to",
-        "homepage": "https://github.com/NixOS/nixpkgs",
-        "owner": "NixOS",
-        "repo": "nixpkgs-channels",
-        "rev": "34c7eb7545d155cc5b6f499b23a7cb1c96ab4d59",
-        "sha256": "11z6ajj108fy2q5g8y4higlcaqncrbjm3dnv17pvif6avagw4mcb",
-        "type": "tarball",
-        "url": "https://github.com/NixOS/nixpkgs-channels/archive/34c7eb7545d155cc5b6f499b23a7cb1c96ab4d59.tar.gz",
-        "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
-    },
     "overlays-ldapvi": {
         "ref": "master",
         "repo": "http://www.lichteblau.com/git/ldapvi.git",
     "overlays-ldapvi": {
         "ref": "master",
         "repo": "http://www.lichteblau.com/git/ldapvi.git",
index a7b24cd98c7cd7dfe7d78daf57eadb0f39612a91..18d48eb552c4eda3da184c2b991ba3dd8b8f69ad 100644 (file)
@@ -1,14 +1,8 @@
-export
-PASSWORD_STORE_DIR = $(shell pwd)/secrets
-NIXOPS_STATE ?= ./state/eldiron.nixops
-NIXOPS_DEPLOYMENT = cef694f3-081d-11e9-b31f-0242ec186adf
-nixpkgs ?= $(shell cat ../nix/sources.json | jq -r '."nixpkgs-nixops".url')
-nixpkgsNext ?= $(shell cat ../nix/sources.json | jq -r '."nixpkgs-nixops-next".url')
-nixpkgsPrevious ?= $(shell cat ../nix/sources.json | jq -r '."nixpkgs-nixops-previous".url')
-NIX_PATH = nixpkgs=${nixpkgs}:nixpkgsNext=${nixpkgsNext}:nixpkgsPrevious=${nixpkgsPrevious}
-
-NIXOPS := $(shell NIX_PATH=$(NIX_PATH) nix-build --no-out-link -E "with import <nixpkgs> { overlays = builtins.attrValues (import ../overlays); }; nixops")/bin/nixops
-NIXOPS_PRIV = ./scripts/with_env $(NIXOPS)
+ifndef NIXOPS_ENV_LOADED
+  $(error "Please load environment with direnv")
+endif
+
+NIXOPS_PRIV = ./scripts/with_env nixops
 
 ###### Current channel information
 nix-info:
 
 ###### Current channel information
 nix-info:
@@ -102,21 +96,21 @@ cleanup: delete-generations
 
 ###### Pull environment and deployment from remote
 pull_deployment:
 
 ###### Pull environment and deployment from remote
 pull_deployment:
-       @if $(NIXOPS) info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null ; then \
+       @if nixops info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null ; then \
          echo "This will remove your current deployment file and recreate it!. Continue? [y/N]" && \
          read y && \
          [ "$$y" = "y" -o "$$y" = "Y" ] && \
          echo "This will remove your current deployment file and recreate it!. Continue? [y/N]" && \
          read y && \
          [ "$$y" = "y" -o "$$y" = "Y" ] && \
-         $(NIXOPS) delete --force -d $(NIXOPS_DEPLOYMENT); \
+         nixops delete --force -d $(NIXOPS_DEPLOYMENT); \
        fi
        fi
-       pass show Nixops/Deployment | $(NIXOPS) import
-       $(NIXOPS) modify -d $(NIXOPS_DEPLOYMENT) "$$(pwd)/default.nix"
+       pass show Nixops/Deployment | nixops import
+       nixops modify -d $(NIXOPS_DEPLOYMENT) "$$(pwd)/default.nix"
 .PHONY: pull_deployment
 
 deployment_is_set:
 .PHONY: pull_deployment
 
 deployment_is_set:
-       $(NIXOPS) info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null
+       nixops info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null
 .PHONY: deployment_is_set
 
 ###### Push deployment information to password store
 push_deployment:
 .PHONY: deployment_is_set
 
 ###### Push deployment information to password store
 push_deployment:
-       $(NIXOPS) export | pass insert -m Nixops/Deployment
+       nixops export | pass insert -m Nixops/Deployment
 .PHONY: push
 .PHONY: push
index 26e74b5f6d77b2f1851c9159f249344ad7f17b6c..9882f787f120c855a8b291bdf534d24356c143b1 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 
 #!/usr/bin/env bash
 
-if [ -z "$NIXOPS" ]; then
-  echo "Please set NIXOPS to the nixops command"
+if [ -z "$NIXOPS_ENV_LOADED" ]; then
+  echo "Please load the environment with direnv"
   exit 1;
 fi
 
   exit 1;
 fi
 
@@ -10,7 +10,7 @@ chmod go-rwx $TEMP
 
 finish() {
   rm -rf "$TEMP"
 
 finish() {
   rm -rf "$TEMP"
-  $NIXOPS set-args --unset privateFiles
+  nixops set-args --unset privateFiles
 }
 
 trap finish EXIT
 }
 
 trap finish EXIT
@@ -21,6 +21,6 @@ files=$(pass ls Nixops/files | sed -e '1d' -e 's/^.* //')
 for file in $files; do
   pass show "Nixops/files/$file" > $TEMP/$file
 done
 for file in $files; do
   pass show "Nixops/files/$file" > $TEMP/$file
 done
-$NIXOPS set-args --argstr privateFiles "$TEMP"
+nixops set-args --argstr privateFiles "$TEMP"
 
 "$@"
 
 "$@"
diff --git a/shell.nix b/shell.nix
new file mode 100644 (file)
index 0000000..70c7604
--- /dev/null
+++ b/shell.nix
@@ -0,0 +1,4 @@
+{ pkgs ? import <nixpkgs> { overlays = builtins.attrValues (import ./overlays); } }:
+pkgs.mkShell {
+  buildInputs = [ pkgs.nixops pkgs.niv pkgs.pass pkgs.curl pkgs.shellcheck pkgs.jq pkgs.gnumake ];
+}