• Stars
    star
    208
  • Rank 189,015 (Top 4 %)
  • Language
    Rust
  • License
    Creative Commons ...
  • Created over 4 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Make creating nix expressions easy

Nix-template

NOTE: This is still WIP, but should be useful in most situations

Make creating nix expressions easy. Provide a nice way to create largely boilerplate nix-expressions.

Packaging status

Roadmap

  • Finalize cli semantics
  • Ease usage with nixpkgs repo
    • Write to correct location using path
      • Improve logic around directories vs files
      • Improve template-specific items
        • generate buildGoModule's depsSha256
        • generate buildRustPackages's cargoSha256
    • Print top-level addition statement
  • Support Language/frameworks/usage templates:
    • Stdenv
    • Python
    • mkShell
    • Qt
    • Go
    • Rust
    • Flakes
    • NixOS Module
    • NixOS Test
    • Haskell
    • and many more...
  • Add option (-d, --documentation-url) to embed noob-friendly comments and explanations about common usage patterns
  • Allow contributor information to be set locally (similar to git settings)
    • Set maintainer name through $XDG_CONFIG_HOME
    • Set nixpkgs-root path through $XDG_CONFIG_HOME
  • Better integration with fetchers
    • Automatically determine version and sha256
      • Github (need a way to pass owner and repo)
      • Pypi (will need a way to pass pypi pname, as it may differ from installable path)
  • Implement shell completion (nix-template completions )
  • Implement project subcommand, for creating a flake setup for new projects #51
    • Implement init subcommand, for creating new projects #52

Current Usage (--from-url, github and pypi only)

$ nix-template rust -n --from-url github.com/jonringer/nix-template
Creating directory: /home/jon/projects/nixpkgs/pkgs/applications/misc/nix-template
Generating python expression at /home/jon/projects/nixpkgs/pkgs/applications/misc/nix-template/default.nix
Please add the following line to the approriate file in top-level:

  nix-template = callPackage ../applications/misc/nix-template { };

The resulting file:

# $NIXPKGS_ROOT/pkgs/applications/misc/nix-template/default.nix
{ lib
, rustPlatform
, fetchFromGitHub
}:

rustPlatform.buildRustPackage rec {
  pname = "nix-template";
  version = "0.3.0";

  src = fetchFromGitHub {
    owner = "jonringer";
    repo = pname;
    rev = "v${version}";
    sha256 = "sha256-5redgssfwbNEgpjmakIcU8cL4Xg1kPvyK88v+xMqAtw=";
  };

  cargoSha256 = "0000000000000000000000000000000000000000000000000000";

  buildInputs = [ ];

  meta = with lib; {
    description = "Make creating nix expressions easy";
    homepage = "https://github.com/jonringer/nix-template";
    license = licenses.cc0;
    maintainers = with maintainers; [ jonringer ];
  };
}

Current Usage (Generically)

# only need to config once per user
$ nix-template config name jonringer
$ nix-template config nixpkgs-root /home/jon/projects/nixpkgs

# add a package
$ nix-template python --nixpkgs --pname requests -f pypi -l asl20
Creating directory: /home/jon/projects/nixpkgs/pkgs/development/python-modules/requests/
Generating python expression at /home/jon/projects/nixpkgs/pkgs/development/python-modules/requests/default.nix
Please add the following line to the approriate file in top-level:

  requests = callPackage ../development/python-modules/requests { };
# pkgs/development/python-modules/requests/default.nix
{ lib
, buildPythonPackage
, fetchPypi
}:

buildPythonPackage rec {
  pname = "requests";
  version = "0.0.1";

  src = fetchPypi {
    inherit pname version;
    sha256 = "0000000000000000000000000000000000000000000000000000";
  };

  propagatedBuildInputs = [ ];

  pythonImportsCheck = [ "requests" ];

  meta = with lib; {
    description = "CHANGEME";
    homepage = "https://github.com/CHANGEME/requests/";
    license = licenses.asl20;
    maintainer = with maintainers; [ jonringer ];
  };
}

Installation

