mirror of
https://github.com/nix-community/nix-direnv.git
synced 2025-12-18 15:01:19 +01:00
commit
97ed44cc73
9 changed files with 120 additions and 7 deletions
12
.github/workflows/test.yml
vendored
Normal file
12
.github/workflows/test.yml
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
name: "Test"
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
jobs:
|
||||||
|
tests:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: cachix/install-nix-action@v7
|
||||||
|
- run:
|
||||||
|
nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixpkgs-unstable.tar.gz ci.nix --run 'true'
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
# nix-direnv
|
# nix-direnv
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
A fast, persistent use_nix implementation for direnv.
|
A fast, persistent use_nix implementation for direnv.
|
||||||
Prominent features:
|
Prominent features:
|
||||||
|
|
||||||
|
|
|
||||||
21
ci.nix
Normal file
21
ci.nix
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
with import <nixpkgs> {};
|
||||||
|
mkShell {
|
||||||
|
nativeBuildInputs = [
|
||||||
|
shellcheck direnv mypy python3.pkgs.black python3.pkgs.flake8
|
||||||
|
];
|
||||||
|
|
||||||
|
shellHook = ''
|
||||||
|
set -e
|
||||||
|
echo -e "\x1b[32m## run shellcheck\x1b[0m"
|
||||||
|
LC_ALL=en_US.utf-8 black --check .
|
||||||
|
echo -e "\x1b[32m## run black\x1b[0m"
|
||||||
|
LC_ALL=en_US.utf-8 black --check .
|
||||||
|
echo -e "\x1b[32m## run flake8\x1b[0m"
|
||||||
|
flake8 --ignore E501 tests
|
||||||
|
echo -e "\x1b[32m## run mypy\x1b[0m"
|
||||||
|
mypy tests
|
||||||
|
|
||||||
|
echo -e "\x1b[32m## run unittest\x1b[0m"
|
||||||
|
${pkgs.python3.interpreter} -m unittest discover tests
|
||||||
|
'';
|
||||||
|
}
|
||||||
26
default.nix
Normal file
26
default.nix
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
{ pkgs ? import <nixpkgs> {} }:
|
||||||
|
|
||||||
|
with pkgs;
|
||||||
|
stdenv.mkDerivation {
|
||||||
|
name = "nix-direnv";
|
||||||
|
|
||||||
|
src = ./.;
|
||||||
|
|
||||||
|
postPatch = ''
|
||||||
|
substituteInPlace direnvrc \
|
||||||
|
--replace "grep" "${gnugrep}/bin/grep" \
|
||||||
|
--replace "nix-shell" "${nix}/bin/nix-shell" \
|
||||||
|
--replace "nix-instantiate" "${nix}/bin/nix-shell"
|
||||||
|
'';
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
install -m500 -D direnvrc $out/share/nix-direnv/direnvrc
|
||||||
|
'';
|
||||||
|
|
||||||
|
meta = with stdenv.lib; {
|
||||||
|
description = "A fast, persistent use_nix implementation for direnv";
|
||||||
|
homepage = "https://github.com/nix-community/nix-direnv";
|
||||||
|
license = licenses.mit;
|
||||||
|
platforms = platforms.unix;
|
||||||
|
};
|
||||||
|
}
|
||||||
11
direnvrc
11
direnvrc
|
|
@ -1,5 +1,4 @@
|
||||||
#!/usr/bin/env bash
|
# shellcheck shell=bash
|
||||||
|
|
||||||
|
|
||||||
use_nix() {
|
use_nix() {
|
||||||
local path
|
local path
|
||||||
|
|
@ -43,7 +42,7 @@ use_nix() {
|
||||||
log_status using cached derivation
|
log_status using cached derivation
|
||||||
fi
|
fi
|
||||||
local term_backup=$TERM path_backup=$PATH
|
local term_backup=$TERM path_backup=$PATH
|
||||||
if [[ ! -z ${TMPDIR+x} ]]; then
|
if [[ -n ${TMPDIR+x} ]]; then
|
||||||
local tmp_backup=$TMPDIR
|
local tmp_backup=$TMPDIR
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -54,7 +53,7 @@ use_nix() {
|
||||||
read -r cache_content < "$cache"
|
read -r cache_content < "$cache"
|
||||||
eval "$cache_content"
|
eval "$cache_content"
|
||||||
export PATH=$PATH:$path_backup TERM=$term_backup
|
export PATH=$PATH:$path_backup TERM=$term_backup
|
||||||
if [[ ! -z ${tmp_backup+x} ]]; then
|
if [[ -n ${tmp_backup+x} ]]; then
|
||||||
export TMPDIR=${tmp_backup}
|
export TMPDIR=${tmp_backup}
|
||||||
else
|
else
|
||||||
unset TMPDIR
|
unset TMPDIR
|
||||||
|
|
@ -62,14 +61,14 @@ use_nix() {
|
||||||
|
|
||||||
# `nix-shell --pure` sets invalid ssl certificate paths
|
# `nix-shell --pure` sets invalid ssl certificate paths
|
||||||
if [[ "${SSL_CERT_FILE:-}" = /no-cert-file.crt ]]; then
|
if [[ "${SSL_CERT_FILE:-}" = /no-cert-file.crt ]]; then
|
||||||
if [[ ! -z ${impure_ssl_cert_file+x} ]]; then
|
if [[ -n ${impure_ssl_cert_file+x} ]]; then
|
||||||
export SSL_CERT_FILE=${impure_ssl_cert_file}
|
export SSL_CERT_FILE=${impure_ssl_cert_file}
|
||||||
else
|
else
|
||||||
unset SSL_CERT_FILE
|
unset SSL_CERT_FILE
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [[ "${NIX_SSL_CERT_FILE:-}" = /no-cert-file.crt ]]; then
|
if [[ "${NIX_SSL_CERT_FILE:-}" = /no-cert-file.crt ]]; then
|
||||||
if [[ ! -z ${impure_nix_ssl_cert_file+x} ]]; then
|
if [[ -n ${impure_nix_ssl_cert_file+x} ]]; then
|
||||||
export NIX_SSL_CERT_FILE=${impure_nix_ssl_cert_file}
|
export NIX_SSL_CERT_FILE=${impure_nix_ssl_cert_file}
|
||||||
else
|
else
|
||||||
unset NIX_SSL_CERT_FILE
|
unset NIX_SSL_CERT_FILE
|
||||||
|
|
|
||||||
8
shell.nix
Normal file
8
shell.nix
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
with import <nixpkgs> {};
|
||||||
|
mkShell {
|
||||||
|
nativeBuildInputs = [
|
||||||
|
python3
|
||||||
|
shellcheck
|
||||||
|
direnv
|
||||||
|
];
|
||||||
|
}
|
||||||
39
tests/test.py
Normal file
39
tests/test.py
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
#!/usr/bin/env python2
|
||||||
|
|
||||||
|
from tempfile import TemporaryDirectory
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
from pathlib import Path
|
||||||
|
import shutil
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
|
TEST_ROOT = Path(__file__).resolve().parent
|
||||||
|
|
||||||
|
|
||||||
|
class IntegrationTest(unittest.TestCase):
|
||||||
|
def setUp(self) -> None:
|
||||||
|
self.env = os.environ.copy()
|
||||||
|
self.dir = TemporaryDirectory()
|
||||||
|
self.env["HOME"] = str(self.dir.name)
|
||||||
|
self.testenv = Path(self.dir.name).joinpath("testenv")
|
||||||
|
shutil.copytree(TEST_ROOT.joinpath("testenv"), self.testenv)
|
||||||
|
direnvrc = str(TEST_ROOT.parent.joinpath("direnvrc"))
|
||||||
|
with open(self.testenv.joinpath(".envrc"), "w") as f:
|
||||||
|
f.write(f"source {direnvrc}\n")
|
||||||
|
f.write(f"use nix")
|
||||||
|
|
||||||
|
def test_direnv(self) -> None:
|
||||||
|
subprocess.run(
|
||||||
|
["direnv", "allow"], cwd=str(self.testenv), env=self.env, check=True
|
||||||
|
)
|
||||||
|
subprocess.run(
|
||||||
|
["direnv", "exec", str(self.testenv), "hello"], env=self.env, check=True
|
||||||
|
)
|
||||||
|
|
||||||
|
def tearDown(self) -> None:
|
||||||
|
self.dir.cleanup()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
2
tests/testenv/.envrc
Normal file
2
tests/testenv/.envrc
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
source ../../direnvrc
|
||||||
|
use nix
|
||||||
4
tests/testenv/shell.nix
Normal file
4
tests/testenv/shell.nix
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
with import <nixpkgs> {};
|
||||||
|
mkShell {
|
||||||
|
nativeBuildInputs = [ hello ];
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue