From ad19f920cf0c96f181f5f1df7324d080554e38fe Mon Sep 17 00:00:00 2001 From: zimbatm Date: Wed, 18 May 2022 13:59:21 +0200 Subject: [PATCH] introduce lib.mkFlake This makes the most common use-case a tiny bit less verbose. --- README.md | 13 +++++------ lib.nix | 3 +++ template/default/flake.nix | 45 ++++++++++++++++++-------------------- 3 files changed, 29 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 28407fb..65c3fe1 100644 --- a/README.md +++ b/README.md @@ -34,18 +34,15 @@ Otherwise, add the input, flake-modules-core.inputs.nixpkgs.follows = "nixpkgs"; ``` -then slide `evalFlakeModule` between your outputs function head and body, +then slide `mkFlake` between your outputs function head and body, ``` outputs = { self, flake-modules-core, ... }: - (flake-modules-core.lib.evalFlakeModule - { inherit self; } - { - flake = { - # Put your original flake attributes here. - } + flake-modules-core.lib.mkFlake { inherit self; } { + flake = { + # Put your original flake attributes here. } - ).config.flake; + }; ``` Now you can add the remaining module attributes like in the [the template](./template/default/flake.nix). diff --git a/lib.nix b/lib.nix index 0a3a9c3..23a35a1 100644 --- a/lib.nix +++ b/lib.nix @@ -38,6 +38,9 @@ let modules = [ ./all-modules.nix module ]; }; + mkFlake = args: module: + (flake-modules-core-lib.evalFlakeModule args module).config.flake; + # For extending options in an already declared submodule. # Workaround for https://github.com/NixOS/nixpkgs/issues/146882 mkSubmoduleOptions = diff --git a/template/default/flake.nix b/template/default/flake.nix index 1cb62a3..ba5f5e6 100644 --- a/template/default/flake.nix +++ b/template/default/flake.nix @@ -8,31 +8,28 @@ }; outputs = { self, flake-modules-core, ... }: - (flake-modules-core.lib.evalFlakeModule - { inherit self; } - { - imports = [ - # To import a flake module - # 1. Add foo to inputs - # 2. Add foo as a parameter to the outputs function - # 3. Add here: foo.flakeModule + flake-modules-core.mkFlake { inherit self; } { + imports = [ + # To import a flake module + # 1. Add foo to inputs + # 2. Add foo as a parameter to the outputs function + # 3. Add here: foo.flakeModule - ]; - systems = [ "x86_64-linux" "aarch64-darwin" ]; - perSystem = system: { config, self', inputs', pkgs, ... }: { - # Per-system attributes can be defined here. The self' and inputs' - # module parameters provide easy access to attributes of the same - # system. + ]; + systems = [ "x86_64-linux" "aarch64-darwin" ]; + perSystem = system: { config, self', inputs', pkgs, ... }: { + # Per-system attributes can be defined here. The self' and inputs' + # module parameters provide easy access to attributes of the same + # system. - # Equivalent to inputs'.nixpkgs.legacyPackages.hello; - packages.hello = pkgs.hello; - }; - 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. + # Equivalent to inputs'.nixpkgs.legacyPackages.hello; + packages.hello = pkgs.hello; + }; + 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; + }; + }; }