feat: linux-devshell: init
This commit is contained in:
@@ -108,6 +108,7 @@
|
|||||||
nativeBuildInputs = with pkgs; [pkg-config curl];
|
nativeBuildInputs = with pkgs; [pkg-config curl];
|
||||||
};
|
};
|
||||||
dbToolPkgs = pkgs.callPackage ./db-tool { inherit self; };
|
dbToolPkgs = pkgs.callPackage ./db-tool { inherit self; };
|
||||||
|
linuxDevShellPkgs = pkgs.callPackage ./linux-devshell {};
|
||||||
in {
|
in {
|
||||||
py3-datetime = pkgs.callPackage ./py3-datetime.nix {};
|
py3-datetime = pkgs.callPackage ./py3-datetime.nix {};
|
||||||
py3-marzban = pkgs.callPackage ./py3-marzban.nix { inherit self; };
|
py3-marzban = pkgs.callPackage ./py3-marzban.nix { inherit self; };
|
||||||
@@ -146,6 +147,8 @@ in {
|
|||||||
"postgres-init" = dbToolPkgs."postgres-init";
|
"postgres-init" = dbToolPkgs."postgres-init";
|
||||||
"postgres-cleanup" = dbToolPkgs."postgres-cleanup";
|
"postgres-cleanup" = dbToolPkgs."postgres-cleanup";
|
||||||
"hectic-inheritance" = dbToolPkgs."hectic-inheritance";
|
"hectic-inheritance" = dbToolPkgs."hectic-inheritance";
|
||||||
|
"linux-devshell" = linuxDevShellPkgs.linux-devshell;
|
||||||
|
"linux-devshell-standalone" = linuxDevShellPkgs.linux-devshell-standalone;
|
||||||
nbt2json = pkgs.callPackage ./nbt2json {};
|
nbt2json = pkgs.callPackage ./nbt2json {};
|
||||||
hemar-parser = pkgs.callPackage ./hemar/parser {};
|
hemar-parser = pkgs.callPackage ./hemar/parser {};
|
||||||
AstroTuxLauncher = pkgs.callPackage ./AstroTuxLauncher.nix {};
|
AstroTuxLauncher = pkgs.callPackage ./AstroTuxLauncher.nix {};
|
||||||
|
|||||||
48
package/linux-devshell/default.nix
Normal file
48
package/linux-devshell/default.nix
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
{ dash, hectic, curl, coreutils, gawk, procps, writeTextFile, lib }:
|
||||||
|
let
|
||||||
|
shell = "${dash}/bin/dash";
|
||||||
|
bashOptions = [
|
||||||
|
"errexit"
|
||||||
|
"nounset"
|
||||||
|
];
|
||||||
|
|
||||||
|
logHelpers = builtins.readFile ../../lib/shell/logs.sh;
|
||||||
|
scriptText = builtins.readFile ./linux-devshell.sh;
|
||||||
|
|
||||||
|
linuxDevShell = hectic.writeShellApplication {
|
||||||
|
inherit shell bashOptions;
|
||||||
|
name = "linux-devshell";
|
||||||
|
runtimeInputs = [ curl coreutils gawk procps ];
|
||||||
|
excludeShellChecks = [ "SC2034" "SC1090" ];
|
||||||
|
|
||||||
|
text = ''
|
||||||
|
${logHelpers}
|
||||||
|
${scriptText}
|
||||||
|
'';
|
||||||
|
|
||||||
|
meta = {
|
||||||
|
description = "Install Nix and enter development shell";
|
||||||
|
mainProgram = "linux-devshell";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
linuxDevShellStandalone = writeTextFile {
|
||||||
|
name = "linux-devshell";
|
||||||
|
executable = true;
|
||||||
|
text = ''
|
||||||
|
#!${shell}
|
||||||
|
${lib.concatMapStringsSep "\n" (option: "set -o ${option}") bashOptions}
|
||||||
|
|
||||||
|
${logHelpers}
|
||||||
|
${scriptText}
|
||||||
|
'';
|
||||||
|
meta = {
|
||||||
|
description = "Standalone linux-devshell script (single file)";
|
||||||
|
mainProgram = "linux-devshell";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
linux-devshell = linuxDevShell;
|
||||||
|
linux-devshell-standalone = linuxDevShellStandalone;
|
||||||
|
}
|
||||||
81
package/linux-devshell/linux-devshell.sh
Normal file
81
package/linux-devshell/linux-devshell.sh
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
NIX_HOOK="${HOME}/.nix-profile/etc/profile.d/nix.sh"
|
||||||
|
|
||||||
|
detect_shell() {
|
||||||
|
self=detect_shell
|
||||||
|
|
||||||
|
if [ "$0" != "$self" ]; then
|
||||||
|
case "$0" in
|
||||||
|
/*) [ -x "$0" ] && { printf '%s\n' "$0"; return 0; } ;;
|
||||||
|
*) command -v "$0" 2>/dev/null && return 0 ;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
_shell="$(ps -p $$ -o args= 2>/dev/null | awk '{print $1}')"
|
||||||
|
[ -n "$_shell" ] && command -v "$_shell" 2>/dev/null && {
|
||||||
|
command -v "$_shell"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
[ -r "/proc/$$/exe" ] && readlink -f "/proc/$$/exe" && return 0
|
||||||
|
|
||||||
|
[ -x "$SHELL" ] && printf '%s\n' "$SHELL" && return 0
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
install_nix() {
|
||||||
|
log_info "Nix not found. Installing via nixos.org/nix/install --no-daemon..."
|
||||||
|
|
||||||
|
if ! command -v curl >/dev/null 2>&1; then
|
||||||
|
log_error "curl is required. Install it with: sudo pacman -S curl"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
NIX_INSTALL="$(mktemp)"
|
||||||
|
trap 'rm -f "$NIX_INSTALL"' EXIT
|
||||||
|
|
||||||
|
if ! curl -sSfL https://nixos.org/nix/install -o "$NIX_INSTALL"; then
|
||||||
|
log_error "Failed to download Nix installer."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
sh "$NIX_INSTALL" --no-daemon || true
|
||||||
|
|
||||||
|
NIX_CONF_DIR="${XDG_CONFIG_HOME:-${HOME}/.config}/nix"
|
||||||
|
mkdir -p "$NIX_CONF_DIR"
|
||||||
|
NIX_CONF="${NIX_CONF_DIR}/nix.conf"
|
||||||
|
if ! grep -q 'build-users-group' "$NIX_CONF" 2>/dev/null; then
|
||||||
|
printf 'build-users-group =\nextra-experimental-features = nix-command flakes\n' >> "$NIX_CONF"
|
||||||
|
log_info "Patched nix.conf: disabled build-users-group."
|
||||||
|
fi
|
||||||
|
|
||||||
|
log_info "Nix installed successfully."
|
||||||
|
}
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
||||||
|
|
||||||
|
if [ -f "$NIX_HOOK" ]; then
|
||||||
|
. "$NIX_HOOK"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command -v nix >/dev/null 2>&1; then
|
||||||
|
install_nix
|
||||||
|
if [ -f "$NIX_HOOK" ]; then
|
||||||
|
. "$NIX_HOOK"
|
||||||
|
fi
|
||||||
|
if ! command -v nix >/dev/null 2>&1; then
|
||||||
|
log_error "Nix binary still not found after installation. Try opening a new terminal."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
log_info "Nix is already installed -- skipping installation."
|
||||||
|
fi
|
||||||
|
|
||||||
|
CURR_SHELL="$(detect_shell)"
|
||||||
|
log_info "Entering dev shell (nix develop) with shell: ${CURR_SHELL}..."
|
||||||
|
log_info "Repository: ${REPO_ROOT}"
|
||||||
|
|
||||||
|
exec nix --extra-experimental-features 'nix-command flakes' \
|
||||||
|
develop "${REPO_ROOT}" \
|
||||||
|
-c "$CURR_SHELL"
|
||||||
Reference in New Issue
Block a user