Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI and pre-commit hooks for nix files #374

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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 .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use_flake
16 changes: 16 additions & 0 deletions .github/workflows/flake-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "Lint"

on:
push:
pull_request:

jobs:
checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v25
with:
nix_path: nixpkgs=channel:nixpkgs-unstable
- run: |
nix flake check -L
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ result

# Colmena --keep-result roots directory
.gcroots

# pre-commit
.pre-commit-config.yaml
2 changes: 1 addition & 1 deletion build/datadog/hydra.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{config, pkgs, ...}:
{ pkgs, ...}:
{
systemd.services.dd-agent.environment.PYTHONPATH = "${pkgs.pythonPackages.requests}/lib/python2.7/site-packages";
environment.etc =
Expand Down
4 changes: 1 addition & 3 deletions build/diffoscope.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{ config, pkgs, ... }:

with pkgs.lib;
{ pkgs, ... }:

let

Expand Down
8 changes: 3 additions & 5 deletions build/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@
inputs.rfc39.url = "github:NixOS/rfc39";
inputs.rfc39.inputs.nixpkgs.follows = "nixpkgs";

outputs = flakes @ { self, agenix, colmena, disko, hydra, hydra-scale-equinix-metal, nix, nixpkgs, nixos-channel-scripts, nix-netboot-serve, rfc39 }:
outputs = { self, agenix, colmena, disko, hydra, hydra-scale-equinix-metal, nix, nixpkgs, nixos-channel-scripts, nix-netboot-serve, rfc39 }:
let
inherit (nixpkgs) lib;

flakesModule = {
imports = [
agenix.nixosModules.age
Expand Down Expand Up @@ -87,13 +85,13 @@
deployment = {
targetHost = "${name}.nixos.org";
};
}) (self.nixosConfigurations);
}) self.nixosConfigurations;

