81: remove the _file references r=Mic92 a=zimbatm



Co-authored-by: zimbatm <zimbatm@zimbatm.com>
This commit is contained in:
bors[bot] 2023-02-27 13:05:48 +00:00 committed by GitHub
commit d3394d6d90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 15 additions and 35 deletions

View File

@ -2,23 +2,3 @@
This page explains some of the design decisions that have been made trough
this project.
## What are there `_file` attributes in the NixOS modules?
TL;DR: to provide better error reporting.
This is a bit of a subtle issue, combining knowlede about both Flakes and the Nix module system, so please hang with me.
First, there are two types of imports in the Nix ecosystem:
1. The `import` builtin function. This can be used anywhere in the code read a target Nix file, and return the evaluation result in its place.
2. The `imports` attribute in the Nix module system. This takes a list of either path, attr or function, which is then used to extend the module system with new option of config values.
The reason to add the `_file` attribute is that it's used to report when there are value or type clashes while building the config tree.
It helps the user be pointed directly to the right location. Typically, NixOS modules are passed as a path, and in that case, the module system transparently annotates the module with the `_file` attribute so you don't see it in most cases.
Now let's talk about flakes.
When running `nix flake check`, Nix expects the NixOS modules to sit in the `nixosModules.<name>` prefix. And that the value is a function. If we give it a path, it will fail the check. So we can't have a path to (2) and therefor need to use (1) and annotate the `_file` manually.
Case closed :)

View File

@ -2,7 +2,7 @@
# Common configuration accross *all* the machines
{ config, pkgs, lib, ... }:
{
_file = ./default.nix;
imports = [
./flake.nix
./mdmonitor-fix.nix

View File

@ -1,5 +1,5 @@
{
_file = ./default.nix;
imports = [
../common
./pipewire.nix

View File

@ -1,6 +1,6 @@
{ modulesPath, ... }:
{
_file = ./default.nix;
imports = [
"${modulesPath}/virtualisation/amazon-image.nix"
../../mixins/cloud-init.nix

View File

@ -1,6 +1,6 @@
{ config, modulesPath, lib, ... }:
{
_file = ./default.nix;
imports = [
../../mixins/cloud-init.nix
"${modulesPath}/profiles/qemu-guest.nix"

View File

@ -1,5 +1,5 @@
{ lib, config, ... }: {
_file = ./amd.nix;
imports = [ ./. ];
boot.kernelModules = [ "kvm-amd" ];

View File

@ -1,5 +1,5 @@
{ lib, config, ... }: {
_file = ./intel.nix;
imports = [ ./. ];
boot.kernelModules = [ "kvm-intel" ];

View File

@ -1,6 +1,6 @@
{ lib, ... }:
{
_file = ./cloud-init.nix;
config = {
services.cloud-init.enable = true;
services.cloud-init.network.enable = true;

View File

@ -1,5 +1,5 @@
{ config, lib, ... }: {
_file = ./nginx.nix;
networking.firewall.allowedTCPPorts = [ 443 80 ];
services.nginx = {

View File

@ -1,6 +1,6 @@
# Add this mixin to machines that boot with EFI
{
_file = ./systemd-boot.nix;
# Only enable during install
#boot.loader.efi.canTouchEfiVariables = true;

View File

@ -9,7 +9,7 @@ let
hasNvme = lib.any (m: m == "nvme") config.boot.initrd.availableKernelModules;
in
{
_file = ./telegraf.nix;
systemd.services.telegraf.path = lib.optional (!isVM && hasNvme) pkgs.nvme-cli;
services.telegraf = {

View File

@ -1,6 +1,6 @@
{ pkgs, lib, ... }:
{
_file = ./terminfo.nix;
# various terminfo packages
environment.systemPackages = [
pkgs.wezterm.terminfo # this one does not need compilation

View File

@ -3,7 +3,7 @@
, lib
, ...
}: {
_file = ./tracing.nix;
programs.bcc.enable = !pkgs.stdenv.hostPlatform.isRiscV;
programs.sysdig.enable = !pkgs.stdenv.isAarch64 && !pkgs.stdenv.hostPlatform.isRiscV;

View File

@ -3,7 +3,7 @@ let
cfg = config.roles.github-actions-runner;
in
{
_file = ./github-actions-runner.nix;
imports = [
../modules/github-runners
];

View File

@ -3,7 +3,7 @@ let
cfg = config.roles.nix-remote-builder;
in
{
_file = ./nix-remote-builder.nix;
options.roles.nix-remote-builder = {
schedulerPublicKeys = lib.mkOption {

View File

@ -2,7 +2,7 @@
# Common configuration accross *all* the machines
{ config, pkgs, lib, ... }:
{
_file = ./default.nix;
imports = [
../common
];