This commit is contained in:
commit
95a533c876
451 changed files with 18255 additions and 0 deletions
1
templates/dev/c-hello/.envrc
Normal file
1
templates/dev/c-hello/.envrc
Normal file
|
|
@ -0,0 +1 @@
|
|||
use flake
|
||||
23
templates/dev/c-hello/.github/workflows/c-nix.yml
vendored
Normal file
23
templates/dev/c-hello/.github/workflows/c-nix.yml
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
name: C Nix Pipeline
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
build-and-test:
|
||||
name: Build and Test
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Nix
|
||||
uses: cachix/install-nix-action@v18
|
||||
with:
|
||||
nix_path: nixpkgs=channel:nixos-unstable
|
||||
|
||||
- name: Run nix flake check
|
||||
run: nix flake check
|
||||
7
templates/dev/c-hello/.gitignore
vendored
Normal file
7
templates/dev/c-hello/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
.cache/
|
||||
.direnv/
|
||||
.pre-commit-config.yaml
|
||||
bin/
|
||||
build/
|
||||
compile_commands.json
|
||||
result/
|
||||
51
templates/dev/c-hello/Makefile
Normal file
51
templates/dev/c-hello/Makefile
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
PNAME = hello-world
|
||||
|
||||
BUILD_DIR = build
|
||||
INCLUDE_DIR = include
|
||||
SRC_DIR = src
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -I$(INCLUDE_DIR) -Wall -Wextra -g
|
||||
|
||||
TARGET = $(BUILD_DIR)/$(PNAME)
|
||||
SRCS = $(wildcard $(SRC_DIR)/*.c)
|
||||
OBJS = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(SRCS))
|
||||
|
||||
# Default target
|
||||
all: $(TARGET)
|
||||
|
||||
# Build the executable
|
||||
$(TARGET): $(OBJS)
|
||||
$(CC) $(OBJS) -o $@
|
||||
|
||||
# Compile source files into object files
|
||||
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c | $(BUILD_DIR)
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
# Create the build directory
|
||||
$(BUILD_DIR):
|
||||
mkdir -p $(BUILD_DIR)
|
||||
|
||||
# Run the executable
|
||||
run: $(TARGET)
|
||||
@$(TARGET)
|
||||
|
||||
# Clean built files
|
||||
clean:
|
||||
rm -rf $(BUILD_DIR)
|
||||
|
||||
# Clean then build
|
||||
rebuild: clean all
|
||||
|
||||
# Display help information
|
||||
help:
|
||||
@echo "Makefile Usage:"
|
||||
@echo ""
|
||||
@echo " make - Builds the executable (default)"
|
||||
@echo " make all - Same as 'make'"
|
||||
@echo " make run - Builds the executable if needed and then runs it"
|
||||
@echo " make clean - Removes the build directory and all built files"
|
||||
@echo " make rebuild - Performs a clean first, then builds the project"
|
||||
@echo " make help - Displays this help message"
|
||||
|
||||
.PHONY: all clean run rebuild help
|
||||
2
templates/dev/c-hello/build.sh
Normal file
2
templates/dev/c-hello/build.sh
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
make clean
|
||||
bear --output build/compile_commands.json -- make all
|
||||
144
templates/dev/c-hello/flake.nix
Normal file
144
templates/dev/c-hello/flake.nix
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
{
|
||||
description = "A hello world template in C";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "nixpkgs/nixos-unstable";
|
||||
pre-commit-hooks = {
|
||||
url = "github:cachix/pre-commit-hooks.nix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
};
|
||||
|
||||
outputs =
|
||||
{
|
||||
self,
|
||||
nixpkgs,
|
||||
pre-commit-hooks,
|
||||
...
|
||||
}:
|
||||
let
|
||||
pname = "hello-world"; # Also change this in the Makefile
|
||||
version = "0.1.0";
|
||||
|
||||
supportedSystems = [
|
||||
"x86_64-linux"
|
||||
"aarch64-linux"
|
||||
"x86_64-darwin"
|
||||
"aarch64-darwin"
|
||||
];
|
||||
|
||||
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
|
||||
|
||||
nixpkgsFor = forAllSystems (
|
||||
system:
|
||||
import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [ self.overlays.default ];
|
||||
}
|
||||
);
|
||||
in
|
||||
{
|
||||
overlays.default = final: prev: {
|
||||
"${pname}" = final.stdenv.mkDerivation rec {
|
||||
inherit pname version;
|
||||
src = ./.;
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp build/${pname} $out/bin/
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
packages = forAllSystems (system: {
|
||||
default = nixpkgsFor.${system}."${pname}";
|
||||
"${pname}" = nixpkgsFor.${system}."${pname}";
|
||||
});
|
||||
|
||||
devShells = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgsFor.${system};
|
||||
in
|
||||
{
|
||||
default = pkgs.mkShell {
|
||||
buildInputs =
|
||||
self.checks.${system}.pre-commit-check.enabledPackages
|
||||
++ (with pkgs; [
|
||||
bear
|
||||
coreutils
|
||||
gcc
|
||||
gdb
|
||||
gnumake
|
||||
]);
|
||||
shellHook = self.checks.${system}.pre-commit-check.shellHook + ''
|
||||
export LD_LIBRARY_PATH=${pkgs.stdenv.cc.cc.lib}/lib:$LD_LIBRARY_PATH
|
||||
'';
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
formatter = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
config = self.checks.${system}.pre-commit-check.config;
|
||||
inherit (config) package configFile;
|
||||
script = ''
|
||||
${pkgs.lib.getExe package} run --all-files --config ${configFile}
|
||||
'';
|
||||
in
|
||||
pkgs.writeShellScriptBin "pre-commit-run" script
|
||||
);
|
||||
|
||||
checks = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgsFor.${system};
|
||||
flakePkgs = self.packages.${system};
|
||||
in
|
||||
{
|
||||
build-packages = pkgs.linkFarm "flake-packages-${system}" flakePkgs;
|
||||
|
||||
integration-test =
|
||||
let
|
||||
exe = "${flakePkgs.${pname}}/bin/${pname}";
|
||||
in
|
||||
pkgs.runCommand "${pname}-test"
|
||||
{
|
||||
nativeBuildInputs = [
|
||||
pkgs.synixutils
|
||||
flakePkgs.${pname}
|
||||
];
|
||||
}
|
||||
''
|
||||
assert_equal() {
|
||||
if [[ "$1" != "$2" ]]; then
|
||||
echo "Test failed: Expected '$1' but got '$2'"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
exp1="Hello, world!"
|
||||
out1="$(${exe})"
|
||||
|
||||
assert_equal "$exp1" "$out1"
|
||||
|
||||
echo "Test passed!" > $out
|
||||
'';
|
||||
|
||||
pre-commit-check = pre-commit-hooks.lib.${system}.run {
|
||||
src = ./.;
|
||||
hooks = {
|
||||
nixfmt = {
|
||||
enable = true;
|
||||
};
|
||||
clang-format = {
|
||||
enable = true;
|
||||
types_or = nixpkgs.lib.mkForce [ "c" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
8
templates/dev/c-hello/src/main.c
Normal file
8
templates/dev/c-hello/src/main.c
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
printf("Hello, world!\n");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
1
templates/dev/esp-blink/.envrc
Normal file
1
templates/dev/esp-blink/.envrc
Normal file
|
|
@ -0,0 +1 @@
|
|||
use flake
|
||||
6
templates/dev/esp-blink/.gitignore
vendored
Normal file
6
templates/dev/esp-blink/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
.cache/
|
||||
.direnv/
|
||||
build/
|
||||
managed_components/
|
||||
sdkconfig
|
||||
sdkconfig.old
|
||||
5
templates/dev/esp-blink/CMakeLists.txt
Normal file
5
templates/dev/esp-blink/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
idf_build_set_property(MINIMAL_BUILD ON)
|
||||
project(blink)
|
||||
33
templates/dev/esp-blink/README.md
Normal file
33
templates/dev/esp-blink/README.md
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# ESP32 blink template
|
||||
|
||||
Set `BLINK_GPIO` to your LED pin in [`main/main.c`](./main/main.c).
|
||||
|
||||
## Clean the build directory
|
||||
|
||||
```bash
|
||||
idf.py fullclean
|
||||
```
|
||||
|
||||
## Set the build target
|
||||
|
||||
```bash
|
||||
idf.py set-target esp32s3
|
||||
```
|
||||
|
||||
## Open configuration menu
|
||||
|
||||
```bash
|
||||
idf.py menuconfig
|
||||
```
|
||||
|
||||
## Build the project
|
||||
|
||||
```bash
|
||||
idf.py all
|
||||
```
|
||||
|
||||
## Flash the binary
|
||||
|
||||
```bash
|
||||
idf.py flash
|
||||
```
|
||||
103
templates/dev/esp-blink/flake.nix
Normal file
103
templates/dev/esp-blink/flake.nix
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
{
|
||||
description = "A blink template for ESP32";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "nixpkgs/nixpkgs-unstable";
|
||||
esp = {
|
||||
url = "github:mirrexagon/nixpkgs-esp-dev";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
pre-commit-hooks = {
|
||||
url = "github:cachix/pre-commit-hooks.nix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
};
|
||||
|
||||
outputs =
|
||||
{
|
||||
self,
|
||||
nixpkgs,
|
||||
esp,
|
||||
pre-commit-hooks,
|
||||
...
|
||||
}:
|
||||
let
|
||||
pname = "blink"; # Also change this in CMakeLists.txt
|
||||
version = "0.1.0";
|
||||
|
||||
supportedSystems = [
|
||||
"x86_64-linux"
|
||||
"aarch64-linux"
|
||||
"x86_64-darwin"
|
||||
"aarch64-darwin"
|
||||
];
|
||||
|
||||
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
|
||||
|
||||
nixpkgsFor = forAllSystems (
|
||||
system:
|
||||
import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [
|
||||
self.overlays.default
|
||||
esp.overlays.default
|
||||
];
|
||||
}
|
||||
);
|
||||
in
|
||||
{
|
||||
overlays.default = final: prev: { };
|
||||
|
||||
packages = forAllSystems (system: { });
|
||||
|
||||
devShells = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgsFor.${system};
|
||||
in
|
||||
{
|
||||
default = esp.devShells."${system}".default;
|
||||
}
|
||||
);
|
||||
|
||||
formatter = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
config = self.checks.${system}.pre-commit-check.config;
|
||||
inherit (config) package configFile;
|
||||
script = ''
|
||||
${pkgs.lib.getExe package} run --all-files --config ${configFile}
|
||||
'';
|
||||
in
|
||||
pkgs.writeShellScriptBin "pre-commit-run" script
|
||||
);
|
||||
|
||||
checks = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgsFor.${system};
|
||||
flakePkgs = self.packages.${system};
|
||||
in
|
||||
{
|
||||
build-packages = pkgs.linkFarm "flake-packages-${system}" flakePkgs;
|
||||
|
||||
pre-commit-check = pre-commit-hooks.lib.${system}.run {
|
||||
src = ./.;
|
||||
hooks = {
|
||||
nixfmt = {
|
||||
enable = true;
|
||||
};
|
||||
clang-format = {
|
||||
enable = true;
|
||||
types_or = nixpkgs.lib.mkForce [
|
||||
"c"
|
||||
"cpp"
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
4
templates/dev/esp-blink/main/CMakeLists.txt
Normal file
4
templates/dev/esp-blink/main/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
idf_component_register(
|
||||
SRCS "main.c"
|
||||
INCLUDE_DIRS "."
|
||||
)
|
||||
2
templates/dev/esp-blink/main/idf_component.yml
Normal file
2
templates/dev/esp-blink/main/idf_component.yml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
espressif/led_strip: "^3.0.0"
|
||||
33
templates/dev/esp-blink/main/main.c
Normal file
33
templates/dev/esp-blink/main/main.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#include "driver/gpio.h"
|
||||
#include "esp_log.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static const char *TAG = "BLINK";
|
||||
|
||||
#define BLINK_GPIO 38
|
||||
#define BLINK_PERIOD 1000
|
||||
|
||||
static uint8_t s_led_state = 0;
|
||||
|
||||
static void blink_led(void) { gpio_set_level(BLINK_GPIO, s_led_state); }
|
||||
|
||||
static void configure_led(void) {
|
||||
ESP_LOGI(TAG, "Example configured to blink GPIO LED!");
|
||||
gpio_reset_pin(BLINK_GPIO);
|
||||
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
|
||||
}
|
||||
|
||||
static void delay_ms(uint32_t ms) { vTaskDelay(pdMS_TO_TICKS(ms)); }
|
||||
|
||||
void app_main(void) {
|
||||
configure_led();
|
||||
|
||||
while (1) {
|
||||
ESP_LOGI(TAG, "Turning the LED %s!", s_led_state == true ? "ON" : "OFF");
|
||||
blink_led();
|
||||
s_led_state = !s_led_state;
|
||||
delay_ms(BLINK_PERIOD);
|
||||
}
|
||||
}
|
||||
1
templates/dev/flask-hello/.envrc
Normal file
1
templates/dev/flask-hello/.envrc
Normal file
|
|
@ -0,0 +1 @@
|
|||
use flake
|
||||
23
templates/dev/flask-hello/.github/workflows/python-nix.yml
vendored
Normal file
23
templates/dev/flask-hello/.github/workflows/python-nix.yml
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
name: Python Nix Pipeline
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
build-and-test:
|
||||
name: Build and Test
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Nix
|
||||
uses: cachix/install-nix-action@v18
|
||||
with:
|
||||
nix_path: nixpkgs=channel:nixos-unstable
|
||||
|
||||
- name: Run nix flake check
|
||||
run: nix flake check
|
||||
30
templates/dev/flask-hello/.gitignore
vendored
Normal file
30
templates/dev/flask-hello/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
# Byte-compiled Python files
|
||||
*.py[cod]
|
||||
__pycache__/
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
*.egg
|
||||
*.egg-info/
|
||||
.coverage
|
||||
.htmlcov/
|
||||
.pytest_cache/
|
||||
.tox/
|
||||
.venv/
|
||||
.direnv/
|
||||
ENV/
|
||||
build/
|
||||
dist/
|
||||
env.bak/
|
||||
env/
|
||||
venv.bak/
|
||||
venv/
|
||||
|
||||
# IDE/editor files
|
||||
*.sublime-project
|
||||
*.sublime-workspace
|
||||
.idea/
|
||||
.vscode/
|
||||
|
||||
# Nix-related files
|
||||
result
|
||||
5
templates/dev/flask-hello/app.py
Normal file
5
templates/dev/flask-hello/app.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from flask_hello import create_app
|
||||
|
||||
app = create_app()
|
||||
77
templates/dev/flask-hello/flake.nix
Normal file
77
templates/dev/flask-hello/flake.nix
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
{
|
||||
description = "A hello world template for Python Flask";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
pre-commit-hooks = {
|
||||
url = "github:cachix/pre-commit-hooks.nix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
};
|
||||
|
||||
outputs =
|
||||
{
|
||||
self,
|
||||
nixpkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
supportedSystems = [
|
||||
"x86_64-linux"
|
||||
"aarch64-linux"
|
||||
"x86_64-darwin"
|
||||
"aarch64-darwin"
|
||||
];
|
||||
|
||||
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
|
||||
|
||||
nixpkgsFor = forAllSystems (
|
||||
system:
|
||||
import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [ self.overlays.default ];
|
||||
}
|
||||
);
|
||||
in
|
||||
{
|
||||
overlays.default = final: _prev: {
|
||||
flask_hello = self.packages.${final.system}.default;
|
||||
};
|
||||
|
||||
packages = forAllSystems (system: {
|
||||
default = nixpkgsFor.${system}.callPackage ./nix/package.nix { };
|
||||
});
|
||||
|
||||
devShells = forAllSystems (system: {
|
||||
default = import ./nix/shell.nix { pkgs = nixpkgsFor.${system}; };
|
||||
});
|
||||
|
||||
nixosModules = {
|
||||
flask_hello = import ./nix/module.nix;
|
||||
};
|
||||
|
||||
formatter = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
config = self.checks.${system}.pre-commit-check.config;
|
||||
inherit (config) package configFile;
|
||||
script = ''
|
||||
${pkgs.lib.getExe package} run --all-files --config ${configFile}
|
||||
'';
|
||||
in
|
||||
pkgs.writeShellScriptBin "pre-commit-run" script
|
||||
);
|
||||
|
||||
checks = forAllSystems (system: {
|
||||
build-packages = nixpkgsFor."${system}".linkFarm "flake-packages-${system}" self.packages.${system};
|
||||
pre-commit-check = self.inputs.pre-commit-hooks.lib.${system}.run {
|
||||
src = ./.;
|
||||
hooks = {
|
||||
nixfmt.enable = true;
|
||||
black.enable = true;
|
||||
};
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
17
templates/dev/flask-hello/flask_hello/__init__.py
Normal file
17
templates/dev/flask-hello/flask_hello/__init__.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
from flask import Flask
|
||||
|
||||
|
||||
def create_app():
|
||||
app = Flask(__name__)
|
||||
|
||||
from .blueprints.home import home_bp
|
||||
|
||||
app.register_blueprint(home_bp)
|
||||
|
||||
from flask import render_template
|
||||
|
||||
@app.errorhandler(404)
|
||||
def not_found_error(error):
|
||||
return render_template("errors.html", error="Page not found"), 404
|
||||
|
||||
return app
|
||||
8
templates/dev/flask-hello/flask_hello/blueprints/home.py
Normal file
8
templates/dev/flask-hello/flask_hello/blueprints/home.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from flask import Blueprint, render_template
|
||||
|
||||
home_bp = Blueprint("home", __name__)
|
||||
|
||||
|
||||
@home_bp.route("/")
|
||||
def index():
|
||||
return render_template("index.html")
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
margin: 40px;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #333;
|
||||
}
|
||||
12
templates/dev/flask-hello/flask_hello/templates/base.html
Normal file
12
templates/dev/flask-hello/flask_hello/templates/base.html
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{% block title %}Flask App{% endblock %}</title>
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
|
||||
</head>
|
||||
<body>
|
||||
{% block content %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Error</h1>
|
||||
<p>{{ error }}</p>
|
||||
<a href="{{ url_for('home.index') }}">Go Home</a>
|
||||
{% endblock %}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Hello, World!</h1>
|
||||
<p>Welcome to your Flask application.</p>
|
||||
{% endblock %}
|
||||
132
templates/dev/flask-hello/nix/module.nix
Normal file
132
templates/dev/flask-hello/nix/module.nix
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
{
|
||||
inputs,
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
cfg = config.services.flask_hello;
|
||||
domain = config.networking.domain;
|
||||
fqdn = if (cfg.nginx.subdomain != "") then "${cfg.nginx.subdomain}.${domain}" else domain;
|
||||
|
||||
python-with-packages = pkgs.python3.withPackages (
|
||||
p: with p; [
|
||||
flask
|
||||
]
|
||||
);
|
||||
|
||||
inherit (lib)
|
||||
concatStringsSep
|
||||
getExe
|
||||
mkDefault
|
||||
mkEnableOption
|
||||
mkIf
|
||||
mkOption
|
||||
mkPackageOption
|
||||
types
|
||||
;
|
||||
in
|
||||
{
|
||||
options.services.flask_hello = {
|
||||
enable = mkEnableOption "Flask Hello World service.";
|
||||
|
||||
package = mkPackageOption pkgs "flask_hello" { };
|
||||
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 5000;
|
||||
description = "The port to listen on.";
|
||||
};
|
||||
|
||||
user = mkOption {
|
||||
type = types.str;
|
||||
description = "The user the Flask service will run as.";
|
||||
default = "flaskapp";
|
||||
};
|
||||
|
||||
group = mkOption {
|
||||
type = types.str;
|
||||
description = "The group the Flask service will run as.";
|
||||
default = "flaskapp";
|
||||
};
|
||||
|
||||
nginx = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = "Enable Nginx as a reverse proxy for the Flask application.";
|
||||
};
|
||||
subdomain = mkOption {
|
||||
type = types.str;
|
||||
default = "flask_hello";
|
||||
description = "Subdomain for the Nginx virtual host. Leave empty for root domain.";
|
||||
};
|
||||
ssl = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = "Enable SSL for the Nginx virtual host using ACME.";
|
||||
};
|
||||
};
|
||||
|
||||
gunicorn.extraArgs = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = "Extra arguments for gunicorn.";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
nixpkgs.overlays = [ inputs.flask_hello.overlays.default ];
|
||||
|
||||
networking.firewall.allowedTCPPorts = [
|
||||
80 # ACME challenge
|
||||
443
|
||||
];
|
||||
|
||||
systemd.services.flask_hello = {
|
||||
description = "Flask Hello World";
|
||||
after = [ "network.target" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
environment = {
|
||||
PYTHONPATH = "${python-with-packages}/${python-with-packages.sitePackages}";
|
||||
};
|
||||
serviceConfig = {
|
||||
ExecStart = ''
|
||||
${getExe pkgs.python3Packages.gunicorn} \
|
||||
--bind=127.0.0.1:${toString cfg.port} \
|
||||
${concatStringsSep " " cfg.gunicorn.extraArgs} \
|
||||
app:app
|
||||
'';
|
||||
WorkingDirectory = "${cfg.package}";
|
||||
Restart = "on-failure";
|
||||
User = cfg.user;
|
||||
Group = cfg.group;
|
||||
};
|
||||
};
|
||||
|
||||
users.users."${cfg.user}" = {
|
||||
home = "/var/lib/${cfg.user}";
|
||||
isSystemUser = true;
|
||||
group = cfg.group;
|
||||
};
|
||||
users.groups."${cfg.group}" = { };
|
||||
|
||||
services.nginx = mkIf cfg.nginx.enable {
|
||||
enable = mkDefault true;
|
||||
virtualHosts."${fqdn}" = {
|
||||
enableACME = cfg.nginx.ssl;
|
||||
forceSSL = cfg.nginx.ssl;
|
||||
locations."/".proxyPass = "http://127.0.0.1:${toString cfg.port}";
|
||||
};
|
||||
};
|
||||
|
||||
security.acme = mkIf (cfg.nginx.enable && cfg.nginx.ssl) {
|
||||
acceptTerms = true;
|
||||
defaults.email = mkDefault "postmaster@${domain}";
|
||||
defaults.webroot = mkDefault "/var/lib/acme/acme-challenge";
|
||||
certs."${domain}".postRun = "systemctl reload nginx.service";
|
||||
};
|
||||
};
|
||||
}
|
||||
31
templates/dev/flask-hello/nix/package.nix
Normal file
31
templates/dev/flask-hello/nix/package.nix
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
python3,
|
||||
...
|
||||
}:
|
||||
|
||||
python3.pkgs.buildPythonApplication rec {
|
||||
pname = "flask_hello";
|
||||
version = "0.1.0";
|
||||
pyproject = true;
|
||||
|
||||
build-system = [ python3.pkgs.setuptools ];
|
||||
|
||||
dependencies = with python3.pkgs; [
|
||||
flask
|
||||
];
|
||||
|
||||
src = ../.;
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
|
||||
mkdir -p $out
|
||||
cp -r $src/${pname} $out/
|
||||
cp $src/app.py $out/
|
||||
chmod +x $out/app.py
|
||||
|
||||
runHook postInstall
|
||||
'';
|
||||
|
||||
doCheck = false;
|
||||
}
|
||||
17
templates/dev/flask-hello/nix/shell.nix
Normal file
17
templates/dev/flask-hello/nix/shell.nix
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
...
|
||||
}:
|
||||
|
||||
pkgs.mkShell {
|
||||
buildInputs = [
|
||||
(pkgs.python3.withPackages (
|
||||
p: with p; [
|
||||
flask
|
||||
gunicorn
|
||||
]
|
||||
))
|
||||
pkgs.nixfmt-tree
|
||||
pkgs.black
|
||||
];
|
||||
}
|
||||
13
templates/dev/flask-hello/pyproject.toml
Normal file
13
templates/dev/flask-hello/pyproject.toml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
[build-system]
|
||||
requires = ["setuptools"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "flask_hello"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"flask",
|
||||
]
|
||||
|
||||
[tool.setuptools.packages.find]
|
||||
include = ["flask_hello*"]
|
||||
23
templates/dev/py-hello/.github/workflows/python-nix.yml
vendored
Normal file
23
templates/dev/py-hello/.github/workflows/python-nix.yml
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
name: Python Nix Pipeline
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
build-and-test:
|
||||
name: Build and Test
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Nix
|
||||
uses: cachix/install-nix-action@v18
|
||||
with:
|
||||
nix_path: nixpkgs=channel:nixos-unstable
|
||||
|
||||
- name: Run nix flake check
|
||||
run: nix flake check
|
||||
29
templates/dev/py-hello/.gitignore
vendored
Normal file
29
templates/dev/py-hello/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
# Byte-compiled Python files
|
||||
*.py[cod]
|
||||
__pycache__/
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
*.egg
|
||||
*.egg-info/
|
||||
.coverage
|
||||
.htmlcov/
|
||||
.pytest_cache/
|
||||
.tox/
|
||||
.venv/
|
||||
ENV/
|
||||
build/
|
||||
dist/
|
||||
env.bak/
|
||||
env/
|
||||
venv.bak/
|
||||
venv/
|
||||
|
||||
# IDE/editor files
|
||||
*.sublime-project
|
||||
*.sublime-workspace
|
||||
.idea/
|
||||
.vscode/
|
||||
|
||||
# Nix-related files
|
||||
result
|
||||
131
templates/dev/py-hello/flake.nix
Normal file
131
templates/dev/py-hello/flake.nix
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
{
|
||||
description = "A hello world template in Python";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "nixpkgs/nixos-unstable";
|
||||
pre-commit-hooks = {
|
||||
url = "github:cachix/pre-commit-hooks.nix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
};
|
||||
|
||||
outputs =
|
||||
{
|
||||
self,
|
||||
nixpkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
pname = "hello-world";
|
||||
version = "0.1.0";
|
||||
|
||||
supportedSystems = [
|
||||
"x86_64-linux"
|
||||
"aarch64-linux"
|
||||
"x86_64-darwin"
|
||||
"aarch64-darwin"
|
||||
];
|
||||
|
||||
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
|
||||
|
||||
nixpkgsFor = forAllSystems (
|
||||
system:
|
||||
import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [ self.overlays.default ];
|
||||
}
|
||||
);
|
||||
in
|
||||
{
|
||||
overlays.default =
|
||||
final: prev:
|
||||
let
|
||||
python = final.python312;
|
||||
in
|
||||
{
|
||||
"${pname}" = python.pkgs.buildPythonApplication {
|
||||
inherit pname version;
|
||||
pyproject = true;
|
||||
src = ./.;
|
||||
build-system = [
|
||||
python.pkgs.setuptools
|
||||
python.pkgs.wheel
|
||||
];
|
||||
dependencies = with python.pkgs; [
|
||||
];
|
||||
pythonImportsCheck = [
|
||||
"hello_world"
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
packages = forAllSystems (system: {
|
||||
default = nixpkgsFor.${system}."${pname}";
|
||||
"${pname}" = nixpkgsFor.${system}."${pname}";
|
||||
});
|
||||
|
||||
devShells = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgsFor.${system};
|
||||
python = pkgs.python312;
|
||||
in
|
||||
{
|
||||
default = pkgs.mkShell {
|
||||
inherit (self.checks.${system}.pre-commit-check) shellHook;
|
||||
buildInputs = self.checks.${system}.pre-commit-check.enabledPackages ++ [
|
||||
(python.withPackages (
|
||||
p: with p; [
|
||||
]
|
||||
))
|
||||
];
|
||||
};
|
||||
|
||||
venv = pkgs.mkShell {
|
||||
buildInputs = [
|
||||
python
|
||||
]
|
||||
++ [
|
||||
(python.withPackages (
|
||||
p: with p; [
|
||||
pip
|
||||
]
|
||||
))
|
||||
];
|
||||
shellHook = ''
|
||||
python -m venv .venv
|
||||
source .venv/bin/activate
|
||||
pip install .
|
||||
'';
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
formatter = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
config = self.checks.${system}.pre-commit-check.config;
|
||||
inherit (config) package configFile;
|
||||
script = ''
|
||||
${pkgs.lib.getExe package} run --all-files --config ${configFile}
|
||||
'';
|
||||
in
|
||||
pkgs.writeShellScriptBin "pre-commit-run" script
|
||||
);
|
||||
|
||||
checks = forAllSystems (system: {
|
||||
# TODO: Add integration test
|
||||
|
||||
pre-commit-check = self.inputs.pre-commit-hooks.lib.${system}.run {
|
||||
src = ./.;
|
||||
hooks = {
|
||||
nixfmt = {
|
||||
enable = true;
|
||||
};
|
||||
# TODO: Add Python format check
|
||||
};
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
14
templates/dev/py-hello/pyproject.toml
Normal file
14
templates/dev/py-hello/pyproject.toml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
[build-system]
|
||||
requires = ["setuptools>=75", "wheel"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "hello-world"
|
||||
version = "0.1.0"
|
||||
requires-python = ">=3.12"
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
[project.scripts]
|
||||
hello-world = "hello_world.__main__:main"
|
||||
1
templates/dev/py-hello/src/hello_world/__init__.py
Normal file
1
templates/dev/py-hello/src/hello_world/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
# This file is intentionally empty.
|
||||
5
templates/dev/py-hello/src/hello_world/__main__.py
Normal file
5
templates/dev/py-hello/src/hello_world/__main__.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
def main():
|
||||
print("Hello, world!")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
26
templates/dev/rs-hello/.github/workflows/rust-nix.yml
vendored
Normal file
26
templates/dev/rs-hello/.github/workflows/rust-nix.yml
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
name: Rust Nix Pipeline
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
build-and-test:
|
||||
name: Build and Test
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Nix
|
||||
uses: cachix/install-nix-action@v18
|
||||
with:
|
||||
nix_path: nixpkgs=channel:nixos-unstable
|
||||
|
||||
- name: Run cargo tests in dev shell
|
||||
run: nix develop --command bash -c "cargo test"
|
||||
|
||||
- name: Run nix flake check
|
||||
run: nix flake check
|
||||
3
templates/dev/rs-hello/.gitignore
vendored
Normal file
3
templates/dev/rs-hello/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
.pre-commit-config.yaml
|
||||
result/
|
||||
target/
|
||||
8
templates/dev/rs-hello/Cargo.toml
Normal file
8
templates/dev/rs-hello/Cargo.toml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "hello-world"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
authors = ["Your Name <your.email@example.com>"]
|
||||
description = "A simple Hello World program"
|
||||
|
||||
[dependencies]
|
||||
127
templates/dev/rs-hello/flake.nix
Normal file
127
templates/dev/rs-hello/flake.nix
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
{
|
||||
description = "A hello world template in Rust";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "nixpkgs/nixos-unstable";
|
||||
pre-commit-hooks = {
|
||||
url = "github:cachix/pre-commit-hooks.nix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
};
|
||||
|
||||
outputs =
|
||||
{
|
||||
self,
|
||||
nixpkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
pname = "hello-world";
|
||||
version = "0.1.0";
|
||||
|
||||
supportedSystems = [
|
||||
"x86_64-linux"
|
||||
"aarch64-linux"
|
||||
"x86_64-darwin"
|
||||
"aarch64-darwin"
|
||||
];
|
||||
|
||||
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
|
||||
|
||||
nixpkgsFor = forAllSystems (
|
||||
system:
|
||||
import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [ self.overlays.default ];
|
||||
}
|
||||
);
|
||||
in
|
||||
{
|
||||
overlays.default = final: prev: {
|
||||
"${pname}" = final.rustPlatform.buildRustPackage {
|
||||
inherit pname version;
|
||||
src = ./.;
|
||||
cargoLock.lockFile = ./Cargo.lock;
|
||||
nativeBuildInputs = with final; [ pkg-config ];
|
||||
};
|
||||
};
|
||||
|
||||
packages = forAllSystems (system: {
|
||||
default = nixpkgsFor.${system}."${pname}";
|
||||
"${pname}" = nixpkgsFor.${system}."${pname}";
|
||||
});
|
||||
|
||||
devShells = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgsFor.${system};
|
||||
in
|
||||
{
|
||||
default = pkgs.mkShell {
|
||||
inherit (self.checks.${system}.pre-commit-check) shellHook;
|
||||
buildInputs =
|
||||
self.checks.${system}.pre-commit-check.enabledPackages
|
||||
++ (with pkgs; [
|
||||
cargo
|
||||
pkg-config
|
||||
pre-commit
|
||||
rust-analyzer
|
||||
rustc
|
||||
]);
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
formatter = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
config = self.checks.${system}.pre-commit-check.config;
|
||||
inherit (config) package configFile;
|
||||
script = ''
|
||||
${pkgs.lib.getExe package} run --all-files --config ${configFile}
|
||||
'';
|
||||
in
|
||||
pkgs.writeShellScriptBin "pre-commit-run" script
|
||||
);
|
||||
|
||||
checks = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgsFor.${system};
|
||||
in
|
||||
{
|
||||
integration-test =
|
||||
pkgs.runCommand "hello-world-test"
|
||||
{
|
||||
nativeBuildInputs = [
|
||||
pkgs.synixutils
|
||||
self.packages.${system}.${pname}
|
||||
];
|
||||
}
|
||||
''
|
||||
output=$(hello-world)
|
||||
|
||||
echo "$output" | grep -q "Hello, World!" || {
|
||||
echo "Test failed: Expected 'Hello, World!' but got: $output"
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo "Hello World test passed!" > $out
|
||||
'';
|
||||
|
||||
pre-commit-check = self.inputs.pre-commit-hooks.lib.${system}.run {
|
||||
src = ./.;
|
||||
hooks = {
|
||||
nixfmt = {
|
||||
enable = true;
|
||||
};
|
||||
rustfmt = {
|
||||
enable = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
11
templates/dev/rs-hello/src/main.rs
Normal file
11
templates/dev/rs-hello/src/main.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn test_hello_world() {
|
||||
assert!(true);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue