diff --git a/flake.nix b/flake.nix index 888582ad..58d64b70 100644 --- a/flake.nix +++ b/flake.nix @@ -22,6 +22,7 @@ imports = [ ./flake-parts/packages.nix ./flake-parts/formatting.nix + ./templates/flake-module.nix ./templates/python-project/flake-module.nix ./pkgs/clan-cli/flake-module.nix ]; diff --git a/templates/flake-module.nix b/templates/flake-module.nix new file mode 100644 index 00000000..22b1070d --- /dev/null +++ b/templates/flake-module.nix @@ -0,0 +1,12 @@ +{ ... }: { + flake.templates = { + new-clan = { + description = "Initialize a new clan flake"; + path = ./new-clan; + }; + python-project = { + description = "Initialize a new internal python project"; + path = ./python-project; + }; + }; +} diff --git a/templates/new-clan/default.nix b/templates/new-clan/default.nix new file mode 100644 index 00000000..4691d646 --- /dev/null +++ b/templates/new-clan/default.nix @@ -0,0 +1,16 @@ +# This file provides backward compatibility to nix < 2.4 clients +let + flake = + import + ( + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + in + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + } + ) + { src = ./.; }; +in +flake.defaultNix diff --git a/templates/new-clan/flake.nix b/templates/new-clan/flake.nix new file mode 100644 index 00000000..c710aae4 --- /dev/null +++ b/templates/new-clan/flake.nix @@ -0,0 +1,25 @@ +{ + description = ""; + + inputs = { + flake-parts.url = "github:hercules-ci/flake-parts"; + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; + nixpkgs.url = "nixpkgs/nixos-unstable"; + }; + + outputs = inputs @ { flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + + systems = builtins.fromJSON (builtins.readFile ./systems.json); + + imports = + let + relPaths = builtins.fromJSON (builtins.readFile ./imports.json); + paths = map (path: ./. + path) relPaths; + in + paths; + }; +} diff --git a/templates/new-clan/imports.json b/templates/new-clan/imports.json new file mode 100644 index 00000000..fe51488c --- /dev/null +++ b/templates/new-clan/imports.json @@ -0,0 +1 @@ +[] diff --git a/templates/new-clan/shell.nix b/templates/new-clan/shell.nix new file mode 100644 index 00000000..804c2a41 --- /dev/null +++ b/templates/new-clan/shell.nix @@ -0,0 +1,2 @@ +(import ./default.nix).devShells.${builtins.currentSystem}.default + or (throw "dev-shell not defined. Cannot find flake attribute devShell.${builtins.currentSystem}.default") diff --git a/templates/new-clan/systems.json b/templates/new-clan/systems.json new file mode 100644 index 00000000..5f3305fb --- /dev/null +++ b/templates/new-clan/systems.json @@ -0,0 +1,3 @@ +[ + "x86_64-linux" +]