diff --git a/.gitignore b/.gitignore index 3c8e258e..8a9f47c1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ __pycache__/ # Replit *.replit -*.nix # C extensions *.so @@ -172,4 +171,7 @@ tux/extensions/* # misc slim.report.json -prisma_binaries/ \ No newline at end of file +prisma_binaries/ + +# direnv +.direnv/ diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..34ba8dfe --- /dev/null +++ b/flake.lock @@ -0,0 +1,62 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1743550720, + "narHash": "sha256-hIshGgKZCgWh6AYJpJmRgFdR3WUbkY04o82X05xqQiY=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "c621e8422220273271f52058f618c94e405bb0f5", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "ref": "main", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1743315132, + "narHash": "sha256-6hl6L/tRnwubHcA4pfUUtk542wn2Om+D4UnDhlDW9BE=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "52faf482a3889b7619003c0daec593a1912fddc1", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1743296961, + "narHash": "sha256-b1EdN3cULCqtorQ4QeWgLMrd5ZGOjLSLemfa00heasc=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "e4822aea2a6d1cdd36653c134cacfd64c97ff4fa", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..dd617b42 --- /dev/null +++ b/flake.nix @@ -0,0 +1,63 @@ +{ + description = "All Thing's Linux discord bot - Tux"; + + inputs = { + nixpkgs = { + type = "github"; + owner = "NixOS"; + repo = "nixpkgs"; + ref = "nixos-unstable"; + }; + + flake-parts = { + type = "github"; + owner = "hercules-ci"; + repo = "flake-parts"; + ref = "main"; + }; + }; + + outputs = inputs@{ + self, + nixpkgs, + flake-parts, + ... + }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ + "x86_64-linux" + "x86_64-darwin" + "aarch64-linux" + "aarch64-darwin" + ]; + + perSystem = { pkgs, self', system, ... }: { + devShells = { + default = self'.devShells.tux; + tux = pkgs.callPackage ./shell.nix { inherit pkgs self; }; + }; + + apps.envrc = { + type = "app"; + program = self'.packages.envrc; + }; + + # Creates .envrc if does not exist + packages.envrc = pkgs.writeShellScriptBin "envrc" '' + echo + + if [ ! -e ".envrc" ]; then + echo "Creating .envrc" + printf "use flake .\n\n\n" | cat - .env.example > .envrc + echo + + echo "The directory is now set up for direnv usage." + echo + else + echo "Please delete .envrc if you wish to recreate it." + echo + fi + ''; + }; + }; +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 00000000..5c029a28 --- /dev/null +++ b/shell.nix @@ -0,0 +1,27 @@ +{ pkgs ? import {}, self ? null }: + +pkgs.mkShell { + buildInputs = if self == null then [] else [ + self.packages.${pkgs.system}.envrc + ]; + + packages = with pkgs; [ + python313 + poetry + git + jq + ]; + + shellHook = '' + # See perSystem.packages.envrc + if command -v envrc >/dev/null 2>&1; then + envrc + fi + + # Enters the user's preferred shell using a more robust method + $(getent passwd $(id -un) | cut -d: -f7 | tr -d '\n') + + # Exits after child shell exits + exit + ''; +}