nix-init
Generate Nix packages from URLs with hash prefetching, dependency inference, license detection, and more [maintainer=@figsoda]
Top Related Projects
A fast, persistent use_nix/use_flake implementation for direnv [maintainer=@Mic92 / @bbenne10]
Nix, the purely functional package manager
Per project developer environments
Fast, Declarative, Reproducible, and Composable Developer Environments using Nix
Simplified nix packaging for various programming language ecosystems [maintainer=@DavHau]
Quick Overview
nix-community/nix-init is a command-line tool designed to simplify the process of creating Nix flakes and packages. It automates the generation of Nix expressions for various programming languages and build systems, making it easier for developers to integrate their projects with the Nix ecosystem.
Pros
- Streamlines the creation of Nix flakes and packages
- Supports multiple programming languages and build systems
- Reduces the learning curve for newcomers to Nix
- Generates well-structured and idiomatic Nix expressions
Cons
- May not cover all possible project configurations
- Generated expressions might require manual tweaking for complex projects
- Depends on external tools and services for some functionalities
- Limited to supported languages and build systems
Getting Started
To use nix-init, follow these steps:
-
Install nix-init using Nix:
nix-env -iA nixpkgs.nix-init
-
Navigate to your project directory and run:
nix-init
-
Follow the interactive prompts to configure your project.
-
Review and adjust the generated Nix files as needed.
For more detailed instructions and options, refer to the project's README on GitHub.
Competitor Comparisons
A fast, persistent use_nix/use_flake implementation for direnv [maintainer=@Mic92 / @bbenne10]
Pros of nix-direnv
- Seamlessly integrates with direnv for automatic environment switching
- Provides faster shell startup times compared to nix-shell
- Supports caching of build environments for improved performance
Cons of nix-direnv
- Requires additional setup and configuration compared to nix-init
- May have a steeper learning curve for users unfamiliar with direnv
- Limited to shell environment management, unlike nix-init's broader scope
Code Comparison
nix-direnv:
use_nix() {
local path="$(nix-instantiate --find-file nixpkgs)"
if [ -f "${path}/.version-suffix" ]; then
local version="$(< $path/.version-suffix)"
elif [ -f "${path}/.git" ]; then
local version="$(cd $path && git rev-parse --short HEAD)"
fi
local cache=".direnv/cache-${version:-unknown}"
nix-init:
{ pkgs ? import <nixpkgs> { } }:
pkgs.mkShell {
buildInputs = with pkgs; [
# Add your dependencies here
];
}
The nix-direnv code snippet shows how it integrates with direnv and manages caching, while the nix-init example demonstrates a basic Nix shell configuration. nix-direnv focuses on environment management, whereas nix-init provides a starting point for Nix project initialization.
Nix, the purely functional package manager
Pros of nix
- Official Nix package manager repository with extensive documentation
- Larger community and more active development
- Comprehensive toolset for package management and system configuration
Cons of nix
- Steeper learning curve for beginners
- More complex setup process compared to nix-init
- Requires more manual configuration for project-specific setups
Code Comparison
nix:
{ stdenv, lib, fetchFromGitHub }:
stdenv.mkDerivation rec {
pname = "example";
version = "1.0.0";
src = fetchFromGitHub {
owner = "example";
repo = "example";
rev = "v${version}";
sha256 = "...";
};
}
nix-init:
{
description = "A simple Nix flake";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
outputs = { self, nixpkgs }: {
defaultPackage.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.hello;
};
}
The nix repository provides a more traditional Nix expression for package definition, while nix-init focuses on generating Nix flakes with a simpler structure. nix-init aims to streamline the process of creating Nix projects, especially for newcomers, by providing an interactive CLI tool. However, nix offers more flexibility and power for advanced users who need fine-grained control over package definitions and system configurations.
Per project developer environments
Pros of devshell
- More comprehensive development environment setup, including shell hooks and packages
- Supports multiple shells and environments within a single project
- Provides a modular approach with built-in modules for common development tasks
Cons of devshell
- Steeper learning curve due to more complex configuration options
- May be overkill for simple projects or quick prototyping
- Requires more setup and maintenance compared to nix-init's streamlined approach
Code Comparison
nix-init:
{
description = "A simple Nix flake";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
outputs = { self, nixpkgs }: {
# Basic package definition
};
}
devshell:
{ pkgs ? import <nixpkgs> { } }:
pkgs.devshell.mkShell {
imports = [ (pkgs.devshell.importTOML ./devshell.toml) ];
packages = [ pkgs.hello ];
commands = [
{ package = pkgs.git; }
];
}
The code comparison shows that nix-init focuses on creating a basic Nix flake structure, while devshell provides a more detailed development environment configuration with package management and command definitions. devshell's approach allows for more customization and flexibility in setting up project-specific development environments.
Fast, Declarative, Reproducible, and Composable Developer Environments using Nix
Pros of devenv
- More comprehensive development environment setup, including services and processes
- Supports multiple languages and frameworks out-of-the-box
- Provides a user-friendly CLI for managing development environments
Cons of devenv
- Steeper learning curve due to more complex configuration options
- Potentially heavier resource usage for full environment setups
- May be overkill for simple projects or quick prototypes
Code Comparison
nix-init:
{ pkgs ? import <nixpkgs> { } }:
pkgs.mkShell {
buildInputs = with pkgs; [
# Add your dependencies here
];
}
devenv:
{ pkgs, ... }:
{
packages = [ pkgs.hello ];
languages.python.enable = true;
services.postgres.enable = true;
processes.web.exec = "python app.py";
}
The code comparison shows that nix-init provides a simpler, more bare-bones setup using mkShell
, while devenv offers a more structured and feature-rich configuration with built-in support for languages, services, and processes. nix-init is better suited for quick, custom environments, whereas devenv excels in creating comprehensive, reproducible development setups across multiple projects and team members.
Simplified nix packaging for various programming language ecosystems [maintainer=@DavHau]
Pros of dream2nix
- Supports a wider range of programming languages and build systems
- Offers more advanced features for complex project setups
- Provides better integration with existing Nix ecosystems
Cons of dream2nix
- Steeper learning curve for beginners
- May be overkill for simple projects
- Requires more configuration and setup time
Code Comparison
nix-init:
{ lib, stdenv, fetchFromGitHub }:
stdenv.mkDerivation rec {
pname = "example";
version = "1.0.0";
dream2nix:
{ dream2nix, ... }:
dream2nix.makeFlakeOutputs {
systems = ["x86_64-linux"];
config.projectRoot = ./.;
source = ./.;
nix-init is designed for simpler Nix package definitions, while dream2nix offers a more comprehensive approach to project management and packaging. nix-init is better suited for quick, straightforward package creation, whereas dream2nix excels in handling complex, multi-language projects with intricate dependencies.
dream2nix provides more flexibility and power but requires a deeper understanding of Nix concepts. It's particularly useful for large-scale projects or when working with diverse ecosystems. nix-init, on the other hand, is more accessible for newcomers and ideal for smaller, single-language projects where simplicity is preferred over advanced features.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
nix-init
Generate Nix packages from URLs
Note: It is likely that the generated package will not work without some tweaks, also remember to double check the license and description even if it does work
- Hash prefetching powered by nurl with support for
cargoHash
andvendorHash
- Dependency inference for Rust, Go, and Python projects
- Interactive prompts with fuzzy tab completions
- License detection
Installation
The latest release of nix-init is packaged in nixpkgs and kept up to date on the unstable branches
If you want to use a more recent snapshot of nix-init, it is also available as a
flake. The following command is equivalent to running nix-init --help
:
nix run github:nix-community/nix-init -- --help
or if you don't have flakes enabled:
nix run --extra-experimental-features "flakes nix-command" github:nix-community/nix-init -- --help
Usage
Usage: nix-init [OPTIONS] [OUTPUT]
Arguments:
[OUTPUT] The path or directory to output the generated file to
Options:
-u, --url <URL> Specify the URL
-n, --nixpkgs <NIXPKGS> Path to nixpkgs (in nix)
-C, --commit[=<COMMIT>] Commit the changes if the output path is name-based (RFC 140) [possible values: true, false]
-c, --config <CONFIG> Specify the config file
-h, --help Print help
-V, --version Print version
Supported builders
stdenv.mkDerivation
buildRustPackage
buildPythonApplication
andbuildPythonPackage
buildGoModule
Supported fetchers
fetchCrate
fetchFromGitHub
fetchFromGitLab
fetchFromGitea
fetchPypi
- All other fetchers supported by nurl are also supported, you just have to manually input the tag/revision of the package
Configuration
nix-init will try to find nix-init/config.toml
under XDG configuration
directories
# ~/.config/nix-init/config.toml
# maintainers that will get added to the package meta
maintainers = ["figsoda"]
# path to nixpkgs (in nix), equivalent to `--nixpkgs`
nixpkgs = "<nixpkgs>" # use the nixpkgs from channels (default)
# nixpkgs = 'builtins.getFlake "nixpkgs"' # use the nixpkgs from the flake registry
# commit the changes if the output path is name-based (RFC 140)
# see https://github.com/NixOS/nixpkgs/tree/master/pkgs/by-name for more information
commit = true
# access tokens to access private repositories and avoid rate limits
[access-tokens]
"github.com" = "ghp_blahblahblah..."
"gitlab.com".command = ["secret-tool", "or", "whatever", "you", "use"]
"gitlab.gnome.org".file = "/path/to/api/token"
Changelog
See CHANGELOG.md
Top Related Projects
A fast, persistent use_nix/use_flake implementation for direnv [maintainer=@Mic92 / @bbenne10]
Nix, the purely functional package manager
Per project developer environments
Fast, Declarative, Reproducible, and Composable Developer Environments using Nix
Simplified nix packaging for various programming language ecosystems [maintainer=@DavHau]
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot