Giter Club home page Giter Club logo

todomvc-nix's Introduction

TodoMVC-Nix

One-stop reference to build TodoMVC application inside the Nix world

built with nix

Nix Flake

Are you new to Nix? Or are you use Nix, but still don't know how Nix is useful for your company? Maybe you have use Nix/NixOS in your current project, and you want to know how other project (using other programming language) fits into Nix world? TodoMVC-Nix can help you to understand how your project is structured using Nix to ease your project development setting.

This project's goal is to provide Nix user on every level (beginner, intermediate, and advance) a reference for building project using Nix programming language new feature called Flakes. This project contains several project written in different programming language and also how to nixified it.

Related article: todomvc-nix: One-Stop Solution for Developing Projects Using Nix

Structure

Technology Stack

[Back to the Table of Contents] ↑

TodoMVC-Nix has several examples on how fullstack project is structured using Nix Flakes. This stack can be used as an example for early stage startup or some new project which might want to consider to use Nix in their development journey. The stack consists of the following:

  • Backend
    • Rust
    • Haskell
  • Frontend
    • Rust
    • Haskell
  • Database
    • PostgreSQL

Another language and stack will be added accordingly.

Get Started

[Back to the Table of Contents] ↑

Before exploring the project, there are several things that need to be prepared first as explained below.

Prerequisites

[Back to the Table of Contents] ↑

Make sure that you have the following package installed in your machine:

Setup

[Back to the Table of Contents] ↑

Non-nix-flake user

This repository can be used using plain nix-build or nix-shell. This is possible with the help of flake-compat as mentioned in default.nix. To build the package, just run:

$ nix-build -A defaultNix.legacyPackages.x86_64-linux.nix.haskellBackend

and to enter into Nix shell, run:

$ nix-shell

Nix-flake user

If you want to use this repo with flakes feature, please enable it using the following method:

Linux and Windows Subsystem Linux 2 (WSL2)

Install Nix as instructed above. Next, install nixUnstable by running the following code:

nix-env -iA nixpkgs.nixFlakes

Lastly, open your ~/.config/nix/nix.conf or /etc/nix/nix.conf file and add:

experimental-features = nix-command flakes

NixOS

Add the following code into your configuration.nix:

{ pkgs, ... }: {
  nix = {
    package = pkgs.nixFlakes;
      extraOptions = ''
        experimental-features = nix-command flakes
      '';
  };
}

Usage

[Back to the Table of Contents] ↑

Clone this repository, and enter into it:

$ git clone https://github.com/nix-community/todomvc-nix.git
$ cd todomvc-nix

run nix develop and wait until the downloading/caching the dependencies are finished.

Once it is finished, you can refer to the documentation below:

For Developers

[Back to the Table of Contents] ↑

Build

[Back to the Table of Contents] ↑

Building package in Nix Flakes is simply by running the following code:

nix build .#todomvc.nix.haskellBackend

The above example will build todo-haskell package which is a backend built in Haskell. Here is the breakdown of the command:

  • nix build - is a nix v2 command to build package
  • .#todomvc.nix.haskellBackend
    • . - it means the directory contain flake.nix,
    • # - it is to separate between directory and package,
    • todomvc.nix.haskellBackend - is the package describe in the overlay that we want to build.

The result of the build will be available in the result folder.

Run

[Back to the Table of Contents] ↑

By running nix develop in the project, some command as written in shell.nix will be available in the PATH.

There is also custom script that can be created to simplify the command as specified in the commands attributes in shell.nix.

For example, command pgstart can be run to start the postgresql server. pgstart is custom script based on the following code:

{
  name = "pgstart";
  help = "start psql service";
  command = "${todomvc.nix.database.pgutil.start_pg} || echo '''PG start failed''' ";
}

Please refer to shell.nix for further command and package.

Acknowledgements

[Back to the Table of Contents] ↑

Most of the code that we put in this repo has previously been made by others. Here we credit the repository that we take the code from.

todomvc-nix's People

Contributors

dependabot[bot] avatar jfroche avatar mrsekut avatar nicknovitski avatar peterbecich avatar r-k-b avatar rizary avatar roberth avatar workflow avatar zimbatm 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

todomvc-nix's Issues

Adding new language as backend and frontend

This repo is the first repo that I use as an example when learning how to package Haskell backend. It would be nice if I can add Rust and Golang into the backend.

In the frontend side, I would like to add Typescript, or Svelte.

Rust backend still doesn't build

After updating nix/rust-backend/default.nix as well as Cargo.lock, running nix build .#nix.rustBackend fails with

error[E0277]: the trait bound `std::string::String: log::kv::value::ToValue` is not satisfied
  --> /build/rust-backend-0.1.0-vendor.tar.gz/tide/src/log/middleware.rs:43:9
   |
