Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic nix fmt configuration #2600

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
10 changes: 3 additions & 7 deletions .github/actions/lint_code/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ description: "Run lints checks for project"
runs:
using: composite
steps:
- uses: cachix/install-nix-action@v27
- name: Install runner
uses: ./.github/actions/install_runner
- run: source venv/bin/activate
shell: bash
- name: Black, pylint and tailing whitespaces checks

- name: All checks + pylint checks
shell: bash
run: ./format.sh --check
- if: ${{ failure() }}
Expand All @@ -18,12 +20,6 @@ runs:
exit 1

'
- name: 'Install shellcheck'
shell: bash
run: sudo apt-get install -y shellcheck
- name: 'Run shellcheck'
shell: bash
run: ./utils/scripts/shellcheck.sh
- name: Install node
uses: actions/setup-node@v4
with:
Expand Down
38 changes: 0 additions & 38 deletions .shellcheck

This file was deleted.

5 changes: 0 additions & 5 deletions .shellcheckrc

This file was deleted.

83 changes: 60 additions & 23 deletions flake.lock

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

114 changes: 66 additions & 48 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,65 +1,83 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/master";
description = "sys-tests";
nixConfig.bash-prompt-prefix = "\[system-tests\] ";

# cross-platform convenience
inputs = {
flake-utils.url = "github:numtide/flake-utils";
treefmt-nix.url = "github:numtide/treefmt-nix";

# backwards compatibility with nix-build and nix-shell
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-24.05-darwin";
nixpkgs-black-pinned.url = "github:NixOS/nixpkgs/6625284c397b44bc9518a5a1567c1b5aae455c08";
};

outputs = { self, nixpkgs, flake-utils, flake-compat }:
# resolve for all platforms in turn
flake-utils.lib.eachDefaultSystem (system:
let
# packages for this system platform
pkgs = nixpkgs.legacyPackages.${system};

# control versions
outputs = {
self,
nixpkgs,
flake-utils,
treefmt-nix,
nixpkgs-black-pinned,
}: (flake-utils.lib.eachDefaultSystem (system: let
pkgs-black = import nixpkgs-black-pinned {inherit system;};

# get these python packages from nix
python_packages = python-packages: [
python-packages.pip
];
pinned-black = pkgs-black.black;

# use this pyton version, and include the abvoe packages
python = pkgs.python312.withPackages python_packages;
in {
devShell = pkgs.stdenv.mkDerivation {
name = "devshell";
black-overlay = final: prev: {
black = pinned-black;
};

buildInputs = with pkgs; [
# version to use + default packages are declared above
python
pkgs = import nixpkgs {
inherit system;
overlays = [
black-overlay
];
};

black = pkgs.black;

# linters
shellcheck
treefmt = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;

# for scripts
bash
fswatch
rsync
] ++ lib.optionals (pkgs.stdenv.isDarwin) [
# for python watchdog package
darwin.apple_sdk.frameworks.CoreServices
];
python = pkgs.python39;
in {
packages = {
default = treefmt.config.build.wrapper;
};
devShells.default =
pkgs.mkShell
{
packages = [
pkgs.curl
pkgs.bash
pkgs.coreutils
pkgs.fswatch
pkgs.rsync
pkgs.shellcheck

treefmt.config.build.wrapper
python

pkgs.ruff
];

shellHook = ''
export PYTHON_VERSION="$(python -c 'import platform; import re; print(re.sub(r"\.\d+$", "", platform.python_version()))')"
buildInputs = [python.pkgs.venvShellHook];
venvDir = "./venv";

# replicate virtualenv behaviour
export PIP_PREFIX="$PWD/vendor/python/$PYTHON_VERSION/packages"
export PYTHONPATH="$PIP_PREFIX/lib/python$PYTHON_VERSION/site-packages:$PYTHONPATH"
unset SOURCE_DATE_EPOCH
export PATH="$PIP_PREFIX/bin:$PATH"
postVenvCreation = ''
unset SOURCE_DATE_EPOCH
pip install -r requirements.txt
'';
postShellHook = ''
unset SOURCE_DATE_EPOCH
# hack: can't find libstdc++.so.8 otherwise
# pawel: hack-disabled as this breaks everything on my system - since my gcc is newer than nixs
# export LD_LIBRARY_PATH="${pkgs.stdenv.cc.cc.lib}/lib"
'';
};

# hack: can't find libstdc++.so.8 otherwise
export LD_LIBRARY_PATH="${pkgs.stdenv.cc.cc.lib}/lib"
'';
};
}
);
formatter = treefmt.config.build.wrapper;
checks = {
formatting = treefmt.config.build.check self;
};
}));
}

# todo Merge with upstream changes
10 changes: 10 additions & 0 deletions format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,21 @@ while [[ "$#" -gt 0 ]]; do
shift
done

echo "Running treefmt-nix ..."
if [ "$COMMAND" == "fix" ]; then
nix fmt


else
nix flake check
fi

if [ ! -d "venv/" ]; then
echo "Runner is not installed, installing it (ETA 60s)"
./build.sh -i runner
fi

# shellcheck source=/dev/null
source venv/bin/activate

echo "Running mypy type checks..."
Expand Down
Loading
Loading