Code Monkey home page Code Monkey logo

dev-templates's Introduction

Nix flake templates for easy dev environments

built with nix

To initialize (where ${ENV} is listed in the table below):

nix flake init --template github:the-nix-way/dev-templates#${ENV}

Here's an example (for the rust template):

# Initialize in the current project
nix flake init --template github:the-nix-way/dev-templates#rust

# Create a new project
nix flake new --template github:the-nix-way/dev-templates#rust ${NEW_PROJECT_DIRECTORY}

How to use the templates

Once your preferred template has been initialized, you can use the provided shell in two ways:

  1. If you have nix-direnv installed, you can initialize the environment by running direnv allow.
  2. If you don't have nix-direnv installed, you can run nix develop to open up the Nix-defined shell.

Available templates

Language/framework/tool Template
Bun bun
C/C++ c-cpp
Clojure clojure
C# csharp
Cue cue
Dhall dhall
Elixir elixir
Elm elm
Empty (change at will) empty
Gleam gleam
Go go
Hashicorp tools hashi
Haxe haxe
Java java
Kotlin kotlin
LaTeX latex
Nickel nickel
Nim nim
Nix nix
Node.js node
OCaml ocaml
Open Policy Agent opa
PHP php
Protobuf protobuf
Pulumi pulumi
Purescript purescript
R r
Ruby ruby
Rust rust
Scala scala
[Shell] shell
Vlang vlang
Zig zig

Template contents

The sections below list what each template includes. In all cases, you're free to add and remove packages as you see fit; the templates are just boilerplate.

A dev template that's fully customizable.

  • Ruby 3.2.2, plus the standard Ruby tools (bundle, gem, etc.)
  • Rust, including cargo, Clippy, and the other standard tools. The Rust version is determined as follows, in order:

    • From the rust-toolchain.toml file if present
    • From the rust-toolchain file if present
    • Version 1.78.0 if neither is present
  • rust-analyzer 2024-04-29

  • [cargo-edit] 0.12.2

  • cargo-deny 0.14.23

Code organization

All of the templates have only the root flake as a flake input. That root flake provides a common revision of Nixpkgs and flake-utils to all the templates.

dev-templates's People

Contributors

573 avatar bwkam avatar derekbelrose avatar drupol avatar g0dm0d avatar hobr avatar jakuzure avatar joelbenway avatar lucperkins avatar noot-toon avatar nothingmuch avatar nueidris avatar s1syph0s avatar sgiath avatar sstubbs avatar taha-yassine avatar ymgyt avatar yvieta 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

dev-templates's Issues

bun template not found

I'm trying to use the bun template with the following command:

nix flake init --template github:the-nix-way/dev-templates#bun

However it is producing this error:

error: flake 'github:the-nix-way/dev-templates' does not provide attribute 'templates.bun' or 'bun'
Did you mean cue?

To see if there was some problem with my environment, I tried to use cue with:

nix flake init --template github:the-nix-way/dev-templates#cue

And that produced output indicating success:

wrote: /home/p/Development/.envrc
wrote: /home/p/Development/flake.lock
wrote: /home/p/Development/flake.nix

I'm new to Nix and flakes, but it does appear that bun is missing from file: https://github.com/the-nix-way/dev-templates/blob/main/flake.nix even though there is a folder for it. bun is listed in the README so I assume it was intended that it be a supported option.

Support for both LTS and latest node version?

