feat: shared utils
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.env
|
||||||
28
flake.nix
28
flake.nix
@@ -27,17 +27,7 @@
|
|||||||
|
|
||||||
envErrorMessage = varName: "Error: The ${varName} environment variable is not set.";
|
envErrorMessage = varName: "Error: The ${varName} environment variable is not set.";
|
||||||
|
|
||||||
parseEnv = file: let
|
parseEnv = import ./parse-env.nix;
|
||||||
lines = builtins.filter (line: builtins.match "^var=.*" line != null) (builtins.readFile file);
|
|
||||||
attributes = builtins.listToAttrs (builtins.map (line: let
|
|
||||||
parts = builtins.split "=" line;
|
|
||||||
key = builtins.substring 0 (builtins.stringLength parts[0] - 3) parts[0]; # Remove "var" prefix
|
|
||||||
value = parts[1];
|
|
||||||
in {
|
|
||||||
name = key;
|
|
||||||
value = value;
|
|
||||||
}) lines);
|
|
||||||
in attributes;
|
|
||||||
|
|
||||||
dotEnv = builtins.getEnv "DOTENV";
|
dotEnv = builtins.getEnv "DOTENV";
|
||||||
minorEnvironment =
|
minorEnvironment =
|
||||||
@@ -82,6 +72,20 @@
|
|||||||
# Execute the system's nvim with your custom arguments
|
# Execute the system's nvim with your custom arguments
|
||||||
exec "$SYSTEM_NVIM" --cmd 'lua vim.o.exrc = true' "$@"
|
exec "$SYSTEM_NVIM" --cmd 'lua vim.o.exrc = true' "$@"
|
||||||
'';
|
'';
|
||||||
|
printobstacle =
|
||||||
|
let
|
||||||
|
name = "printobstacle";
|
||||||
|
in
|
||||||
|
pkgs.writeShellScriptBin "${name}" ''
|
||||||
|
printf "%s%s%s\n" "''${RED}" "$*" "''${RESET}"
|
||||||
|
'';
|
||||||
|
printprogress =
|
||||||
|
let
|
||||||
|
name = "printprogress";
|
||||||
|
in
|
||||||
|
pkgs.writeShellScriptBin "${name}" ''
|
||||||
|
printf "%s%s%s\n" "''${YELLOW}" "$*" "''${RESET}"
|
||||||
|
'';
|
||||||
colorize = pkgs.writeShellScriptBin "colorize" ''
|
colorize = pkgs.writeShellScriptBin "colorize" ''
|
||||||
awk '
|
awk '
|
||||||
BEGIN {
|
BEGIN {
|
||||||
@@ -115,7 +119,7 @@
|
|||||||
}) // {
|
}) // {
|
||||||
lib = {
|
lib = {
|
||||||
# -- For all systems --
|
# -- For all systems --
|
||||||
inherit forAllSystemsWithPkgs forSpecSystemsWithPkgs;
|
inherit dotEnv minorEnvironment parseEnv forAllSystemsWithPkgs forSpecSystemsWithPkgs;
|
||||||
|
|
||||||
# -- Env processing --
|
# -- Env processing --
|
||||||
getEnv = varName: let
|
getEnv = varName: let
|
||||||
|
|||||||
14
parse-env.nix
Normal file
14
parse-env.nix
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# TODO: allow multiline
|
||||||
|
file: let
|
||||||
|
envText = builtins.readFile file;
|
||||||
|
envLines = builtins.split "\n" envText;
|
||||||
|
lines = builtins.filter (line: (builtins.match "^.*=.*" line) != null) envLines;
|
||||||
|
#attributes = builtins.listToAttrs (builtins.map (line: let
|
||||||
|
# parts = builtins.split "=" line;
|
||||||
|
# key = builtins.substring 0 (builtins.stringLength parts[0] - 3) parts[0]; # Remove "var" prefix
|
||||||
|
# value = parts[1];
|
||||||
|
#in {
|
||||||
|
# name = key;
|
||||||
|
# value = value;
|
||||||
|
#}) lines);
|
||||||
|
in {inherit envLines lines;}
|
||||||
Reference in New Issue
Block a user