Giter VIP home page Giter VIP logo

fastapi-nixos-starter-pack's Introduction

FastAPI NixOS Starter Pack

This tutorial shows how to deploy an API on the Web using FastAPI on a NixOS system.

Implementing the API

1. Install direnv

Add to your /etc/nixos/confirguration.nix

  environment.systemPackages = with pkgs; [
    direnv
  ];

2. Clone this repo

git clone [email protected]:nphilou/fastapi-nixos-starter-pack.git

3. Allow direnv

You'll probably get something like

direnv: error /home/.../fastapi-nixos-starter-pack/.envrc is blocked. Run `direnv allow` to approve its content 

So you just have to run:

direnv allow

4. Create a virtual env (could be useful if you are using Pycharm)

nix-build env.nix -o venv

Then tell PyCharm to use this venv

5. Run the API

uvicorn main:app --reload

or using Python:

python main.py

The reload param is optional. If everything is working correctly, you can go to the next step.

Deploy the API on a NixOS system

  1. Use a DNS Service (like https://dns.he.net/) to link the domain name to your server

yourdomainname.com -> your_ip_address (A record)

  1. Create some port forwarding on your router

your_ip_address -> your_local_ip_address (on ports 80 and 443 for example)

  1. Import myproject.nix into your system:

This file contains the backend service, the reverse proxy and the SSL certification system

{ config, pkgs, ... }:

{
  imports =
    [
      /home/.../myproject.nix
    ];
}

and sudo nixos-rebuild switch.

fastapi-nixos-starter-pack's People

Contributors

nphilou avatar

Stargazers

Gunnar Þór Magnússon avatar

Watchers

 avatar  avatar

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.