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,
inputs,
self,
flakeUtil,
root,
}:
let
util = import ./util.nix { inherit lib; };
util = import ./util.nix { inherit flakeUtil lib; };
registry = import ./registry.nix {
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) (
builtins.readDir root
);

View File

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

View File

@@ -1,24 +1,6 @@
{ 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
{ flakeUtil, lib }:
{
inherit collectNixFiles;
flake = flakeUtil;
bridgeName = id: "br-vlan${toString id}";

View File

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

View File

@@ -6,12 +6,15 @@
system,
}:
let
util = import ./util.nix { inherit lib; };
dotfiles = import ../dotfiles {
inherit
inputs
lib
self
;
flakeUtil = util;
root = root + "/configs/nixos";
};
in
@@ -21,6 +24,16 @@ in
inherit inputs system;
}).config.build.wrapper;
packages.${system} = import ./packages.nix {
inherit
inputs
lib
root
system
util
;
};
apps.${system} = import ./apps.nix {
inherit
inputs
@@ -28,6 +41,7 @@ in
system
;
formatter = self.formatter.${system};
xatu = self.packages.${system}.xatu;
};
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-testlogs"
| "target"
| "testdata"
| "third_party"
) || name == "result"
|| name.starts_with("result-")