-
Notifications
You must be signed in to change notification settings - Fork 330
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
Showing
7 changed files
with
187 additions
and
90 deletions.
There are no files selected for viewing
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,46 +1,17 @@ | ||
{ config, pkgs }: | ||
let | ||
lib = pkgs.lib; | ||
version = lib.fileContents ./modules/latest-version; | ||
in | ||
pkgs.writeScriptBin "devenv" '' | ||
#!/usr/bin/env bash | ||
# we want subshells to fail the program | ||
set -e | ||
|
||
NIX_FLAGS="--show-trace --extra-experimental-features nix-command --extra-experimental-features flakes" | ||
app = pkgs.writeShellApplication { | ||
name = "devenv-flake-cli"; | ||
runtimeInputs = with pkgs; [ docopts ]; | ||
text = builtins.readFile ./devenv-devShell.sh; | ||
}; | ||
|
||
command=$1 | ||
if [[ ! -z $command ]]; then | ||
shift | ||
fi | ||
case $command in | ||
up) | ||
procfilescript=${config.procfileScript} | ||
if [ "$(cat $procfilescript|tail -n +2)" = "" ]; then | ||
echo "No 'processes' option defined: https://devenv.sh/processes/" | ||
exit 1 | ||
else | ||
$procfilescript | ||
fi | ||
;; | ||
version) | ||
echo "devenv: ${version}" | ||
;; | ||
*) | ||
echo "https://devenv.sh (version ${version}): Fast, Declarative, Reproducible, and Composable Developer Environments" | ||
echo | ||
echo "This is a flake integration wrapper that comes with a subset of functionality from the flakeless devenv CLI." | ||
echo | ||
echo "Usage: devenv command" | ||
echo | ||
echo "Commands:" | ||
echo | ||
echo "up Starts processes in foreground. See http://devenv.sh/processes" | ||
echo "version Display devenv version" | ||
echo | ||
exit 1 | ||
esac | ||
'' | ||
envs = lib.concatStringsSep " " (lib.mapAttrsToList lib.toShellVar { | ||
PROCFILESCRIPT = config.procfileScript; | ||
VERSION = lib.fileContents ./modules/latest-version; | ||
CUSTOM_NIX = "${pkgs.nix}/bin/nix"; | ||
}); | ||
in | ||
pkgs.writeScriptBin "devenv" ''${envs} "${app}/bin/devenv-flake-cli" "$@"'' |
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,94 @@ | ||
#!/usr/bin/env bash | ||
set -eEuo pipefail | ||
|
||
if [ "${DEBUG:-}" == 1 ]; then | ||
set -x | ||
fi | ||
PROCFILESCRIPT="${PROCFILESCRIPT:-"placeholder"}" | ||
VERSION="${VERSION:-"placeholder"}" | ||
CUSTOM_NIX="${CUSTOM_NIX:-"nix"}" | ||
|
||
NIX_FLAGS=(--show-trace --extra-experimental-features 'nix-command flakes') | ||
|
||
function nix { | ||
"$CUSTOM_NIX" "${NIX_FLAGS[@]}" "${@}" | ||
} | ||
|
||
function container { | ||
declare -A args | ||
set -x | ||
# shellcheck disable=SC2016 | ||
eval "$(docopts -A args -h ' | ||
Usage: container [options] <container-name> [--] [<run-args>...] | ||
Options: | ||
-s <shell>, --shell <shell> `devenv.shells.<shell>` to use. [default: default] | ||
-r <name>, --registry <name> Registry to copy the container to. | ||
Available shortcuts: config, local-docker, local [default: config] | ||
--copy Copy the container to the registry. | ||
--copy-args <args> Arguments passed to `skopeo copy`. | ||
--docker-run Execute `docker run`. | ||
--podman-run Execute `podman run`. | ||
' : "$@")" | ||
|
||
local registry="${args['--registry']}" | ||
|
||
local app_prefix="${DEVENV_ROOT}#devenv-${args['--shell']}-container-${args['<container-name>']}" | ||
|
||
if [[ "${args['--copy']}" != false || "${args['--docker-run']}" != false || "${args['--podman-run']}" != false ]]; then | ||
if [[ ${args['--docker-run']} == true ]]; then | ||
registry=local-docker | ||
elif [[ ${args['--podman-run']} == true ]]; then | ||
registry=local | ||
fi | ||
# shellcheck disable=SC2086 | ||
nix run "${app_prefix}-copy-to" "${registry}" ${args['--copy-args']} | ||
fi | ||
|
||
# shellcheck disable=SC1090 | ||
source "$(command -v docopts.sh)" | ||
|
||
if [[ "${args['--docker-run']}" != false ]]; then | ||
# shellcheck disable=SC2046 | ||
nix run "${app_prefix}-docker-run" -- $(docopt_get_values args '<run-args>') | ||
elif [[ "${args['--podman-run']}" != false ]]; then | ||
# shellcheck disable=SC2046 | ||
nix run "${app_prefix}-podman-run" -- $(docopt_get_values args '<run-args>') | ||
fi | ||
} | ||
|
||
command="${1:-}" | ||
if [[ -n "$command" ]]; then | ||
shift | ||
fi | ||
|
||
case "$command" in | ||
up) | ||
if [ "$(tail -n +2 <<<"$PROCFILESCRIPT")" = "" ]; then | ||
echo "No 'processes' option defined: https://devenv.sh/processes/" | ||
exit 1 | ||
else | ||
"$PROCFILESCRIPT" | ||
fi | ||
;; | ||
container) | ||
container "$@" | ||
;; | ||
version) | ||
echo "devenv: ${VERSION}" | ||
;; | ||
*) | ||
echo "https://devenv.sh (version ${VERSION}): Fast, Declarative, Reproducible, and Composable Developer Environments" | ||
echo | ||
echo "This is a flake integration wrapper that comes with a subset of functionality from the flakeless devenv CLI." | ||
echo | ||
echo "Usage: devenv command" | ||
echo | ||
echo "Commands:" | ||
echo | ||
echo "up Starts processes in foreground. See http://devenv.sh/processes" | ||
echo "version Display devenv version" | ||
echo | ||
exit 1 | ||
;; | ||
esac |
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
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,8 @@ | ||
if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then | ||
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs=" | ||
fi | ||
|
||
if ! use flake . --impure | ||
then | ||
echo "devenv could not be build. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2 | ||
fi |
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