moss

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 4081449db87f0efcad5edfb61798ad27bff91f41
parent 87aea8893beadb084c8100d983f96e1883e0c656
Author: Daniel Barlow <dan@telent.net>
Date:   Tue, 10 Aug 2021 21:51:22 +0100

use full pathnames for external commands

Diffstat:
MMakefile | 9++++++++-
Mdefault.nix | 3++-
Mmoss.rb | 13+++++++++----
3 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,8 +1,15 @@ default: moss.rb +AGE?=$(shell command -v age) +AGE_KEYGEN?=$(shell command -v age-keygen) +GIT?=$(shell command -v git) + install: default mkdir -p $(prefix)/bin - cp moss.rb $(prefix)/bin/moss + sed < moss.rb > $(prefix)/bin/moss \ + -e 's@^AGE=.*$$@AGE="$(AGE)"@' \ + -e 's@^AGE_KEYGEN=.*$$@AGE_KEYGEN="$(AGE_KEYGEN)"@' \ + -e 's@^GIT=.*$$@GIT="$(GIT)"@' gemset.nix: Gemfile nix-shell -p bundler -p bundix --run "bundle lock && bundix" diff --git a/default.nix b/default.nix @@ -1,10 +1,11 @@ { stdenv +, git , callPackage}: let age = callPackage ./age.nix {}; in stdenv.mkDerivation { name = "moss"; src = ./.; - buildInputs = [ age ]; + buildInputs = [ age git ]; installPhase = '' make install prefix=$out ''; diff --git a/moss.rb b/moss.rb @@ -3,6 +3,11 @@ require 'pathname' require 'tempfile' require 'json' +# don't change these lines without changing the sed commands in Makefile +AGE='age' +AGE_KEYGEN='age-keygen' +GIT='git' + def xdg_data_home ENV.fetch("XDG_DATA_HOME", "#{ENV['HOME']}/.local/share") end @@ -32,7 +37,7 @@ class Moss store.mkpath FileUtils.cp(keyfile, store.parent.join("identity")) File.open(store.join(".recipients"), "w") do |f| - f.write `age-keygen -y #{keyfile.to_s.inspect}` + f.write `#{AGE_KEYGEN} -y #{keyfile.to_s.inspect}` end end @@ -65,7 +70,7 @@ class Moss def write_secret(name, content) pathname = store.join("#{name}.age") pathname.dirname.mkpath - IO.popen("age -a --recipients-file #{recipients_for_secret(name)} -o #{pathname.to_s}", "w") do |f| + IO.popen("#{AGE} -a --recipients-file #{recipients_for_secret(name)} -o #{pathname.to_s}", "w") do |f| f.write(content) end if git_managed? @@ -76,7 +81,7 @@ class Moss def read_secret(name) pathname = store.join("#{name}.age") File.exist?(pathname) or raise "Can't open #{pathname}: $!" - `age -i #{identity_file} -d #{pathname}` + `#{AGE} -i #{identity_file} -d #{pathname}` end def secrets @@ -159,7 +164,7 @@ when 'init' keyfile = Pathname.new(parameters.first) MOSS.create(keyfile) when 'git' - Kernel.system("/usr/bin/env", "git", *parameters, {chdir: MOSS.store}) + Kernel.system(GIT, *parameters, {chdir: MOSS.store}) else raise "command #{action} unrecognized" end