diff --git a/README.md b/README.md index 052ed2b..26accf9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Essence +# Prix du gaz -Carte de chaleur des prix d'essence au Québec affichant les prix en temps réel des stations à travers la province. +Carte des prix d'essence au Québec affichant les prix en temps réel des stations à travers la province. ## Fonctionnalités @@ -28,7 +28,7 @@ direnv allow go run . # Ou avec des paramètres personnalisés -PORT=8080 ESSENCE_DB=./essence.db go run . +PORT=8080 PRIXDUGAZ_DB=./prixdugaz.db go run . ``` Le serveur démarre à `http://localhost:8080` et redirige `/` vers `/map`. @@ -49,19 +49,19 @@ Le serveur démarre à `http://localhost:8080` et redirige `/` vers `/map`. | Variable | Défaut | Description | |----------|--------|-------------| | `PORT` | `8080` | Port d'écoute HTTP | -| `ESSENCE_DB` | `./essence.db` | Chemin de la base de données SQLite | +| `PRIXDUGAZ_DB` | `./prixdugaz.db` | Chemin de la base de données SQLite | ## Compilation ```sh -go build -o essence . +go build -o prixdugaz . ``` Ou via Nix : ```sh nix build -./result/bin/essence +./result/bin/prixdugaz ``` ## Formatage et analyse statique @@ -72,6 +72,39 @@ goimports -w . go vet ./... ``` +## Déploiement sur NixOS + +Le projet fournit un module NixOS via le flake. Ajoutez-le à votre configuration : + +**1. Ajoutez le flake comme entrée (`flake.nix`) :** + +```nix +inputs.prixdugaz.url = "github:Polensky/prixdugaz"; +``` + +**2. Importez le module NixOS et activez le service :** + +```nix +imports = [ inputs.prixdugaz.nixosModules.default ]; + +services.prixdugaz = { + enable = true; + port = 8080; # optionnel, 8080 par défaut + openFirewall = true; # optionnel, ouvre le port dans le pare-feu +}; +``` + +**Options disponibles :** + +| Option | Défaut | Description | +|--------|--------|-------------| +| `enable` | `false` | Active le service | +| `port` | `8080` | Port d'écoute HTTP | +| `dataDir` | `/var/lib/prixdugaz` | Répertoire de la base de données SQLite | +| `openFirewall` | `false` | Ouvre le port dans le pare-feu | +| `package` | flake par défaut | Paquet Prix du gaz à utiliser | + + ## Licence MIT diff --git a/flake.nix b/flake.nix index eb424d6..32ff44a 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "Essence Quebec - Gas price heatmap"; + description = "Prix du gaz Quebec - Gas price heatmap"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; @@ -21,7 +21,7 @@ }; packages.default = pkgs.buildGoModule { - pname = "essence"; + pname = "prixdugaz"; version = "0.1.0"; src = ./.; vendorHash = "sha256-iiobqg0INKuzTyC/VMGcX5CfroqqbKnwlJLVAOCZbEE="; diff --git a/go.mod b/go.mod index 0b4c827..351c584 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/polen/essence +module github.com/polen/prixdugaz go 1.25.0 diff --git a/main.go b/main.go index 1d9533f..b6223ec 100644 --- a/main.go +++ b/main.go @@ -107,9 +107,9 @@ func main() { port = defaultPort } - dbPath := os.Getenv("ESSENCE_DB") + dbPath := os.Getenv("PRIXDUGAZ_DB") if dbPath == "" { - dbPath = "./essence.db" + dbPath = "./prixdugaz.db" } var err error @@ -983,7 +983,7 @@ func fetchAndParse() (*StationsResponse, error) { return nil, fmt.Errorf("creating request: %w", err) } req.Header.Set("Accept-Encoding", "gzip") - req.Header.Set("User-Agent", "essence-quebec-map/1.0") + req.Header.Set("User-Agent", "prixdugaz-quebec-map/1.0") client := &http.Client{Timeout: 30 * time.Second} resp, err := client.Do(req) diff --git a/nixos-module.nix b/nixos-module.nix index a2367c5..e8fb6ae 100644 --- a/nixos-module.nix +++ b/nixos-module.nix @@ -2,48 +2,48 @@ { config, lib, pkgs, ... }: let - cfg = config.services.essence; + cfg = config.services.prixdugaz; in { - options.services.essence = { - enable = lib.mkEnableOption "Essence Quebec gas price map"; + options.services.prixdugaz = { + enable = lib.mkEnableOption "Prix du gaz Quebec gas price map"; port = lib.mkOption { type = lib.types.port; default = 8080; - description = "Port the Essence web server listens on."; + description = "Port the Prix du gaz web server listens on."; }; dataDir = lib.mkOption { type = lib.types.str; - default = "/var/lib/essence"; + default = "/var/lib/prixdugaz"; description = "Directory where the SQLite database is stored."; }; openFirewall = lib.mkOption { type = lib.types.bool; default = false; - description = "Whether to open the firewall for the Essence web server port."; + description = "Whether to open the firewall for the Prix du gaz web server port."; }; package = lib.mkOption { type = lib.types.package; default = self.packages.${pkgs.system}.default; defaultText = lib.literalExpression "self.packages.\${pkgs.system}.default"; - description = "The Essence package to use."; + description = "The Prix du gaz package to use."; }; }; config = lib.mkIf cfg.enable { - systemd.services.essence = { - description = "Essence Quebec - Gas price map"; + systemd.services.prixdugaz = { + description = "Prix du gaz Quebec - Gas price map"; wantedBy = [ "multi-user.target" ]; after = [ "network-online.target" ]; wants = [ "network-online.target" ]; environment = { - PORT = toString cfg.port; - ESSENCE_DB = "${cfg.dataDir}/essence.db"; + PORT = toString cfg.port; + PRIXDUGAZ_DB = "${cfg.dataDir}/prixdugaz.db"; }; serviceConfig = { @@ -52,7 +52,7 @@ in RestartSec = 5; DynamicUser = true; - StateDirectory = "essence"; + StateDirectory = "prixdugaz"; StateDirectoryMode = "0750"; # Hardening