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

Nix Flake Maintainance #236

Merged
merged 8 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 15 additions & 24 deletions doc.nix
Original file line number Diff line number Diff line change
@@ -1,36 +1,27 @@
{ lib
, stdenv
, west2nixHook
, pythonEnv
, cmake
, ninja
, doxygen
, mscgen
, graphviz
, git
, zephyr
, bridle
{
lib,
stdenv,
west2nixHook,
pythonEnv,
cmake,
ninja,
doxygen,
mscgen,
graphviz,
git,
zephyr,
bridle,
bridleHook,
}:

stdenv.mkDerivation {

name = "bridle-doc";
src = bridle;
unpackPhase = ''
cp -r ${bridle} bridle
chmod +w -R bridle
cd bridle
git init
git config user.email "[email protected]"
git config user.name "Foo"
git checkout -b fake-branch
git add -A
git commit -m "Fake Commnit"
cd ..
'';

nativeBuildInputs = [
west2nixHook
bridleHook
pythonEnv
cmake
ninja
Expand Down
46 changes: 32 additions & 14 deletions flake.lock

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

52 changes: 34 additions & 18 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";

nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";

zephyr = {
type = "github";
owner = "tiacsys";
Expand All @@ -27,40 +29,54 @@
pyproject-nix.url = "github:nix-community/pyproject.nix";

python-deps = {
url = "github:irockasingranite/bridle-python-deps";
type = "github";
owner = "Irockasingranite";
repo = "bridle-python-deps";
ref = "main";
inputs.nixpkgs.follows = "nixpkgs";
};

};

outputs = { self, nixpkgs, flake-utils, ... }@inputs:
(flake-utils.lib.eachDefaultSystem (system:
outputs =
{
self,
nixpkgs,
nixpkgs-unstable,
flake-utils,
...
}@inputs:
(flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
pkgs-unstable = nixpkgs-unstable.legacyPackages.${system};
inherit (nixpkgs) lib;

west2nix = callPackage inputs.west2nix.lib.mkWest2nix { };

callPackage = pkgs.newScope (pkgs // {
bridle = self;
zephyr = inputs.zephyr;
zephyr-nix = inputs.zephyr-nix.packages.${system};
pyproject-nix = inputs.pyproject-nix;
pythonEnv = callPackage ./python.nix {
python-deps = inputs.python-deps.packages.${system};
};
west2nixHook = west2nix.mkWest2nixHook {
manifest = ./west2nix.toml;
};
});
callPackage = pkgs.newScope (
pkgs
// {
bridle = self;
zephyr = inputs.zephyr;
zephyr-nix = inputs.zephyr-nix.packages.${system};
pyproject-nix = inputs.pyproject-nix;
pythonEnv = callPackage ./python.nix { python-deps = inputs.python-deps.packages.${system}; };
west2nixHook = west2nix.mkWest2nixHook { manifest = ./west2nix.toml; };
bridleHook = callPackage ./hook.nix { };
}
);

in {
formatter = pkgs.nixfmt;
in
{
formatter = pkgs-unstable.nixfmt-rfc-style;

packages.west2nix = inputs.west2nix.packages.${system}.default;

devShells.default = callPackage ./shell.nix { };

packages.doc = callPackage ./doc.nix { };
}));
}
));
}
15 changes: 15 additions & 0 deletions hook.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
lib,
makeSetupHook,
gitMinimal,
bridle,
}:

makeSetupHook {
name = "nix-bridle-hook.sh";
propagatedBuildInputs = [ gitMinimal ];
substitutions = {
git = lib.getExe gitMinimal;
inherit bridle;
};
} ./nix-bridle-hook.sh
16 changes: 16 additions & 0 deletions nix-bridle-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function _bridleUnpackPhase {
runHook preUnpack
cp -r @bridle@ bridle
chmod +w -R bridle
cd bridle
@git@ init
@git@ config user.email "[email protected]"
@git@ config user.name "Foo"
@git@ checkout -b fake-branch
@git@ add -A
@git@ commit -m "Fake Commnit"
cd ..
runHook postUnpack
}

unpackPhase=(_bridleUnpackPhase)
59 changes: 34 additions & 25 deletions python.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{ python3
, zephyr
, bridle
, python-deps
, pyproject-nix
, clang-tools
, gitlint
, lib
{
python3,
zephyr,
bridle,
python-deps,
pyproject-nix,
clang-tools,
gitlint,
lib,
}:

let
Expand All @@ -26,9 +27,11 @@ let
pyedbglib
pykitinfo
pymcuprog
python-can
sphinx-tsn-theme
sphinxcontrib-svg2pdfconverter
sphinx-csv-filter;
sphinx-csv-filter
;
};
};

Expand All @@ -43,23 +46,29 @@ let

# Can't validate the combined packages sets, but we can at least check for
# conflicts within each subset
invalidConstraints = zephyr-project.validators.validateVersionConstraints { inherit python; }
invalidConstraints =
zephyr-project.validators.validateVersionConstraints { inherit python; }
// bridle-project.validators.validateVersionConstraints { inherit python; };

in
lib.warnIf
(invalidConstraints != { })
lib.warnIf (invalidConstraints != { })
"pythonEnv: Found invalid Python constraints for: ${builtins.toJSON (lib.attrNames invalidConstraints)}"
(python.buildEnv.override {
extraLibs = (bridle-project.renderers.withPackages {
inherit python;
# Nest one project's withPackages within the other to get a combined package
# set. If we want more than two, we should name these lambdas to reduce
# indentation.
extraPackages = (zephyr-project.renderers.withPackages {
inherit python;
extraPackages = ps: [ ps.west ];
});
}) python.pkgs;
ignoreCollisions = true;
})
(
python.buildEnv.override {
extraLibs =
(bridle-project.renderers.withPackages {
inherit python;
# Nest one project's withPackages within the other to get a combined package
# set. If we want more than two, we should name these lambdas to reduce
# indentation.
extraPackages = (
zephyr-project.renderers.withPackages {
inherit python;
extraPackages = ps: [ ps.west ];
}
);
})
python.pkgs;
ignoreCollisions = true;
}
)
21 changes: 11 additions & 10 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{ lib
, callPackage
, pythonEnv
, mkShell
, zephyr
, zephyr-nix
, bridle
, cmake
, ninja
, git
{
lib,
callPackage,
pythonEnv,
mkShell,
zephyr,
zephyr-nix,
bridle,
cmake,
ninja,
git,
}:

mkShell {
Expand Down
Loading
Loading