diff --git a/CHANGELOG.md b/CHANGELOG.md index d2d2edc..3763e67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ Template: # Upcoming Release +## New Features + +- Add patchNixpkgs function and pre-patched patchedNixpkgs output. + # v0.3.0 ## New Features diff --git a/demo/homeassistant/flake.lock b/demo/homeassistant/flake.lock index 6f267df..6042126 100644 --- a/demo/homeassistant/flake.lock +++ b/demo/homeassistant/flake.lock @@ -35,11 +35,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1736883708, - "narHash": "sha256-uQ+NQ0/xYU0N1CnXsa2zghgNaOPxWpMJXSUJJ9W7140=", + "lastModified": 1742069588, + "narHash": "sha256-C7jVfohcGzdZRF6DO+ybyG/sqpo1h6bZi9T56sxLy+k=", "owner": "nixos", "repo": "nixpkgs", - "rev": "eb62e6aa39ea67e0b8018ba8ea077efe65807dc8", + "rev": "c80f6a7e10b39afcc1894e02ef785b1ad0b0d7e5", "type": "github" }, "original": { @@ -49,29 +49,13 @@ "type": "github" } }, - "nixpkgs-stable": { - "locked": { - "lastModified": 1721524707, - "narHash": "sha256-5NctRsoE54N86nWd0psae70YSLfrOek3Kv1e8KoXe/0=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "556533a23879fc7e5f98dd2e0b31a6911a213171", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "release-24.05", - "repo": "nixpkgs", - "type": "github" - } - }, "nixpkgs_2": { "locked": { - "lastModified": 1721466660, - "narHash": "sha256-pFSxgSZqZ3h+5Du0KvEL1ccDZBwu4zvOil1zzrPNb3c=", + "lastModified": 1744868846, + "narHash": "sha256-5RJTdUHDmj12Qsv7XOhuospjAjATNiTMElplWnJE9Hs=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "6e14bbce7bea6c4efd7adfa88a40dac750d80100", + "rev": "ebe4301cbd8f81c4f8d3244b3632338bbeb6d49c", "type": "github" }, "original": { @@ -111,12 +95,13 @@ "nmdsrc": "nmdsrc" }, "locked": { - "lastModified": 1742237336, - "narHash": "sha256-KQlWwQ0XoLhjobgfK9CGrIPA4KofnUVO1Btid1Ca+OU=", - "owner": "ibizaman", - "repo": "selfhostblocks", - "rev": "023991b4b7bc8edc0276b3a45d1842ed2da7ae76", - "type": "github" + "lastModified": 1750057967, + "narHash": "sha256-1pSPIuhpbKVBxEejKiQ6NG9AP9Jc9EO09N1QGUuyQ0c=", + "ref": "refs/heads/patchNixpkgs", + "rev": "ba5d242c2578c4864883818dd8ff50a15d9326b2", + "revCount": 715, + "type": "git", + "url": "file:///home/timi/Projects/selfhostblocks" }, "original": { "owner": "ibizaman", @@ -126,15 +111,14 @@ }, "sops-nix": { "inputs": { - "nixpkgs": "nixpkgs_2", - "nixpkgs-stable": "nixpkgs-stable" + "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1723501126, - "narHash": "sha256-N9IcHgj/p1+2Pvk8P4Zc1bfrMwld5PcosVA0nL6IGdE=", + "lastModified": 1749592509, + "narHash": "sha256-VunQzfZFA+Y6x3wYi2UE4DEQ8qKoAZZCnZPUlSoqC+A=", "owner": "Mic92", "repo": "sops-nix", - "rev": "be0eec2d27563590194a9206f551a6f73d52fa34", + "rev": "50754dfaa0e24e313c626900d44ef431f3210138", "type": "github" }, "original": { diff --git a/demo/homeassistant/flake.nix b/demo/homeassistant/flake.nix index d57e065..1239273 100644 --- a/demo/homeassistant/flake.nix +++ b/demo/homeassistant/flake.nix @@ -9,13 +9,7 @@ outputs = inputs@{ self, selfhostblocks, sops-nix }: let system = "x86_64-linux"; - originPkgs = selfhostblocks.inputs.nixpkgs; - - nixpkgs' = originPkgs.legacyPackages.${system}.applyPatches { - name = "nixpkgs-patched"; - src = originPkgs; - patches = selfhostblocks.patches.${system}; - }; + nixpkgs' = selfhostblocks.lib.${system}.patchedNixpkgs; nixosSystem' = import "${nixpkgs'}/nixos/lib/eval-config.nix"; basic = { config, ... }: { diff --git a/demo/nextcloud/flake.lock b/demo/nextcloud/flake.lock index f0720fa..d008340 100644 --- a/demo/nextcloud/flake.lock +++ b/demo/nextcloud/flake.lock @@ -35,11 +35,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1736883708, - "narHash": "sha256-uQ+NQ0/xYU0N1CnXsa2zghgNaOPxWpMJXSUJJ9W7140=", + "lastModified": 1742069588, + "narHash": "sha256-C7jVfohcGzdZRF6DO+ybyG/sqpo1h6bZi9T56sxLy+k=", "owner": "nixos", "repo": "nixpkgs", - "rev": "eb62e6aa39ea67e0b8018ba8ea077efe65807dc8", + "rev": "c80f6a7e10b39afcc1894e02ef785b1ad0b0d7e5", "type": "github" }, "original": { @@ -111,12 +111,13 @@ "nmdsrc": "nmdsrc" }, "locked": { - "lastModified": 1742039945, - "narHash": "sha256-DMKGfQce0Jzv3ylln1LBBA6b9h2O4W2YCvyr+ZKIWNk=", - "owner": "ibizaman", - "repo": "selfhostblocks", - "rev": "9ac30326cd46e2760d5cd31a443fd2e61f1b88c0", - "type": "github" + "lastModified": 1750063370, + "narHash": "sha256-rpte6uSniCfDsM2T8Fo39VSZ1zRz9cJDOYgGFf/VGe8=", + "ref": "refs/heads/patchNixpkgs", + "rev": "2c06db033c60c2b8640b9b4d6c420f093974b62d", + "revCount": 715, + "type": "git", + "url": "file:///home/timi/Projects/selfhostblocks" }, "original": { "owner": "ibizaman", diff --git a/demo/nextcloud/flake.nix b/demo/nextcloud/flake.nix index 4b17974..679a207 100644 --- a/demo/nextcloud/flake.nix +++ b/demo/nextcloud/flake.nix @@ -9,13 +9,7 @@ outputs = inputs@{ self, selfhostblocks, sops-nix }: let system = "x86_64-linux"; - originPkgs = selfhostblocks.inputs.nixpkgs; - - nixpkgs' = originPkgs.legacyPackages.${system}.applyPatches { - name = "nixpkgs-patched"; - src = originPkgs; - patches = selfhostblocks.patches.${system}; - }; + nixpkgs' = selfhostblocks.lib.${system}.patchedNixpkgs; nixosSystem' = import "${nixpkgs'}/nixos/lib/eval-config.nix"; basic = { config, ... }: { diff --git a/docs/usage.md b/docs/usage.md index 1247aa7..09875f2 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -39,21 +39,19 @@ deployments. Also, patches can be applied by Self Host Blocks. To handle all thi following code instead wherever you import `nixpkgs`: ```nix -let - system = "x86_64-linux"; - originPkgs = selfhostblocks.inputs.nixpkgs; +{ + inputs.selfhostblocks.url = "github:ibizaman/selfhostblocks"; - nixpkgs' = originPkgs.legacyPackages.${system}.applyPatches { - name = "nixpkgs-patched"; - src = originPkgs; - patches = selfhostblocks.patches.${system}; - }; + outputs = { selfhostblocks, ... }: let + system = "x86_64-linux"; + shbLib = selfhostblocks.lib.${system}; - shbNixpkgs = import nixpkgs' { - inherit system; - }; -in - # ... Use shbNixpkgs + nixpkgs' = shbLib.patchedNixpkgs; + + shbNixpkgs = import nixpkgs' { + inherit system; + }; + in ``` Advanced users can if they wish use a version of `nixpkgs` of their choosing but then we cannot @@ -115,13 +113,9 @@ The following snippets show how to deploy Self Host Blocks using the standard de outputs = { self, selfhostblocks }: { let system = "x86_64-linux"; - originPkgs = selfhostblocks.inputs.nixpkgs; + shbLib = selfhostblocks.lib.${system}; - nixpkgs' = originPkgs.legacyPackages.${system}.applyPatches { - name = "nixpkgs-patched"; - src = originPkgs; - patches = selfhostblocks.patches.${system}; - }; + nixpkgs' = shbLib.patchedNixpkgs; nixosSystem' = import "${nixpkgs'}/nixos/lib/eval-config.nix"; in @@ -153,13 +147,9 @@ some not using Self Host Blocks, then you can do the following: outputs = { self, selfhostblocks }: { let system = "x86_64-linux"; - originPkgs = selfhostblocks.inputs.nixpkgs; + shbLib = selfhostblocks.lib.${system}; - nixpkgs' = originPkgs.legacyPackages.${system}.applyPatches { - name = "nixpkgs-patched"; - src = originPkgs; - patches = selfhostblocks.patches.${system}; - }; + nixpkgs' = shbLib.patchedNixpkgs; shbNixpkgs = import nixpkgs' { inherit system; @@ -197,13 +187,9 @@ The following snippets show how to deploy Self Host Blocks using the deployment outputs = { self, selfhostblocks }: { let system = "x86_64-linux"; - originPkgs = selfhostblocks.inputs.nixpkgs; + shbLib = selfhostblocks.lib.${system}; - nixpkgs' = originPkgs.legacyPackages.${system}.applyPatches { - name = "nixpkgs-patched"; - src = originPkgs; - patches = selfhostblocks.patches.${system}; - }; + nixpkgs' = shbLib.patchedNixpkgs; shbNixpkgs = import nixpkgs' { inherit system; @@ -241,13 +227,9 @@ in this case you can use the `colmena.meta.nodeNixpkgs` option: outputs = { self, selfhostblocks }: { let system = "x86_64-linux"; - originPkgs = selfhostblocks.inputs.nixpkgs; + shbLib = selfhostblocks.lib.${system}; - nixpkgs' = originPkgs.legacyPackages.${system}.applyPatches { - name = "nixpkgs-patched"; - src = originPkgs; - patches = selfhostblocks.patches.${system}; - }; + nixpkgs' = shbLib.patchedNixpkgs; shbNixpkgs = import nixpkgs' { inherit system; @@ -294,17 +276,13 @@ The following snippets show how to deploy Self Host Blocks using the deployment outputs = { self, selfhostblocks }: { let system = "x86_64-linux"; - originPkgs = selfhostblocks.inputs.nixpkgs; + shbLib = selfhostblocks.lib.${system}; - shbNixpkgs = originPkgs.legacyPackages.${system}.applyPatches { - name = "nixpkgs-patched"; - src = originPkgs; - patches = selfhostblocks.patches.${system}; - }; + nixpkgs' = shbLib.patchedNixpkgs; shbPkgs = import shbNixpkgs { inherit system; }; - deployPkgs = import originPkgs { + deployPkgs = import selfhostblocks.inputs.nixpkgs { inherit system; overlays = [ deploy-rs.overlay @@ -365,17 +343,13 @@ in this case you can do: outputs = { self, selfhostblocks }: { let system = "x86_64-linux"; - originPkgs = selfhostblocks.inputs.nixpkgs; + shbLib = selfhostblocks.lib.${system}; - shbNixpkgs = originPkgs.legacyPackages.${system}.applyPatches { - name = "nixpkgs-patched"; - src = originPkgs; - patches = selfhostblocks.patches.${system}; - }; + nixpkgs' = shbLib.patchedNixpkgs; - shbPkgs = import shbNixpkgs { inherit system; }; + shbPkgs = import nixpkgs' { inherit system; }; - deployPkgs = import originPkgs { + deployPkgs = import selfhostblocks.inputs.nixpkgs { inherit system; overlays = [ deploy-rs.overlay @@ -568,18 +542,14 @@ as well as [Skarabox][], my sibling project used to bootstrap a server. outputs = { self, skarabox, selfhostblocks, sops-nix, deploy-rs }: let system = "x86_64-linux"; - originPkgs = selfhostblocks.inputs.nixpkgs; + shbLib = selfhostblocks.lib.${system}; - shbNixpkgs = originPkgs.legacyPackages.${system}.applyPatches { - name = "nixpkgs-patched"; - src = originPkgs; - patches = selfhostblocks.patches.${system}; - }; + nixpkgs' = shbLib.patchedNixpkgs; - shbPkgs = import shbNixpkgs { inherit system; }; + shbPkgs = import nixpkgs' { inherit system; }; # Taken from https://github.com/serokell/deploy-rs?tab=readme-ov-file#overall-usage - deployPkgs = import originPkgs { + deployPkgs = import selfhostblocks.inputs.nixpkgs { inherit system; overlays = [ deploy-rs.overlay diff --git a/flake.nix b/flake.nix index 5a3e73a..f225d54 100644 --- a/flake.nix +++ b/flake.nix @@ -11,21 +11,30 @@ }; }; - outputs = { nixpkgs, nix-flake-tests, flake-utils, nmdsrc, ... }: flake-utils.lib.eachDefaultSystem (system: + outputs = inputs@{ nixpkgs, nix-flake-tests, flake-utils, nmdsrc, ... }: flake-utils.lib.eachDefaultSystem (system: let originPkgs = nixpkgs.legacyPackages.${system}; - patches = originPkgs.lib.optionals (system == "x86_64-linux") [ + shbPatches = originPkgs.lib.optionals (system == "x86_64-linux") [ # Leaving commented out for an example. # (originPkgs.fetchpatch { # url = "https://github.com/NixOS/nixpkgs/pull/317107.patch"; # hash = "sha256-hoLrqV7XtR1hP/m0rV9hjYUBtrSjay0qcPUYlKKuVWk="; # }) ]; - patchedNixpkgs = originPkgs.applyPatches { + patchNixpkgs = { + nixpkgs, + patches, + system, + }: nixpkgs.legacyPackages.${system}.applyPatches { name = "nixpkgs-patched"; src = nixpkgs; inherit patches; }; + patchedNixpkgs = (patchNixpkgs { + nixpkgs = inputs.nixpkgs; + patches = shbPatches; + inherit system; + }); pkgs = import patchedNixpkgs { inherit system; @@ -90,8 +99,6 @@ ]; in { - inherit patches; - nixosModules.default = { config, ... }: { imports = allModules; }; @@ -158,6 +165,8 @@ (pkgs.callPackage ./lib {}) // { contracts = pkgs.callPackage ./modules/contracts {}; + patches = shbPatches; + inherit patchNixpkgs patchedNixpkgs; }; checks =