Skip to content

Commit

Permalink
🎀 Introduce Nix linting (#8)
Browse files Browse the repository at this point in the history
This prevents dead nix code and improves overall code style consistency.
  • Loading branch information
aaronmondal authored May 24, 2024
1 parent 291a660 commit c3efb9c
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 46 deletions.
2 changes: 1 addition & 1 deletion flake-module.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lib, self, flake-parts-lib, ... }:
{ lib, flake-parts-lib, ... }:
let
inherit (lib)
mkOption
Expand Down
30 changes: 16 additions & 14 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,21 @@
# nixpkgs used by nativelink as the the "global" nixpkgs. We do this by
# setting `nixpkgs.follows = "nativelink/nixpkgs"` above.

inputs.flake-utils.follows = "flake-utils";
inputs.flake-parts.follows = "flake-parts";
inputs.pre-commit-hooks.follows = "pre-commit-hooks";
inputs = {
flake-utils.follows = "flake-utils";
flake-parts.follows = "flake-parts";
pre-commit-hooks.follows = "pre-commit-hooks";
};
};
rules_ll = {
url = "github:eomii/rules_ll/5ac0546db310da08d44f14271066e0b159611c25";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
inputs.flake-parts.follows = "flake-parts";
inputs.pre-commit-hooks.follows = "pre-commit-hooks";
inputs.nativelink.follows = "nativelink";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
flake-parts.follows = "flake-parts";
pre-commit-hooks.follows = "pre-commit-hooks";
nativelink.follows = "nativelink";
};
};
nix2container = {
follows = "nativelink/nix2container";
Expand All @@ -54,7 +58,6 @@
outputs =
{ self
, nixpkgs
, flake-utils
, pre-commit-hooks
, flake-parts
, nativelink
Expand All @@ -81,17 +84,16 @@
, ...
}:
let
inherit (inputs.nativelink.packages.${system}) native-cli lre-cc nativelink-debug;

tinfo6-bin = pkgs.callPackage ./tinfo6-bin.nix { };

ncurses6-bin = pkgs.callPackage ./ncurses6-bin.nix { };

native-cli = inputs.nativelink.packages.${system}.native-cli;

lre-mojo-cluster = pkgs.callPackage ./local-remote-execution/lre-mojo-cluster.nix {
inherit native-cli;
};

lre-cc = nativelink.packages.${system}.lre-cc;
inherit (nix2container.packages.${system}.nix2container) buildImage;

mojo = pkgs.callPackage ./mojo.nix {
Expand All @@ -114,7 +116,7 @@

createWorker = pkgs.callPackage ./local-remote-execution/create-worker.nix {
inherit buildImage self;
nativelink = nativelink.packages.${system}.nativelink-debug;
nativelink = nativelink-debug;
};

bazel = pkgs.writeShellScriptBin "bazel" ''
Expand All @@ -139,7 +141,7 @@
};
rules_ll.settings.llEnv =
let
openssl = (pkgs.openssl.override { static = true; });
openssl = pkgs.openssl.override { static = true; };
in
rules_ll.lib.defaultLlEnv {
inherit pkgs;
Expand Down
8 changes: 0 additions & 8 deletions lre-bazel.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@
, ...
}:

let
# The specific commit to use
nativelinkCommit = "75105df746c626da76f74e412764e6755296a8ab";

# Base URL for GitHub access
githubBaseUrl = "github:TraceMachina/nativelink/";
in

writeShellScriptBin "lre-bazel" ''
EXECUTOR=$(${kubectl}/bin/kubectl get gtw scheduler -o=jsonpath='{.status.addresses[0].value}')
CACHE=$(${kubectl}/bin/kubectl get gtw cache -o=jsonpath='{.status.addresses[0].value}')
Expand Down
2 changes: 1 addition & 1 deletion modules/rules_mojo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
let
inherit (lib) mkOption types;

inherit (pkgs) runCommand writeText git;
inherit (pkgs) runCommand git;

processedActionEnvs = map (x: "build --@rules_mojo//mojo:" + x) config.mojoEnv;

Expand Down
2 changes: 2 additions & 0 deletions pre-commit-hooks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@

# Nix
nixpkgs-fmt.enable = true;
statix.enable = true;
deadnix.enable = true;

# Vale
vale = {
Expand Down
51 changes: 29 additions & 22 deletions templates/default/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,44 +34,48 @@
# nixpkgs used by nativelink as the the "global" nixpkgs. We do this by
# setting `nixpkgs.follows = "nativelink/nixpkgs"` above.

inputs.flake-utils.follows = "flake-utils";
inputs.flake-parts.follows = "flake-parts";
inputs.pre-commit-hooks.follows = "pre-commit-hooks";
inputs = {
flake-utils.follows = "flake-utils";
flake-parts.follows = "flake-parts";
pre-commit-hooks.follows = "pre-commit-hooks";
};
};
rules_ll = {
# Keep this commit in sync with the rules_ll commit in `MODULE.bazel`.
url = "github:eomii/rules_ll/5ac0546db310da08d44f14271066e0b159611c25";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
inputs.flake-parts.follows = "flake-parts";
inputs.pre-commit-hooks.follows = "pre-commit-hooks";
inputs.nativelink.follows = "nativelink";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
flake-parts.follows = "flake-parts";
pre-commit-hooks.follows = "pre-commit-hooks";
nativelink.follows = "nativelink";
};
};
nix2container = {
follows = "nativelink/nix2container";
};
rules_mojo = {
# Keep this commit in sync with the rules_mojo commit in `MODULE.bazel`
url = "github:TraceMachina/rules_mojo/<TODO: Specify rules_mojo commit>";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
inputs.flake-parts.follows = "flake-parts";
inputs.pre-commit-hooks.follows = "pre-commit-hooks";
inputs.nativelink.follows = "nativelink";
inputs.rules_ll.follows = "rules_ll";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
flake-parts.follows = "flake-parts";
pre-commit-hooks.follows = "pre-commit-hooks";
nativelink.follows = "nativelink";
rules_ll.follows = "rules_ll";
};
};
};

