0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-11-07 05:09:30 -05:00

Port away from flake-utils (#35675)

`flake-utils` is currently only used for outputting system-specific dev
shells. This can actually be achieved only using functionality already
present within `nixpkgs`, thus there is no need for an extra dependency.

Additionally, we move to use the `packages` and `env` args for `mkShell`
to more clearly outline what they are used for.

---

Further reading:
https://determinate.systems/blog/best-practices-for-nix-at-work/#avoid-flake-helper-libraries-if-possible

As a side note, using `with` to import large scopes is [discouraged by
official Nix
resources](https://nix.dev/guides/best-practices#with-scopes), so an
alternative approach to list installed packages could be something like
this:

```nix
packages =
  (builtins.attrValues {
    inherit (pkgs)
      # generic
      git
      git-lfs
      gnumake
      gnused
      gnutar
      gzip
      zip

      # frontend
      cairo
      pixman
      pkg-config

      # linting
      uv

      # backend
      gofumpt
      sqlite
      ;

    inherit
      # frontend
      nodejs
      pnpm

      # linting
      python3

      # backend
      go
      ;
  })
  ++ linuxOnlyInputs;
```

But I saw this as too pedantic to include in the initial PR.

Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
Naxdy
2025-11-04 17:28:59 +01:00
committed by GitHub
parent 850012bf5c
commit 2be51d0b27
2 changed files with 80 additions and 93 deletions

34
flake.lock generated
View File

@@ -1,23 +1,5 @@
{ {
"nodes": { "nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1760038930, "lastModified": 1760038930,
@@ -36,24 +18,8 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs" "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", "root": "root",

139
flake.nix
View File

@@ -1,73 +1,94 @@
{ {
inputs = { inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
}; };
outputs = outputs =
{ nixpkgs, flake-utils, ... }: { nixpkgs, ... }:
flake-utils.lib.eachDefaultSystem ( let
system: supportedSystems = [
let "aarch64-darwin"
pkgs = nixpkgs.legacyPackages.${system}; "aarch64-linux"
in "x86_64-darwin"
{ "x86_64-linux"
devShells.default = ];
with pkgs;
forEachSupportedSystem =
f:
nixpkgs.lib.genAttrs supportedSystems (
system:
let let
# only bump toolchain versions here pkgs = import nixpkgs {
go = go_1_25; inherit system;
nodejs = nodejs_24;
python3 = python312;
pnpm = pnpm_10;
# Platform-specific dependencies
linuxOnlyInputs = lib.optionals pkgs.stdenv.isLinux [
glibc.static
];
linuxOnlyEnv = lib.optionalAttrs pkgs.stdenv.isLinux {
CFLAGS = "-I${glibc.static.dev}/include";
LDFLAGS = "-L ${glibc.static}/lib";
}; };
in in
pkgs.mkShell ( f { inherit pkgs; }
{ );
buildInputs = [ in
# generic {
git devShells = forEachSupportedSystem (
git-lfs { pkgs, ... }:
gnumake {
gnused default =
gnutar let
gzip inherit (pkgs) lib;
zip
# frontend # only bump toolchain versions here
nodejs go = pkgs.go_1_25;
pnpm nodejs = pkgs.nodejs_24;
cairo python3 = pkgs.python312;
pixman pnpm = pkgs.pnpm_10;
pkg-config
# linting # Platform-specific dependencies
python3 linuxOnlyInputs = lib.optionals pkgs.stdenv.isLinux [
uv pkgs.glibc.static
];
# backend linuxOnlyEnv = lib.optionalAttrs pkgs.stdenv.isLinux {
go CFLAGS = "-I${pkgs.glibc.static.dev}/include";
gofumpt LDFLAGS = "-L ${pkgs.glibc.static}/lib";
sqlite };
] in
++ linuxOnlyInputs; pkgs.mkShell {
packages =
with pkgs;
[
# generic
git
git-lfs
gnumake
gnused
gnutar
gzip
zip
GO = "${go}/bin/go"; # frontend
GOROOT = "${go}/share/go"; nodejs
pnpm
cairo
pixman
pkg-config
TAGS = "sqlite sqlite_unlock_notify"; # linting
STATIC = "true"; python3
} uv
// linuxOnlyEnv
); # backend
} go
); gofumpt
sqlite
]
++ linuxOnlyInputs;
env = {
GO = "${go}/bin/go";
GOROOT = "${go}/share/go";
TAGS = "sqlite sqlite_unlock_notify";
STATIC = "true";
}
// linuxOnlyEnv;
};
}
);
};
} }