From f845dec656cbeb7a39f8b57b97da37767f5b7a4c Mon Sep 17 00:00:00 2001 From: a-kenji Date: Fri, 8 Nov 2024 11:42:42 +0100 Subject: [PATCH] templates: add a minimal flake-parts template --- templates/minimal-flake-parts/.gitignore | 2 ++ templates/minimal-flake-parts/checks.nix | 22 +++++++++++++++ templates/minimal-flake-parts/clan.nix | 11 ++++++++ templates/minimal-flake-parts/devshells.nix | 17 ++++++++++++ templates/minimal-flake-parts/flake.nix | 30 +++++++++++++++++++++ 5 files changed, 82 insertions(+) create mode 100644 templates/minimal-flake-parts/.gitignore create mode 100644 templates/minimal-flake-parts/checks.nix create mode 100644 templates/minimal-flake-parts/clan.nix create mode 100644 templates/minimal-flake-parts/devshells.nix create mode 100644 templates/minimal-flake-parts/flake.nix diff --git a/templates/minimal-flake-parts/.gitignore b/templates/minimal-flake-parts/.gitignore new file mode 100644 index 000000000..4812d58f9 --- /dev/null +++ b/templates/minimal-flake-parts/.gitignore @@ -0,0 +1,2 @@ +result +.direnv/ diff --git a/templates/minimal-flake-parts/checks.nix b/templates/minimal-flake-parts/checks.nix new file mode 100644 index 000000000..8de32fa02 --- /dev/null +++ b/templates/minimal-flake-parts/checks.nix @@ -0,0 +1,22 @@ +{ self, ... }: +{ + perSystem = + { + self', + lib, + system, + ... + }: + { + checks = + let + nixosMachines = lib.mapAttrs' ( + name: config: lib.nameValuePair "nixos-${name}" config.config.system.build.toplevel + ) ((lib.filterAttrs (_: config: config.pkgs.system == system)) self.nixosConfigurations); + + packages = lib.mapAttrs' (n: lib.nameValuePair "package-${n}") self'.packages; + devShells = lib.mapAttrs' (n: lib.nameValuePair "devShell-${n}") self'.devShells; + in + nixosMachines // packages // devShells; + }; +} diff --git a/templates/minimal-flake-parts/clan.nix b/templates/minimal-flake-parts/clan.nix new file mode 100644 index 000000000..c03f62adf --- /dev/null +++ b/templates/minimal-flake-parts/clan.nix @@ -0,0 +1,11 @@ +{ inputs, ... }: +{ + imports = [ + inputs.clan.flakeModules.default + ]; + clan = { + specialArgs = { + inherit inputs; + }; + }; +} diff --git a/templates/minimal-flake-parts/devshells.nix b/templates/minimal-flake-parts/devshells.nix new file mode 100644 index 000000000..43a2d86db --- /dev/null +++ b/templates/minimal-flake-parts/devshells.nix @@ -0,0 +1,17 @@ +_: { + perSystem = + { + pkgs, + inputs', + ... + }: + { + devShells = { + default = pkgs.mkShellNoCC { + packages = [ + inputs'.clan.packages.default + ]; + }; + }; + }; +} diff --git a/templates/minimal-flake-parts/flake.nix b/templates/minimal-flake-parts/flake.nix new file mode 100644 index 000000000..219180d93 --- /dev/null +++ b/templates/minimal-flake-parts/flake.nix @@ -0,0 +1,30 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + + clan.url = "git+https://git.clan.lol/clan/clan-core?shallow=1"; + clan.inputs.nixpkgs.follows = "nixpkgs"; + clan.inputs.flake-parts.follows = "flake-parts"; + + flake-parts.url = "github:hercules-ci/flake-parts?shallow=1"; + flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs"; + + }; + + outputs = + inputs@{ flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } ( + { ... }: + { + systems = [ + "x86_64-linux" + ]; + + imports = [ + ./checks.nix + ./clan.nix + ./devshells.nix + ]; + } + ); +}