outputs =
{ self
, nixpkgs
, flake-utils
, pre-commit-hooks
, flake-parts
, nativelink
, rules_ll
, rules_mojo
, nix2container
, ...
} @ inputs:
flake-parts.lib.mkFlake { inherit inputs; }
Expand All @@ -92,6 +96,9 @@
, lib
, ...
}:
let
inherit (inputs.nativelink.packages.${system}) lre-cc;
in
{
_module.args.pkgs = import self.inputs.nixpkgs {
inherit system;
Expand All @@ -100,14 +107,14 @@
# config.cudaSupport = true;
};
local-remote-execution.settings = {
inherit (nativelink.packages.${system}.lre-cc.meta) Env;
inherit (lre-cc.meta) Env;
};
pre-commit.settings = {
hooks = import ./pre-commit-hooks.nix { inherit pkgs; };
};
rules_ll.settings.llEnv =
let
openssl = (pkgs.openssl.override { static = true; });
openssl = pkgs.openssl.override { static = true; };
in
rules_ll.lib.defaultLlEnv {
inherit pkgs;
Expand All @@ -116,12 +123,12 @@
};
rules_mojo.settings.mojoEnv = rules_mojo.lib.defaultMojoEnv {
inherit pkgs;
mojo = inputs.rules_mojo.packages.${system}.mojo;
inherit (inputs.rules_mojo.packages.${system}) mojo;
};
packages = {
lre-mojo = rules_mojo.packages.${system}.lre-mojo;
lre-cc = nativelink.packages.${system}.lre-cc;
nativelink-worker-lre-mojo = rules_mojo.packages.${system}.lre-mojo;
inherit lre-cc;
inherit (inputs.rules_mojo.packages.${system}) lre-mojo;
nativelink-worker-lre-mojo = lre-mojo;
};
devShells.default = pkgs.mkShell {
nativeBuildInputs = [
Expand Down

0 comments on commit c3efb9c

Please sign in to comment.