diff --git a/.gitattributes b/.gitattributes index 8d8b02c..775d1d4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -7,3 +7,6 @@ migrations/*.sql text eol=lf .gitea/scripts/* text eol=lf *.png binary *.pdf binary +# Nix reads flake.lock as JSON either way; keep both LF like the fleet. +*.nix text eol=lf +flake.lock text eol=lf diff --git a/.gitignore b/.gitignore index cc9ed6c..f4f54f2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ /tests/e2e/shots/ *.log .env +# nix build +/result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..c89ac38 --- /dev/null +++ b/flake.lock @@ -0,0 +1,43 @@ +{ + "nodes": { + "crane": { + "locked": { + "lastModified": 1794870543, + "narHash": "sha256-RQc417nQURjHvaUkVFLyvaQ6Px18G7ZHjRF9bYUkScg=", + "owner": "ipetkov", + "repo": "crane", + "rev": "dbd1288af7a7ec997cb912c034b1a1962938173e", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1794537146, + "narHash": "sha256-Wpz/7x/YWnDIBu7yj6ixe8j6fIMsidd9Y+o1PqPF3iM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d5cc6833999746cffdfe0598f7bc801a57b887a9", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..b2f9ef2 --- /dev/null +++ b/flake.nix @@ -0,0 +1,73 @@ +{ + description = "visa.buildfor.life: immigration records, deadlines and extension packs for foreigners in Thailand"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + crane.url = "github:ipetkov/crane"; + }; + + outputs = + { + self, + nixpkgs, + crane, + }: + let + systems = [ + "x86_64-linux" + "aarch64-linux" + ]; + forAll = f: nixpkgs.lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system}); + + # The server: one binary with its templates, static files and + # migrations compiled in (build.rs, sqlx::migrate!). The tests need + # PostgreSQL, so the package build runs none; CI and the fleet's VM + # test (checks.visa in cnx-network-clan) cover them. + package = + pkgs: + let + craneLib = crane.mkLib pkgs; + inherit (pkgs) lib; + src = lib.fileset.toSource { + root = ./.; + fileset = lib.fileset.unions [ + ./Cargo.toml + ./Cargo.lock + ./build.rs + ./src + ./templates + ./static + ./migrations + # Cargo.toml names tests/main.rs as a target + ./tests + ]; + }; + common = { + inherit src; + pname = "visa"; + version = "0.1.0"; + strictDeps = true; + doCheck = false; + }; + cargoArtifacts = craneLib.buildDepsOnly common; + in + craneLib.buildPackage ( + common + // { + inherit cargoArtifacts; + cargoExtraArgs = "--locked --bin visa"; + meta = { + description = "Immigration records, deadlines and extension packs for foreigners in Thailand"; + homepage = "https://git.b4l.co.th/B4L/visa"; + mainProgram = "visa"; + }; + } + ); + in + { + packages = forAll (pkgs: rec { + visa = package pkgs; + default = visa; + }); + }; +}