The node template is currently set to use version 18, which is the current LTS version of node (actually 18.16.0, but that's a nixpkgs channel cutoff issue). It would be great to have a template for both LTS and the latest release, although I am not sure this is possible without switching to nixpkgs unstable/master.

Perhaps we could add an unstable input to the flake and use that explicitly?

Automate update flake.lock

Can you please add a workflow to the .github/workflows directory that automatically update the flake lock files? So if you initialize a template (for example rust) you get the newest version?

Rust template: nixpkgs is a thunk while a string, Boolean, or integer is expected

It seems that there is a superfluous inputs in the inputs {} of the rust template.

How to reproduce:

nix flake new --template "github:the-nix-way/dev-templates#rust" test_project
direnv allow test_project
cd test_project

The error will be:

direnv: using flake
error:
       … while evaluating flake attribute 'nixpkgs'

         at /nix/store/w0rll2jadma2hc6fjmfmb69fjhlqz7n6-source/flake.nix:5:5:

            4|   inputs = {
            5|     inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.*.tar.gz";
             |     ^
            6|     rust-overlay = {

       error: flake input attribute 'nixpkgs' is a thunk while a string, Boolean, or integer is expected

Tweaked Python file throws error

I ended up with this:

flake-utils.lib.eachDefaultSystem (system:
    let
      # overlays = [
      #   (self: super: {
      #     python = super.python311;
      #   })
      # ];

      # pkgs = import nixpkgs { inherit overlays system; };
      pkgs = import nixpkgs { inherit system; };
    in
    {
      devShells.default = pkgs.mkShell {
        packages = with pkgs; [ python311 virtualenv protobuf ] ++
          (with pkgs.python311Packages; [ pip protobuf ]);

        shellHook = ''
          ${pkgs.python}/bin/python --version
        '';
      };
    });

Don't really see the point of the overlay or of mach-nix.

which is giving me this error:

error: builder for '/nix/store/8v2nc3j1z6m1k3fzw51nn8sxlmxjp0h0-python3.11-pyext-0.8.drv' failed with exit code 1;
       last 10 log lines:
       > Executing setuptoolsBuildPhase
       > Traceback (most recent call last):
       >   File "/private/tmp/nix-build-python3.11-pyext-0.8.drv-0/source/nix_run_setup", line 8, in <module>
       >     exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\\r\\n', '\\n'), __file__, 'exec'))
       >   File "setup.py", line 6, in <module>
       >     import pyext
       >   File "/private/tmp/nix-build-python3.11-pyext-0.8.drv-0/source/pyext.py", line 118, in <module>
       >     oargspec = inspect.getargspec
       >                ^^^^^^^^^^^^^^^^^^
       > AttributeError: module 'inspect' has no attribute 'getargspec'. Did you mean: 'getargs'?
       For full logs, run 'nix log /nix/store/8v2nc3j1z6m1k3fzw51nn8sxlmxjp0h0-python3.11-pyext-0.8.drv'.
error: 1 dependencies of derivation '/nix/store/45hvqqc10rgqjyn716cpb23x3xf2qhq1-python3.11-protobuf-4.21.8.drv' failed to build
error: 1 dependencies of derivation '/nix/store/ixisv4p5j0yw8l9d8a372x7xg3gyic5q-nix-shell-env.drv' failed to build

Not sure what is happening here.

rust-analyzer support in vscode

rust-analyzer support in vscode

In order for rust analyzer fails because it needs rust-src. Using oxalica's cheat-sheet, I was able to achieve that. However, I am unsure if this is the optimal way to do so, so I'm merely reproducing it below.

{
  description = "A Nix-flake-based Rust development environment";

  inputs = {
    flake-utils.url = "github:numtide/flake-utils";
    nixpkgs.url = "github:NixOS/nixpkgs";
    rust-overlay.url = "github:oxalica/rust-overlay";
  };

  outputs =
    { self
    , flake-utils
    , nixpkgs
    , rust-overlay
    }:

    flake-utils.lib.eachDefaultSystem (system:
    let
      overlays = [
        (import rust-overlay)
        (self: super: {
          rustToolchain =
            let
              rust = super.rust-bin;
              toolchain =
                if builtins.pathExists ./rust-toolchain.toml then
                  rust.fromRustupToolchainFile ./rust-toolchain.toml
                else if builtins.pathExists ./rust-toolchain then
                  rust.fromRustupToolchainFile ./rust-toolchain
                else
                  rust.stable.latest.default;
            in
            toolchain.override {
              extensions = [ "rust-src" ];
            };
        })
      ];

      pkgs = import nixpkgs { inherit system overlays; };
    in
    {
      devShell = pkgs.mkShell {
        nativeBuildInputs = with pkgs; [
          rustToolchain
          # rust-src
          openssl
          pkg-config
          cargo-audit
          cargo-deny
          cargo-cross
          rust-analyzer
        ] ++ pkgs.lib.optionals (pkgs.stdenv.isLinux) (with pkgs; [ cargo-watch ]); # Currently broken on macOS

        shellHook = ''
          ${pkgs.rustToolchain}/bin/cargo --version
        '';
      };
    });
}

Elixir flake does not work on Linux

Hi thanks a ton for these templates, they have been very helpful.

When I tried the elixir template it did not work on Linux as it tries to install the mac packages, it looks like it was just missing some braces.

I will open a PR if that helps.

Thanks again for your efforts.

Add empty template

I don't think it is feasible to provide template for every single use case, so having an 'empty' template which would not contain any dependencies and give users ability to start with empty list of packages would be great.

difference with nix-flake-dev-environments

Hi, I don't really understand the difference between this repo and nix-flake-dev-environments.
They seem to deserve a pretty similar objective.
In my case, I set up a small shell function to be able to set up quickly dev env.

nix-quick () {
        nix flake new --template github:the-nix-way/dev-templates#$1 $2
}

Should I create two function for the two repos ?

Add swift template

Any chance to have a template for swift programming? with source-kit and other useful tools, thanks!

How can I add an unfree dependency to `buildInputs`?

Like jetbrains.idea-ultimate ref option b) below:

error: Package ‘idea-ultimate-2022.1.3’ in /nix/store/vxkgqbm8k5l9b6kp66dzcrb2w7qgdbgg-source/pkgs/applications/editors/jetbrains/default.nix:123 has an unfree license (‘unfree’), refusing to evaluate.

       a) To temporarily allow unfree packages, you can use an environment variable
          for a single invocation of the nix tools.

            $ export NIXPKGS_ALLOW_UNFREE=1

        Note: For `nix shell`, `nix build`, `nix develop` or any other Nix 2.4+
        (Flake) command, `--impure` must be passed in order to read this
        environment variable.

       b) For `nixos-rebuild` you can set
         { nixpkgs.config.allowUnfree = true; }
       in configuration.nix to override this.

       Alternatively you can configure a predicate to allow specific packages:
         { nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
             "idea-ultimate"
           ];
         }

       c) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
         { allowUnfree = true; }
       to ~/.config/nixpkgs/config.nix.
(use '--show-trace' to show detailed location information)
direnv: nix-direnv: renewed cache
direnv: export ~XDG_DATA_DIRS

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.