Giter Site home page Giter Site logo

templates's Introduction

Official Nix templates

Templates are there to help you start your Nix project.

$ nix flake init --template templates#full

or

$ nix flake new --template templates#full ./my-new-project

Each template ships with a tutorial (README.md) which explains in details how to use it and extend it.

How to contribute

Main purpose of this repository is to collect most common templates to help newcomers learn Nix. For this purpose the collection of templates is limited to provided an opinionated and curated list.

Other templates for more advanced topics can be found in nix-community/templates.

TODO: templates should be also discoverable on search.nixos.org

Opening issues

What is required to submit a template?

Each template needs:

  • name

    Folder with the same name should be created and this is a location of the template. An entry with name is requred in flake.nix.

  • description

    A description that explains the content of the template in one sentence. An entry with description is requred in flake.nix.

  • maintainers

    Each template needs one of more maintainers with the knowledge of specific area. Each template has an entry in .github/CODEOWNERS with maintainers next to them.

  • tutorial

    Tutorial showing the usage of the template should be placed in README.md.

License

Note: contributing implies licensing those contributions under the terms of COPYING, which is the MIT license.

templates's People

Contributors

asymmetric avatar bts avatar cab404 avatar domenkozar avatar edolstra avatar eonpatapon avatar garbas avatar ifd3f avatar josephlucas avatar kindrowboat avatar kovirobi avatar kranzes avatar l-as avatar matthewcroughan avatar mmesch avatar nixinator avatar peterbecich avatar pinpox avatar rexcrazy804 avatar schuelermine avatar smaug123 avatar supersandro2000 avatar teto avatar timhae avatar tomberek avatar tomodachi94 avatar vcunat avatar wantenmn avatar winston0410 avatar yvan-sraka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

templates's Issues

[Rust template] Clang error

Hi, thanks for these useful templates!

Unfortunately, the rust one can face the error: linking with cc failed: exit status: 1 error on Mac M1...

It worked perfectly, until I run cargo add sqlx then try to cargo build:

Compiling sqlx-macros v0.7.4
error: linking with `cc` failed: exit status: 1
[...]
  = note: ld: framework not found SystemConfiguration
          clang-16: error: linker command failed with exit code 1 (use -v to see invocation)

error: could not compile `sqlx-macros` (lib) due to 1 previous error

I know this error is linked to clang but I don't find any way to solve it on my Mac M1...
That would be great to have inside the template, the workaround to avoid any other Mac user to face this error.

I don't have any modifications on the flake.nix or the shell.nix generated and created by the template.

Cheers and thanks again!

Add a multi-platform template

The current templates are all for flakes with only a single platform. It would be useful to have something for e.g. both linux and macos at once.

nix bundle broken on busybox because of wrong tar flags

I'm trying to use a binary created by running

nix bundle nixpkgs#pkgsi686Linux.curl

on a minimal buildroot image (:sweat_smile:), but get this error:

tar: invalid option -- j
BusyBox v1.31.1 (2020-07-17 17:53:41 CDT) multi-call binary.

Usage: tar c|x|t [-hvokO] [-f TARFILE] [-C DIR] [-T FILE] [-X FILE] [--exclude PATTERN]... [FILE]...

And on the next invocation:

../run: line 1: ./nix/store/yigc12h43pdv2mn3cfb3k0xw3rsfdb8a-startup: not found

Delete this repo

Solves #66

Flakes are distributed, so there's no need to centralize any templates.

Template request: an isolated project

I think it would be very useful to have a general template where people can add their dependencies and run nix develop (or whatever command is needed to open my shell with the new apps). With some documentation on how to use it on the flake itself.

I would like to initialize a flake, add packages like nixpkgs.git nixpkgs.grep nixpkgs.sed nixpkgs.redis mygithubdependency.app. And finally run a command and have the shell with those deps, this way people using my project could run the scripts of whatever I've configured. I tried the different templates but I couldn't do it, I find very hard to achieve this πŸ˜…