# TODO: flake-utils.lib.eachDefaultSystem
devShell.x86_64-linux = let
pkgs = import nixpkgs { system = "x86_64-linux"; };
in pkgs.mkShell {
buildInputs = with pkgs; [
buildInputs = [
agenix.packages.x86_64-linux.agenix
colmena.packages.x86_64-linux.colmena
];
Expand Down
2 changes: 1 addition & 1 deletion build/hydra-proxy.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ config, lib, pkgs, ...}:
{ config, ...}:

{
services.nginx = {
Expand Down
6 changes: 2 additions & 4 deletions build/hydra-scaler.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{ config, pkgs, lib, ... }:

{
services.hydra-scale-equinix-metal = {
enable = true;
Expand All @@ -8,7 +6,7 @@
secretFile = "/root/keys/hydra-scale-equinix-metal-env";
interval = ["*:0/5"];
config = let
netboot_base = https://netboot.nixos.org/dispatch/hydra/hydra.nixos.org/equinix-metal-builders/main;
netboot_base = "https://netboot.nixos.org/dispatch/hydra/hydra.nixos.org/equinix-metal-builders/main";
in {
metro = "any";
tags = ["hydra"];
Expand All @@ -24,7 +22,7 @@
# The netboot URL for arm64 big-parallel is: https://netboot.nixos.org/dispatch/hydra/hydra.nixos.org/equinix-metal-builders/main/c3-large-arm--big-parallel ("Always PXE" enabled, "hydra" tag)
# The netboot URL for arm64 small is: https://netboot.nixos.org/dispatch/hydra/hydra.nixos.org/equinix-metal-builders/main/c3-large-arm ("Always PXE" enabled, "hydra" tag)

x86_64-linux = rec {
x86_64-linux = {
bigparallel = {
divisor = 16;
minimum = 1;
Expand Down
2 changes: 1 addition & 1 deletion build/hydra.nix
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ in
'';

# Work around https://github.com/NixOS/hydra/issues/1337
services.hydra-dev.package = pkgs.hydra.overrideAttrs(final: prev: {
services.hydra-dev.package = pkgs.hydra.overrideAttrs(_: prev: {
postPatch = ''
${prev.postPatch or ""}
rm src/lib/Hydra/Plugin/DeclarativeJobsets.pm
Expand Down
2 changes: 1 addition & 1 deletion build/packet-importer.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ config, lib, pkgs, ... }:
{ pkgs, ... }:
let
importer = pkgs.callPackage ../hydra-packet-importer { };
in
Expand Down
4 changes: 0 additions & 4 deletions build/pluto/prometheus/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
{ config
, ...
}:

{
imports = [
./alertmanager.nix
Expand Down
5 changes: 1 addition & 4 deletions build/rhea/configuration.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ nodes, config, lib, pkgs, ... }:
{ pkgs, ... }:
{
imports =
[ ./hardware-configuration.nix
Expand Down Expand Up @@ -44,9 +44,6 @@

nix.extraOptions = "gc-keep-outputs = false";

#services.postfix.enable = true;
#services.postfix.hostname = "hydra.nixos.org";

# Don't rate-limit the journal.
services.journald.rateLimitBurst = 0;

Expand Down
2 changes: 1 addition & 1 deletion build/rhea/hardware-configuration.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ config, lib, pkgs, modulesPath, ... }:
{ config, lib, modulesPath, ... }:

{
imports =
Expand Down
2 changes: 1 addition & 1 deletion channels.nix
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,5 @@ rec {
};
};

channels-with-urls = (builtins.mapAttrs (name: about: about.job) channels);
channels-with-urls = builtins.mapAttrs (_: about: about.job) channels;
}
123 changes: 123 additions & 0 deletions flake.lock

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

33 changes: 33 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
description = "NixOS Infra";

inputs = {
nixpkgs.url = "github:NIxOS/nixpkgs";
git-hooks = {
url = "github:cachix/git-hooks.nix";
inputs = {
nixpkgs.follows = "nixpkgs";
nixpkgs-stable.follows = "nixpkgs";
};
};
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, git-hooks, flake-utils }:
flake-utils.lib.eachSystem [ "aarch64-linux" "x86_64-linux" ] (system: {
checks = {
pre-commit = git-hooks.lib.${system}.run {
src = ./.;
hooks = {
deadnix.enable = true;
statix.enable = true;
};
};
};
devShells.default = nixpkgs.legacyPackages.${system}.mkShell {
buildInputs = self.checks.${system}.pre-commit.enabledPackages;
inherit (self.checks.${system}.pre-commit) shellHook;
};
}
);
}
1 change: 0 additions & 1 deletion lib/service-order.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#
# Given a set of services, make them run one at a time in a specific
# order, on a timer.
{ lib }:
{
# Given a list of systemd service, give each one an After
# attribute, so they start in a specific order. The returned
Expand Down
4 changes: 2 additions & 2 deletions macs/nix-darwin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ in
'';

environment.etc."per-user/root/ssh/authorized_keys".text = concatStringsSep "\n"
([
[
(authorizedNixStoreKey sshKeys.hydra-queue-runner)
]);
];


system.activationScripts.postActivation.text = ''
Expand Down
4 changes: 2 additions & 2 deletions non-critical-infra/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@
outputs = { self, nixpkgs, flake-utils, colmena, disko, srvos, first-time-contribution-tagger, sops-nix, ... }@inputs:
let
importConfig = path: (lib.mapAttrs (name: value: import (path + "/${name}/default.nix")) (lib.filterAttrs (_: v: v == "directory") (builtins.readDir path)));
lib = nixpkgs.lib;
inherit (nixpkgs) lib;
in
{

nixosConfigurations = builtins.mapAttrs
(name: value: nixpkgs.lib.nixosSystem {
lib = lib;
inherit lib;
system = "x86_64-linux";
specialArgs = {
inherit inputs;
Expand Down
14 changes: 7 additions & 7 deletions non-critical-infra/modules/postfix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
enable = true;
domains = config.networking.fqdn;
selector = "mail";
user = config.services.postfix.user;
group = config.services.postfix.group;
inherit (config.services.postfix)
user
group
;
keyPath = "/run/opendkim-keys";
};

systemd.services.opendkim.serviceConfig = {
ExecStartPre = [
(
"+${pkgs.writeShellScript "opendkim-keys" ''
install -o ${config.services.postfix.user} -g ${config.services.postfix.group} -D -m0700 ${config.sops.secrets.opendkim-private-key.path} /run/opendkim-keys/${config.services.opendkim.selector}.private
''}"
)
"+${pkgs.writeShellScript "opendkim-keys" ''
install -o ${config.services.postfix.user} -g ${config.services.postfix.group} -D -m0700 ${config.sops.secrets.opendkim-private-key.path} /run/opendkim-keys/${config.services.opendkim.selector}.private
''}"
];
};

Expand Down
6 changes: 6 additions & 0 deletions statix.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
disabled = [
"repeated_keys"
]
nix_version = '2.4'
ignore = ['.direnv']

6 changes: 3 additions & 3 deletions survey/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
# https://github.com/NixOS/nixpkgs/pull/157832
inputs.nixpkgs.url = "github:garbas/nixpkgs/update-limesurvey";

outputs = flakes @ { self, nixpkgs }:
outputs = { self, nixpkgs }:
let
customOverlay = final: prev: {
customOverlay = _: prev: {
limesurvey = prev.limesurvey.overrideAttrs (old: {
installPhase = old.installPhase + ''
mkdir -p $out/share/limesurvey/upload/themes/survey/generalfiles/
Expand All @@ -27,7 +27,7 @@
[
"${nixpkgs}/nixos/modules/virtualisation/amazon-image.nix"
../modules/common.nix
({ config, pkgs, lib, ... }:
({ pkgs, lib, ... }:
{
ec2.hvm = true;

Expand Down
Loading