diff --git a/.gitignore b/.gitignore index 0b745e2..95d48c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,14 @@ /target -.env \ No newline at end of file +/result +.env + +# Devenv +.devenv* +devenv.local.nix +devenv.local.yaml + +# direnv +.direnv + +# pre-commit +.pre-commit-config.yaml diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..12c8d37 --- /dev/null +++ b/default.nix @@ -0,0 +1,6 @@ +{ rustPlatform }: +rustPlatform.buildRustPackage { + name = "mensa-upb-api"; + src = ./.; + cargoLock.lockFile = ./Cargo.lock; +} diff --git a/devenv.lock b/devenv.lock new file mode 100644 index 0000000..1648ed7 --- /dev/null +++ b/devenv.lock @@ -0,0 +1,103 @@ +{ + "nodes": { + "devenv": { + "locked": { + "dir": "src/modules", + "lastModified": 1783427201, + "narHash": "sha256-oaA0ap7w1XF1P5w4IpP+F4XfLwww2R9ht8MW1auaOms=", + "owner": "cachix", + "repo": "devenv", + "rev": "821e0be605bd00b1aaf6113406c4babc3ce12d23", + "type": "github" + }, + "original": { + "dir": "src/modules", + "owner": "cachix", + "repo": "devenv", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1767039857, + "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=", + "owner": "NixOS", + "repo": "flake-compat", + "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "flake-compat", + "type": "github" + } + }, + "git-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1783008725, + "narHash": "sha256-jGiy6+sxjNWXSjp25uoJuNfyH9zBK1PEDY0lVoL4ibQ=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "bca82caa46d5ec0f5d422c61fb1e30bc51313cbe", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "nixpkgs": { + "inputs": { + "nixpkgs-src": "nixpkgs-src" + }, + "locked": { + "lastModified": 1783345554, + "narHash": "sha256-LZhOm4kqjHUnwP4CNHpaqqEVcumGNd1PvOEOad8LkS0=", + "owner": "cachix", + "repo": "devenv-nixpkgs", + "rev": "6004ea8c229fe9d41b21c6f4c76bf6c2e10771dd", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "rolling", + "repo": "devenv-nixpkgs", + "type": "github" + } + }, + "nixpkgs-src": { + "flake": false, + "locked": { + "lastModified": 1783279667, + "narHash": "sha256-/NAkDSsve+GNM0Bt6tleJdCGfsTlK89nPjkVOzZMo0s=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f205b5574fd0cb7da5b702a2da51507b7f4fdd1b", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "devenv": "devenv", + "git-hooks": "git-hooks", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} \ No newline at end of file diff --git a/devenv.nix b/devenv.nix new file mode 100644 index 0000000..a3dd094 --- /dev/null +++ b/devenv.nix @@ -0,0 +1,40 @@ +{ + pkgs, + lib, + config, + inputs, + ... +}: +{ + packages = [ pkgs.git pkgs.sqlx-cli ]; + + languages.rust.enable = true; + + env.DATABASE_URL = "postgres://mensa-upb:mensa-upb@${config.services.postgres.listen_addresses}:${toString config.services.postgres.port}/mensa-upb"; + + services.postgres = { + enable = true; + initialDatabases = [ + { + name = "mensa-upb"; + user = "mensa-upb"; + pass = "mensa-upb"; + } + ]; + listen_addresses = "localhost"; + }; + + git-hooks.hooks = { + clippy.enable = true; + + sqlx-prepare = { + enable = true; + + name = "Run cargo sqlx prepare"; + entry = "cargo sqlx prepare --workspace --no-dotenv"; + pass_filenames = false; + }; + }; + + # See full reference at https://devenv.sh/reference/options/ +} diff --git a/devenv.yaml b/devenv.yaml new file mode 100644 index 0000000..b311010 --- /dev/null +++ b/devenv.yaml @@ -0,0 +1,8 @@ +inputs: + git-hooks: + url: github:cachix/git-hooks.nix + inputs: + nixpkgs: + follows: nixpkgs + nixpkgs: + url: github:cachix/devenv-nixpkgs/rolling diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..c067cc0 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1783224372, + "narHash": "sha256-8i/87eeoqiGE4yOTjwSA3Eh/ziJRQEmd/unYU+K27sk=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "d407951447dcd00442e97087bf374aad70c04cea", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..9cfada9 --- /dev/null +++ b/flake.nix @@ -0,0 +1,32 @@ +{ + description = "Mensa UPB scraper and API"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + }; + + outputs = + { self, nixpkgs }: + let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + in + { + + packages.${system}.default = pkgs.callPackage ./default.nix { }; + + devShells.${system}.default = pkgs.mkShell { + buildInputs = with pkgs; [ + devenv + cargo + rustc + rustfmt + clippy + rust-analyzer + sqlx-cli + ]; + env.RUST_SRC_PATH = pkgs.rust.packages.stable.rustPlatform.rustLibSrc; + }; + + }; +}