I think maybe one of the hardest parts for me is to import another flake on github. This would be useful to import other projects in my projects.

Thanks!

Template paths need to be nix store paths

According to the flake output schema docs the template path argument needs to be a nix store path. CI using something like

nix --store ~/nix flake check -L

would currently fail because the paths are relative. This is not noticeable without the --store flag on an empty nix store, because the paths in local git repos will already be on the users local /nix/store path. I think the solution here is to convert all template directories to implicit derivations by using something like this:

- path = ./mytemplate;
+ path = "${./mytemplate}";

@domenkozar I think this is is also an issue in the devenv repo and probably in many other repos as well. We noticed this because our CI for eomii/rules_ll#65 failed. Before I start sending PRs everywhere, is my proposed solution correct or am I missing something?

cc @jaroeichler

Should this repo have a build/test/autoupdate pipeline?

These flake templates track nixpkgs-unstable , however the do have flake.lock files, which should reduce breakage going forward into the future. (where i am from).

Should the these templates be 'nix flaked update' (ed) automagically and recomitted?

Also, be a good pattern add some 'nix flake check' code too, showing new flake users best practise

Weird breakage in templates (but fixable) can be the kiss of death for new users, and send them into a spiral of confusion and despair (but maybe slightly less despair form the Operating systems they just came from). This is a little more critical if @garbas wants to put them on the nixos learn web site.

Maybe if i want nix guarantee's I should by a toaster. ( which is my nickname).

Specifying codeowners?

Looking at #58 (comment), @Smaug123 raises a good point. It doesn't make sense for folks submitting a new template to add themselves as a codeowner unless they're also given commit access to this repo. Would it make more sense to adopt the maintainer's model that nixpkgs uses?

haskell-hello is broken

To reproduce:
$ nix flake init --template templates#haskell-hello
$ nix run

error: unable to execute '/nix/store/sbh1n1x3jb6wqai70cb27dgi5wfnl4rj-i31yf46plqpg0lz6vhxw07hg3lp77imv-source-0.0.0/bin/i31yf46plqpg0lz6vhxw07hg3lp77imv-source': No such file or directory

Check activity

Is this still a thing ? I thought it was a good idea and I have a couple of templates to share.

Add wasm-pack flake for Rust

I have a working flake for using wasm-pack in NixOS, but I am not sure if using rustc and rustup better than using rust-overlay like https://github.com/oxalica/rust-overlay. Any thoughts?

{
  description = "joli-string";

  outputs = { self, nixpkgs }:
    let system = "x86_64-linux";
    in {
      devShell.${system} = (({ pkgs, ... }:
        pkgs.mkShell {
          buildInputs = with pkgs; [
            wasm-pack
            cargo
            (rustc.override {
              stdenv = stdenv.override {
                targetPlatform = {
                  isRedox = false;
                  isMusl = false;
                  parsed = {
                    cpu = { name = "wasm32"; };
                    vendor = { name = "unknown"; };
                    kernel = { name = "unknown"; };
                    abi = { name = "unknown"; };
                  };
                };
              };
            })
            rustup
          ];

          shellHook = "";
        }) { pkgs = nixpkgs.legacyPackages.${system}; });
    };
}

No simple template with a proper build / dependency example

The templates feature for nix flake seems like a great opportunity to offer easy-setup build environments, particularly for individuals working on non-nix projects and just getting started.

One template I was unable to find was a simple example that's sufficient for nix develop and a simple Makefile build. That is, a template that might serve as a replacement for a simple default.nix / shell.nix, but follow the new flake pattern

with (import <nixpkgs> {});
stdenv.mkDerivation {
   name = "foo";
   buildInputs = [ ... ];
}

But the defaultTemplate and templates#trivial both just build an existing package, without any clarity as to build inputs / dev environment.

On the other hand, there are examples like simpleContainer, bash-hello, and rust-web-server are comparatively large, including nixos modules, VM tests, system compatibility, and other features.

