first commit
This commit is contained in:
96
flake.nix
Normal file
96
flake.nix
Normal file
@@ -0,0 +1,96 @@
|
||||
{
|
||||
description = "A Nix-flake-based Python development environment for the Fagos Discord bot";
|
||||
inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1";
|
||||
outputs = inputs:
|
||||
let
|
||||
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
|
||||
forEachSupportedSystem = f: inputs.nixpkgs.lib.genAttrs supportedSystems (system: f {
|
||||
pkgs = import inputs.nixpkgs { inherit system; };
|
||||
});
|
||||
version = "3.13";
|
||||
in
|
||||
{
|
||||
# Development shell for `nix develop`
|
||||
devShells = forEachSupportedSystem ({ pkgs }:
|
||||
let
|
||||
concatMajorMinor = v:
|
||||
pkgs.lib.pipe v [
|
||||
pkgs.lib.versions.splitVersion
|
||||
(pkgs.lib.sublist 0 2)
|
||||
pkgs.lib.concatStrings
|
||||
];
|
||||
python = pkgs."python${concatMajorMinor version}";
|
||||
in
|
||||
{
|
||||
default = pkgs.mkShell {
|
||||
venvDir = ".venv";
|
||||
postShellHook = ''
|
||||
venvVersionWarn() {
|
||||
local venvVersion
|
||||
venvVersion="$("$venvDir/bin/python" -c 'import platform; print(platform.python_version())')"
|
||||
[[ "$venvVersion" == "${python.version}" ]] && return
|
||||
cat <<EOF
|
||||
Warning: Python version mismatch: [$venvVersion (venv)] != [${python.version}]
|
||||
Delete '$venvDir' and reload to rebuild for version ${python.version}
|
||||
EOF
|
||||
}
|
||||
venvVersionWarn
|
||||
'';
|
||||
packages = with python.pkgs; [
|
||||
venvShellHook
|
||||
pip
|
||||
discordpy
|
||||
];
|
||||
};
|
||||
});
|
||||
|
||||
# Packages for `nix build`
|
||||
packages = forEachSupportedSystem ({ pkgs }:
|
||||
let
|
||||
concatMajorMinor = v:
|
||||
pkgs.lib.pipe v [
|
||||
pkgs.lib.versions.splitVersion
|
||||
(pkgs.lib.sublist 0 2)
|
||||
pkgs.lib.concatStrings
|
||||
];
|
||||
python = pkgs."python${concatMajorMinor version}";
|
||||
# Define the bot package using buildPythonApplication
|
||||
fagos = python.pkgs.buildPythonApplication {
|
||||
pname = "fagos";
|
||||
version = "0.1.0";
|
||||
src = ./.;
|
||||
format = "pyproject"; # Remove if no pyproject.toml
|
||||
nativeBuildInputs = with python.pkgs; [ setuptools ];
|
||||
propagatedBuildInputs = with python.pkgs; [ discordpy ];
|
||||
doCheck = false;
|
||||
};
|
||||
in
|
||||
{
|
||||
default = fagos;
|
||||
});
|
||||
|
||||
# Apps for `nix run`
|
||||
apps = forEachSupportedSystem ({ pkgs }:
|
||||
let
|
||||
concatMajorMinor = v:
|
||||
pkgs.lib.pipe v [
|
||||
pkgs.lib.versions.splitVersion
|
||||
(pkgs.lib.sublist 0 2)
|
||||
pkgs.lib.concatStrings
|
||||
];
|
||||
python = pkgs."python${concatMajorMinor version}";
|
||||
# Create a Python environment with discordpy
|
||||
myPython = python.withPackages (ps: with ps; [ discordpy ]);
|
||||
# Create a shell script to run bot.py
|
||||
fagosApp = pkgs.writeShellScriptBin "fagos" ''
|
||||
exec ${myPython}/bin/python ${./bot.py} "$@"
|
||||
'';
|
||||
in
|
||||
{
|
||||
default = {
|
||||
type = "app";
|
||||
program = "${fagosApp}/bin/fagos";
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user