diff --git a/configs/flake-parts/templates.nix b/configs/flake-parts/templates.nix index ba9ad4fe..c8c40fea 100644 --- a/configs/flake-parts/templates.nix +++ b/configs/flake-parts/templates.nix @@ -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"; diff --git a/templates/basic-nix-module-flake/flake.nix b/templates/basic-nix-module-flake/flake.nix new file mode 100644 index 00000000..729110a6 --- /dev/null +++ b/templates/basic-nix-module-flake/flake.nix @@ -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 + ]; + }; +} diff --git a/templates/basic-nix-module-flake/nix/flake/default.nix b/templates/basic-nix-module-flake/nix/flake/default.nix new file mode 100644 index 00000000..365ce6eb --- /dev/null +++ b/templates/basic-nix-module-flake/nix/flake/default.nix @@ -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"; + }) + ]; + }; + }; +} diff --git a/templates/basic-nix-module-flake/nix/modules/default.nix b/templates/basic-nix-module-flake/nix/modules/default.nix new file mode 100644 index 00000000..83b02d13 --- /dev/null +++ b/templates/basic-nix-module-flake/nix/modules/default.nix @@ -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. + ''; + }; + }; +} diff --git a/templates/basic-nix-module-flake/shell.nix b/templates/basic-nix-module-flake/shell.nix new file mode 100644 index 00000000..c8b688c1 --- /dev/null +++ b/templates/basic-nix-module-flake/shell.nix @@ -0,0 +1,10 @@ +{ pkgs ? import { } }: + +with pkgs; + +mkShell { + packages = [ + nixpkgs-fmt + treefmt + ]; +} diff --git a/templates/basic-nix-module-flake/treefmt.toml b/templates/basic-nix-module-flake/treefmt.toml new file mode 100644 index 00000000..aa56b8d9 --- /dev/null +++ b/templates/basic-nix-module-flake/treefmt.toml @@ -0,0 +1,3 @@ +[formatter.nix] +command = "nixpkgs-fmt" +includes = [ "*.nix" ]