43 | /         log::info!("<-- Request received", {
44 | |             method: method,
45 | |             path: path,
46 | |         });
   | |___________^ the trait `log::kv::value::ToValue` is not implemented for `std::string::String`
   |
   = note: required for the cast to the object type `dyn log::kv::value::ToValue`
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

Here's a branch that has the updates I ran.

Unable to run `nix develop`

I get the following warning when running nix develop:

error: hash mismatch in fixed-output derivation '/nix/store/c7zzc9z2qn2958y9xb2cq2k9z9lpcyb7-channel-rust-stable.toml.drv':
         specified: sha256-+EFKtTDUlFY0aUXdSvrz7tAhf5/GsqyVOp8skXGTEJM=
            got:    sha256-MJyH6FPVI7diJql9d+pifu5aoqejvvXyJ+6WSJDWaIA=

fails to build on darwin

Trying to follow the Readme.md:

%  git clone https://github.com/nix-community/todomvc-nix           
Cloning into 'todomvc-nix'...
remote: Enumerating objects: 1165, done.
remote: Counting objects: 100% (763/763), done.
remote: Compressing objects: 100% (426/426), done.
remote: Total 1165 (delta 341), reused 649 (delta 250), pack-reused 402
Receiving objects: 100% (1165/1165), 9.83 MiB | 2.42 MiB/s, done.
Resolving deltas: 100% (516/516), done.
sloth% cd todomvc-nix 
sloth% nix develop
error: flake 'git+file:///Users/dap/proj/todomvc-nix' does not provide attribute 'devShells.x86_64-darwin.default', 'devShell.x86_64-darwin', 'packages.x86_64-darwin.default' or 'defaultPackage.x86_64-darwin'
       Did you mean devShell

System info:

System Version: macOS 12.3 (21E230)
Kernel Version: Darwin 21.4.0
Boot Volume: Macintosh HD
Boot Mode: Normal
...
Secure Virtual Memory: Enabled
System Integrity Protection: Enabled
Time since boot: 9 days 7:22

% nix --version
nix (Nix) 2.7.0

Nixpkgs pin broken on release-18.09

I'm getting this on NixOS stable:

$ nix-build 
building '/nix/store/5yikvvp7wclvq9x2i1vfnwwx4il5x0y5-931a0b8be80661902baefb3e7d55403be893e0e6.tar.gz-unpacked.drv'...
while setting up the build environment: executing '/nix/store/czx8vkrb9jdgjyz8qfksh10vrnqa723l-bash-4.4-p23/bin/bash': No such file or directory
builder for '/nix/store/5yikvvp7wclvq9x2i1vfnwwx4il5x0y5-931a0b8be80661902baefb3e7d55403be893e0e6.tar.gz-unpacked.drv' failed with exit code 1
error: build of '/nix/store/5yikvvp7wclvq9x2i1vfnwwx4il5x0y5-931a0b8be80661902baefb3e7d55403be893e0e6.tar.gz-unpacked.drv' failed

After updating stale rust-stable sha256, Rust backend doesn't build

On this branch, I updated the rust-stable sha256 since it was old. After doing that, I couldn't build the Rust backend, so I tried cargo update, but still couldn't build. I ran nix flake update hoping that would improve the situation, but no dice. After doing all of this, here's what happens when I try to build the backend:

   Compiling tide v0.13.0
   Compiling sqlx-macros v0.3.5
error[E0277]: the trait bound `std::string::String: log::kv::value::ToValue` is not satisfied
  --> /build/rust-backend-0.1.0-vendor.tar.gz/tide/src/log/middleware.rs:43:9
   |
43 | /         log::info!("<-- Request received", {
44 | |             method: method,
45 | |             path: path,
46 | |         });
   | |___________^ the trait `log::kv::value::ToValue` is not implemented for `std::string::String`
   |
   = note: required for the cast to the object type `dyn log::kv::value::ToValue`
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

I'm not knowledgeable with Rust, so I'm not sure how to handle this.

Adding new CD/CI system from dev to prod

I am in the middle of working on something similar to this repo. Then I thought it will be nice if I just move all my work into todomvc-nix.

My idea is to add the new Flake system, and GitHub action into the repo so every newcomer to Nix language can use this repo as their starting project.

To add some notes, I see some new posts on using Nix and Bazel together into the project, and some people found it too difficult to integrate it. I am planning to add into this repo, what do you think?

hash mismatch when running `nix develop`

I ran nix develop and got the following message:

error: --- Error ---------------------------------------------------------------------------------------------------------------------------- nix
hash mismatch in fixed-output derivation '/nix/store/5pb8dycgqsrspqg7kpdsp0fchnb5f9d6-channel-rust-stable.toml.drv':
  specified: sha256-7zt+rHZxx+ha4P/UnT2aNIuBtjPkejVI2PycAt+Apiw=
     got:    sha256-KCh2UBGtdlBJ/4UOqZlxUtcyefv7MH1neoVNV4z0nWs=
(use '--show-trace' to show detailed location information)

I'm running NixOS 20.09 with flake support enabled.

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.