diff --git a/flake.nix b/flake.nix index f952447e..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; diff --git a/template/dogfood/flake.nix b/template/dogfood/flake.nix new file mode 100644 index 00000000..61cbf5f7 --- /dev/null +++ b/template/dogfood/flake.nix @@ -0,0 +1,27 @@ +{ + description = "Description for the project"; + + inputs = { + nixpkgs_24_05.url = "github:NixOS/nixpkgs/nixos-24.05"; + }; + + outputs = { flake-parts, self, nixpkgs, ... }@inputs: + flake-parts.lib.mkFlake + { + inherit inputs; + } + (topLevel: { + imports = [ + flake-parts.flakeModules.partitions + ./modules/dev.nix + ]; + + systems = [ "x86_64-linux" "aarch64-darwin" ]; + + partitionedAttrs.devShells = "dogfood"; + partitionedAttrs.packages = "dogfood"; + partitions.dogfood = { + module = topLevel.config.flake.flakeModules.dev; + }; + }); +} diff --git a/template/dogfood/modules/custom-hello.nix b/template/dogfood/modules/custom-hello.nix new file mode 100644 index 00000000..e97ca61d --- /dev/null +++ b/template/dogfood/modules/custom-hello.nix @@ -0,0 +1,33 @@ +{ inputs, flake-parts-lib, lib, ... }: +{ + imports = [ + inputs.flake-parts.flakeModules.flakeModules + ]; + + 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_24_05.legacyPackages.${system}.hello.override { + stdenv = + if cfg.enableUserStdenv then + pkgs.stdenv + else + inputs.nixpkgs_24_05.legacyPackages.${system}.stdenv; + }).overrideAttrs (oldAttrs: { + meta = oldAttrs.meta // { + 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 24.05" + }"; + }; + }); + }); + }; +} diff --git a/template/dogfood/modules/dev.nix b/template/dogfood/modules/dev.nix new file mode 100644 index 00000000..814ea731 --- /dev/null +++ b/template/dogfood/modules/dev.nix @@ -0,0 +1,27 @@ +{ flake-parts-lib, inputs, ... }@topLevel: +{ + imports = [ + inputs.flake-parts.flakeModules.flakeModules + + # For `topLevel.config.flake.flakeModules.customHello` + ./custom-hello.nix + ]; + + flake.flakeModules.dev = { + imports = [ + # For `perSystem.config.packages.hello + 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 ]; + shellHook = '' + hello + ''; + }; + }); + }; +}