Skip to content

Commit

Permalink
Nix initial support for build the app
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelchcki committed May 17, 2024
1 parent aa0a45a commit 7153222
Show file tree
Hide file tree
Showing 7 changed files with 355 additions and 3 deletions.
1 change: 1 addition & 0 deletions .envrc.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use nix
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ htmlcov/
.coverage
.coverage.*
.cache

# nix/direnv
.envrc
247 changes: 247 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 91 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
description = "ddapm_test_agent";
nixConfig.bash-prompt-prefix = "\[ddapm_test_agent\] ";

inputs = {
flake-utils.url = "github:numtide/flake-utils";
treefmt-nix.url = "github:numtide/treefmt-nix";
nixpkgs.url = "github:NixOS/nixpkgs/23.11";

pyproject-nix.url = "github:nix-community/pyproject.nix";

nix2containerPkg.url = "github:nlewo/nix2container";
};

outputs = {
self,
nixpkgs,
flake-utils,
treefmt-nix,
pyproject-nix,
nix2containerPkg,
}:
flake-utils.lib.eachDefaultSystem (system: let
project = pyproject-nix.lib.project.loadPyproject {
projectRoot = ./.;
};
pkgs = nixpkgs.legacyPackages.${system};
nix2container = nix2containerPkg.packages.${system}.nix2container;

python = pkgs.python312;
pythonPkgs = pkgs.python312Packages;

packageAttrs = project.renderers.buildPythonPackage {inherit python;};
packageDeps = project.renderers.withPackages {inherit python;};

pythonDevEnv = python.withPackages packageDeps;

treefmt = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;

finalPackage = python.pkgs.buildPythonPackage packageAttrs;
finalApp = python.pkgs.buildPythonApplication packageAttrs;
devEnv = pkgs.buildEnv {
name = "root";
paths = [pkgs.bashInteractive pkgs.coreutils treefmt.config.build.wrapper pythonDevEnv];
pathsToLink = ["/bin"];
};
in {
packages = {
python = python;
ciContainer = nix2container.buildImage {
name = "registry.ddbuild.io/apm-reliability-environment/handmade/nixci";

copyToRoot = pkgs.buildEnv {
name = "root";
paths = [devEnv pythonPkgs.pytest];
pathsToLink = ["/bin"];
};
};
toolContainer = nix2container.buildImage {
name = "registry.ddbuild.io/apm-reliability-environment/handmade/docker-builder";
tag = "latest";
config = {
entrypoint = ["/bin/docker-builder"];
};

copyToRoot = pkgs.buildEnv {
name = "root";
paths = [finalApp];
pathsToLink = ["/bin"];
};
};
};

packages.default = finalPackage;
formatter = treefmt.config.build.wrapper;

devShells.default =
pkgs.mkShell
{
venvDir = "./.venv";
nativeBuildInputs = [pythonDevEnv pythonPkgs.venvShellHook];
packages = [
devEnv
pythonPkgs.pytest
];
postShellHook = ''
export PYTHONPATH="$PYTHONPATH:$(pwd)" # ensuring pytest invocation works
'';
};
});
}
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(builtins.getFlake ("git+file://" + toString ./.)).devShells.${builtins.currentSystem}.default
3 changes: 0 additions & 3 deletions test_deps.txt

This file was deleted.

12 changes: 12 additions & 0 deletions treefmt.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# treefmt.nix
{pkgs, ...}: {
# Used to find the project root
projectRootFile = "flake.nix";
# Enable the Nix formatter "alejandra"
programs.alejandra.enable = true;

# Format py sources
programs.black.enable = true;
# Format .sh scripts
programs.shfmt.enable = true;
}

0 comments on commit 7153222

Please sign in to comment.