From b8ba3056da39e2763094b7c695da0c9d5ee287c5 Mon Sep 17 00:00:00 2001 From: Seth Flynn Date: Sun, 2 Feb 2025 14:42:48 -0500 Subject: templates/standard: expand --- templates/standard/default.nix | 15 ++++++++++--- templates/standard/flake.nix | 44 +++++++++++++++++++++----------------- templates/standard/nix/module.nix | 27 +++++++++++++++++++++++ templates/standard/nix/package.nix | 1 + templates/standard/shell.nix | 16 ++++++++++++++ 5 files changed, 80 insertions(+), 23 deletions(-) create mode 100644 templates/standard/nix/module.nix create mode 100644 templates/standard/nix/package.nix create mode 100644 templates/standard/shell.nix diff --git a/templates/standard/default.nix b/templates/standard/default.nix index b782208..f2b2028 100644 --- a/templates/standard/default.nix +++ b/templates/standard/default.nix @@ -7,6 +7,15 @@ nixpkgs ? , system ? builtins.currentSystem, }: -{ - inherit (pkgs) hello; -} + +let + inherit (pkgs) lib; + + callPackage = lib.callPackageWith (pkgs // pkgs'); + + pkgs' = { + hello = callPackage ./nix/package.nix { }; + }; +in + +pkgs' diff --git a/templates/standard/flake.nix b/templates/standard/flake.nix index 9c80e4b..23f6853 100644 --- a/templates/standard/flake.nix +++ b/templates/standard/flake.nix @@ -5,6 +5,7 @@ outputs = { self, nixpkgs }: + let inherit (nixpkgs) lib; @@ -16,54 +17,57 @@ ]; forAllSystems = lib.genAttrs systems; - nixpkgsFor = nixpkgs.legacyPackages; in + { checks = forAllSystems ( system: + let - pkgs = nixpkgsFor.${system}; + pkgs = nixpkgs.legacyPackages.${system}; mkCheck = name: deps: script: - pkgs.runCommand name { nativeBuildInputs = deps; } script; + pkgs.runCommand name { nativeBuildInputs = deps; } '' + ${script} + touch $out + ''; in - { - nixfmt = mkCheck "check-nixfmt" [ pkgs.nixfmt-rfc-style ] '' - nixfmt --check ${self} - touch $out - ''; + { + nixfmt = mkCheck "check-nixfmt" [ pkgs.nixfmt-rfc-style ] "nixfmt --check ${self}/**.nix"; } ); devShells = forAllSystems ( system: + let - pkgs = nixpkgsFor.${system}; + pkgs = nixpkgs.legacyPackages.${system}; in - { - default = pkgs.mkShell { - packages = [ pkgs.bash ]; - inputsFrom = [ self.packages.${system}.hello ]; + { + default = import ./shell.nix { + inherit pkgs; + inherit (self.packages.${system}) hello; }; } ); - formatter = forAllSystems (system: nixpkgsFor.${system}.nixfmt-rfc-style); + formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style); + + nixosModules.default = lib.modules.importApply ./nix/module.nix { inherit self; }; packages = forAllSystems ( system: + let - pkgs = import ./default.nix { - pkgs = nixpkgsFor.${system}; - }; + pkgs = nixpkgs.legacyPackages.${system}; - isAvailable = lib.meta.availableOn { inherit system; }; - pkgs' = lib.filterAttrs (_: isAvailable) pkgs; + pkgs' = import ./default.nix { inherit pkgs; }; in - pkgs // { default = pkgs'.hello or pkgs.emptyFile; } + + pkgs' // { default = pkgs'.hello or pkgs.emptyFile; } ); }; } diff --git a/templates/standard/nix/module.nix b/templates/standard/nix/module.nix new file mode 100644 index 0000000..36e91ea --- /dev/null +++ b/templates/standard/nix/module.nix @@ -0,0 +1,27 @@ +self: +{ + config, + lib, + pkgs, + ... +}: + +let + namespace = "myProgram"; + cfg = config.services.${namespace}; + + inherit (pkgs.stdenv.hostPlatform) system; + packages = self.packages.${system} or throw "myProgram: ${system} is not supported"; +in + +{ + options.services.${namespace} = { + enable = lib.mkEnableOption "something amazing"; + + package = lib.mkPackageOption packages "hello" { }; + }; + + config = { + environment.systemPackages = [ cfg.package ]; + }; +} diff --git a/templates/standard/nix/package.nix b/templates/standard/nix/package.nix new file mode 100644 index 0000000..46f9694 --- /dev/null +++ b/templates/standard/nix/package.nix @@ -0,0 +1 @@ +{ runCommand }: runCommand "hello" { } "echo 'hello' > $out" diff --git a/templates/standard/shell.nix b/templates/standard/shell.nix new file mode 100644 index 0000000..ded42bb --- /dev/null +++ b/templates/standard/shell.nix @@ -0,0 +1,16 @@ +{ + pkgs ? import nixpkgs { + inherit system; + config = { }; + overlays = [ ]; + }, + nixpkgs ? , + system ? builtins.currentSystem, + hello ? (import ./default.nix { inherit pkgs; }).hello, +}: + +pkgs.mkShell { + packages = [ pkgs.bash ]; + + inputsFrom = [ hello ]; +} -- cgit v1.2.3