from nixpkgs (unstable, not available in 20.03):

$ nixenv -iA nix-template

with nix-cli (from this repository):

$ nix-env -f default.nix -iA ""

with cargo

$ cargo install --path .

Development

Installing depedencies on nixpkgs:

nix-shell
# or
nix develop

Other platforms, you'll need the following dependencies:

  • cargo
  • rustc
  • rust-clippy

End Goal (Only better nixpkgs support missing)

# only need to config once per user
$ nix-template config name jonringer
$ nix-template config nixpkgs-root /home/jon/projects/nixpkgs

# add a package
$ nix-template python --nixpkgs -u https://pypi.org/project/requests/
Determining latest release for requests
Creating directory: /home/jon/projects/nixpkgs/pkgs/development/python-modules/requests/
Generating python expression at /home/jon/projects/nixpkgs/pkgs/development/python-modules/requests/default.nix
For an addition to nixpkgs as a python package, please add the following to pkgs/top-level/python-packages.nix:

  requests = callPackage ../development/python-modules/requests { };

For an addition to nixpkgs as a python application, please add the following to pkgs/top-level/all-packages.nix:

  requests = with python3Packages; toPythonApplication requests { };
{ lib
, buildPythonPackage
, fetchPypi
, certifi
, charset-normalizer
, idna
, urllib3
}:

buildPythonPackage rec {
  pname = "requests";
  version = "2.28.1";

  src = fetchPypi {
    inherit pname version;
    sha256 = "sha256-fFWZsQL+3apmHIJsVqtP7ii/0X9avKHrvj5/GdfJeYM=";
  };

  propagatedBuildInputs = [
    certifi
    charset-normalizer
    idna
    urllib3
  ];

  pythonImportsCheck = [ "requests" ];

  meta = with lib; {
    description = "Python HTTP for Humans";
    homepage = "https://requests.readthedocs.io";
    license = licenses.asl20;
    maintainers = with maintainers; [ jonringer ];
  };
}

More Repositories

1

nixpkgs-config

~/.config/nixpkgs
Nix
148
star
2

basinix

(WIP) Nix CI pull request review website
Rust
50
star
3

poly-repo-roadmap

Roadmap for creating a poly-repo nixpkgs fork
46
star
4

server-configuration

Build server nixos configuration
Nix
26
star
5

flake-v2

What flakes should have been
20
star
6

AoC2021

Advent of Code for 2021
Nix
14
star
7

green-design

WIP: A tool for designing and planning gardens, farms, and landscapes.
Nix
11
star
8

nixos-polytest

Allow you to evaluate many nixos closures from different points in time
Nix
10
star
9

nixos-configurations

NixOS configurations that I use
Nix
7
star
10

stdenv

Minimal repo to create a nix stdenv
Nix
5
star
11

multiple-package-versions-proposal

Proposal for standardizing package variants
3
star
12

to-dev-shell-proposal

Proposal to allow for any mkDerivation to be coerced into a devShell
3
star
13

nixpkgs-update-pypi-releases

Fetches releases from pypi for https://github.com/ryantm/nixpkgs-update
Python
3
star
14

oko

Command Line runner for projects
Haskell
3
star
15

nix-test-staging-next

Nix file used to validate `staging-next` in Nixpkgs
Nix
3
star
16

lndir-simple

Xorg's lndir utility, but optimized for nixpkgs
Shell
2
star
17

pkgs-modules-proposal

Allow for `pkgs.config` to be configured with user supplied modules
2
star
18

spiffers

Rust implementation of SPIFFE
Rust
2
star
19

rename-cross-deps-proposal

Proposal to rename stdenv.mkDerivation inputs to something more ergonomic
2
star
20

normalize-attr-to-path-proposal

Proposal to align file paths to how the package is exposed in the package set
1
star
21

python-pkgs

Python package set for use with core-pkgs
Nix
1
star
22

scope-import-proposal

Proposal to add something similar to callPackage, but for non-derivations
1
star
23

core-pkgs

Core packages and NixOS modules for a poly-repo nixpkgs fork
1
star