Compat creates legacy default.nix/shell.nix files but doesn't show a fresh flake.nix

Can a template be added for a small reasonable build, such as for building a project which was not originally developed using nixpkgs? Possibly for a particular language like C but which in that case could be readily adapted

attribute self.lastModifiedDate missing

Context

Several templates in this repository have a reference to the attribute "self.lastModifiedDate", in each of these cases it appears that this property cant be read properly. Ive tested this with the bash-hello and the rust-web-server templates both of which give an error because of the missing attribute. The same holds for the attributes "self.lastModified" and "self.shortRev".

Steps to reproduce

Init one of the flakes in this repository, then build it.

$ nix flake init -t templates#bash-hello
$ nix build
error: attribute 'lastModifiedDate' missing

       at /nix/store/xhqq97pf0v5bd7nk1gwsirr4v621c2il-source/flake.nix:11:40:

           10|       # Generate a user-friendly version number.
           11|       version = builtins.substring 0 8 self.lastModifiedDate;
             |                                        ^
           12|
(use '--show-trace' to show detailed location information)

Possible solutions

  1. Make the flakes work as they are.
  2. Add a workaround into the templates.

Expected behaviour

Nix builds the flake without any problems.

Additional information

  • The nixpkgs flake.nix uses a workaround with a default value.
  • This commit message, which fixes the same issue, suggests that something about the path fetcher is broken.

The haskell template uses IFD

The haskell template uses "callCabal2nix" which in turn uses IFD which is forbidden in flakes by default for a good reason.

Are more maintainers needed for this repo?

Hey @domenkozar and others, I've noticed several issues and approved PRs growing old in this repo. I realize that it may not be as high a priority other parts of the nix project, but I do think the health of this repo is important for helping folks adopt templates. Does this repo need additional maintainers to help lighten the load? I'd be happy to volunteer.

Feature request: generator

Instead of copying flake and modify manually we should have a generator like many language have a build-system init.

I see two issues with the current template approach:

  • non parity (some have overlays other have flake-util rust/shell.nix other have complete description and some have overlay (like the precedent))
  • duplication that cause out of date template (All with different nixpkgs input 20.03 for instance)

Missing readme for rust template

"Each template ships with a tutorial (README.md) which explains in details how to use it and extend it."

this readme is missing from the rust directory

#40 broke `nix flake show templates`

The merge of #40 broke conformance with the schema because it has an assignment to haskell.nix under the templates attribute set. Now templates.haskell has a single attribute nix instead of the expected path and description.

Is `defaultPackage` deprecated?

I'm seeing some places mention that defaultPackage has been deprecated in favor of packages.default.

I see both the former and the latter used in various templates in this repository. As a newcomer it's leaving me confused what the recommended is?

bash-hello template broken with unstable

The tests for the bash-hello template (and possibly other templates aswell) don't work anymore with nixos-unstable.
There seem to have been changes in the testing libraries, but I didn't have any luck finding out how to fix them

Changing the inputs from:

  inputs.nixpkgs.url = "nixpkgs/nixos-21.05";

to

  inputs.nixpkgs.url = "nixpkgs/nixos-unstable";

Fails on nix flake show:

❯ nix flake show
git+file:///home/pinpox/code/github.com/pinpox/test123
β”œβ”€β”€β”€checks
β”‚   β”œβ”€β”€β”€aarch64-darwin
β”‚   β”œβ”€β”€β”€aarch64-linux
error: expected a derivation

What's "aated" and "pa>"

Are they typos or shorthand?

templates/full/flake.nix

Lines 80 to 86 in 2f86534

# The value of the follows attribute is aated sequence of input names denoting the pa>
# of inputs to be followed from the root flake. Overrides and follows can be combined, e.g.
inputs.nixops.url = "nixops";
inputs.dwarffs.url = "dwarffs";
inputs.dwarffs.inputs.nixpkgs.follows = "nixpkgs";

Setup CI

There should be github actions that tests the common commands on all flakes.

Would appreciate if someone can make a PR

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.