Skip to content

Commit

Permalink
style(nix): Reformat *.nix files with nixfmt-rfc-style
Browse files Browse the repository at this point in the history
  • Loading branch information
PetarKirov committed May 5, 2024
1 parent 68cbecf commit 5665713
Show file tree
Hide file tree
Showing 25 changed files with 1,120 additions and 1,075 deletions.
11 changes: 8 additions & 3 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
inherit (lock.nodes.flake-compat.locked) owner repo rev narHash;
inherit (lock.nodes.flake-compat.locked)
owner
repo
rev
narHash
;
flake-compat = fetchTarball {
url = "https:/${owner}/${repo}/archive/${rev}.tar.gz";
sha256 = narHash;
};
thisFlake = import flake-compat {src = ./.;};
thisFlake = import flake-compat { src = ./.; };
in
thisFlake.defaultNix
thisFlake.defaultNix
68 changes: 41 additions & 27 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
description = "Nix packages for D projects";

nixConfig = {
extra-substituters = ["https://dlang-community.cachix.org"];
extra-trusted-public-keys = ["dlang-community.cachix.org-1:eAX1RqX4PjTDPCAp/TvcZP+DYBco2nJBackkAJ2BsDQ="];
extra-substituters = [ "https://dlang-community.cachix.org" ];
extra-trusted-public-keys = [
"dlang-community.cachix.org-1:eAX1RqX4PjTDPCAp/TvcZP+DYBco2nJBackkAJ2BsDQ="
];
};

inputs = {
Expand All @@ -17,33 +19,45 @@
};
};

