Code
Pre-requisites
You will need to have the following installed:
Important
We use a Flake-based workflow. You can certainly develop for nixos-facter
without Flakes and leverage
much of what is listed below, but it is left up to the reader to determine how to make that work.
Go development
The default devshell is a modified version of the underlying Nix derivation for nixos-facter
. As such, it provides
all the necessary tooling and utilities for working on nixos-facter
.
nix/devshells/default.nix |
---|
| {
perSystem,
pkgs,
...
}:
perSystem.self.nixos-facter.overrideAttrs (old: {
GOROOT = "${old.passthru.go}/share/go";
nativeBuildInputs = old.nativeBuildInputs ++ [
pkgs.enumer
pkgs.delve
pkgs.pprof
pkgs.gotools
pkgs.golangci-lint
pkgs.cobra-cli
pkgs.fx # json tui
perSystem.hwinfo.default
];
shellHook = ''
# this is only needed for hermetic builds
unset GO_NO_VENDOR_CHECKS GOSUMDB GOPROXY GOFLAGS
'';
})
|
Direnv should load this by default when entering the root of the repository.
For the most part, you should be able to develop normally as you would any other Go program.
Important
When you have completed making any changes and have tested it as you would any other Go program, it is important
to ensure it works when run as a Nix package.
This can be done with nix run .# -- <args>
, which will build the Nix derivation and execute the resultant
nixos-facter
binary.
We use treefmt and treefmt-nix to format the repository by running nix fmt
from the root directory.
nix/formatter.nix |
---|
| {
pkgs,
flake,
inputs,
...
}:
let
mod = inputs.treefmt-nix.lib.evalModule pkgs {
projectRootFile = ".git/config";
programs =
{
nixfmt.enable = true;
deadnix.enable = true;
gofumpt.enable = true;
prettier.enable = true;
statix.enable = true;
}
// pkgs.lib.optionalAttrs (pkgs.system != "riscv64-linux") {
shellcheck.enable = true;
};
settings = {
global.excludes = [
"LICENSE"
# unsupported extensions
"*.{gif,png,svg,tape,mts,lock,mod,sum,toml,env,envrc,gitignore}"
];
formatter = {
deadnix = {
priority = 1;
};
statix = {
priority = 2;
};
nixfmt = {
priority = 3;
};
prettier = {
options = [
"--tab-width"
"4"
];
includes = [ "*.{css,html,js,json,jsx,md,mdx,scss,ts,yaml}" ];
};
};
};
};
wrapper = mod.config.build.wrapper // {
passthru.tests.check = mod.config.build.check flake;
};
unsupported = pkgs.writeShellApplication {
name = "unsupported-platform";
text = ''
echo "nix fmt is not supported on ${pkgs.hostPlatform.system}";
'';
};
in
# nixfmt-rfc-style is based on Haskell, which is broke on RiscV currently
if pkgs.hostPlatform.isRiscV then unsupported else wrapper
|
Checks
Running nix flake check
will build all the devshells and Nix packages, as well as check the formatting with treefmt
and any other Flake checks that have been configured.
Documentation
When making changes, it is important to add or update any relevant sections in the documentation within the same
pull request.
For more information see the next section.