← back to Exo
Integrate flake parts
7e19804aa576ebb27d207b5b7bb9099b96638fd8 · 2025-08-13 11:55:22 +0300 · Andrei Cravtov
Files touched
M .envrcA .flake-modules/flake-root.nixA .flake-modules/go-forwarder.nixA .flake-modules/just-flake.nixM .gitignoreM flake.lockM flake.nixM justfileM networking/forwarder/go.mod
Diff
commit 7e19804aa576ebb27d207b5b7bb9099b96638fd8
Author: Andrei Cravtov <the.andrei.cravtov@gmail.com>
Date: Wed Aug 13 11:55:22 2025 +0300
Integrate flake parts
---
.envrc | 3 +-
.flake-modules/flake-root.nix | 45 +++++++++++
.flake-modules/go-forwarder.nix | 72 +++++++++++++++++
.flake-modules/just-flake.nix | 54 +++++++++++++
.gitignore | 5 +-
flake.lock | 104 ++++++++++++++++++------
flake.nix | 175 ++++++++++++++++++++++++++--------------
justfile | 6 ++
networking/forwarder/go.mod | 4 +-
9 files changed, 377 insertions(+), 91 deletions(-)
diff --git a/.envrc b/.envrc
index 8392d159..613b6c8d 100644
--- a/.envrc
+++ b/.envrc
@@ -1 +1,2 @@
-use flake
\ No newline at end of file
+use flake
+# eval "$shellHook" # https://github.com/nix-community/nix-direnv/issues/109#issuecomment-992514426
\ No newline at end of file
diff --git a/.flake-modules/flake-root.nix b/.flake-modules/flake-root.nix
new file mode 100644
index 00000000..02ca1735
--- /dev/null
+++ b/.flake-modules/flake-root.nix
@@ -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
+ };
+ };
+}
diff --git a/.flake-modules/go-forwarder.nix b/.flake-modules/go-forwarder.nix
new file mode 100644
index 00000000..6d711645
--- /dev/null
+++ b/.flake-modules/go-forwarder.nix
@@ -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)
+ '';
+ };
+ };
+}
diff --git a/.flake-modules/just-flake.nix b/.flake-modules/just-flake.nix
new file mode 100644
index 00000000..2208a58c
--- /dev/null
+++ b/.flake-modules/just-flake.nix
@@ -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 ];
+ };
+ };
+}
diff --git a/.gitignore b/.gitignore
index 7650e517..2b800b88 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,4 +14,7 @@ build/
*.xcuserstate
rust/target/
-rust/Cargo.lock
\ No newline at end of file
+rust/Cargo.lock
+
+# Says this symlink should be git-ignored https://github.com/juspay/just-flake
+just-flake.just
\ No newline at end of file
diff --git a/flake.lock b/flake.lock
index 5feb92a9..7e9d54e3 100644
--- a/flake.lock
+++ b/flake.lock
@@ -1,20 +1,86 @@
{
"nodes": {
- "flake-utils": {
+ "flake-compat": {
+ "flake": false,
+ "locked": {
+ "lastModified": 1696426674,
+ "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
+ "owner": "edolstra",
+ "repo": "flake-compat",
+ "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
+ "type": "github"
+ },
+ "original": {
+ "owner": "edolstra",
+ "repo": "flake-compat",
+ "type": "github"
+ }
+ },
+ "flake-parts": {
"inputs": {
- "systems": "systems"
+ "nixpkgs-lib": [
+ "nixpkgs"
+ ]
},
"locked": {
- "lastModified": 1731533236,
- "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
- "owner": "numtide",
- "repo": "flake-utils",
- "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
+ "lastModified": 1754420989,
+ "narHash": "sha256-3e4wHzNwTMg7GaeLH9A091DMaO9AfFxUjpfqbddCUeo=",
+ "owner": "hercules-ci",
+ "repo": "flake-parts",
+ "rev": "7f38f25a44023a21a504bd3fd9d4f41c4a39f55c",
"type": "github"
},
"original": {
- "owner": "numtide",
- "repo": "flake-utils",
+ "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",
diff --git a/flake.nix b/flake.nix
index 4fe1f075..ce7d82d1 100644
--- a/flake.nix
+++ b/flake.nix
@@ -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;
- };
-
- # 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;
+ nixpkgs-lib = inputs.nixpkgs.lib;
- vendorHash = "sha256-BXIGg2QYqHDz2TNe8hLAGC6jVlffp9766H+WdkkuVgA=";
+ # 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
+ ));
- # Only the main package at the repository root needs building.
- subPackages = [ "." ];
+ # 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 { };
};
-
- buildInputs = with pkgs; [
+ in
+ {
+ imports = [
+ inputs.make-shell.flakeModules.default
+ flakeModules.flakeRoot
+ flakeModules.justFlake
+ flakeModules.goForwarder
];
- nativeBuildInputs = with pkgs; [
+ systems = [
+ "x86_64-linux"
+ "aarch64-darwin"
];
- in
- {
- packages = {
- inherit forwarder;
- default = forwarder;
- };
-
- apps = {
- forwarder = {
- type = "app";
- program = "${forwarder}/bin/forwarder";
- };
- python-lsp = {
- type = "app";
- program = "${pkgs.basedpyright}/bin/basedpyright-langserver";
+ perSystem =
+ {
+ config,
+ self',
+ inputs',
+ pkgs,
+ system,
+ ...
+ }:
+ let
+ buildInputs = with pkgs; [
+ ];
+ nativeBuildInputs = with pkgs; [
+ ];
+ 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;
};
- default = self.apps.${system}.forwarder;
- };
- devShells.default = pkgs.mkShell {
- packages = [
- pkgs.python313
- pkgs.uv
- pkgs.just
- pkgs.protobuf
- pkgs.basedpyright
- pkgs.ruff
- go
- ];
+ make-shells.default = {
+ packages = [
+ pkgs.python313
+ pkgs.uv
+ pkgs.protobuf
+ pkgs.basedpyright
+ pkgs.ruff
+ ];
- # TODO: change this into exported env via nix directly???
- shellHook = ''
- export GOPATH=$(mktemp -d)
- '';
+ nativeBuildInputs =
+ with pkgs;
+ [
+ nixpkgs-fmt
+ cmake
+ ]
+ ++ buildInputs
+ ++ nativeBuildInputs;
- 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";
+ };
- # 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.
+
+ };
+ }
);
-}
\ No newline at end of file
+}
diff --git a/justfile b/justfile
index 871eec6d..b7787c26 100644
--- a/justfile
+++ b/justfile
@@ -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
diff --git a/networking/forwarder/go.mod b/networking/forwarder/go.mod
index 8c3a2aae..47079c0f 100644
--- a/networking/forwarder/go.mod
+++ b/networking/forwarder/go.mod
@@ -1,8 +1,6 @@
module forwarder
-go 1.23.8
-
-toolchain go1.24.3
+go 1.24.3
replace forwarder/src => ./src
← dbcd09aa No 70b
·
back to Exo
·
collection of fixes for Shanghai demo 57073f35 →