summaryrefslogtreecommitdiff
path: root/templates/standard
diff options
context:
space:
mode:
Diffstat (limited to 'templates/standard')
-rw-r--r--templates/standard/default.nix15
-rw-r--r--templates/standard/flake.nix44
-rw-r--r--templates/standard/nix/module.nix27
-rw-r--r--templates/standard/nix/package.nix1
-rw-r--r--templates/standard/shell.nix16
5 files changed, 80 insertions, 23 deletions
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 ? <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 ? <nixpkgs>,
+ system ? builtins.currentSystem,
+ hello ? (import ./default.nix { inherit pkgs; }).hello,
+}:
+
+pkgs.mkShell {
+ packages = [ pkgs.bash ];
+
+ inputsFrom = [ hello ];
+}