Skip to content

Commit

Permalink
Merge pull request #131 from Uzaaft/feat/nix-ci
Browse files Browse the repository at this point in the history
build(nix): add alejandra and formatting nix code to CI
  • Loading branch information
trag1c authored Jan 17, 2025
2 parents 406912f + 8e278a2 commit 0ca7da9
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 64 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ jobs:
run: |
nix develop -c ruff check
nix develop -c ruff format --check
nix develop -c alejandra --check .
40 changes: 25 additions & 15 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,35 @@
};

# Used for shell.nix
flake-compat = { url = github:edolstra/flake-compat; flake = false; };
flake-compat = {
url = github:edolstra/flake-compat;
flake = false;
};
};

outputs = { self, nixpkgs, flake-utils, ... }@inputs:
let
overlays = [
# Our repo overlay
(import ./nix/overlay.nix)

# poetry2nix overlay
inputs.poetry2nix.overlays.default
];

# Our supported systems are the same supported systems as the Zig binaries
systems = builtins.attrNames inputs.zig.packages;
in flake-utils.lib.eachSystem systems (system:
let pkgs = import nixpkgs { inherit overlays system; };
outputs = {
self,
nixpkgs,
flake-utils,
...
} @ inputs: let
overlays = [
# Our repo overlay
(import ./nix/overlay.nix)

# poetry2nix overlay
inputs.poetry2nix.overlays.default
];

# Our supported systems are the same supported systems as the Zig binaries
systems = builtins.attrNames inputs.zig.packages;
in
flake-utils.lib.eachSystem systems (
system: let
pkgs = import nixpkgs {inherit overlays system;};
in rec {
devShell = pkgs.devShell;
formatter = pkgs.alejandra;

packages.app = pkgs.app;
defaultPackage = packages.app;
Expand Down
71 changes: 41 additions & 30 deletions nix/devshell.nix
Original file line number Diff line number Diff line change
@@ -1,34 +1,45 @@
{ mkShell, lib, stdenv
{
mkShell,
lib,
stdenv,
# Deps
poetry,
python3,
# Our app
pythonApp,
# Deps for ci
alejandra,
}: let
rpathLibs =
[
# None yet
]
++ lib.optionals stdenv.isLinux [
# None yet
];
in
mkShell rec {
name = "ghostty-discord-bot";

# Deps
, poetry
, python3
nativeBuildInputs =
[
# Python lib
python3
poetry
]
++ lib.optionals stdenv.isLinux [
# None yet
];

# Our app
, pythonApp
}:
let
rpathLibs = [
# None yet
] ++ lib.optionals stdenv.isLinux [
# None yet
];
packages = [
# Required for CI for format checking.
alejandra
];

in mkShell rec {
name = "ghostty-discord-bot";
buildInputs = rpathLibs ++ [pythonApp.devEnv];

nativeBuildInputs = [
# Python lib
python3
poetry
] ++ lib.optionals stdenv.isLinux [
# None yet
];

buildInputs = rpathLibs ++ [ pythonApp.devEnv ];

# This should be set onto the rpath of the ghostty binary if you want
# it to be "portable" across the system.
LD_LIBRARY_PATH = lib.makeLibraryPath rpathLibs;
DYLD_LIBRARY_PATH = lib.makeLibraryPath rpathLibs;
}
# This should be set onto the rpath of the ghostty binary if you want
# it to be "portable" across the system.
LD_LIBRARY_PATH = lib.makeLibraryPath rpathLibs;
DYLD_LIBRARY_PATH = lib.makeLibraryPath rpathLibs;
}
6 changes: 3 additions & 3 deletions nix/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ final: prev: rec {
#

# Our custom packages related directly to our application
devShell = prev.callPackage ./devshell.nix { };
pythonApp = prev.callPackage ./python-app.nix { };
app = prev.callPackage ./package.nix { };
devShell = prev.callPackage ./devshell.nix {};
pythonApp = prev.callPackage ./python-app.nix {};
app = prev.callPackage ./package.nix {};
}
32 changes: 16 additions & 16 deletions nix/package.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{ stdenv
, writeShellScriptBin
, pythonApp
}:

let
{
stdenv,
writeShellScriptBin,
pythonApp,
}: let
# The main script to run the app
app = writeShellScriptBin "app" ''
${pythonApp.app.dependencyEnv}/bin/uvicorn 'app.main:app' \
Expand All @@ -15,13 +14,14 @@ let
shell = writeShellScriptBin "shell" ''
${pythonApp.app.dependencyEnv}/bin/python
'';
in stdenv.mkDerivation {
name = "ghostty-discord-bot";
version = "0.1.0";
phases = "installPhase fixupPhase";
installPhase = ''
mkdir -p $out/bin
ln -s ${app}/bin/app $out/bin/app
ln -s ${shell}/bin/shell $out/bin/shell
'';
}
in
stdenv.mkDerivation {
name = "ghostty-discord-bot";
version = "0.1.0";
phases = "installPhase fixupPhase";
installPhase = ''
mkdir -p $out/bin
ln -s ${app}/bin/app $out/bin/app
ln -s ${shell}/bin/shell $out/bin/shell
'';
}

0 comments on commit 0ca7da9

Please sign in to comment.