forked from tapis-project/tapis-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
149 lines (139 loc) · 5.7 KB
/
Copy pathflake.nix
File metadata and controls
149 lines (139 loc) · 5.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
{
description = "TapisUI DevEnv";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
#pnpm2nix.url = "github:nzbr/pnpm2nix-nzbr";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
commonPackages = [
pkgs.gnugrep
pkgs.nodejs_22
#pkgs.nodePackages.npm
pkgs.pnpm
pkgs.git
pkgs.xdg-utils
pkgs.which
pkgs.ripgrep
pkgs.fd
#pkgs.coreutils # clear is not provided # gives clear and other stuff!
] ++ pkgs.lib.optional pkgs.stdenv.isDarwin pkgs.darwin.cctools; # Example: add Darwin-specific tools if needed
NPM_CONFIG_PREFIX = "${toString ./.}/npm_config_prefix";
# Using builtins.replaceStrings to convert newlines to their escaped form for the shell
helpText = ''
Useful to have help text to refer to in nix. I just use scripts now, but this example stays.
'';
# Convert newlines to literal \n for shell echo -e
tapisuiHelpMsg = builtins.replaceStrings ["\n"] ["\\n"] helpText;
# menu script package with an optional version parameter
tapisMenu = pkgs.writeScriptBin "menu" ''
#!${pkgs.bash}/bin/bash
echo -e "\033[34mEntering TapisUI development environment...\033[0m"
# if input $1 is version or --version, show npm and node version
if [[ "$1" == "version" || "$1" == "--version" ]]; then
NPM_VERSION=$(${pkgs.nodePackages.npm}/bin/npm --version)
NODE_VERSION=$(${pkgs.nodejs_22}/bin/node --version)
PNPM_VERSION=$(${pkgs.pnpm}/bin/pnpm --version)
echo -e "npm: $NPM_VERSION"
echo -e "pnpm: $PNPM_VERSION"
echo -e "node: $NODE_VERSION"
fi
echo -e "\nDevelopment commands:
==========================
- pnpm run init-project: initialize tapis-ui project, creates .env, installs deps, and runs
- pnpm run dev: Start a hot-reloading dev server
- pnpm install: install all rootpkg and subpkg dependencies from one module location
- pnpm -r build: Build the rootpkg (-r to build all subpkgs)
- pnpm run docker: docker build and deploy
- pnpm run test: Run all tests
- pnpm run prettier: Ran by 'dev', but should be done before commit
Other commands:
==========================
- menu: callable from nix shell, shows this help message
- menu --version: shows npm and node version + menu
- nix develop -i: --ignore-environment to isolate nix shell from user env
- nix develop .#menu: runs 'menu version' in nix shell
- nix flake show: to view flake outputs
- pnpm run: list all pnpm scripts in root package.json
- pnpm -r build | list | audit | outdated: cool commands, run pnpm for more info
"
'';
# Create a welcome alias that points to menu
tapisWelcome = pkgs.writeScriptBin "welcome" ''
#!${pkgs.bash}/bin/bash
echo -e "\033[31m'welcome' is deprecated, use 'menu' instead.\033[0m"
${tapisMenu}/bin/menu "$@"
'';
## This doesn't use anything yet, but might be a replacement for default mkDerivation
# inherit (pnpm2nix.packages.${system}) mkPnpmPackage;
# frontend = mkPnpmPackage {
# pname = "tapisui";
# version = "1.0.0";
# src = ./.;
# nodejs = pkgs.nodejs_22;
# pnpm = pkgs.pnpm;
# #extraBuildInputs = commonPackages;
# nativeBuildInputs = commonPackages;
# configurePhase = ''
# export HOME=$TMPDIR
# pnpm install --frozen-lockfile
# '';
# buildPhase = ''
# export HOME=$TMPDIR
# pnpm install --frozen-lockfile
# pnpm run build
# '';
# };
in {
devShells = {
default = pkgs.mkShell {
packages = commonPackages ++ [
tapisMenu
tapisWelcome
];
shellHook = ''
alias npm="echo -e '\033[33mHowdy! We use pnpm round these parts. Seem to have found you using npm. More details in readme.\033[0m' && pnpm"
#alias npm=pnpm
#export NPM_CONFIG_PREFIX=${NPM_CONFIG_PREFIX}
#export PATH="${NPM_CONFIG_PREFIX}/bin:$PATH"
#export CHOKIDAR_USEPOLLING=true
#export SHELL=$(which zsh)
#ulimit -n 2000
menu version
'';
};
menu = pkgs.mkShell {
packages = commonPackages ++ [ tapisMenu tapisWelcome ];
shellHook = ''
# Just show the help message and exit
menu version
exit
'';
};
};
packages = {
#inherit frontend;
# You can run default mkDerivation with `nix build .#default`
# Default build using pnpm
default = pkgs.stdenv.mkDerivation {
name = "tapisui-build";
src = ./.;
buildInputs = commonPackages;
buildPhase = ''
echo "This doesn't work. :) Use 'nix develop' to enter the dev shell and run pnpm commands instead."
export HOME=$TMPDIR
pnpm install --frozen-lockfile
pnpm run build --verbose
'';
installPhase = ''
mkdir -p $out
cp -r dist/* $out/
'';
};
};
}
);
}