# No user-configurable parameters{ pkgs,...}:{# Shell script that produces the final environmentbootstrap= ''
# Copy the folder containing the `idx-template` files to the final# project folder for the new workspace. ${./.} inserts the directory# of the checked-out Git folder containing this template.
cp -rf ${./.} "$out"
# Set some permissions
chmod -R +w "$out"
# Remove the template files themselves and any connection to the template's# Git repository
rm -rf "$out/.git" "$out/idx-template".{nix,json}
'';}
# idx-template.nix{pkgs}:{packages=[# Enable "node", "npm" and "npx" in the bootstrap script below.# Note, this is NOT the list of packages available to the workspace once# it's created. Those go in .idx/dev.nix
pkgs.nodejs
];bootstrap= ''
mkdir "$out"
# We can now use "npm"
npm init --yes my-boot-strap@latest "$out"
''
}
如果您有一个形参,则沿用上一部分中的示例
ID 为 language 的枚举,其值可能为 ts 或 js,您可以使用
就像这样:
# idx-template.nix# Accept additional arguments to this template corresponding to template# parameter IDs, including default values (language=ts by default in this example).{ pkgs,language ? "ts",...}:{packages=[
pkgs.nodejs
];bootstrap= ''
# We use Nix string interpolation to pass the user's chosen programming# language to our script.
npm init --yes my-boot-strap@latest "$out" ----lang=${language}
''
}
# .idx/dev.nix{pkgs}:{...idx={# Workspace lifecycle hooksworkspace={# Runs when a workspace is first created with this `dev.nix` fileonCreate={# Open editors for the following files by default, if they exist.# The last file in the list will be focused.
default.openFiles=[
"src/index.css"
"src/index.js"
"src/index.html"
];# Include other scripts here, as needed, for example:# installDependencies = "npm install";};# To run something each time the workspace is (re)started, use the `onStart` hook};# Enable previews and customize configurationpreviews={...};};}