Skip to content

Commit

Permalink
style: format all code using nixfmt-rfc-style
Browse files Browse the repository at this point in the history
  • Loading branch information
wrvsrx committed Mar 13, 2024
1 parent 4fffceb commit 143bffd
Show file tree
Hide file tree
Showing 43 changed files with 662 additions and 559 deletions.
165 changes: 89 additions & 76 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,85 +10,98 @@
nixpkgs.follows = "flake-lock/nixpkgs";
flake-parts.follows = "flake-lock/flake-parts";
};
outputs = inputs': inputs'.flake-parts.lib.mkFlake { inputs = inputs'; } ({ withSystem, inputs, ... }:
let
inherit (import ./pkgs)
pkgs-to-packages
pkgs-to-flat-packages
pkgs-to-python-modules
pkgs-to-vim-plugins
;
templates = import ./templates;
in
{
systems = [ "x86_64-linux" ];
flake = {
inherit templates;
lib = {
# this function is modified from nix official implementation
# https://github.com/NixOS/nix/blob/56dc6ed8410510033b835d48b3bd22766e8349a0/src/libexpr/flake/call-flake.nix#L7-L61
importFlake =
{ path
, inputs
, narHash
}:
let
flake = import (path + "/flake.nix");
outputs = flake.outputs (inputs // { self = result; });
result = outputs // { outPath = path; inherit inputs outputs narHash; _type = "flake"; };
in
result;
patchFlake =
{ flake
, system
, patchesToFetch
}:
let
initial-pkgs = import inputs.nixpkgs { inherit system; };
src = initial-pkgs.applyPatches {
name = "patched-flake";
src = flake;
patches = [ (map initial-pkgs.fetchpatch patchesToFetch) ];
};
narHashDrv = initial-pkgs.stdenvNoCC.mkDerivation {
name = "narHash";
nativeBuildInputs = [ initial-pkgs.nix ];
unpackPhase = "true";
installPhase = ''
echo \"sha256- > $out
nix-hash --type sha256 --base64 ${src} >> $out
echo \" >> $out
'';
outputs =
inputs':
inputs'.flake-parts.lib.mkFlake { inputs = inputs'; } (
{ withSystem, inputs, ... }:
let
inherit (import ./pkgs)
pkgs-to-packages
pkgs-to-flat-packages
pkgs-to-python-modules
pkgs-to-vim-plugins
;
templates = import ./templates;
in
{
systems = [ "x86_64-linux" ];
flake = {
inherit templates;
lib = {
# this function is modified from nix official implementation
# https://github.com/NixOS/nix/blob/56dc6ed8410510033b835d48b3bd22766e8349a0/src/libexpr/flake/call-flake.nix#L7-L61
importFlake =
{
path,
inputs,
narHash,
}:
let
flake = import (path + "/flake.nix");
outputs = flake.outputs (inputs // { self = result; });
result = outputs // {
outPath = path;
inherit inputs outputs narHash;
_type = "flake";
};
in
result;
patchFlake =
{
flake,
system,
patchesToFetch,
}:
let
initial-pkgs = import inputs.nixpkgs { inherit system; };
src = initial-pkgs.applyPatches {
name = "patched-flake";
src = flake;
patches = [ (map initial-pkgs.fetchpatch patchesToFetch) ];
};
narHashDrv = initial-pkgs.stdenvNoCC.mkDerivation {
name = "narHash";
nativeBuildInputs = [ initial-pkgs.nix ];
unpackPhase = "true";
installPhase = ''
echo \"sha256- > $out
nix-hash --type sha256 --base64 ${src} >> $out
echo \" >> $out
'';
};
narHash = import "${narHashDrv}";
in
inputs.self.lib.importFlake {
inherit narHash;
inherit (flake) inputs;
path = src;
};
narHash = import "${narHashDrv}";
};
overlays.default =
final: prev:
let
# it seems that using `extend` cause infinite evaluation of overlays
pkgs = prev // (inputs.pnpm2nix-nzbr.overlays.default { } prev);
in
inputs.self.lib.importFlake {
inherit narHash;
inherit (flake) inputs;
path = src;
pkgs-to-flat-packages pkgs
// {
pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [ (pkgs-to-python-modules pkgs) ];
vimPlugins = prev.vimPlugins // (pkgs-to-vim-plugins pkgs);
};
};
overlays. default = final: prev:
let
# it seems that using `extend` cause infinite evaluation of overlays
pkgs = prev // (inputs.pnpm2nix-nzbr.overlays.default { } prev);
in
pkgs-to-flat-packages pkgs // {
pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [ (pkgs-to-python-modules pkgs) ];
vimPlugins = prev.vimPlugins // (pkgs-to-vim-plugins pkgs);
perSystem =
{ system, pkgs, ... }:
rec {
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
config.allowUnfree = true;
overlays = [ inputs.pnpm2nix-nzbr.overlays.default ];
};
packages = pkgs-to-packages pkgs;
checks = packages;
formatter = pkgs.nixfmt-rfc-style;
devShells.default = pkgs.mkShell { nativeBuildInputs = [ pkgs.nvfetcher ]; };
};
};
perSystem = { system, pkgs, ... }: rec {
_module. args. pkgs = import inputs.nixpkgs {
inherit system;
config.allowUnfree = true;
overlays = [ inputs.pnpm2nix-nzbr.overlays.default ];
};
packages = pkgs-to-packages pkgs;
checks = packages;
formatter = pkgs.nixfmt-rfc-style;
devShells.default = pkgs.mkShell { nativeBuildInputs = [ pkgs.nvfetcher ]; };
};
});
}
);
}

