Initial commit: minimal JavaScript template with Nix

Features:
- Nix + Flakes for reproducible environments
- Bun (fast JavaScript runtime)
- Vite (development server & build tool)
- ESLint + Prettier (linting & formatting)
- Devshell commands via just
- Modular structure using flake-parts
- Omnix template support for initialization
This commit is contained in:
♥ Minnie ♥ 2025-10-27 20:02:55 +08:00
commit 6f67a0dc1a
Signed by: jasmine
GPG key ID: 8563E358D4E8040E
16 changed files with 385 additions and 0 deletions

1
.envrc Normal file
View file

@ -0,0 +1 @@
use flake

9
.gitignore vendored Normal file
View file

@ -0,0 +1,9 @@
# Dependencies
node_modules/
# Build output
dist/
build/
# Direnv
.direnv/

6
.prettierignore Normal file
View file

@ -0,0 +1,6 @@
# Dependencies
node_modules
# Build output
dist
build

58
Justfile Normal file
View file

@ -0,0 +1,58 @@
# List available commands
default:
@just --list
# Start development server with hot reload
dev:
bun run dev
# Add a package dependency
add package:
bun add {{package}}
# Add a dev dependency
add-dev package:
bun add -d {{package}}
# Remove a package dependency
remove package:
bun remove {{package}}
# Build for production
build:
bun run build
# Preview production build
preview:
bun run preview
# Install dependencies
install:
bun install
# Update flake inputs
update:
nix flake update
# Clean build artifacts and dependencies
clean:
rm -rf dist node_modules bun.lockb
# Format code with prettierd
format:
prettierd --write .
# Check formatting without making changes
format-check:
prettierd --check .
# Lint code with eslint
lint:
eslint .
# Lint and auto-fix issues
lint-fix:
eslint --fix .
# Check both formatting and linting
check: format-check lint

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2025 sajenim
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

51
README.md Normal file
View file

@ -0,0 +1,51 @@
# JavaScript Template
A minimal JavaScript development template using Nix. Key features:
- Nix + Flakes for reproducible environments
- Bun (fast JavaScript runtime)
- Vite (development server & build tool)
- ESLint + Prettier (linting & formatting)
- Devshell commands via just
## Prerequisites
- [Nix](https://nixos.org/download.html) with flakes enabled
- [direnv](https://direnv.net/) (optional but recommended)
## Getting Started
Initialize a new project using [omnix](https://omnix.page):
```sh
nix run nixpkgs#omnix -- \
init github:sajenim/javascript-template -o ./my-project
```
Then enter the development environment:
```sh
cd my-project
direnv allow # Or use: nix develop
just dev
```
**NixOS users:** If bun-installed binaries fail to find system libraries, enable FHS compatibility:
```nix
# nix/modules/devshell.nix
fhs = true;
```
## Customization
This template provides minimal, sensible defaults. Customize as needed:
- Add dependencies: `just add <package>`
- Modify linting rules in `eslint.config.js`
- Add Prettier config via `.prettierrc` if needed
- Extend `Justfile` with project-specific commands
## Acknowledgments
- [srid's haskell-template](https://github.com/srid/haskell-template)

BIN
bun.lockb Executable file

Binary file not shown.

13
eslint.config.js Normal file
View file

@ -0,0 +1,13 @@
export default [
{
ignores: ["dist", "build", "node_modules"],
},
{
files: ["**/*.js"],
languageOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
rules: {},
},
];

77
flake.lock generated Normal file
View file

@ -0,0 +1,77 @@
{
"nodes": {
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1760948891,
"narHash": "sha256-TmWcdiUUaWk8J4lpjzu4gCGxWY6/Ok7mOK4fIFfBuU4=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "864599284fc7c0ba6357ed89ed5e2cd5040f0c04",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1751274312,
"narHash": "sha256-/bVBlRpECLVzjV19t5KMdMFWSwKLtb5RyXdjz3LJT+g=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "50ab793786d9de88ee30ec4e4c24fb4236fc2674",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-24.11",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1754788789,
"narHash": "sha256-x2rJ+Ovzq0sCMpgfgGaaqgBSwY+LST+WbZ6TytnT9Rk=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "a73b9c743612e4244d865a2fdee11865283c04e6",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"root": {
"inputs": {
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs",
"systems": "systems"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

18
flake.nix Normal file
View file

@ -0,0 +1,18 @@
{
description = "Nix template for JavaScript projects, powered by Bun";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
systems.url = "github:nix-systems/default";
flake-parts.url = "github:hercules-ci/flake-parts";
};
outputs = inputs:
inputs.flake-parts.lib.mkFlake {inherit inputs;} {
systems = import inputs.systems;
imports = [
./nix/modules/devshell.nix
./nix/modules/template.nix
];
};
}

13
index.html Normal file
View file

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JavaScript App</title>
<link rel="stylesheet" href="src/style.css">
</head>
<body>
<div id="app"></div>
<script type="module" src="src/main.js"></script>
</body>
</html>

43
nix/modules/devshell.nix Normal file
View file

@ -0,0 +1,43 @@
{inputs, lib, ...}: let
# FHS compatibility for NixOS (steam-run wrapper)
# Enable if bun-installed binaries fail to find system libraries
fhs = false;
in {
perSystem = {system, ...}: let
pkgs = import inputs.nixpkgs {
inherit system;
config.allowUnfree = fhs;
};
fhsPackages = lib.optionals fhs [
pkgs.steam-run
];
fhsSetup = lib.optionalString fhs ''
alias bun="steam-run bun"
'';
in {
devShells.default = pkgs.mkShell {
nativeBuildInputs = with pkgs;
[
bun
eslint
just
prettierd
]
++ fhsPackages;
shellHook = ''
${fhsSetup}
if [ -f package.json ]; then
echo "Installing dependencies..."
bun install
fi
echo ""
echo "💡 Run 'just' to see available commands"
'';
};
};
}

19
nix/modules/template.nix Normal file
View file

@ -0,0 +1,19 @@
{inputs, ...}: {
flake = rec {
templates.default = {
description = "A minimal JavaScript project template with Bun and Nix";
path = inputs.self;
};
om.templates.javascript-template = {
template = templates.default;
params = [
{
name = "package-name";
description = "Name of the JavaScript package";
placeholder = "javascript-template";
}
];
};
};
}

13
package.json Normal file
View file

@ -0,0 +1,13 @@
{
"name": "javascript-template",
"version": "1.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"vite": "^6.0.0"
}
}

8
src/main.js Normal file
View file

@ -0,0 +1,8 @@
const app = document.getElementById("app");
app.innerHTML = `
<h1>JavaScript Template</h1>
<p>Edit <code>src/main.js</code> to get started.</p>
`;
console.log("Development server running");

35
src/style.css Normal file
View file

@ -0,0 +1,35 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: system-ui, -apple-system, sans-serif;
line-height: 1.6;
padding: 2rem;
background: #f5f5f5;
color: #333;
}
#app {
max-width: 800px;
margin: 0 auto;
padding: 2rem;
background: white;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
h1 {
margin-bottom: 1rem;
color: #2c3e50;
}
code {
padding: 0.2em 0.4em;
background: #f0f0f0;
border-radius: 3px;
font-family: "Monaco", "Courier New", monospace;
font-size: 0.9em;
}