flake: add basic-nix-module-flake template

This commit is contained in:
Gabriel Arazas 2024-02-10 17:19:11 +08:00
parent 79e118e609
commit 473540b952
No known key found for this signature in database
GPG Key ID: ADE0C41DAB221FCC
6 changed files with 90 additions and 0 deletions

View File

@ -6,6 +6,10 @@
path = ../../templates/basic-devshell;
description = "Basic development shell template";
};
basic-nix-module-flake = {
path = ../../templates/basic-nix-module-flake;
description = "Basic Nix module flake template";
};
basic-overlay-flake = {
path = ../../templates/basic-overlay-flake;
description = "Basic overlay as a flake";

View File

@ -0,0 +1,20 @@
{
description = "Basic Nix module flake description";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
};
outputs = inputs@{ self, nixpkgs, ... }:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"x86_64-linux"
"aarch64-linux"
];
imports = [
./nix/flake
];
};
}

View File

@ -0,0 +1,32 @@
{ lib, inputs, ... }: {
flake = {
nixosModules.default = ../modules;
};
perSystem = { lib, pkgs, system, ... }: {
formatter = pkgs.treefmt;
devShells.default = import ../../shell.nix { inherit pkgs; };
# Just make sure it actually compiles with a very minimal NixOS
# configuration.
checks.nixos-module-test =
let
nixosSystem = args:
import "${inputs.nixpkgs}/nixos/lib/eval-config.nix" args;
in
nixosSystem {
modules = [
({ modulesPath, ... }: {
imports = [
"${modulesPath}/profiles/minimal.nix"
];
nixpkgs.hostPlatform = system;
boot.loader.grub.enable = false;
fileSystems."/".device = "nodev";
})
];
};
};
}

View File

@ -0,0 +1,21 @@
{ config, lib, pkgs, ... }:
let
cfg = config.programs.foo;
settingsFormat = pkgs.format.json { };
in
{
options.programs.foo = {
enable = lib.mkEnableOption "foo, a sample program";
package = lib.mkPackageOption pkgs "foo" { };
settings = lib.mkOption {
type = settingsFormat.type;
default = { };
# TODO: Don't forget to set an example here.
description = ''
The settings of the program.
'';
};
};
}

View File

@ -0,0 +1,10 @@
{ pkgs ? import <nixpkgs> { } }:
with pkgs;
mkShell {
packages = [
nixpkgs-fmt
treefmt
];
}

View File

@ -0,0 +1,3 @@
[formatter.nix]
command = "nixpkgs-fmt"
includes = [ "*.nix" ]