From aafcaf1f664b9b084f0ac295d65d9c8ba0919cdb Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Mon, 8 May 2023 18:41:25 -0700 Subject: [PATCH 01/16] Add dogfood template --- flake.nix | 6 ++++ template/dogfood/flake.nix | 17 ++++++++++ .../dogfood/modules/anotherFlakeModule.nix | 8 +++++ template/dogfood/modules/dogfood.nix | 32 +++++++++++++++++++ template/dogfood/modules/hello.nix | 11 +++++++ 5 files changed, 74 insertions(+) create mode 100644 template/dogfood/flake.nix create mode 100644 template/dogfood/modules/anotherFlakeModule.nix create mode 100644 template/dogfood/modules/dogfood.nix create mode 100644 template/dogfood/modules/hello.nix diff --git a/flake.nix b/flake.nix index 5d1447b7..3d785114 100644 --- a/flake.nix +++ b/flake.nix @@ -26,6 +26,12 @@ A minimal flake using flake-parts importing nixpkgs with the unfree option. ''; }; + dogfood = { + path = ./template/dogfood; + description = '' + A minimal flake using flake-parts creating flake modules to build its own outputs. + ''; + }; }; flakeModules = { easyOverlay = ./extras/easyOverlay.nix; diff --git a/template/dogfood/flake.nix b/template/dogfood/flake.nix new file mode 100644 index 00000000..c55668de --- /dev/null +++ b/template/dogfood/flake.nix @@ -0,0 +1,17 @@ +{ + description = "Description for the project"; + + inputs = { + nixpkgs_22_11.url = "github:NixOS/nixpkgs/nixos-22.11"; + }; + + outputs = { flake-parts, ... }@inputs: + flake-parts.lib.mkFlake { inherit inputs; } ( + flake-parts.lib.mkFlake + { + # Workaround for https://github.com/hercules-ci/flake-parts/issues/148 + inputs = inputs // { self.outPath = ./.; }; + } + ./modules/dogfood.nix + ).flakeModules.dogfood; +} diff --git a/template/dogfood/modules/anotherFlakeModule.nix b/template/dogfood/modules/anotherFlakeModule.nix new file mode 100644 index 00000000..3df25e4b --- /dev/null +++ b/template/dogfood/modules/anotherFlakeModule.nix @@ -0,0 +1,8 @@ +{inputs, ...}: { + imports = [ + inputs.flake-parts.flakeModules.flakeModules + ]; + flake.flakeModules.anotherFlakeModule = { + # Define another flake module here + }; +} \ No newline at end of file diff --git a/template/dogfood/modules/dogfood.nix b/template/dogfood/modules/dogfood.nix new file mode 100644 index 00000000..996324b9 --- /dev/null +++ b/template/dogfood/modules/dogfood.nix @@ -0,0 +1,32 @@ +{flake-parts-lib, lib, inputs, ...}: { + imports = [ + ./hello.nix + inputs.flake-parts.flakeModules.flakeModules + ]; + config.systems = [ "x86_64-linux" "aarch64-darwin" ]; + options.flake = lib.mkOption { + type = lib.types.submoduleWith { + modules = [ + (flake: { + flakeModules.dogfood = { + config.systems = [ "x86_64-linux" "aarch64-darwin" ]; + imports = [ + flake.config.flakeModules.hello + + # Expose flake modules + ./dogfood.nix + ./hello.nix + ./anotherFlakeModule.nix + ]; + options.perSystem = flake-parts-lib.mkPerSystemOption (perSystem: { + apps.default = { + type = "app"; + program = "${perSystem.config.packages.hello_22_11}/bin/hello"; + }; + }); + }; + }) + ]; + }; + }; +} \ No newline at end of file diff --git a/template/dogfood/modules/hello.nix b/template/dogfood/modules/hello.nix new file mode 100644 index 00000000..94799497 --- /dev/null +++ b/template/dogfood/modules/hello.nix @@ -0,0 +1,11 @@ +{inputs, flake-parts-lib, ...}: { + imports = [ + inputs.flake-parts.flakeModules.flakeModules + ]; + flake.flakeModules.hello = { + options.perSystem = flake-parts-lib.mkPerSystemOption ({ system, ... }: { + packages.hello_22_11 = + inputs.nixpkgs_22_11.legacyPackages.${system}.hello; + }); + }; +} \ No newline at end of file From a13fbf2b39fff53cc09421c969b8eb9851eda998 Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Mon, 8 May 2023 19:18:57 -0700 Subject: [PATCH 02/16] Create a more sophisticated lazy self --- template/dogfood/flake.nix | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/template/dogfood/flake.nix b/template/dogfood/flake.nix index c55668de..412198dd 100644 --- a/template/dogfood/flake.nix +++ b/template/dogfood/flake.nix @@ -5,12 +5,17 @@ nixpkgs_22_11.url = "github:NixOS/nixpkgs/nixos-22.11"; }; - outputs = { flake-parts, ... }@inputs: + outputs = { flake-parts, self, ... }@inputs: flake-parts.lib.mkFlake { inherit inputs; } ( flake-parts.lib.mkFlake { + inherit inputs; # Workaround for https://github.com/hercules-ci/flake-parts/issues/148 - inputs = inputs // { self.outPath = ./.; }; + self = { + outPath = ./.; + inherit (self) + _type inputs lastModified lastModifiedDate narHash outputs sourceInfo submodules; + }; } ./modules/dogfood.nix ).flakeModules.dogfood; From d30b7b26d0d08b540db9a9647171020305b5e026 Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Tue, 9 May 2023 00:33:48 -0700 Subject: [PATCH 03/16] Simplify dogfood.nix --- template/dogfood/modules/dogfood.nix | 43 +++++++++++----------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/template/dogfood/modules/dogfood.nix b/template/dogfood/modules/dogfood.nix index 996324b9..7febe02d 100644 --- a/template/dogfood/modules/dogfood.nix +++ b/template/dogfood/modules/dogfood.nix @@ -1,32 +1,23 @@ -{flake-parts-lib, lib, inputs, ...}: { +{flake-parts-lib, lib, inputs, ...}@topLevel: { imports = [ ./hello.nix inputs.flake-parts.flakeModules.flakeModules ]; - config.systems = [ "x86_64-linux" "aarch64-darwin" ]; - options.flake = lib.mkOption { - type = lib.types.submoduleWith { - modules = [ - (flake: { - flakeModules.dogfood = { - config.systems = [ "x86_64-linux" "aarch64-darwin" ]; - imports = [ - flake.config.flakeModules.hello + flake.flakeModules.dogfood = { + config.systems = [ "x86_64-linux" "aarch64-darwin" ]; + imports = [ + topLevel.config.flake.flakeModules.hello - # Expose flake modules - ./dogfood.nix - ./hello.nix - ./anotherFlakeModule.nix - ]; - options.perSystem = flake-parts-lib.mkPerSystemOption (perSystem: { - apps.default = { - type = "app"; - program = "${perSystem.config.packages.hello_22_11}/bin/hello"; - }; - }); - }; - }) - ]; - }; + # Expose flake modules + ./dogfood.nix + ./hello.nix + ./anotherFlakeModule.nix + ]; + options.perSystem = flake-parts-lib.mkPerSystemOption (perSystem: { + apps.default = { + type = "app"; + program = "${perSystem.config.packages.hello_22_11}/bin/hello"; + }; + }); }; -} \ No newline at end of file +} From 7ca7b6face8f55878d7b583b6f5fe5b7e9f8d4a9 Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Tue, 9 May 2023 09:55:42 -0700 Subject: [PATCH 04/16] Use moduleLocation instead of changing self --- template/dogfood/flake.nix | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/template/dogfood/flake.nix b/template/dogfood/flake.nix index 412198dd..20285e93 100644 --- a/template/dogfood/flake.nix +++ b/template/dogfood/flake.nix @@ -10,12 +10,7 @@ flake-parts.lib.mkFlake { inherit inputs; - # Workaround for https://github.com/hercules-ci/flake-parts/issues/148 - self = { - outPath = ./.; - inherit (self) - _type inputs lastModified lastModifiedDate narHash outputs sourceInfo submodules; - }; + moduleLocation = ./.; } ./modules/dogfood.nix ).flakeModules.dogfood; From 8ad164c064d9e1b51bb573ab3918f9667912d27b Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Tue, 9 May 2023 10:02:31 -0700 Subject: [PATCH 05/16] Use flake.nix as the location --- template/dogfood/flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/dogfood/flake.nix b/template/dogfood/flake.nix index 20285e93..4f78f041 100644 --- a/template/dogfood/flake.nix +++ b/template/dogfood/flake.nix @@ -10,7 +10,7 @@ flake-parts.lib.mkFlake { inherit inputs; - moduleLocation = ./.; + moduleLocation = ./flake.nix; } ./modules/dogfood.nix ).flakeModules.dogfood; From 89c069df9e14048c89b0af4a65b7aeb2a034e98f Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Tue, 31 Oct 2023 23:16:06 +0000 Subject: [PATCH 06/16] Add bootstrap step --- template/dogfood/flake.nix | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/template/dogfood/flake.nix b/template/dogfood/flake.nix index 4f78f041..86350d4d 100644 --- a/template/dogfood/flake.nix +++ b/template/dogfood/flake.nix @@ -5,13 +5,14 @@ nixpkgs_22_11.url = "github:NixOS/nixpkgs/nixos-22.11"; }; - outputs = { flake-parts, self, ... }@inputs: - flake-parts.lib.mkFlake { inherit inputs; } ( + outputs = { flake-parts, self, ... }@inputs: let + bootstrap = flake-parts.lib.mkFlake { inherit inputs; moduleLocation = ./flake.nix; } - ./modules/dogfood.nix - ).flakeModules.dogfood; + ./modules/dogfood.nix; + in + flake-parts.lib.mkFlake { inherit inputs; } bootstrap.flakeModules.dogfood; } From 863f8b69be7cb7d4cb4e793c031b5d60f0fc97d0 Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Fri, 3 Nov 2023 14:48:37 +0000 Subject: [PATCH 07/16] Add a dev flake --- template/dogfood/.envrc | 1 + template/dogfood/.gitignore | 1 + template/dogfood/dev/flake.nix | 11 +++++++++++ template/dogfood/flake.nix | 23 +++++++++++++---------- template/dogfood/modules/dev.nix | 20 ++++++++++++++++++++ template/dogfood/modules/dogfood.nix | 23 ----------------------- 6 files changed, 46 insertions(+), 33 deletions(-) create mode 100644 template/dogfood/.envrc create mode 100644 template/dogfood/.gitignore create mode 100644 template/dogfood/dev/flake.nix create mode 100644 template/dogfood/modules/dev.nix delete mode 100644 template/dogfood/modules/dogfood.nix diff --git a/template/dogfood/.envrc b/template/dogfood/.envrc new file mode 100644 index 00000000..48049575 --- /dev/null +++ b/template/dogfood/.envrc @@ -0,0 +1 @@ +use flake ./dev --no-write-lock-file --show-trace \ No newline at end of file diff --git a/template/dogfood/.gitignore b/template/dogfood/.gitignore new file mode 100644 index 00000000..04744984 --- /dev/null +++ b/template/dogfood/.gitignore @@ -0,0 +1 @@ +/.direnv/ \ No newline at end of file diff --git a/template/dogfood/dev/flake.nix b/template/dogfood/dev/flake.nix new file mode 100644 index 00000000..89c9168a --- /dev/null +++ b/template/dogfood/dev/flake.nix @@ -0,0 +1,11 @@ +{ + description = "The dev flake to set up the devShell. It dogfoods modules provided by the public flake"; + + inputs = { + public.url = "path:.."; + nixpkgs.follows = "public/nixpkgs"; + flake-parts.follows = "public/flake-parts"; + }; + + outputs = { public, flake-parts, nixpkgs, self, ... }@inputs: flake-parts.lib.mkFlake { inherit inputs; } public.flakeModules.dev; +} diff --git a/template/dogfood/flake.nix b/template/dogfood/flake.nix index 86350d4d..60edd9e0 100644 --- a/template/dogfood/flake.nix +++ b/template/dogfood/flake.nix @@ -5,14 +5,17 @@ nixpkgs_22_11.url = "github:NixOS/nixpkgs/nixos-22.11"; }; - outputs = { flake-parts, self, ... }@inputs: let - bootstrap = - flake-parts.lib.mkFlake - { - inherit inputs; - moduleLocation = ./flake.nix; - } - ./modules/dogfood.nix; - in - flake-parts.lib.mkFlake { inherit inputs; } bootstrap.flakeModules.dogfood; + outputs = { flake-parts, self, nixpkgs, ... }@inputs: + flake-parts.lib.mkFlake + { + inherit inputs; + moduleLocation = ./flake.nix; + } + { + imports = [ + ./modules/anotherFlakeModule.nix + ./modules/dev.nix + ./modules/hello.nix + ]; + }; } diff --git a/template/dogfood/modules/dev.nix b/template/dogfood/modules/dev.nix new file mode 100644 index 00000000..4682d9fd --- /dev/null +++ b/template/dogfood/modules/dev.nix @@ -0,0 +1,20 @@ +{flake-parts-lib, lib, inputs, ...}@topLevel: { + imports = [ + ./hello.nix + inputs.flake-parts.flakeModules.flakeModules + ]; + flake.flakeModules.dev = { + config.systems = [ "x86_64-linux" "aarch64-darwin" ]; + imports = [ + topLevel.config.flake.flakeModules.hello + ]; + options.perSystem = flake-parts-lib.mkPerSystemOption ({pkgs, ...}@perSystem: { + devShells.default = pkgs.mkShell { + buildInputs = [ perSystem.config.packages.hello_22_11 ]; + shellHook = '' + hello + ''; + }; + }); + }; +} diff --git a/template/dogfood/modules/dogfood.nix b/template/dogfood/modules/dogfood.nix deleted file mode 100644 index 7febe02d..00000000 --- a/template/dogfood/modules/dogfood.nix +++ /dev/null @@ -1,23 +0,0 @@ -{flake-parts-lib, lib, inputs, ...}@topLevel: { - imports = [ - ./hello.nix - inputs.flake-parts.flakeModules.flakeModules - ]; - flake.flakeModules.dogfood = { - config.systems = [ "x86_64-linux" "aarch64-darwin" ]; - imports = [ - topLevel.config.flake.flakeModules.hello - - # Expose flake modules - ./dogfood.nix - ./hello.nix - ./anotherFlakeModule.nix - ]; - options.perSystem = flake-parts-lib.mkPerSystemOption (perSystem: { - apps.default = { - type = "app"; - program = "${perSystem.config.packages.hello_22_11}/bin/hello"; - }; - }); - }; -} From 7b75530a52b605ed6068a8d5cba9495560b84a65 Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Fri, 3 Nov 2023 17:28:27 +0000 Subject: [PATCH 08/16] Avoid double mkFlake --- template/dogfood/.envrc | 1 - template/dogfood/dev/flake.nix | 11 ----------- template/dogfood/flake.nix | 1 - template/dogfood/modules/dev.nix | 13 +++++++++---- template/dogfood/modules/hello.nix | 5 ++++- 5 files changed, 13 insertions(+), 18 deletions(-) delete mode 100644 template/dogfood/.envrc delete mode 100644 template/dogfood/dev/flake.nix diff --git a/template/dogfood/.envrc b/template/dogfood/.envrc deleted file mode 100644 index 48049575..00000000 --- a/template/dogfood/.envrc +++ /dev/null @@ -1 +0,0 @@ -use flake ./dev --no-write-lock-file --show-trace \ No newline at end of file diff --git a/template/dogfood/dev/flake.nix b/template/dogfood/dev/flake.nix deleted file mode 100644 index 89c9168a..00000000 --- a/template/dogfood/dev/flake.nix +++ /dev/null @@ -1,11 +0,0 @@ -{ - description = "The dev flake to set up the devShell. It dogfoods modules provided by the public flake"; - - inputs = { - public.url = "path:.."; - nixpkgs.follows = "public/nixpkgs"; - flake-parts.follows = "public/flake-parts"; - }; - - outputs = { public, flake-parts, nixpkgs, self, ... }@inputs: flake-parts.lib.mkFlake { inherit inputs; } public.flakeModules.dev; -} diff --git a/template/dogfood/flake.nix b/template/dogfood/flake.nix index 60edd9e0..aef3cdfe 100644 --- a/template/dogfood/flake.nix +++ b/template/dogfood/flake.nix @@ -15,7 +15,6 @@ imports = [ ./modules/anotherFlakeModule.nix ./modules/dev.nix - ./modules/hello.nix ]; }; } diff --git a/template/dogfood/modules/dev.nix b/template/dogfood/modules/dev.nix index 4682d9fd..8fdcb66e 100644 --- a/template/dogfood/modules/dev.nix +++ b/template/dogfood/modules/dev.nix @@ -1,12 +1,17 @@ -{flake-parts-lib, lib, inputs, ...}@topLevel: { +{flake-parts-lib, lib, inputs, ...}@topLevel: +rec { imports = [ - ./hello.nix inputs.flake-parts.flakeModules.flakeModules + flake.flakeModules.dev ]; - flake.flakeModules.dev = { + flake.flakeModules.dev = dev: { config.systems = [ "x86_64-linux" "aarch64-darwin" ]; imports = [ - topLevel.config.flake.flakeModules.hello + ( + if topLevel.moduleLocation == dev.moduleLocation + then ./hello.nix # Use file name to dogfood a flake module defined from the current flake to avoid infinite recursion + else topLevel.config.flake.flakeModules.hello # Use attributes to reference the flake module from other flakes + ) ]; options.perSystem = flake-parts-lib.mkPerSystemOption ({pkgs, ...}@perSystem: { devShells.default = pkgs.mkShell { diff --git a/template/dogfood/modules/hello.nix b/template/dogfood/modules/hello.nix index 94799497..001d609b 100644 --- a/template/dogfood/modules/hello.nix +++ b/template/dogfood/modules/hello.nix @@ -1,7 +1,10 @@ -{inputs, flake-parts-lib, ...}: { +{inputs, flake-parts-lib, ...}: +rec { imports = [ inputs.flake-parts.flakeModules.flakeModules + flake.flakeModules.hello ]; + flake.flakeModules.hello = { options.perSystem = flake-parts-lib.mkPerSystemOption ({ system, ... }: { packages.hello_22_11 = From 478396adb9ca44604afeb5812c74f007d86a8260 Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Fri, 3 Nov 2023 11:21:50 -0700 Subject: [PATCH 09/16] Update dev.nix --- template/dogfood/modules/dev.nix | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/template/dogfood/modules/dev.nix b/template/dogfood/modules/dev.nix index 8fdcb66e..216e1483 100644 --- a/template/dogfood/modules/dev.nix +++ b/template/dogfood/modules/dev.nix @@ -3,16 +3,18 @@ rec { imports = [ inputs.flake-parts.flakeModules.flakeModules flake.flakeModules.dev + + # Use file name to dogfood a flake module defined from the current flake to avoid infinite recursion + ./hello.nix ]; flake.flakeModules.dev = dev: { - config.systems = [ "x86_64-linux" "aarch64-darwin" ]; - imports = [ - ( - if topLevel.moduleLocation == dev.moduleLocation - then ./hello.nix # Use file name to dogfood a flake module defined from the current flake to avoid infinite recursion - else topLevel.config.flake.flakeModules.hello # Use attributes to reference the flake module from other flakes - ) + imports = lib.lists.optionals (topLevel.moduleLocation != dev.moduleLocation) [ + # Use attributes to reference the flake module from other flakes + topLevel.config.flake.flakeModules.hello ]; + + config.systems = [ "x86_64-linux" "aarch64-darwin" ]; + options.perSystem = flake-parts-lib.mkPerSystemOption ({pkgs, ...}@perSystem: { devShells.default = pkgs.mkShell { buildInputs = [ perSystem.config.packages.hello_22_11 ]; From de10e510ab5bbf1ef3b5cb3c3236b03411c38f04 Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Fri, 3 Nov 2023 18:57:48 +0000 Subject: [PATCH 10/16] Update to nixpkgs 23.05 --- template/dogfood/flake.nix | 2 +- template/dogfood/modules/hello.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/template/dogfood/flake.nix b/template/dogfood/flake.nix index aef3cdfe..dc32ee69 100644 --- a/template/dogfood/flake.nix +++ b/template/dogfood/flake.nix @@ -2,7 +2,7 @@ description = "Description for the project"; inputs = { - nixpkgs_22_11.url = "github:NixOS/nixpkgs/nixos-22.11"; + nixpkgs_23_05.url = "github:NixOS/nixpkgs/nixos-23.05"; }; outputs = { flake-parts, self, nixpkgs, ... }@inputs: diff --git a/template/dogfood/modules/hello.nix b/template/dogfood/modules/hello.nix index 001d609b..7c95ff83 100644 --- a/template/dogfood/modules/hello.nix +++ b/template/dogfood/modules/hello.nix @@ -8,7 +8,7 @@ rec { flake.flakeModules.hello = { options.perSystem = flake-parts-lib.mkPerSystemOption ({ system, ... }: { packages.hello_22_11 = - inputs.nixpkgs_22_11.legacyPackages.${system}.hello; + inputs.nixpkgs_23_05.legacyPackages.${system}.hello; }); }; } \ No newline at end of file From 539814ffb7680a563dd6f5417765ba442cea7967 Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Fri, 3 Nov 2023 22:09:43 +0000 Subject: [PATCH 11/16] Remove .gitignore --- template/dogfood/.gitignore | 1 - 1 file changed, 1 deletion(-) delete mode 100644 template/dogfood/.gitignore diff --git a/template/dogfood/.gitignore b/template/dogfood/.gitignore deleted file mode 100644 index 04744984..00000000 --- a/template/dogfood/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/.direnv/ \ No newline at end of file From b75dd7cb1773a083ae35f626dcf69be8f034d67f Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Fri, 3 Nov 2023 22:10:15 +0000 Subject: [PATCH 12/16] Avoid moduleLocation comparison --- template/dogfood/flake.nix | 1 + template/dogfood/modules/dev.nix | 19 ++++++++++++------- template/dogfood/modules/hello.nix | 4 +++- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/template/dogfood/flake.nix b/template/dogfood/flake.nix index dc32ee69..169d10e0 100644 --- a/template/dogfood/flake.nix +++ b/template/dogfood/flake.nix @@ -14,6 +14,7 @@ { imports = [ ./modules/anotherFlakeModule.nix + ./modules/hello.nix ./modules/dev.nix ]; }; diff --git a/template/dogfood/modules/dev.nix b/template/dogfood/modules/dev.nix index 216e1483..0da2e0f2 100644 --- a/template/dogfood/modules/dev.nix +++ b/template/dogfood/modules/dev.nix @@ -1,18 +1,23 @@ -{flake-parts-lib, lib, inputs, ...}@topLevel: +{flake-parts-lib, lib, inputs, ...}@topLevel: rec { imports = [ inputs.flake-parts.flakeModules.flakeModules - flake.flakeModules.dev # Use file name to dogfood a flake module defined from the current flake to avoid infinite recursion ./hello.nix + + { + flake.flakeModules.dev.imports = [ + # Use attributes to reference the flake module from other flakes + topLevel.config.flake.flakeModules.hello + ]; + } + + # Reference `flake.flakeModules.dev` via `rec` instead of `config` to avoid infinite recursion + flake.flakeModules.dev ]; - flake.flakeModules.dev = dev: { - imports = lib.lists.optionals (topLevel.moduleLocation != dev.moduleLocation) [ - # Use attributes to reference the flake module from other flakes - topLevel.config.flake.flakeModules.hello - ]; + flake.flakeModules.dev = { config.systems = [ "x86_64-linux" "aarch64-darwin" ]; options.perSystem = flake-parts-lib.mkPerSystemOption ({pkgs, ...}@perSystem: { diff --git a/template/dogfood/modules/hello.nix b/template/dogfood/modules/hello.nix index 7c95ff83..4e25a10d 100644 --- a/template/dogfood/modules/hello.nix +++ b/template/dogfood/modules/hello.nix @@ -2,6 +2,8 @@ rec { imports = [ inputs.flake-parts.flakeModules.flakeModules + + # Reference `flake.flakeModules.hello` via `rec` instead of `config` to avoid infinite recursion flake.flakeModules.hello ]; @@ -11,4 +13,4 @@ rec { inputs.nixpkgs_23_05.legacyPackages.${system}.hello; }); }; -} \ No newline at end of file +} From 0bbf4aa352ec512d2a40e7a37788ef0511f8ccf9 Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Thu, 12 Sep 2024 17:19:50 +0000 Subject: [PATCH 13/16] Dogfooding via partitions --- flake.nix | 12 ++++----- template/dogfood/flake.nix | 20 ++++++++++---- .../dogfood/modules/anotherFlakeModule.nix | 8 ------ template/dogfood/modules/custom-hello.nix | 19 +++++++++++++ template/dogfood/modules/dev.nix | 27 +++++++------------ template/dogfood/modules/hello.nix | 16 ----------- 6 files changed, 50 insertions(+), 52 deletions(-) delete mode 100644 template/dogfood/modules/anotherFlakeModule.nix create mode 100644 template/dogfood/modules/custom-hello.nix delete mode 100644 template/dogfood/modules/hello.nix diff --git a/flake.nix b/flake.nix index c19ff747..c79acf48 100644 --- a/flake.nix +++ b/flake.nix @@ -44,6 +44,12 @@ - a check with runCommand ''; }; + dogfood = { + path = ./template/dogfood; + description = '' + A minimal flake using flake-parts creating flake modules to build its own outputs. + ''; + }; }; flakeModules = { easyOverlay = ./extras/easyOverlay.nix; @@ -65,12 +71,6 @@ flake = { inherit lib templates flakeModules; }; - dogfood = { - path = ./template/dogfood; - description = '' - A minimal flake using flake-parts creating flake modules to build its own outputs. - ''; - }; }; } diff --git a/template/dogfood/flake.nix b/template/dogfood/flake.nix index 169d10e0..1e6abc1d 100644 --- a/template/dogfood/flake.nix +++ b/template/dogfood/flake.nix @@ -9,13 +9,23 @@ flake-parts.lib.mkFlake { inherit inputs; - moduleLocation = ./flake.nix; } - { + ({ config, lib, ... }: { imports = [ - ./modules/anotherFlakeModule.nix - ./modules/hello.nix + flake-parts.flakeModules.partitions ./modules/dev.nix ]; - }; + + systems = [ "x86_64-linux" "aarch64-darwin" ]; + + partitionedAttrs.devShells = "dogfood"; + partitionedAttrs.packages = "dogfood"; + partitions.dogfood = { + module = { + imports = [ + config.flake.flakeModules.dev + ]; + }; + }; + }); } diff --git a/template/dogfood/modules/anotherFlakeModule.nix b/template/dogfood/modules/anotherFlakeModule.nix deleted file mode 100644 index 3df25e4b..00000000 --- a/template/dogfood/modules/anotherFlakeModule.nix +++ /dev/null @@ -1,8 +0,0 @@ -{inputs, ...}: { - imports = [ - inputs.flake-parts.flakeModules.flakeModules - ]; - flake.flakeModules.anotherFlakeModule = { - # Define another flake module here - }; -} \ No newline at end of file diff --git a/template/dogfood/modules/custom-hello.nix b/template/dogfood/modules/custom-hello.nix new file mode 100644 index 00000000..9921f0fd --- /dev/null +++ b/template/dogfood/modules/custom-hello.nix @@ -0,0 +1,19 @@ +{ inputs, flake-parts-lib, ... }: +{ + imports = [ + inputs.flake-parts.flakeModules.flakeModules + ]; + + flake.flakeModules.customHello = { + options.perSystem = flake-parts-lib.mkPerSystemOption ({ pkgs, system, ... }: { + packages.hello = + (inputs.nixpkgs_23_05.legacyPackages.${system}.hello.override { + stdenv = pkgs.gcc11Stdenv; + }).overrideAttrs (oldAttrs: { + meta = oldAttrs.meta // { + description = "A hello package from the `flakeModules.customHello` author's nixpkgs 23.05, built with gcc 11 from `flakeModules.customHello` user's nixpkgs"; + }; + }); + }); + }; +} diff --git a/template/dogfood/modules/dev.nix b/template/dogfood/modules/dev.nix index 0da2e0f2..088ac2ae 100644 --- a/template/dogfood/modules/dev.nix +++ b/template/dogfood/modules/dev.nix @@ -1,28 +1,21 @@ -{flake-parts-lib, lib, inputs, ...}@topLevel: -rec { +{ flake-parts-lib, inputs, ... }@topLevel: +{ imports = [ inputs.flake-parts.flakeModules.flakeModules - # Use file name to dogfood a flake module defined from the current flake to avoid infinite recursion - ./hello.nix - - { - flake.flakeModules.dev.imports = [ - # Use attributes to reference the flake module from other flakes - topLevel.config.flake.flakeModules.hello - ]; - } - - # Reference `flake.flakeModules.dev` via `rec` instead of `config` to avoid infinite recursion - flake.flakeModules.dev + # For `topLevel.config.flake.flakeModules.customHello` + ./custom-hello.nix ]; flake.flakeModules.dev = { - config.systems = [ "x86_64-linux" "aarch64-darwin" ]; + imports = [ + # For `perSystem.config.packages.hello + topLevel.config.flake.flakeModules.customHello + ]; - options.perSystem = flake-parts-lib.mkPerSystemOption ({pkgs, ...}@perSystem: { + options.perSystem = flake-parts-lib.mkPerSystemOption ({ pkgs, ... }@perSystem: { devShells.default = pkgs.mkShell { - buildInputs = [ perSystem.config.packages.hello_22_11 ]; + buildInputs = [ perSystem.config.packages.hello ]; shellHook = '' hello ''; diff --git a/template/dogfood/modules/hello.nix b/template/dogfood/modules/hello.nix deleted file mode 100644 index 4e25a10d..00000000 --- a/template/dogfood/modules/hello.nix +++ /dev/null @@ -1,16 +0,0 @@ -{inputs, flake-parts-lib, ...}: -rec { - imports = [ - inputs.flake-parts.flakeModules.flakeModules - - # Reference `flake.flakeModules.hello` via `rec` instead of `config` to avoid infinite recursion - flake.flakeModules.hello - ]; - - flake.flakeModules.hello = { - options.perSystem = flake-parts-lib.mkPerSystemOption ({ system, ... }: { - packages.hello_22_11 = - inputs.nixpkgs_23_05.legacyPackages.${system}.hello; - }); - }; -} From 5ce87680c3bea2b77fd9011585dd3842a84c3507 Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Thu, 12 Sep 2024 17:36:33 +0000 Subject: [PATCH 14/16] Add `options.enableUserStdenv` --- template/dogfood/flake.nix | 8 ++------ template/dogfood/modules/custom-hello.nix | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/template/dogfood/flake.nix b/template/dogfood/flake.nix index 1e6abc1d..198e8d94 100644 --- a/template/dogfood/flake.nix +++ b/template/dogfood/flake.nix @@ -10,7 +10,7 @@ { inherit inputs; } - ({ config, lib, ... }: { + (topLevel: { imports = [ flake-parts.flakeModules.partitions ./modules/dev.nix @@ -21,11 +21,7 @@ partitionedAttrs.devShells = "dogfood"; partitionedAttrs.packages = "dogfood"; partitions.dogfood = { - module = { - imports = [ - config.flake.flakeModules.dev - ]; - }; + module = topLevel.config.flake.flakeModules.dev; }; }); } diff --git a/template/dogfood/modules/custom-hello.nix b/template/dogfood/modules/custom-hello.nix index 9921f0fd..3bf8397b 100644 --- a/template/dogfood/modules/custom-hello.nix +++ b/template/dogfood/modules/custom-hello.nix @@ -1,17 +1,27 @@ -{ inputs, flake-parts-lib, ... }: +{ inputs, flake-parts-lib, lib, ... }: { imports = [ inputs.flake-parts.flakeModules.flakeModules ]; - flake.flakeModules.customHello = { + flake.flakeModules.customHello = flakeModule: { + options.enableUserStdenv = lib.mkEnableOption "stdenv from `flakeModules.customHello` user's nixpkgs"; options.perSystem = flake-parts-lib.mkPerSystemOption ({ pkgs, system, ... }: { packages.hello = (inputs.nixpkgs_23_05.legacyPackages.${system}.hello.override { - stdenv = pkgs.gcc11Stdenv; + stdenv = + if flakeModule.config.enableUserStdenv then + pkgs.stdenv + else + inputs.nixpkgs_23_05.legacyPackages.${system}.stdenv; }).overrideAttrs (oldAttrs: { meta = oldAttrs.meta // { - description = "A hello package from the `flakeModules.customHello` author's nixpkgs 23.05, built with gcc 11 from `flakeModules.customHello` user's nixpkgs"; + description = "A hello package from the `flakeModules.customHello` author's nixpkgs 23.05, built with stdenv from ${ + if flakeModule.config.enableUserStdenv then + "the `flakeModules.customHello` user's nixpkgs" + else + "the `flakeModules.customHello` author's nixpkgs 23.05" + }"; }; }); }); From 1796154f6ec24cd57418e7d85457187070100b87 Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Thu, 12 Sep 2024 17:41:37 +0000 Subject: [PATCH 15/16] Move `enableUserStdenv` to `customHello.enableUserStdenv` --- template/dogfood/modules/custom-hello.nix | 40 +++++++++++++---------- template/dogfood/modules/dev.nix | 2 ++ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/template/dogfood/modules/custom-hello.nix b/template/dogfood/modules/custom-hello.nix index 3bf8397b..068d303c 100644 --- a/template/dogfood/modules/custom-hello.nix +++ b/template/dogfood/modules/custom-hello.nix @@ -4,26 +4,30 @@ inputs.flake-parts.flakeModules.flakeModules ]; - flake.flakeModules.customHello = flakeModule: { - options.enableUserStdenv = lib.mkEnableOption "stdenv from `flakeModules.customHello` user's nixpkgs"; - options.perSystem = flake-parts-lib.mkPerSystemOption ({ pkgs, system, ... }: { - packages.hello = - (inputs.nixpkgs_23_05.legacyPackages.${system}.hello.override { - stdenv = - if flakeModule.config.enableUserStdenv then - pkgs.stdenv - else - inputs.nixpkgs_23_05.legacyPackages.${system}.stdenv; - }).overrideAttrs (oldAttrs: { - meta = oldAttrs.meta // { - description = "A hello package from the `flakeModules.customHello` author's nixpkgs 23.05, built with stdenv from ${ - if flakeModule.config.enableUserStdenv then + flake.flakeModules.customHello = flakeModule: + let + cfg = flakeModule.config.customHello; + in + { + options.customHello.enableUserStdenv = lib.mkEnableOption "stdenv from `flakeModules.customHello` user's nixpkgs"; + options.perSystem = flake-parts-lib.mkPerSystemOption ({ pkgs, system, ... }: { + packages.hello = + (inputs.nixpkgs_23_05.legacyPackages.${system}.hello.override { + stdenv = + if cfg.enableUserStdenv then + pkgs.stdenv + else + inputs.nixpkgs_23_05.legacyPackages.${system}.stdenv; + }).overrideAttrs (oldAttrs: { + meta = oldAttrs.meta // { + description = "A hello package from the `flakeModules.customHello` author's nixpkgs 23.05, built with stdenv from ${ + if cfg.enableUserStdenv then "the `flakeModules.customHello` user's nixpkgs" else "the `flakeModules.customHello` author's nixpkgs 23.05" }"; - }; - }); - }); - }; + }; + }); + }); + }; } diff --git a/template/dogfood/modules/dev.nix b/template/dogfood/modules/dev.nix index 088ac2ae..814ea731 100644 --- a/template/dogfood/modules/dev.nix +++ b/template/dogfood/modules/dev.nix @@ -13,6 +13,8 @@ topLevel.config.flake.flakeModules.customHello ]; + config.customHello.enableUserStdenv = true; + options.perSystem = flake-parts-lib.mkPerSystemOption ({ pkgs, ... }@perSystem: { devShells.default = pkgs.mkShell { buildInputs = [ perSystem.config.packages.hello ]; From 56f98c596a62f92ad92b1d7a10654362995a2192 Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Thu, 12 Sep 2024 17:43:20 +0000 Subject: [PATCH 16/16] 23.05 -> 24.05 --- template/dogfood/flake.nix | 2 +- template/dogfood/modules/custom-hello.nix | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/template/dogfood/flake.nix b/template/dogfood/flake.nix index 198e8d94..61cbf5f7 100644 --- a/template/dogfood/flake.nix +++ b/template/dogfood/flake.nix @@ -2,7 +2,7 @@ description = "Description for the project"; inputs = { - nixpkgs_23_05.url = "github:NixOS/nixpkgs/nixos-23.05"; + nixpkgs_24_05.url = "github:NixOS/nixpkgs/nixos-24.05"; }; outputs = { flake-parts, self, nixpkgs, ... }@inputs: diff --git a/template/dogfood/modules/custom-hello.nix b/template/dogfood/modules/custom-hello.nix index 068d303c..e97ca61d 100644 --- a/template/dogfood/modules/custom-hello.nix +++ b/template/dogfood/modules/custom-hello.nix @@ -12,19 +12,19 @@ options.customHello.enableUserStdenv = lib.mkEnableOption "stdenv from `flakeModules.customHello` user's nixpkgs"; options.perSystem = flake-parts-lib.mkPerSystemOption ({ pkgs, system, ... }: { packages.hello = - (inputs.nixpkgs_23_05.legacyPackages.${system}.hello.override { + (inputs.nixpkgs_24_05.legacyPackages.${system}.hello.override { stdenv = if cfg.enableUserStdenv then pkgs.stdenv else - inputs.nixpkgs_23_05.legacyPackages.${system}.stdenv; + inputs.nixpkgs_24_05.legacyPackages.${system}.stdenv; }).overrideAttrs (oldAttrs: { meta = oldAttrs.meta // { - description = "A hello package from the `flakeModules.customHello` author's nixpkgs 23.05, built with stdenv from ${ + description = "A hello package from the `flakeModules.customHello` author's nixpkgs 24.05, built with stdenv from ${ if cfg.enableUserStdenv then "the `flakeModules.customHello` user's nixpkgs" else - "the `flakeModules.customHello` author's nixpkgs 23.05" + "the `flakeModules.customHello` author's nixpkgs 24.05" }"; }; });