Skip to content
Closed
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
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
28 changes: 28 additions & 0 deletions .github/workflows/nix-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Run nix checks on prs

on:
pull_request:
branches: [ "master", "rewrite/v3" ]

defaults:
run:
shell: bash

jobs:
check:
name: Check Nix
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/flakehub-cache-action@main
- name: Check flake.lock
uses: DeterminateSystems/flake-checker-action@main
with:
fail-mode: true
- name: Check Nix formatting
run: nix flake check
21 changes: 21 additions & 0 deletions .github/workflows/update-nix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: update-flake-lock
on:
workflow_dispatch: # allows manual triggering
schedule:
- cron: '0 0 * * 0' # runs weekly on Sunday at 00:00

permissions:
contents: write
pull-requests: write

jobs:
lockfile:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/flakehub-cache-action@main
- uses: DeterminateSystems/update-flake-lock@main
with:
pr-title: "Update flake.lock"
pr-assignees: eveeifyeve
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ config.toml
.etc/blocks.json

flame.svg

.direnv
result
result-*
96 changes: 96 additions & 0 deletions flake.lock

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

78 changes: 78 additions & 0 deletions flake.nix
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff --git a/flake.nix b/flake.nix
index cd51e48..4c69f92 100644
--- a/flake.nix
+++ b/flake.nix
@@ -1,10 +1,15 @@
 {
   inputs = {
     nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
-    flake-parts.url = "github:hercules-ci/flake-parts";
-    flake-compat = {
-      url = "github:edolstra/flake-compat";
-      flake = false;
+    systems.url = "github:nix-systems/default";
+    flake-compat.url = "github:edolstra/flake-compat";
+    treefmt-nix = {
+      url = "github:numtide/treefmt-nix";
+      inputs.nixpkgs.follows = "nixpkgs";
+    };
+    flake-parts = {
+      url = "github:hercules-ci/flake-parts";
+      inputs.nixpkgs-lib.follows = "nixpkgs";
     };
     rust-overlay = {
       url = "github:oxalica/rust-overlay";
@@ -14,13 +19,19 @@
 
   outputs =
     inputs@{
+      systems,
       flake-parts,
+      treefmt-nix,
       nixpkgs,
       rust-overlay,
       ...
     }:
     flake-parts.lib.mkFlake { inherit inputs; } {
-      systems = nixpkgs.lib.systems.flakeExposed;
+      systems = import systems;
+
+      imports = [
+        treefmt-nix.flakeModule
+      ];
 
       perSystem =
         {
@@ -28,51 +39,27 @@
           system,
           ...
         }:
+        let
+          rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
+        in
         {
-          formatter = nixpkgs.legacyPackages.${system}.nixfmt-rfc-style;
           _module.args.pkgs = import inputs.nixpkgs {
             inherit system;
-            overlays = [
-              rust-overlay.overlays.default
-              (self: super: {
-                rustToolchain =
-                  let
-                    rust = super.rust-bin;
-                  in
-                  if builtins.pathExists ./rust-toolchain.toml then
-                    rust.fromRustupToolchainFile ./rust-toolchain.toml
-                  else if builtins.pathExists ./rust-toolchain then
-                    rust.fromRustupToolchainFile ./rust-toolchain
-                  else
-                    rust.nightly.latest.default;
-              })
-            ];
-            config = { };
+            overlays = [ rust-overlay.overlays.default ];
           };
 
-          # Used to check formatting for nix specificly
-          checks.fmt-check =
-            pkgs.runCommand "format-check"
-              {
-                src = ./.;
-                doCheck = true;
-                nativeBuildInputs = [
-                  pkgs.nixfmt-rfc-style
-                ];
-              }
-              ''
-                					nixfmt --check .
-                					touch $out
-                				'';
+          treefmt = {
+            projectRootFile = "flake.lock";
+            programs.nixfmt.enable = true;
+          };
 
           devShells.default = pkgs.mkShell {
-            packages = with pkgs; [
+            packages = [
               rustToolchain
-              pkg-config
-              openssl
+              pkgs.pkg-config
+              pkgs.openssl
             ];
           };
-
         };
     };
 }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I suggest to use numtide/treefmt-nix to create a formatter.
  • I also suggest to use nix-systems/default to reference available systems.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use nix-systems can I ask because nixpkgs.lib.systems.flakeExposed does basically the same thing but with an extra dependancy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<nixpkgs>/lib/systems/flake-systems.nix
This file contains not only x86_64-linux and aarch64-linux, but also i686-linux, powerpc64le-linux and riscv64-linux. Are we even needed to support powerpc64le-linux & riscv64-linux systems?

The nix-systems/default contains only these systems. If we don't support Darwin systems, we can use nix-systems/default-linux.

# github:nix-systems/default

[
  "aarch64-darwin"
  "aarch64-linux"
  "x86_64-darwin"
  "x86_64-linux"
]
# github:nix-systems/default-linux

[
  "aarch64-linux"
  "x86_64-linux"
]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want support for windows, linux and mac, with linux and mac being able to work on ARM64 systems. I have no idea how nix works so if you guys can make that work and are happy to maintain it, I'll merge it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ReCore-sys
Hi. For now, I created a sample branch for @Eveeifyeve , to check my above patch. Please check the commit. If you want the way to check the commit, Feel free to ask me!!
(Now the commit is not include the GitHub Actions, because I don't know that @ReCore-sys really want to check via Nix flakes)
haruki7049@44a9302

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. For now I'd rather not have a CI step for nix flakes since I'm already fighting tooth and nail to get the windows build times to a reasonable level. Either @Eveeifyeve can include your changes or you are welcome to open your own PR and I'll merge that instead, whatever works out best for you guys.

Copy link
Contributor Author

@Eveeifyeve Eveeifyeve Jun 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say that is better for another pr and GitHub actions don't seem right for this job and I am actually removing this or changing it to not open prs but make a commit straight. I have let a lone 30+ prs from GitHub actions updating flakes it does get cluttered very quick.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me. @haruki7049 if you wanna open another PR without the CI modifications I'll merge that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ReCore-sys @Eveeifyeve
#185
Created the PR. Please check.

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs =
inputs@{
flake-parts,
nixpkgs,
rust-overlay,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = nixpkgs.lib.systems.flakeExposed;

perSystem =
{
pkgs,
system,
...
}:
{
formatter = nixpkgs.legacyPackages.${system}.nixfmt-rfc-style;
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
rust-overlay.overlays.default
(self: super: {
rustToolchain =
let
rust = super.rust-bin;
in
if builtins.pathExists ./rust-toolchain.toml then
rust.fromRustupToolchainFile ./rust-toolchain.toml
else if builtins.pathExists ./rust-toolchain then
rust.fromRustupToolchainFile ./rust-toolchain
else
rust.nightly.latest.default;
})
];
config = { };
};

# Used to check formatting for nix specificly
checks.fmt-check =
pkgs.runCommand "format-check"
{
src = ./.;
doCheck = true;
nativeBuildInputs = [
pkgs.nixfmt-rfc-style
];
}
''
nixfmt --check .
touch $out
'';

devShells.default = pkgs.mkShell {
packages = with pkgs; [
rustToolchain
pkg-config
openssl
];
};

};
};
}
12 changes: 12 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(import (
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
nodeName = lock.nodes.root.inputs.flake-compat;
in
fetchTarball {
url =
lock.nodes.${nodeName}.locked.url
or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz";
sha256 = lock.nodes.${nodeName}.locked.narHash;
}
) { src = ./.; }).shellNix
Loading