Examples
Creating JSON, TEXT, TOML or YAML files
# examples/hello.nix
#
# this is one nix file
{
files.json."/generated/hello.json".hello = "world";
files.toml."/generated/hello.toml".hello = "world";
files.yaml."/generated/hello.yaml".hello = "world";
files.hcl."/generated/hello.hcl".hello = "world";
files.text."/generated/hello.txt" = "world";
}
Your file can be complemented with another module
# examples/world.nix
# almost same as previous example
# but show some language feature
let
name = "hello"; # a variable
in
{
files = {
json."/generated/${name}.json".baz = ["foo" "bar" name];
toml."/generated/${name}.toml".baz = ["foo" "bar" name];
yaml = {
"/generated/${name}.yaml" = {
baz = [
"foo"
"bar"
name
];
};
};
};
}
Content generated by those examples are in generated
# ie ./generated/hello.yaml
baz:
- foo
- bar
- hello
hello: world
Dogfooding
This project is configured by module project.nix
# ./project.nix
{
# import other modules
imports = [
./examples/hello.nix
./examples/world.nix
./examples/readme.nix
./examples/gitignore.nix
./examples/license.nix
./examples/interpolation.nix
./examples/docs.nix
./examples/book.nix
./examples/services.nix
./examples/nim.nix
./examples/nushell.nix
./examples/watch.nix
];
# My shell name
devshell.name = "devshell-files";
# install development or deployment tools
packages = [
"convco"
# now we can use 'convco' command https://convco.github.io
# but could be:
# "awscli"
# "azure-cli"
# "cargo"
# "conda"
# "go"
# "nim"
# "nodejs"
# "nodejs-18_x"
# "nushell"
# "pipenv"
# "python39"
# "ruby"
# "rustc"
# "terraform"
# "yarn"
# look at https://search.nixos.org for more packages
];
# create alias
files.alias.feat = ''convco commit --feat $@'';
files.alias.fix = ''convco commit --fix $@'';
files.alias.docs = ''convco commit --docs $@'';
files.alias.alou = ''
#!/usr/bin/env python
print("Alo!") # is hello in portuguese
'';
# now we can use feat, fix, docs and alou commands
# create .envrc for direnv
files.direnv.enable = true;
# disabe file creation when entering in the shell
# call devshell-files instead
# files.on-call = true;
}
This README.md is also a module defined as above
# There is a lot things we could use to write static file
# Basic intro to nix language https://github.com/tazjin/nix-1p
# Some nix functions https://teu5us.github.io/nix-lib.html
{lib, ...}:
{
files.text."/README.md" = builtins.concatStringsSep "\n" [
"# Devshell Files Maker"
(builtins.readFile ./readme/toc.md)
(builtins.readFile ./readme/about.md)
(builtins.readFile ./readme/installation.md)
(builtins.import ./readme/examples.nix)
((builtins.import ./readme/modules.nix) lib)
(builtins.readFile ./readme/todo.md)
(builtins.readFile ./readme/issues.md)
(builtins.readFile ./readme/seeAlso.md)
];
}
Our .gitignore is defined like this
# ./examples/gitignore.nix
{
# create my .gitignore copying ignore patterns from
# github.com/github/gitignore
files.gitignore.enable = true;
files.gitignore.template."Global/Archives" = true;
files.gitignore.template."Global/Backup" = true;
files.gitignore.template."Global/Diff" = true;
files.gitignore.pattern."**/.data" = true;
files.gitignore.pattern."**/.direnv" = true;
files.gitignore.pattern."**/.envrc" = true;
files.gitignore.pattern."**/.gitignore" = true;
files.gitignore.pattern."**/flake.lock" = true;
}
And our LICENSE file is
# ./examples/license.nix
{
# LICENSE file creation
# using templates from https://github.com/spdx/license-list-data
files.license.enable = true;
files.license.spdx.name = "MIT";
files.license.spdx.vars.year = "2023";
files.license.spdx.vars."copyright holders" = "Cruel Intentions";
}