Rewrite to flake-utils

This commit is contained in:
Andreas Zweili 2024-04-04 00:22:21 +02:00
parent 5b094459a1
commit 9c45c7f21a
2 changed files with 89 additions and 59 deletions

View File

@ -215,6 +215,24 @@
"inputs": { "inputs": {
"systems": "systems_4" "systems": "systems_4"
}, },
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_5": {
"inputs": {
"systems": "systems_5"
},
"locked": { "locked": {
"lastModified": 1705309234, "lastModified": 1705309234,
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
@ -508,12 +526,12 @@
}, },
"poetry2nix_2": { "poetry2nix_2": {
"inputs": { "inputs": {
"flake-utils": "flake-utils_4", "flake-utils": "flake-utils_5",
"nix-github-actions": "nix-github-actions_2", "nix-github-actions": "nix-github-actions_2",
"nixpkgs": [ "nixpkgs": [
"nixpkgs" "nixpkgs"
], ],
"systems": "systems_5", "systems": "systems_6",
"treefmt-nix": "treefmt-nix" "treefmt-nix": "treefmt-nix"
}, },
"locked": { "locked": {
@ -587,6 +605,7 @@
"root": { "root": {
"inputs": { "inputs": {
"devenv": "devenv", "devenv": "devenv",
"flake-utils": "flake-utils_4",
"nixpkgs": "nixpkgs_3", "nixpkgs": "nixpkgs_3",
"poetry2nix": "poetry2nix_2" "poetry2nix": "poetry2nix_2"
} }
@ -652,6 +671,21 @@
} }
}, },
"systems_5": { "systems_5": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_6": {
"locked": { "locked": {
"lastModified": 1681028828, "lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",

110
flake.nix
View File

@ -6,6 +6,7 @@
url = "github:nix-community/poetry2nix"; url = "github:nix-community/poetry2nix";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
flake-utils.url = "github:numtide/flake-utils";
}; };
outputs = outputs =
@ -13,65 +14,60 @@
self, self,
nixpkgs, nixpkgs,
devenv, devenv,
flake-utils,
poetry2nix, poetry2nix,
}@inputs: }@inputs:
let flake-utils.lib.eachDefaultSystem (
systems = [ system:
"aarch64-darwin" let
"aarch64-linux" pkgs = nixpkgs.legacyPackages.${system};
"x86_64-darwin" poetry2nix = inputs.poetry2nix.lib.mkPoetry2Nix { inherit pkgs; };
"x86_64-linux" in
]; {
forEachSystem = nixpkgs.lib.genAttrs systems; packages = {
in devenv-up = self.devShells.${system}.default.config.procfileScript;
{ };
packages = forEachSystem (system: { devShells =
devenv-up = self.devShells.${system}.default.config.procfileScript; let
}); config = self.devShells.${system}.default.config;
devShells = forEachSystem ( env = poetry2nix.mkPoetryEnv {
system: projectDir = ./.;
let python = pkgs.python312;
pkgs = nixpkgs.legacyPackages.${system}; };
config = self.devShells.${system}.default.config; tests = pkgs.writeShellScriptBin "python-test" ''
env = mkPoetryEnv { trap "process-compose down &> /dev/null" EXIT
projectDir = ./.; process-compose up --tui=false &
python = pkgs.python312; pytest --cov=src tests.py
}; '';
inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryEnv; in
tests = pkgs.writeShellScriptBin "python-test" '' {
trap "process-compose down &> /dev/null" EXIT default = devenv.lib.mkShell {
process-compose up --tui=false & inherit inputs pkgs;
pytest --cov=src tests.py modules = [
''; {
in env = {
{ NO_SSL = "True";
default = devenv.lib.mkShell { PC_PORT_NUM = "9999";
inherit inputs pkgs;
modules = [
{
env = {
NO_SSL = "True";
PC_PORT_NUM = "9999";
};
enterShell = ''
ln -sf ${config.process-managers.process-compose.configFile} ${config.env.DEVENV_ROOT}/process-compose.yml
'';
packages = [
env
tests
];
process-managers.process-compose.enable = true;
processes = {
webserver = {
process-compose.depends_on.redis.condition = "process_started";
exec = "gunicorn src.main:app";
}; };
}; enterShell = ''
services.redis.enable = true; ln -sf ${config.process-managers.process-compose.configFile} ${config.env.DEVENV_ROOT}/process-compose.yml
} '';
]; packages = [
env
tests
];
process-managers.process-compose.enable = true;
processes = {
webserver = {
process-compose.depends_on.redis.condition = "process_started";
exec = "gunicorn src.main:app";
};
};
services.redis.enable = true;
}
];
};
}; };
} }
); );
};
} }