build(xatu): add flake package #78

Closed
alexion wants to merge 8 commits from feat/package-xatu into main
10 changed files with 106 additions and 23 deletions

View File

@@ -2,10 +2,11 @@
lib, lib,
inputs, inputs,
self, self,
flakeUtil,
root, root,
}: }:
let let
util = import ./util.nix { inherit lib; }; util = import ./util.nix { inherit flakeUtil lib; };
registry = import ./registry.nix { registry = import ./registry.nix {
inherit lib; inherit lib;

View File

@@ -275,7 +275,7 @@ let
}; };
}; };
files = util.collectNixFiles root; files = util.flake.collectNixFiles root;
guestFiles = lib.filterAttrs (file: type: type == "regular" && lib.hasSuffix ".nix" file) ( guestFiles = lib.filterAttrs (file: type: type == "regular" && lib.hasSuffix ".nix" file) (
builtins.readDir root builtins.readDir root
); );

View File

@@ -3,5 +3,5 @@
util, util,
}: }:
{ {
imports = util.collectNixFiles root; imports = util.flake.collectNixFiles root;
} }

View File

@@ -1,24 +1,6 @@
{ lib }: { flakeUtil, lib }:
let
collectNixFiles =
dir:
lib.flatten (
lib.mapAttrsToList (
name: type:
let
path = dir + "/${name}";
in
if type == "directory" then
collectNixFiles path
else if type == "regular" && lib.hasSuffix ".nix" name then
[ path ]
else
[ ]
) (builtins.readDir dir)
);
in
{ {
inherit collectNixFiles; flake = flakeUtil;
bridgeName = id: "br-vlan${toString id}"; bridgeName = id: "br-vlan${toString id}";

View File

@@ -3,6 +3,7 @@
lib, lib,
formatter, formatter,
system, system,
xatu,
}: }:
let let
pkgs = inputs.nixpkgs.legacyPackages.${system}; pkgs = inputs.nixpkgs.legacyPackages.${system};
@@ -17,6 +18,7 @@ in
formatter formatter
pkgs.statix pkgs.statix
pkgs.deadnix pkgs.deadnix
xatu
]; ];
text = '' text = ''
treefmt treefmt
@@ -33,6 +35,7 @@ in
src/xatu/testdata \ src/xatu/testdata \
third_party \ third_party \
-- . -- .
xatu .
treefmt treefmt
''; '';
} }

View File

@@ -6,12 +6,15 @@
system, system,
}: }:
let let
util = import ./util.nix { inherit lib; };
dotfiles = import ../dotfiles { dotfiles = import ../dotfiles {
inherit inherit
inputs inputs
lib lib
self self
; ;
flakeUtil = util;
root = root + "/configs/nixos"; root = root + "/configs/nixos";
}; };
in in
@@ -21,6 +24,16 @@ in
inherit inputs system; inherit inputs system;
}).config.build.wrapper; }).config.build.wrapper;
packages.${system} = import ./packages.nix {
inherit
inputs
lib
root
system
util
;
};
apps.${system} = import ./apps.nix { apps.${system} = import ./apps.nix {
inherit inherit
inputs inputs
@@ -28,6 +41,7 @@ in
system system
; ;
formatter = self.formatter.${system}; formatter = self.formatter.${system};
xatu = self.packages.${system}.xatu;
}; };
inherit (dotfiles) nixosConfigurations; inherit (dotfiles) nixosConfigurations;

26
src/flake/packages.nix Normal file
View File

@@ -0,0 +1,26 @@
{
inputs,
lib,
root,
system,
util,
}:
let
pkgs = inputs.nixpkgs.legacyPackages.${system};
packageFiles = builtins.filter (path: builtins.baseNameOf (toString path) == "package.nix") (
util.collectNixFiles (root + "/src")
);
package = packageFile: {
name = builtins.baseNameOf (toString (builtins.dirOf packageFile));
value = import packageFile {
inherit
lib
pkgs
root
;
};
};
in
builtins.listToAttrs (map package packageFiles)

22
src/flake/util.nix Normal file
View File

@@ -0,0 +1,22 @@
{ lib }:
let
collectNixFiles =
dir:
lib.flatten (
lib.mapAttrsToList (
name: type:
let
path = dir + "/${name}";
in
if type == "directory" then
collectNixFiles path
else if type == "regular" && lib.hasSuffix ".nix" name then
[ path ]
else
[ ]
) (builtins.readDir dir)
);
in
{
inherit collectNixFiles;
}

34
src/xatu/package.nix Normal file
View File

@@ -0,0 +1,34 @@
{
lib,
pkgs,
root,
}:
pkgs.rustPlatform.buildRustPackage {
pname = "xatu";
version = "0.1.0";
src = lib.fileset.toSource {
inherit root;
fileset = lib.fileset.unions [
(root + "/Cargo.lock")
(root + "/Cargo.toml")
(root + "/src/monorepo")
(root + "/src/status")
(root + "/src/xatu")
];
};
postPatch = ''
substituteInPlace Cargo.toml \
--replace-fail ' "src/ariadne",' "" \
--replace-fail ' "src/machoke",' ""
'';
cargoBuildFlags = [
"-p"
"xatu"
"--bin"
"xatu"
];
cargoLock.lockFile = root + "/Cargo.lock";
}

View File

@@ -20,6 +20,7 @@ fn is_excluded_dir(path: &Path) -> bool {
| "bazel-out" | "bazel-out"
| "bazel-testlogs" | "bazel-testlogs"
| "target" | "target"
| "testdata"
| "third_party" | "third_party"
) || name == "result" ) || name == "result"
|| name.starts_with("result-") || name.starts_with("result-")