Skip to content

Commit

Permalink
Update Nix stuff (#3263)
Browse files Browse the repository at this point in the history
  • Loading branch information
lloeki authored Oct 18, 2024
1 parent 9ba819f commit 18686db
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 46 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea
.env
.envrc
.direnv
__pycache__
binaries/*
!binaries/README.md
Expand Down
12 changes: 12 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# flake-compat shim for usage without flakes
(import
(
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
fetchTarball {
url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{ src = ./.; }
).defaultNix

76 changes: 76 additions & 0 deletions flake.lock

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

65 changes: 65 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/master";

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

# backwards compatibility with nix-build and nix-shell
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
};

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

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

# use this pyton version, and include the abvoe packages
python = pkgs.python312.withPackages python_packages;
in {
devShell = pkgs.stdenv.mkDerivation {
name = "devshell";

buildInputs = with pkgs; [
# version to use + default packages are declared above
python


# linters
shellcheck

# for scripts
bash
fswatch
rsync
] ++ lib.optionals (pkgs.stdenv.isDarwin) [
# for python watchdog package
darwin.apple_sdk.frameworks.CoreServices
];


shellHook = ''
export PYTHON_VERSION="$(python -c 'import platform; import re; print(re.sub(r"\.\d+$", "", platform.python_version()))')"
# 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"
# hack: can't find libstdc++.so.8 otherwise
export LD_LIBRARY_PATH="${pkgs.stdenv.cc.cc.lib}/lib"
'';
};
}
);
}
56 changes: 11 additions & 45 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,45 +1,11 @@
{
# use the environment channel
pkgs ? import <nixpkgs> {},

# use a pinned package state
pinned ? import(fetchTarball("https://github.com/NixOS/nixpkgs/archive/c75037bbf909.tar.gz")) {},
}:
let
# get these python packages from nix
python_packages = python-packages: [
python-packages.pip
];

# use this pyton version, and include the abvoe packages
python = pinned.python39.withPackages python_packages;
in pinned.stdenv.mkDerivation {
# unique project name for this environment derivation
name = "system-tests.devshell";

buildInputs = [
# version to use + default packages are declared above
python

# linters
pinned.shellcheck

# for scripts
pinned.bash
pinned.fswatch
pinned.rsync
];

shellHook = ''
export PYTHON_VERSION="$(python -c 'import platform; import re; print(re.sub(r"\.\d+$", "", platform.python_version()))')"
# 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"
# hack: can't find libstdc++.so.8 otherwise
export LD_LIBRARY_PATH="${pinned.stdenv.cc.cc.lib}/lib"
'';
}
# flake-compat shim for usage without flakes
(import
(
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
fetchTarball {
url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{ src = ./.; }
).shellNix
4 changes: 3 additions & 1 deletion utils/scripts/compute_impacted_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ def main():
r"format\.sh": None,
r"pyproject\.toml": None,
r"scenario_groups\.yml": None,
r"shell\.nix": None,
## Nix
r".*\.nix": None,
r"flake\.lock": None,
## few files with lot of effect
r"requirements\.txt": ScenarioGroup.ALL.value,
r"run\.sh": ScenarioGroup.ALL.value,
Expand Down

0 comments on commit 18686db

Please sign in to comment.