13 changes: 7 additions & 6 deletions pkgs/callIFD.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{ callPackage
, source
, src ? source.src
, pname ? source.pname
, version ? source.version
, otherArgs ? { }
{
callPackage,
source,
src ? source.src,
pname ? source.pname,
version ? source.version,
otherArgs ? { },
}:
(callPackage src otherArgs).overrideAttrs {
name = "${pname}-${version}";
Expand Down
12 changes: 5 additions & 7 deletions pkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ let
pkgs-to-python-modules = pkgs: to-python-modules { inherit pkgs to-sources; };
pkgs-to-normal-packages = pkgs: to-normal-packages { inherit pkgs to-sources; };
pkgs-to-override-packages = pkgs: to-override-packages { inherit pkgs to-sources; };
pkgs-to-flat-packages = pkgs:
pkgs-to-flat-packages =
pkgs:
let
normal-packages = pkgs-to-normal-packages pkgs;
override-packages = pkgs-to-override-packages pkgs;
in
normal-packages // override-packages;
pkgs-to-packages = pkgs:
pkgs-to-packages =
pkgs:
let
flat-packages = pkgs-to-flat-packages pkgs;
pythonWithPackages = pkgs.python311.override {
Expand All @@ -22,11 +24,7 @@ let
};
python-packages =
let
inherit (pythonWithPackages.pkgs)
toPythonApplication
vdirsyncer
compdb
;
inherit (pythonWithPackages.pkgs) toPythonApplication vdirsyncer compdb;
in
{
vdirsyncer = toPythonApplication vdirsyncer;
Expand Down
8 changes: 4 additions & 4 deletions pkgs/to-normal-packages/amgcl/default.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{ stdenv
, cmake
, source
{
stdenv,
cmake,
source,
}:
stdenv.mkDerivation {
inherit (source) pname src version;
nativeBuildInputs = [ cmake ];
}

10 changes: 5 additions & 5 deletions pkgs/to-normal-packages/auth-thu/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{ buildGoModule
, lib
, source
{
buildGoModule,
lib,
source,
}:
buildGoModule {
inherit (source) pname src;
Expand All @@ -9,8 +10,7 @@ buildGoModule {
subPackages = [ "cli" ];
postInstall = "mv $out/bin/cli $out/bin/$pname";
meta = with lib; {
description =
"Authentication utility for srun4000 (auth.tsinghua.edu.cn / net.tsinghua.edu.cn / Tsinghua-IPv4)";
description = "Authentication utility for srun4000 (auth.tsinghua.edu.cn / net.tsinghua.edu.cn / Tsinghua-IPv4)";
homepage = "https://github.com/z4yx/GoAuthing";
license = licenses.gpl3Only;
};
Expand Down
25 changes: 16 additions & 9 deletions pkgs/to-normal-packages/autodiff/default.nix
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
{ lib
, stdenv
, cmake
, eigen
, catch2_3
, python3 ? null
, source
{
lib,
stdenv,
cmake,
eigen,
catch2_3,
python3 ? null,
source,
}:

stdenv.mkDerivation rec {
inherit (source) pname src;
patches = [ ./pc.patch ];
version = lib.removePrefix "v" source.version;

nativeBuildInputs = [ cmake eigen catch2_3 ] ++ (if python3 != null then [ python3.pkgs.pybind11 ] else [ ]);
nativeBuildInputs = [
cmake
eigen
catch2_3
] ++ (if python3 != null then [ python3.pkgs.pybind11 ] else [ ]);

# Building the tests currently fails on AArch64 due to internal compiler
# errors (with GCC 9.2):
cmakeFlags = [ "-DRANGES_ENABLE_WERROR=OFF" ] ++ (if python3 != null then [ ] else [ "-DAUTODIFF_BUILD_PYTHON=OFF" ]);
cmakeFlags = [
"-DRANGES_ENABLE_WERROR=OFF"
] ++ (if python3 != null then [ ] else [ "-DAUTODIFF_BUILD_PYTHON=OFF" ]);

# checkTarget = "test";

Expand Down
15 changes: 7 additions & 8 deletions pkgs/to-normal-packages/cccl/default.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{ cudaPackages
, cmake
, python3
, stdenv
, source
{
cudaPackages,
cmake,
python3,
stdenv,
source,
}:
stdenv.mkDerivation {
inherit (source) pname version src;
Expand All @@ -11,9 +12,7 @@ stdenv.mkDerivation {
python3
cudaPackages.cuda_nvcc
];
buildInputs = [
cudaPackages.cuda_cudart
];
buildInputs = [ cudaPackages.cuda_cudart ];
cmakeFlags = [
"-DCCCL_ENABLE_TESTING=OFF"
"-DCCCL_ENABLE_EXAMPLES=OFF"
Expand Down
13 changes: 7 additions & 6 deletions pkgs/to-normal-packages/cmdlime/default.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{ stdenv
, cmake
, source
, sfun
, lib
, seal_lake
{
stdenv,
cmake,
source,
sfun,
lib,
seal_lake,
}:
stdenv.mkDerivation {
inherit (source) pname src;
Expand Down
10 changes: 5 additions & 5 deletions pkgs/to-normal-packages/cnpy/default.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{ stdenv
, cmake
, source
, zlib
{
stdenv,
cmake,
source,
zlib,
}:
stdenv.mkDerivation {
inherit (source) pname src version;
patches = [ ./pc.patch ];
nativeBuildInputs = [ cmake ];
propagatedBuildInputs = [ zlib ];
}

25 changes: 14 additions & 11 deletions pkgs/to-normal-packages/cuda-samples/default.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{ meson
, cmake
, ninja
, pkg-config
, haskellPackages
, stdenv
, fetchFromGitHub
{
meson,
cmake,
ninja,
pkg-config,
haskellPackages,
stdenv,
fetchFromGitHub,
}:
stdenv.mkDerivation rec {
pname = "cuda-samples";
Expand All @@ -29,9 +30,11 @@ stdenv.mkDerivation rec {
cmake
ninja
pkg-config
(haskellPackages.ghcWithPackages (ps: with ps;[
raw-strings-qq
extra
]))
(haskellPackages.ghcWithPackages (
ps: with ps; [
raw-strings-qq
extra
]
))
];
}
Loading

0 comments on commit 143bffd

Please sign in to comment.