This is a template repository for creating applications using Nix Flakes.
- Copy this repository.
- Modify
nix/variables.nixto set your package's name, version, and type. - Write your code in the
srcdirectory.
To build the package, run:
nix build
This will create a result symlink to the built package.
To enter a development shell with all the specified buildInputs, run:
nix develop
Inside the shell, you can use the buildInputs to build your project.
To run the package, run:
nix run
To create a release of the package, run:
nix build .#release.x86_64-linux
This will create a tarball of the package in the result directory.
This template uses a modular system for defining package types. The package type is selected in the nix/variables.nix file by setting the packageType variable.
The available package types are defined as .nix files in the nix/packages directory. Each file defines the buildInputs, buildCommand, and installCommand for a specific language or framework.
You can easily add your own package types by creating a new .nix file in the nix/packages directory.
- c: For C projects.
- rust: For Rust projects.
- python: For Python projects.
- expo: For Expo (React Native) projects.
To add a new app type, you need to create a new .nix file in the nix/packages directory. This file should return an attribute set with the buildInputs, buildCommand, and installCommand for your language or framework.
For example, to add a new app type for Go, you would create a new file called nix/packages/go.nix with the following content:
{ pkgs }:
{
buildInputs = [ pkgs.go ];
buildCommand = "go build -o my-go-app";
installCommand = ''
mkdir -p $out/bin
cp my-go-app $out/bin
'';
}Then, in your nix/variables.nix file, you would set the packageType to "go".
For more details on how to use each package type, please refer to the corresponding file in the nix/packages directory.
This flake provides an overlay that can be used to install the package on NixOS or with Home Manager.
In your configuration.nix:
{
nixpkgs.overlays = [
(import (builtins.fetchTarball {
url = "https://github.com/<owner>/<repo>/archive/<commit>.tar.gz";
})).overlay
];
environment.systemPackages = [ pkgs.<packageName> ];
}In your home.nix:
{
nixpkgs.overlays = [
(import (builtins.fetchTarball {
url = "https://github.com/<owner>/<repo>/archive/<commit>.tar.gz";
})).overlay
];
home.packages = [ pkgs.<packageName> ];
}Contributions are welcome! If you have a new package type that you would like to add, please create a pull request.
- Fork the repository on GitHub.
- Clone your fork to your local machine.
- Create a new branch for your changes.
- Make your changes and commit them.
- Push your changes to your fork.
- Create a pull request from your fork to the upstream repository
github:Preston/FlakeAppTemplate.