Skip to content
Merged
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 .config/selfci/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
local.yaml
31 changes: 31 additions & 0 deletions .config/selfci/ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
set -eou pipefail

function job_lint() {
selfci step start "treefmt"
if ! treefmt --ci ; then
selfci step fail
fi
}

function job_checks() {
selfci step start "flake check"
nix flake check -L
}

case "$SELFCI_JOB_NAME" in
main)
selfci job start "lint"
selfci job start "checks"
;;
checks)
job_checks
;;
lint)
export -f job_lint
nix develop -c bash -c "job_lint"
;;
*)
echo "Unknown job: $SELFCI_JOB_NAME"
exit 1
esac
7 changes: 7 additions & 0 deletions .config/selfci/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
job:
clone-mode: partial
command: ./.config/selfci/ci.sh

mq:
base-branch: master
merge-style: rebase
3 changes: 2 additions & 1 deletion bin/bootstrap.flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
flake-utils.lib.eachDefaultSystem (
system:
let
flakeboxLib = flakebox.lib.${system} { };
pkgs = nixpkgs.legacyPackages.${system};
flakeboxLib = flakebox.lib.mkLib pkgs { };
in
{
devShells = {
Expand Down
2 changes: 2 additions & 0 deletions checks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ onlyDrvs (
workspaceSanity = callPackage ./workspace-sanity { };
workspaceCross = callPackage ./workspace-cross-compile { inherit full; };
customStdenv = callPackage ./custom-stdenv { };
nextest = callPackage ./nextest { };
mergeArgsTests = callPackage ./mergeArgs-tests.nix { };
}
)
)
80 changes: 80 additions & 0 deletions checks/mergeArgs-tests.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{ pkgs, flakeboxLib }:
let
inherit (pkgs) lib;
mergeArgs = flakeboxLib.mergeArgs;

assertEq =
name: actual: expected:
lib.assertMsg (
actual == expected
) "${name}: expected ${builtins.toJSON expected}, got ${builtins.toJSON actual}";

r1 = mergeArgs { buildInputs = [ 1 ]; } { buildInputs = [ 2 ]; };
r2 = mergeArgs { nativeBuildInputs = [ 1 ]; } { nativeBuildInputs = [ 2 ]; };
r3 = mergeArgs { packages = [ 1 ]; } { packages = [ 2 ]; };
r4 =
mergeArgs
{
env = {
A = "1";
};
}
{
env = {
B = "2";
};
};
r5 =
mergeArgs
{
env = {
A = "1";
};
}
{
env = {
A = "2";
};
};
r6 = mergeArgs { } { buildInputs = [ 1 ]; };
r7 = mergeArgs { buildInputs = [ 1 ]; } { };
r8 = mergeArgs { } {
env = {
A = "1";
};
};
r9 = mergeArgs {
env = {
A = "1";
};
} { };
r10 = mergeArgs { foo = "left"; } { bar = "right"; };
r11 = mergeArgs { foo = "left"; } { foo = "right"; };
in

assert assertEq "buildInputs merges both sides" r1.buildInputs [
1
2
];
assert assertEq "nativeBuildInputs merges both sides" r2.nativeBuildInputs [
1
2
];
assert assertEq "packages merges both sides" r3.packages [
1
2
];
assert assertEq "env merges both sides" r4.env {
A = "1";
B = "2";
};
assert assertEq "env right overrides left" r5.env { A = "2"; };
assert assertEq "buildInputs left missing" r6.buildInputs [ 1 ];
assert assertEq "buildInputs right missing" r7.buildInputs [ 1 ];
assert assertEq "env left missing" r8.env { A = "1"; };
assert assertEq "env right missing" r9.env { A = "1"; };
assert assertEq "plain attrs from both sides" r10.foo "left";
assert assertEq "plain attrs from both sides (bar)" r10.bar "right";
assert assertEq "plain attrs right overrides left" r11.foo "right";

pkgs.runCommand "mergeArgs-tests" { } "touch $out"
7 changes: 7 additions & 0 deletions checks/nextest/Cargo.lock

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

12 changes: 12 additions & 0 deletions checks/nextest/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[workspace]
members = ["crate"]
resolver = "2"

[workspace.package]
edition = "2021"

[profile.ci]
debug = "line-tables-only"
inherits = "dev"
incremental = false
lto = "off"
4 changes: 4 additions & 0 deletions checks/nextest/crate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
name = "nextest-check"
version = "0.1.0"
edition = { workspace = true }
4 changes: 4 additions & 0 deletions checks/nextest/crate/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
38 changes: 38 additions & 0 deletions checks/nextest/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{ pkgs, flakeboxLib }:
let
rootDir = builtins.path {
name = "nextest";
path = ./.;
};

buildPaths = [
"Cargo.toml"
"Cargo.lock"
"crate"
];

multiOutput = (flakeboxLib.craneMultiBuild { }) (
craneLib':
let
src = flakeboxLib.filterSubPaths {
root = rootDir;
paths = buildPaths;
};

craneLib = craneLib'.overrideArgs {
pname = "nextest-check";
version = "0.0.1";
inherit src;
};
in
{
workspaceDeps = craneLib.buildWorkspaceDepsOnly { };
nextest = craneLib.cargoNextest {
cargoArtifacts = craneLib.buildWorkspaceDepsOnly { };
};
}
);
in
pkgs.linkFarmFromDrvs "nextest" [
multiOutput.ci.nextest
]
32 changes: 19 additions & 13 deletions docs/building-new-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ index 615d404..860927a 100644
+ outputs = { self, nixpkgs, flakebox, flake-utils }:
+ flake-utils.lib.eachDefaultSystem (system:
+ let
+ flakeboxLib = flakebox.lib.${system} { };
+ pkgs = nixpkgs.legacyPackages.${system};
+ flakeboxLib = flakebox.lib.mkLib pkgs { };
+ in
+ {
+ devShells = flakeboxLib.mkShells {
Expand Down Expand Up @@ -179,7 +180,8 @@ Since that's a bit handful, let me paste the whole content:
outputs = { self, nixpkgs, flakebox, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
flakeboxLib = flakebox.lib.${system} { };
pkgs = nixpkgs.legacyPackages.${system};
flakeboxLib = flakebox.lib.mkLib pkgs { };
in
{
devShells = flakeboxLib.mkShells {
Expand Down Expand Up @@ -316,7 +318,8 @@ index cb41316..08c8f65 100644
@@ -16,8 +16,38 @@
flake-utils.lib.eachDefaultSystem (system:
let
flakeboxLib = flakebox.lib.${system} { };
+ pkgs = nixpkgs.legacyPackages.${system};
flakeboxLib = flakebox.lib.mkLib pkgs { };
+
+ rustSrc = flakeboxLib.filterSubPaths {
+ root = builtins.path {
Expand Down Expand Up @@ -407,19 +410,24 @@ Skipping semgrep check: .config/semgrep.yaml empty
Let's discuss each part of the code:

```
flakeboxLib = flakebox.lib.${system} { };
pkgs = nixpkgs.legacyPackages.${system};
flakeboxLib = flakebox.lib.mkLib pkgs { };
```

`let ... in <expr>` in Nix is used to bind values
to names, that can later be used in `<expr>` following
in.

Our first name binding is `flakeboxLib` which exposes all
Our first name binding is `pkgs` which is the standard way to
get the nixpkgs package set for the current `system`.

Next is `flakeboxLib` which exposes all
Flakebox APIs. `flakebox` is the name of the input
defined in the flake, `flakebox.lib.${system}` is
the library output it exposes for the current `system`.
`flakebox.lib.${system} { }` is a function call, where
`{ }` are the arguments (empty set, defaults).
defined in the flake, `flakebox.lib.mkLib` is
the function used to initialize the library.
`flakebox.lib.mkLib pkgs { }` is a function call, where
`pkgs` is the nixpkgs package set and `{ }` are the
configuration arguments (empty set, defaults).

This is where you can enable/disable/configure various features of flakebox. A list of config options can be found [here](./nixos-options.md)

Expand Down Expand Up @@ -714,11 +722,9 @@ index a65ba7a..f4c64d7 100644
flake-utils.lib.eachDefaultSystem (system:
let
+
+ pkgs = import nixpkgs {
+ inherit system;
+ };
+ pkgs = nixpkgs.legacyPackages.${system};
+
flakeboxLib = flakebox.lib.${system} { };
flakeboxLib = flakebox.lib.mkLib pkgs { };

rustSrc = flakeboxLib.filterSubPaths {
@@ -36,6 +41,10 @@
Expand Down
4 changes: 3 additions & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ Following modifications to `flake.nix` are needed:
# Set project name
projectName = "my-project";

pkgs = nixpkgs.legacyPackages.${system};

# Set up the flakebox lib for your system
flakeboxLib = flakebox.lib.${system} {
flakeboxLib = flakebox.lib.mkLib pkgs {
# customizations go here
config = {
typos.pre-commit.enable = false;
Expand Down
2 changes: 1 addition & 1 deletion docs/native-toolchains.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ These toolchains are meant to be native target toolchains.
To change the default toolchain channel to nightly use:

```nix
flakeboxLib = flakebox.lib.${system} {
flakeboxLib = flakebox.lib.mkLib pkgs {
config = {
toolchain.channel = "complete"; # or "latest", see https://github.com/nix-community/fenix for details
};
Expand Down
Loading