outputs = inputs @ {
self,
nixpkgs,
flake-parts,
...
}:
flake-parts.lib.mkFlake {inherit inputs;} {
systems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"];
imports = [./pkgs ./lib/mk-gh-actions-matrix.nix];
outputs =
inputs@{
self,
nixpkgs,
flake-parts,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
imports = [
./pkgs
./lib/mk-gh-actions-matrix.nix
];

perSystem = {pkgs, ...}: {
devShells.default = import ./shells/default.nix {inherit pkgs;};
devShells.ci = import ./shells/ci.nix {inherit pkgs;};
};
perSystem =
{ pkgs, ... }:
{
devShells.default = import ./shells/default.nix { inherit pkgs; };
devShells.ci = import ./shells/ci.nix { inherit pkgs; };
};

flake.templates = let
lib = nixpkgs.lib;
allTemplates = lib.pipe (builtins.readDir ./templates) [
(lib.filterAttrs (k: v: v == "directory"))
(builtins.mapAttrs (k: v: rec {
path = ./templates + "/${k}";
description = lib.removeSuffix "\n" (
builtins.readFile (path + "/description.txt")
);
}))
];
in
flake.templates =
let
lib = nixpkgs.lib;
allTemplates = lib.pipe (builtins.readDir ./templates) [
(lib.filterAttrs (k: v: v == "directory"))
(builtins.mapAttrs (
k: v: rec {
path = ./templates + "/${k}";
description = lib.removeSuffix "\n" (builtins.readFile (path + "/description.txt"));
}
))
];
in
allTemplates;
};
}
16 changes: 9 additions & 7 deletions lib/build-status.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{lib, ...}: {
getBuildStatus = package: version: system: let
data = import ./../pkgs/${package}/build-status.nix {inherit lib;};
in
data.${version}.${system}
or {
{ lib, ... }:
{
getBuildStatus =
package: version: system:
let
data = import ./../pkgs/${package}/build-status.nix { inherit lib; };
in
data.${version}.${system} or {
# If not build status is found, we assume that the package builds
# successfully with no workarounds.
build = true;
check = true;
skippedTests = [];
skippedTests = [ ];
};
}
53 changes: 24 additions & 29 deletions lib/mk-gh-actions-matrix.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{ lib, self, ... }:
{
lib,
self,
...
}: {
flake = {
lib = rec {
# See https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories
Expand All @@ -19,41 +16,39 @@
"aarch64-darwin" = "flyci-macos-large-latest-m1";
};

inherit (import ./build-status.nix {inherit lib;}) getBuildStatus;
inherit (import ./build-status.nix { inherit lib; }) getBuildStatus;

allowedToFailMap = lib.pipe (mkGHActionsMatrix.include) [
(builtins.groupBy (p: p.package))
(builtins.mapAttrs (
n: v:
builtins.mapAttrs (
s: ps:
(builtins.head ps).allowedToFail
)
(builtins.groupBy (p: p.system) v)
n: v: builtins.mapAttrs (s: ps: (builtins.head ps).allowedToFail) (builtins.groupBy (p: p.system) v)
))
];

mkGHActionsMatrix = {
include = lib.pipe (builtins.attrNames nixSystemToGHPlatform) [
(builtins.concatMap
(
system: let
platform = nixSystemToGHPlatform.${system};
(builtins.concatMap (
system:
let
platform = nixSystemToGHPlatform.${system};
in
map (
package:
let
p = self.packages.${system}.${package};
in
map (package: let
p = self.packages.${system}.${package};
in {
os = platform;
allowedToFail = !(p.passthru.buildStatus or (throw "${package} does not expose build status")).build;
inherit system package;
attrPath = "packages.${system}.${lib.strings.escapeNixIdentifier package}";
})
(builtins.attrNames self.packages.${system})
))
(builtins.sort (a: b:
if (a.package == b.package)
then a.os == "ubuntu-latest"
else a.package < b.package))
{
os = platform;
allowedToFail =
!(p.passthru.buildStatus or (throw "${package} does not expose build status")).build;
inherit system package;
attrPath = "packages.${system}.${lib.strings.escapeNixIdentifier package}";
}
) (builtins.attrNames self.packages.${system})
))
(builtins.sort (
a: b: if (a.package == b.package) then a.os == "ubuntu-latest" else a.package < b.package
))
];
};
};
Expand Down
104 changes: 48 additions & 56 deletions lib/version-catalog.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
lib,
pkgs,
...
}: let
inherit (builtins) attrNames listToAttrs map mapAttrs;
{ lib, pkgs, ... }:
let
inherit (builtins)
attrNames
listToAttrs
map
mapAttrs
;
inherit (lib) nameValuePair pipe optional;

inherit (pkgs) callPackage;
Expand All @@ -12,61 +14,51 @@
};

system = pkgs.hostPlatform.system;
filterBySystem = pkgs:
lib.filterAttrs
(_name: pkg: builtins.elem system pkg.meta.platforms)
pkgs;
in {
genPkgVersions = pkgName: let
mod = ../pkgs/${pkgName}/version-catalog.nix;
inherit
(import mod)
supportedVersions
getSourceVersion
getBinaryVersion
;
filterBySystem = pkgs: lib.filterAttrs (_name: pkg: builtins.elem system pkg.meta.platforms) pkgs;
in
{
genPkgVersions =
pkgName:
let
mod = ../pkgs/${pkgName}/version-catalog.nix;
inherit (import mod) supportedVersions getSourceVersion getBinaryVersion;

supportedTypes =
(optional (getBinaryVersion != null) "binary")
++ (optional (getSourceVersion != null) "source");
supportedTypes =
(optional (getBinaryVersion != null) "binary") ++ (optional (getSourceVersion != null) "source");

sanitizeVersion = version: builtins.replaceStrings ["."] ["_"] version;
sanitizeVersion = version: builtins.replaceStrings [ "." ] [ "_" ] version;

getVersion = type:
if type == "source"
then getSourceVersion
else getBinaryVersion;
in {
flattened = type: let
nameSuffix =
if type == "binary"
then "-binary"
else "";
getVersion = type: if type == "source" then getSourceVersion else getBinaryVersion;
in
pipe (attrNames supportedVersions."${type}") [
(
map (
{
flattened =
type:
let
nameSuffix = if type == "binary" then "-binary" else "";
in
pipe (attrNames supportedVersions."${type}") [
(map (
version:
nameValuePair
"${pkgName}${nameSuffix}-${sanitizeVersion version}"
(callPackage (getVersion type version) darwinPkgs)
)
)
listToAttrs
filterBySystem
];
nameValuePair "${pkgName}${nameSuffix}-${sanitizeVersion version}" (
callPackage (getVersion type version) darwinPkgs
)
))
listToAttrs
filterBySystem
];

hierarchical = {
"${pkgName}" = pipe supportedTypes [
(map (type:
nameValuePair type (
mapAttrs
(version: _: (callPackage (getVersion type version) darwinPkgs))
supportedVersions."${type}"
)))
listToAttrs
filterBySystem
];
hierarchical = {
"${pkgName}" = pipe supportedTypes [
(map (
type:
nameValuePair type (
mapAttrs (version: _: (callPackage (getVersion type version) darwinPkgs))
supportedVersions."${type}"
)
))
listToAttrs
filterBySystem
];
};
};
};
}
9 changes: 5 additions & 4 deletions lib/version-utils.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{...}: {
versionBetween = after: before: version:
((builtins.compareVersions version after) >= 0)
&& ((builtins.compareVersions version before) < 0);
{ ... }:
{
versionBetween =
after: before: version:
((builtins.compareVersions version after) >= 0) && ((builtins.compareVersions version before) < 0);
}
Loading

0 comments on commit 5665713

Please sign in to comment.