Integrate flake parts

This commit is contained in:
Andrei Cravtov
2025-08-13 11:55:22 +03:00
committed by GitHub
parent dbcd09aa53
commit 7e19804aa5
9 changed files with 384 additions and 98 deletions

3
.envrc
View File

@@ -1 +1,2 @@
use flake
use flake
# eval "$shellHook" # https://github.com/nix-community/nix-direnv/issues/109#issuecomment-992514426

View File

@@ -0,0 +1,45 @@
# Provides path to project root with:
# 1. ${lib.getExe config.flake-root.package}
# 2. $FLAKE_ROOT environment-varible
# Top-level parameters that are bound to the provider flake
# These are passed from `flake.nix` using importApply
{
localSelf,
flake-parts-lib,
nixpkgs-lib,
flake-root,
...
}:
# These values would bind to the consumer flake when this flake module is imported:
{
config,
self,
inputs,
getSystem,
moduleWithSystem,
withSystem,
...
}:
# The actual flake-parts module configuration
{
imports = [ flake-root.flakeModule ];
perSystem =
{
config,
self',
inputs',
pkgs,
system,
...
}:
{
flake-root.projectRootFile = "flake.nix"; # Not necessary, as flake.nix is the default
make-shells.default = {
inputsFrom = [ config.flake-root.devShell ]; # Adds $FLAKE_ROOT to environment
};
};
}

View File

@@ -0,0 +1,72 @@
# Configures the Golang support and builds the forwarder
# TODO: split this up in the future as this is unrelated tasks??
# Top-level parameters that are bound to the provider flake
# These are passed from `flake.nix` using importApply
{
localSelf,
flake-parts-lib,
nixpkgs-lib,
...
}:
# These values would bind to the consumer flake when this flake module is imported:
{
config,
self,
inputs,
getSystem,
moduleWithSystem,
withSystem,
...
}:
# The actual flake-parts module configuration
{
perSystem =
{
config,
self',
inputs',
pkgs,
system,
...
}:
let
flakeRoot = nixpkgs-lib.getExe config.flake-root.package;
# Build the networking/forwarder Go utility.
forwarder = pkgs.buildGoModule {
pname = "exo-forwarder";
version = "0.1.0";
src = "${flakeRoot}/networking/forwarder";
vendorHash = "sha256-BXIGg2QYqHDz2TNe8hLAGC6jVlffp9766H+WdkkuVgA=";
# Only the main package at the repository root needs building.
subPackages = [ "." ];
};
in
{
packages = {
inherit forwarder;
};
apps = {
forwarder = {
type = "app";
program = "${forwarder}/bin/forwarder";
};
};
make-shells.default = {
# Go 1.24 compiler align with go.mod
packages = [ pkgs.go_1_24 ];
# TODO: change this into exported env via nix directly???
shellHook = ''
export GOPATH=$(mktemp -d)
'';
};
};
}

View File

@@ -0,0 +1,54 @@
# Provides pretty banner & command index for this flake
# Top-level parameters that are bound to the provider flake
# These are passed from `flake.nix` using importApply
{
localSelf,
flake-parts-lib,
nixpkgs-lib,
just-flake,
...
}:
# These values would bind to the consumer flake when this flake module is imported:
{
config,
self,
inputs,
getSystem,
moduleWithSystem,
withSystem,
...
}:
# The actual flake-parts module configuration
{
imports = [ just-flake.flakeModule ];
perSystem =
{
config,
self',
inputs',
pkgs,
system,
...
}:
{
just-flake.features = {
# treefmt.enable = true;
# rust.enable = true;
# convco.enable = true;
# hello = {
# enable = true;
# justfile = ''
# hello:
# echo Hello World
# '';
# };
};
make-shells.default = {
inputsFrom = [ config.just-flake.outputs.devShell ];
};
};
}

5
.gitignore vendored
View File

@@ -14,4 +14,7 @@ build/
*.xcuserstate
rust/target/
rust/Cargo.lock
rust/Cargo.lock
# Says this symlink should be git-ignored https://github.com/juspay/just-flake
just-flake.just

108
flake.lock generated
View File

@@ -1,20 +1,86 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"lastModified": 1696426674,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-parts": {
"inputs": {
"nixpkgs-lib": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1754420989,
"narHash": "sha256-3e4wHzNwTMg7GaeLH9A091DMaO9AfFxUjpfqbddCUeo=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "7f38f25a44023a21a504bd3fd9d4f41c4a39f55c",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"flake-root": {
"locked": {
"lastModified": 1723604017,
"narHash": "sha256-rBtQ8gg+Dn4Sx/s+pvjdq3CB2wQNzx9XGFq/JVGCB6k=",
"owner": "srid",
"repo": "flake-root",
"rev": "b759a56851e10cb13f6b8e5698af7b59c44be26e",
"type": "github"
},
"original": {
"owner": "srid",
"repo": "flake-root",
"type": "github"
}
},
"just-flake": {
"locked": {
"lastModified": 1713316411,
"narHash": "sha256-NkJfU6H+6vgHkPtZ2ESbZ/h2wnsDQrZvB4vbdUIBx8Q=",
"owner": "juspay",
"repo": "just-flake",
"rev": "0e33952a4bcd16cd54ee3aba8111606c237d4526",
"type": "github"
},
"original": {
"owner": "juspay",
"repo": "just-flake",
"type": "github"
}
},
"make-shell": {
"inputs": {
"flake-compat": "flake-compat"
},
"locked": {
"lastModified": 1733933815,
"narHash": "sha256-9JjM7eT66W4NJAXpGUsdyAFXhBxFWR2Z9LZwUa7Hli0=",
"owner": "nicknovitski",
"repo": "make-shell",
"rev": "ffeceae9956df03571ea8e96ef77c2924f13a63c",
"type": "github"
},
"original": {
"owner": "nicknovitski",
"repo": "make-shell",
"type": "github"
}
},
@@ -36,24 +102,12 @@
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"flake-parts": "flake-parts",
"flake-root": "flake-root",
"just-flake": "just-flake",
"make-shell": "make-shell",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",

