-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Nix initial support for build the app
- Loading branch information
1 parent
aa0a45a
commit 7153222
Showing
7 changed files
with
355 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
use nix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,3 +37,6 @@ htmlcov/ | |
.coverage | ||
.coverage.* | ||
.cache | ||
|
||
# nix/direnv | ||
.envrc |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
''; | ||
}; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(builtins.getFlake ("git+file://" + toString ./.)).devShells.${builtins.currentSystem}.default |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |