mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-01-02 19:14:14 +00:00
nixos-rebuild-ng: add devShell
This commit is contained in:
parent
4def107627
commit
a8b2af2a12
@ -53,6 +53,38 @@ an attempt of the rewrite.
|
||||
|
||||
And use `nixos-rebuild-ng` instead of `nixos-rebuild`.
|
||||
|
||||
## Development
|
||||
|
||||
Run:
|
||||
|
||||
```console
|
||||
nix-build -A nixos-rebuild-ng.tests.ci
|
||||
```
|
||||
|
||||
The command above will run the unit tests and linters, and also check if the
|
||||
code is formatted. However, sometimes is more convenient to run just a few
|
||||
tests to debug, in this case you can run:
|
||||
|
||||
```console
|
||||
nix-shell -A nixos-rebuild-ng.devShell
|
||||
```
|
||||
|
||||
The command above should automatically put you inside `src` directory, and you
|
||||
can run:
|
||||
|
||||
```console
|
||||
# run program
|
||||
python -m nixos_rebuild
|
||||
# run tests
|
||||
python -m pytest
|
||||
# check types
|
||||
mypy .
|
||||
# fix lint issues
|
||||
ruff check --fix .
|
||||
# format code
|
||||
ruff format .
|
||||
```
|
||||
|
||||
## Current caveats
|
||||
|
||||
- For now we will install it in `nixos-rebuild-ng` path by default, to avoid
|
||||
|
@ -1,9 +1,9 @@
|
||||
{
|
||||
lib,
|
||||
installShellFiles,
|
||||
mkShell,
|
||||
nix,
|
||||
nixos-rebuild,
|
||||
nixos-rebuild-ng,
|
||||
python3,
|
||||
runCommand,
|
||||
withNgSuffix ? true,
|
||||
@ -60,37 +60,42 @@ python3.pkgs.buildPythonApplication rec {
|
||||
|
||||
pytestFlagsArray = [ "-vv" ];
|
||||
|
||||
# NOTE: this is a CI test rather than a build-time test because we want to
|
||||
# keep the build closures small
|
||||
passthru.tests = {
|
||||
ci =
|
||||
runCommand "${pname}-ci"
|
||||
{
|
||||
nativeBuildInputs = [
|
||||
nixos-rebuild-ng # to trigger build
|
||||
(python3.withPackages (
|
||||
ps: with ps; [
|
||||
mypy
|
||||
pytest
|
||||
ruff
|
||||
types-tabulate
|
||||
]
|
||||
))
|
||||
];
|
||||
}
|
||||
''
|
||||
export RUFF_CACHE_DIR="$(mktemp -d)"
|
||||
|
||||
echo -e "\x1b[32m## run mypy\x1b[0m"
|
||||
mypy ${src}
|
||||
echo -e "\x1b[32m## run ruff\x1b[0m"
|
||||
ruff check ${src}
|
||||
echo -e "\x1b[32m## run ruff format\x1b[0m"
|
||||
ruff format --check ${src}
|
||||
|
||||
touch $out
|
||||
passthru =
|
||||
let
|
||||
python-with-pkgs = python3.withPackages (
|
||||
ps: with ps; [
|
||||
mypy
|
||||
pytest
|
||||
ruff
|
||||
types-tabulate
|
||||
# dependencies
|
||||
tabulate
|
||||
]
|
||||
);
|
||||
in
|
||||
{
|
||||
devShell = mkShell {
|
||||
packages = [ python-with-pkgs ];
|
||||
shellHook = ''
|
||||
cd pkgs/by-name/ni/nixos-rebuild-ng/src || true
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
# NOTE: this is a passthru test rather than a build-time test because we
|
||||
# want to keep the build closures small
|
||||
tests.ci = runCommand "${pname}-ci" { nativeBuildInputs = [ python-with-pkgs ]; } ''
|
||||
export RUFF_CACHE_DIR="$(mktemp -d)"
|
||||
|
||||
echo -e "\x1b[32m## run mypy\x1b[0m"
|
||||
mypy ${src}
|
||||
echo -e "\x1b[32m## run ruff\x1b[0m"
|
||||
ruff check ${src}
|
||||
echo -e "\x1b[32m## run ruff format\x1b[0m"
|
||||
ruff format --check ${src}
|
||||
|
||||
touch $out
|
||||
'';
|
||||
};
|
||||
|
||||
meta = {
|
||||
description = "Rebuild your NixOS configuration and switch to it, on local hosts and remote";
|
||||
|
@ -231,7 +231,3 @@ def main() -> None:
|
||||
raise ex
|
||||
else:
|
||||
sys.exit(str(ex))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
@ -0,0 +1,4 @@
|
||||
from . import main
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in New Issue
Block a user