From f2e42edb608695f02822ad13ecc7bce2fa891e43 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 11 May 2022 23:05:53 +0200 Subject: [PATCH] Add multi-module template --- flake.nix | 18 ++++++++--- template/multi-module/flake.nix | 33 ++++++++++++++++++++ template/multi-module/hello/flake-module.nix | 18 +++++++++++ 3 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 template/multi-module/flake.nix create mode 100644 template/multi-module/hello/flake-module.nix diff --git a/flake.nix b/flake.nix index 81c2eda..f94577b 100644 --- a/flake.nix +++ b/flake.nix @@ -7,11 +7,19 @@ outputs = { self, nixpkgs, ... }: { lib = import ./lib.nix { inherit (nixpkgs) lib; }; - defaultTemplate = { - path = ./template/default; - description = '' - A minimal flake using flake-modules-core. - ''; + templates = { + default = { + path = ./template/default; + description = '' + A minimal flake using flake-modules-core. + ''; + }; + multi-module = { + path = ./template/multi-module; + description = '' + A minimal flake using flake-modules-core. + ''; + }; }; }; diff --git a/template/multi-module/flake.nix b/template/multi-module/flake.nix new file mode 100644 index 0000000..eba8a28 --- /dev/null +++ b/template/multi-module/flake.nix @@ -0,0 +1,33 @@ +{ + description = "Description for the project"; + + inputs = { + flake-modules-core.url = "github:hercules-ci/flake-modules-core"; + flake-modules-core.inputs.nixpkgs.follows = "nixpkgs"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = { self, flake-modules-core, ... }: + (flake-modules-core.lib.evalFlakeModule + { inherit self; } + { + imports = [ + ./hello/flake-module.nix + ]; + systems = [ "x86_64-linux" "aarch64-darwin" ]; + perSystem = system: { config, self', inputs', ... }: { + # Per-system attributes can be defined here. The self' and inputs' + # module parameters provide easy access to attributes of the same + # system. + + packages.figlet = inputs'.nixpkgs.legacyPackages.figlet; + }; + flake = { + # The usual flake attributes can be defined here, including system- + # agnostic ones like nixosModule and system-enumerating ones, although + # those are more easily expressed in perSystem. + + }; + } + ).config.flake; +} diff --git a/template/multi-module/hello/flake-module.nix b/template/multi-module/hello/flake-module.nix new file mode 100644 index 0000000..e0cdbfe --- /dev/null +++ b/template/multi-module/hello/flake-module.nix @@ -0,0 +1,18 @@ + +# Definitions can be imported from a separate file like this one + +{ self, ... }: { + perSystem = system: { config, self', inputs', ... }: { + # Definitions like this are entirely equivalent to the ones + # you may have directly in flake.nix. + packages.hello = inputs'.nixpkgs.legacyPackages.hello; + }; + flake = { + nixosModules.hello = { pkgs, ... }: { + environment.systemPackages = [ + # or self.inputs.nixpkgs.legacyPackages.${pkgs.stdenv.hostPlatform.system}.hello + self.packages.${pkgs.stdenv.hostPlatform.system}.hello + ]; + }; + }; +} \ No newline at end of file