Newer
Older
description = "Configuration for the bob project";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
devenv.url = "github:cachix/devenv";
mk-shell-bin.url = "github:rrbutani/nix-mk-shell-bin";
flake-root.url = "github:srid/flake-root";
treefmt-nix.url = "github:numtide/treefmt-nix";
versionsTool.url = "git+https://gitlab.schukai.com/oss/utilities/version.git";
nix-templates.url = "git+https://gitlab.schukai.com/schukai/entwicklung/nix-flakes.git";
};
nixConfig = {
extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=";
extra-substituters = "https://devenv.cachix.org";
};
outputs = inputs @ {
...
}:
flake-parts.lib.mkFlake {inherit inputs;} {
imports = [
inputs.devenv.flakeModule
inputs.flake-root.flakeModule
inputs.treefmt-nix.flakeModule
];
systems = (import ./project.nix).supportedSystems;
perSystem = let
common-script = import ./system/scripts/common.nix;
in
{
config,
self',
inputs',
pkgs,
system,
...
}: let
projectDefinition = import ./project.nix;
buildRoot = ./.;
enableDebugPackage = true;
portAsString = toString projectDefinition.k8s.port;
in {
packages = rec {
projectDefinition = import ./project.nix;
sourcePath = ./source;
builtins.readFile (
runCommand "timestamp"
{when = builtins.currentTime;}
"echo -n `date -d @$when +%Y-%m-%d_%H-%M-%S` > $out"
);
in
# https://nixos.wiki/wiki/Go
pkgs.buildGoModule {
pname = projectDefinition.name;
version = projectDefinition.version;
src = sourcePath;
tags = []; # add your tags here (eq "netgo" "osusergo" "static_build")
# The -w turns off DWARF debugging information:
# The -s flag will omit the symbol table and debug information.
"-s -w"
"-X '${projectDefinition.modulePath}/release.version=${projectDefinition.version}'"
"-X '${projectDefinition.modulePath}/release.commit=${projectDefinition.commitHash}'"
"-X '${projectDefinition.modulePath}/release.name=${projectDefinition.name}'"
"-X '${projectDefinition.modulePath}/release.mnemonic=${projectDefinition.mnemonic}'"
"-X '${projectDefinition.modulePath}/release.buildDate=${timestamp}'"
#vendorHash = null;
vendorHash = projectDefinition.vendorHash;
proxyVendor = true;
meta = with system.lib; {
description = projectDefinition.description;
homepage = "https://" + projectDefinition.modulePath;
maintainers = with maintainers; ["schukai GmbH"];
};
buildInputs = [pkgs.bash];
nativeBuildInputs = with system; [pkgs.alejandra pkgs.shellcheck pkgs.shfmt];
doCheck = true;
checkPhase = ''
cd ${sourcePath}
if ! go test -v ./... 2>&1 | cat ; then
echo "Test failed."
exit 1
fi
echo "Test passed: '$out' is as expected."
treefmt.config = {
inherit (config.flake-root) projectRootFile;
programs.alejandra.enable = true;
programs.gofmt.enable = true;
programs.shfmt.enable = true;
programs.shellcheck.enable = true;
programs.yamlfmt.enable = true;
programs.prettier.enable = true;
devenv.shells = let
projectDefinition = import ./project.nix;
buildRoot = ./.;
in {
scripts = let
versionsTool = inputs.versionsTool.defaultPackage."${builtins.currentSystem}";
workingDirectory = builtins.getEnv "PWD";
treefmt.exec = ''
${config.treefmt.build.wrapper}/bin/treefmt
'';
rm-gitlab-pipelines.exec = import ./system/scripts/rm-gitlab-pipelines.nix {
inherit pkgs config buildRoot projectDefinition;
};
update-files.exec = import ./system/scripts/update-files.nix {
inherit pkgs config buildRoot projectDefinition;
};
check-licences.exec = import ./system/scripts/check-licences.nix {
inherit pkgs config buildRoot projectDefinition;
};
update-hashes.exec = import ./system/scripts/update-hashes.nix {
inherit pkgs config buildRoot projectDefinition workingDirectory;
update-version.exec = import ./system/scripts/update-version.nix {
inherit pkgs config buildRoot projectDefinition versionsTool workingDirectory;
};
};
imports = [];
packages = with pkgs; [
inputs.versionsTool.defaultPackage."${builtins.currentSystem}"
inputs.nix-templates.packages."${builtins.currentSystem}".git-commit
nodePackages.prettier-plugin-toml
nodePackages.prettier
];
languages.nix.enable = true;
languages = {go = {enable = true;};};
difftastic.enable = true;
enterShell = ''
post-init-setup
'';
};
};
};
defaultPackage = self.packages.${builtins.currentSystem}.bob;