185
flake.nix
View File

@@ -3,80 +3,133 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils = {
url = "github:numtide/flake-utils";
inputs.nixpkgs.follows = "nixpkgs";
# Use flake-parts for modular configs
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
# Flake-parts wrapper for mkShell
make-shell.url = "github:nicknovitski/make-shell";
# Provides path to project root with:
# 1. ${lib.getExe config.flake-root.package}
# 2. $FLAKE_ROOT environment-varible
flake-root.url = "github:srid/flake-root";
# Provides flake integration with [Just](https://just.systems/man/en/)
just-flake.url = "github:juspay/just-flake";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
outputs =
inputs@{
flake-parts,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } (
{
flake-parts-lib,
self,
...
}:
let
pkgs = (import nixpkgs) {
inherit system;
nixpkgs-lib = inputs.nixpkgs.lib;
# A wraper around importApply that supplies default parameters
importApply' =
path: extraParams:
(flake-parts-lib.importApply path (
nixpkgs-lib.recursiveUpdate {
localSelf = self;
inherit flake-parts-lib;
inherit nixpkgs-lib;
} extraParams
));
# instantiate all the flake modules, passing custom arguments to them as needed
flakeModules = {
flakeRoot = importApply' ./.flake-modules/flake-root.nix { inherit (inputs) flake-root; };
justFlake = importApply' ./.flake-modules/just-flake.nix {
inherit (inputs) just-flake;
};
goForwarder = importApply' ./.flake-modules/go-forwarder.nix { };
};
# Go 1.23 compiler align with go.mod
go = pkgs.go_1_23;
# Build the networking/forwarder Go utility.
forwarder = pkgs.buildGoModule {
pname = "exo-forwarder";
version = "0.1.0";
src = ./networking/forwarder;
vendorHash = "sha256-BXIGg2QYqHDz2TNe8hLAGC6jVlffp9766H+WdkkuVgA=";
# Only the main package at the repository root needs building.
subPackages = [ "." ];
};
buildInputs = with pkgs; [
];
nativeBuildInputs = with pkgs; [
];
in
{
packages = {
inherit forwarder;
default = forwarder;
};
apps = {
forwarder = {
type = "app";
program = "${forwarder}/bin/forwarder";
};
python-lsp = {
type = "app";
program = "${pkgs.basedpyright}/bin/basedpyright-langserver";
};
default = self.apps.${system}.forwarder;
};
devShells.default = pkgs.mkShell {
packages = [
pkgs.python313
pkgs.uv
pkgs.just
pkgs.protobuf
pkgs.basedpyright
pkgs.ruff
go
{
imports = [
inputs.make-shell.flakeModules.default
flakeModules.flakeRoot
flakeModules.justFlake
flakeModules.goForwarder
];
systems = [
"x86_64-linux"
"aarch64-darwin"
];
perSystem =
{
config,
self',
inputs',
pkgs,
system,
...
}:
let
buildInputs = with pkgs; [
];
# TODO: change this into exported env via nix directly???
shellHook = ''
export GOPATH=$(mktemp -d)
'';
nativeBuildInputs = with pkgs; [
nixpkgs-fmt
cmake
] ++ buildInputs ++ nativeBuildInputs;
];
in
{
# Per-system attributes can be defined here. The self' and inputs'
# module parameters provide easy access to attributes of the same
# system.
# NOTE: pkgs is equivalent to inputs'.nixpkgs.legacyPackages.hello;
apps = {
python-lsp = {
type = "app";
program = "${pkgs.basedpyright}/bin/basedpyright-langserver";
};
default = self'.apps.forwarder;
};
# fixes libstdc++.so issues and libgl.so issues
LD_LIBRARY_PATH = "${pkgs.stdenv.cc.cc.lib}/lib";
make-shells.default = {
packages = [
pkgs.python313
pkgs.uv
pkgs.protobuf
pkgs.basedpyright
pkgs.ruff
];
nativeBuildInputs =
with pkgs;
[
nixpkgs-fmt
cmake
]
++ buildInputs
++ nativeBuildInputs;
# Arguments which are intended to be environment variables in the shell environment
# should be changed to attributes of the `env` option
env = {
# fixes libstdc++.so issues and libgl.so issues
LD_LIBRARY_PATH = "${pkgs.stdenv.cc.cc.lib}/lib";
};
# Arbitrary mkDerivation arguments should be changed to be attributes of the `additionalArguments` option
additionalArguments = { };
};
};
}
flake = {
# The usual flake attributes can be defined here, including system-
# agnostic ones like nixosModule and system-enumerating ones, although
# those are more easily expressed in perSystem.
};
}
);
}
}

View File

@@ -1,3 +1,9 @@
# See flake.nix (just-flake)
import "just-flake.just"
default:
@just --list
regenerate-protobufs:
#!/usr/bin/env bash
if [ -f shared/protobufs/schemas/*.proto ]; then

View File

@@ -1,8 +1,6 @@
module forwarder
go 1.23.8
toolchain go1.24.3
go 1.24.3
replace forwarder/src => ./src