feature/flupdt #1
13
README.md
13
README.md
@ -20,8 +20,19 @@ For use in other nix-based projects, `flpudt` is available as
|
|||||||
`packages.${system}.flupdt`. Please see our `examples/` folder for common
|
`packages.${system}.flupdt`. Please see our `examples/` folder for common
|
||||||
use-cases.
|
use-cases.
|
||||||
|
|
||||||
## Why the name?
|
## Why the name
|
||||||
|
|
||||||
`flupdt` comes from Fl(ake) Up(date) D(iff) T(ool). The cli is also available as
|
`flupdt` comes from Fl(ake) Up(date) D(iff) T(ool). The cli is also available as
|
||||||
`flake-update-diff-tool`, for ease-of-use and those who use screen readers or
|
`flake-update-diff-tool`, for ease-of-use and those who use screen readers or
|
||||||
similar accessibility tools that may not react well to `flupdt`.
|
similar accessibility tools that may not react well to `flupdt`.
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
### Update procedure
|
||||||
|
|
||||||
|
Until `rad_development_python` (`rdp`) is in PyPI, we use the below steps to
|
||||||
|
update the lock file when there is an update to `rdp`.
|
||||||
|
|
||||||
|
1. Run `poetry lock` to update the poetry reference to GitHub
|
||||||
|
1. Run `poetry2nix lock` to update the overlay which Poetry2Nix uses
|
||||||
|
1. Run `nix flake check` to verify that all is building as expected
|
||||||
|
@ -29,6 +29,7 @@ in
|
|||||||
deadnix = {
|
deadnix = {
|
||||||
enable = true;
|
enable = true;
|
||||||
settings = {
|
settings = {
|
||||||
|
exclude = [ "poetry-git-overlay.nix" ];
|
||||||
noUnderscore = true; # ignore variables starting with underscore
|
noUnderscore = true; # ignore variables starting with underscore
|
||||||
# ignore lambda patterns (useful for passing args from ({}@args)
|
# ignore lambda patterns (useful for passing args from ({}@args)
|
||||||
# to other functions)
|
# to other functions)
|
||||||
|
12
flake.lock
generated
12
flake.lock
generated
@ -96,11 +96,11 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1722179153,
|
"lastModified": 1722589669,
|
||||||
"narHash": "sha256-ZJ75T0GWpLI4hoaL+YxueHD2pXG+VYpYtPJdwbkERVs=",
|
"narHash": "sha256-rxDnGBZK+Sp3df20nCCRrtQzRrJKxY7KtcYNPo5yfg8=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "dcfb2878c687e5eb5fcbc5116969c45c85be34e2",
|
"rev": "42015a129a2ae1cd43a44490e8235d2b24c8a2e2",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@ -137,11 +137,11 @@
|
|||||||
"treefmt-nix": "treefmt-nix"
|
"treefmt-nix": "treefmt-nix"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1721039874,
|
"lastModified": 1722515463,
|
||||||
"narHash": "sha256-XANsG9GYHip8pxZpbqKf/YGv8tIa0xTh289Y+WNBNfw=",
|
"narHash": "sha256-6FVPz1WzHak65xJQg8tRjVyFEWMesGxfskKaCxDUnRk=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "poetry2nix",
|
"repo": "poetry2nix",
|
||||||
"rev": "d11c01e58587e5f21037ed6477465a7f26a32e27",
|
"rev": "8c25e871bba3f472e1569bbf6c0f52dcc34bf2a4",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
30
flake.nix
30
flake.nix
@ -42,25 +42,28 @@
|
|||||||
nixpkgs,
|
nixpkgs,
|
||||||
flake-utils,
|
flake-utils,
|
||||||
pre-commit-hooks,
|
pre-commit-hooks,
|
||||||
|
poetry2nix,
|
||||||
...
|
...
|
||||||
}@inputs:
|
}@inputs:
|
||||||
flake-utils.lib.eachDefaultSystem (
|
flake-utils.lib.eachDefaultSystem (
|
||||||
system:
|
system:
|
||||||
let
|
let
|
||||||
# see https://github.com/nix-community/poetry2nix/tree/master#api for more functions and examples.
|
# see https://github.com/nix-community/poetry2nix/tree/master#api for more functions and examples.
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system}.extend poetry2nix.overlays.default;
|
||||||
poetry2nix = inputs.poetry2nix.lib.mkPoetry2Nix { inherit pkgs; };
|
|
||||||
|
|
||||||
overrides = poetry2nix.overrides.withDefaults (
|
pyOverrides = _final: prev: {
|
||||||
_final: prev: {
|
# prefer binary wheels instead of source distributions for rust based dependencies
|
||||||
# prefer binary wheels instead of source distributions for rust based dependencies
|
# avoids needing to build them from source. technically a security risk
|
||||||
# avoids needing to build them from source. technically a security risk
|
polars = prev.polars.override { preferWheel = true; };
|
||||||
polars = prev.polars.override { preferWheel = true; };
|
ruff = prev.ruff.override { preferWheel = true; };
|
||||||
ruff = prev.ruff.override { preferWheel = true; };
|
greenlet = prev.greenlet.override { preferWheel = true; };
|
||||||
greenlet = prev.greenlet.override { preferWheel = true; };
|
sqlalchemy = prev.sqlalchemy.override { preferWheel = true; };
|
||||||
sqlalchemy = prev.sqlalchemy.override { preferWheel = true; };
|
};
|
||||||
}
|
|
||||||
|
overlay = pkgs.lib.composeExtensions pyOverrides (
|
||||||
|
import ./poetry-git-overlay.nix { inherit pkgs; }
|
||||||
);
|
);
|
||||||
|
overrides = pkgs.poetry2nix.overrides.withDefaults overlay;
|
||||||
|
|
||||||
poetryConfig = {
|
poetryConfig = {
|
||||||
inherit overrides;
|
inherit overrides;
|
||||||
@ -69,8 +72,9 @@
|
|||||||
};
|
};
|
||||||
in
|
in
|
||||||
rec {
|
rec {
|
||||||
|
inherit pkgs;
|
||||||
packages = {
|
packages = {
|
||||||
flupdt = poetry2nix.mkPoetryApplication poetryConfig // {
|
flupdt = pkgs.poetry2nix.mkPoetryApplication poetryConfig // {
|
||||||
develop = true;
|
develop = true;
|
||||||
};
|
};
|
||||||
default = self.packages.${system}.flupdt;
|
default = self.packages.${system}.flupdt;
|
||||||
@ -81,8 +85,8 @@
|
|||||||
devShells = import ./shell.nix {
|
devShells = import ./shell.nix {
|
||||||
inherit
|
inherit
|
||||||
self
|
self
|
||||||
|
pkgs
|
||||||
poetryConfig
|
poetryConfig
|
||||||
poetry2nix
|
|
||||||
inputs
|
inputs
|
||||||
system
|
system
|
||||||
checks
|
checks
|
||||||
|
@ -8,7 +8,7 @@ def parse_inputs():
|
|||||||
"flake_path", metavar="flake-path", help="path to flake to evaluate"
|
"flake_path", metavar="flake-path", help="path to flake to evaluate"
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--keep-hydra", action="store_true",help="allow evaluating Hydra jobs"
|
"--keep-hydra", action="store_true", help="allow evaluating Hydra jobs"
|
||||||
)
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
return args
|
return args
|
||||||
|
@ -5,9 +5,10 @@ from typing import Optional
|
|||||||
from flupdt.common import bash_wrapper
|
from flupdt.common import bash_wrapper
|
||||||
import re
|
import re
|
||||||
|
|
||||||
drv_re = re.compile(r'.*(/nix/store/.*\.drv).*')
|
drv_re = re.compile(r".*(/nix/store/.*\.drv).*")
|
||||||
|
|
||||||
def evaluate_output(path:str, output: str) -> Optional[str]:
|
|
||||||
|
def evaluate_output(path: str, output: str) -> Optional[str]:
|
||||||
logging.info(f"evaluating {output}")
|
logging.info(f"evaluating {output}")
|
||||||
out = bash_wrapper(f"nix eval {path}#{output}")
|
out = bash_wrapper(f"nix eval {path}#{output}")
|
||||||
logging.debug(out[0])
|
logging.debug(out[0])
|
||||||
|
@ -7,8 +7,8 @@ import logging
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
output_regexes = [
|
output_regexes = [
|
||||||
re.compile(r'checking derivation (.*)...'),
|
re.compile(r"checking derivation (.*)..."),
|
||||||
re.compile(r'checking NixOS configuration \'(nixosConfigurations.*)\'\.\.\.')
|
re.compile(r"checking NixOS configuration \'(nixosConfigurations.*)\'\.\.\."),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -31,11 +31,16 @@ def traverse_json_base(json_dict: dict, path: list[str]) -> list[str]:
|
|||||||
def traverse_json(json_dict: dict) -> list[str]:
|
def traverse_json(json_dict: dict) -> list[str]:
|
||||||
return traverse_json_base(json_dict, [])
|
return traverse_json_base(json_dict, [])
|
||||||
|
|
||||||
def get_derivations_from_check(nix_path:str,path_to_flake:str)-> list[str]:
|
|
||||||
flake_check = bash_wrapper(f"{nix_path} flake check --verbose --keep-going", path=path_to_flake)
|
def get_derivations_from_check(nix_path: str, path_to_flake: str) -> list[str]:
|
||||||
|
flake_check = bash_wrapper(
|
||||||
|
f"{nix_path} flake check --verbose --keep-going", path=path_to_flake
|
||||||
|
)
|
||||||
if flake_check[2] != 0:
|
if flake_check[2] != 0:
|
||||||
logging.warn("nix flake check returned non-zero exit code, collecting all available outputs")
|
logging.warn(
|
||||||
error_out = flake_check[1].split('\n')
|
"nix flake check returned non-zero exit code, collecting all available outputs"
|
||||||
|
)
|
||||||
|
error_out = flake_check[1].split("\n")
|
||||||
possible_outputs = filter(lambda s: s.startswith("checking"), error_out)
|
possible_outputs = filter(lambda s: s.startswith("checking"), error_out)
|
||||||
derivations = []
|
derivations = []
|
||||||
for output in possible_outputs:
|
for output in possible_outputs:
|
||||||
@ -47,20 +52,23 @@ def get_derivations_from_check(nix_path:str,path_to_flake:str)-> list[str]:
|
|||||||
derivations += [match.groups()[0]]
|
derivations += [match.groups()[0]]
|
||||||
return derivations
|
return derivations
|
||||||
|
|
||||||
|
|
||||||
def get_derivations(path_to_flake: str) -> list[str]:
|
def get_derivations(path_to_flake: str) -> list[str]:
|
||||||
nix_path = shutil.which("nix")
|
nix_path = shutil.which("nix")
|
||||||
derivations = []
|
derivations = []
|
||||||
if nix_path is None:
|
if nix_path is None:
|
||||||
raise RuntimeError("nix is not available in the PATH, please verify that it is installed")
|
raise RuntimeError(
|
||||||
|
"nix is not available in the PATH, please verify that it is installed"
|
||||||
|
)
|
||||||
flake_show = bash_wrapper(f"{nix_path} flake show --json", path=path_to_flake)
|
flake_show = bash_wrapper(f"{nix_path} flake show --json", path=path_to_flake)
|
||||||
if flake_show[2] != 0:
|
if flake_show[2] != 0:
|
||||||
logging.error("flake show returned non-zero exit code")
|
logging.error("flake show returned non-zero exit code")
|
||||||
logging.warn("falling back to full evaluation via nix flake check")
|
logging.warn("falling back to full evaluation via nix flake check")
|
||||||
derivations = get_derivations_from_check(nix_path, path_to_flake)
|
derivations = get_derivations_from_check(nix_path, path_to_flake)
|
||||||
else:
|
else:
|
||||||
flake_show_json = json.loads(flake_show[0])
|
flake_show_json = json.loads(flake_show[0])
|
||||||
derivations = traverse_json(flake_show_json)
|
derivations = traverse_json(flake_show_json)
|
||||||
for i in range(len(derivations)):
|
for i in range(len(derivations)):
|
||||||
if derivations[i].startswith("nixosConfigurations"):
|
if derivations[i].startswith("nixosConfigurations"):
|
||||||
derivations[i] += ".config.system.build.toplevel"
|
derivations[i] += ".config.system.build.toplevel"
|
||||||
return derivations
|
return derivations
|
||||||
|
@ -5,13 +5,19 @@ from flupdt.cli import parse_inputs
|
|||||||
from flupdt.flake_eval import evaluate_output
|
from flupdt.flake_eval import evaluate_output
|
||||||
from flupdt.common import configure_logger
|
from flupdt.common import configure_logger
|
||||||
import logging
|
import logging
|
||||||
|
import rad_development_python as rd
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
configure_logger("INFO")
|
rd.configure_logger("INFO")
|
||||||
args = parse_inputs()
|
args = parse_inputs()
|
||||||
|
print("hi")
|
||||||
flake_path = args.flake_path
|
flake_path = args.flake_path
|
||||||
derivations = get_derivations(flake_path)
|
derivations = get_derivations(flake_path)
|
||||||
if not args.keep_hydra and len(list(filter(lambda s: s.startswith("hydraJobs"), derivations))) > 0:
|
if (
|
||||||
|
not args.keep_hydra
|
||||||
|
and len(list(filter(lambda s: s.startswith("hydraJobs"), derivations))) > 0
|
||||||
|
):
|
||||||
logging.info("--keep-hydra flag is not specified, removing Hydra jobs")
|
logging.info("--keep-hydra flag is not specified, removing Hydra jobs")
|
||||||
derivations = filter(lambda s: not s.startswith("hydraJobs"), derivations)
|
derivations = filter(lambda s: not s.startswith("hydraJobs"), derivations)
|
||||||
logging.info(f"derivations: {list(derivations)}")
|
logging.info(f"derivations: {list(derivations)}")
|
||||||
|
12
poetry-git-overlay.nix
Normal file
12
poetry-git-overlay.nix
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{ pkgs }:
|
||||||
|
final: prev: {
|
||||||
|
|
||||||
|
rad-development-python = prev.rad-development-python.overridePythonAttrs (_: {
|
||||||
|
src = pkgs.fetchgit {
|
||||||
|
url = "https://github.com/RAD-Development/rad-development-python";
|
||||||
|
rev = "4ee897ab983234eda6f12dfcfd822bffab01f740";
|
||||||
|
sha256 = "1hxdqnjrznx0c07qn5cdx7p7f7sz2ysydx5l82w0r7rdadj69ik2";
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
1098
poetry.lock
generated
1098
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@ -14,6 +14,7 @@ packages = [{ include = "flupdt" }]
|
|||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = "^3.11"
|
python = "^3.11"
|
||||||
sqlalchemy = "^2.0.31"
|
sqlalchemy = "^2.0.31"
|
||||||
|
rad_development_python = {git = "https://github.com/RAD-Development/rad-development-python", branch = "feature/nix"}
|
||||||
|
|
||||||
[tool.poetry.scripts]
|
[tool.poetry.scripts]
|
||||||
flupdt = "flupdt.main:main"
|
flupdt = "flupdt.main:main"
|
||||||
|
14
shell.nix
14
shell.nix
@ -1,16 +1,13 @@
|
|||||||
{
|
{
|
||||||
self,
|
self,
|
||||||
|
pkgs,
|
||||||
poetryConfig,
|
poetryConfig,
|
||||||
poetry2nix,
|
|
||||||
inputs,
|
|
||||||
checks,
|
checks,
|
||||||
system,
|
system,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
inherit (inputs) nixpkgs;
|
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
|
||||||
|
|
||||||
# construct the shell provided by pre-commit for running hooks
|
# construct the shell provided by pre-commit for running hooks
|
||||||
pre-commit = pkgs.mkShell {
|
pre-commit = pkgs.mkShell {
|
||||||
@ -34,9 +31,14 @@ let
|
|||||||
flupdt = pkgs.mkShell { inputsFrom = [ self.packages.${system}.flupdt ]; };
|
flupdt = pkgs.mkShell { inputsFrom = [ self.packages.${system}.flupdt ]; };
|
||||||
|
|
||||||
# pull in python/poetry dependencies
|
# pull in python/poetry dependencies
|
||||||
poetry = pkgs.mkShell { packages = [ pkgs.poetry ]; };
|
poetry = pkgs.mkShell {
|
||||||
|
packages = [
|
||||||
|
pkgs.poetry
|
||||||
|
pkgs.poetry2nix.cli
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
poetry2nixshell = poetry2nix.mkPoetryEnv poetryConfig;
|
poetry2nixshell = pkgs.poetry2nix.mkPoetryEnv poetryConfig;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
default = pkgs.mkShell {
|
default = pkgs.mkShell {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user