From ecb713781373928405077bf74f7d64d940495642 Mon Sep 17 00:00:00 2001 From: Gavin John Date: Thu, 5 Dec 2024 12:17:16 -0800 Subject: [PATCH] flakeify NUR --- ci/update-nur.sh | 2 ++ flake.lock | 64 ++++++++++++++++++++++++++++++++++++++++++++++- flake.nix | 65 +++++++++++++++++++++++++++++++++++++----------- 3 files changed, 115 insertions(+), 16 deletions(-) diff --git a/ci/update-nur.sh b/ci/update-nur.sh index 8dc4147ce..2881bb370 100755 --- a/ci/update-nur.sh +++ b/ci/update-nur.sh @@ -19,6 +19,8 @@ git clone \ nix run "${DIR}#" -- combine nur-combined +nix flake update nixpkgs + if [[ -z "$(git diff --exit-code)" ]]; then echo "No changes to the output on this push; exiting." else diff --git a/flake.lock b/flake.lock index 5999137c9..5415ac3b8 100644 --- a/flake.lock +++ b/flake.lock @@ -1,6 +1,68 @@ { "nodes": { - "root": {} + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1733312601, + "narHash": "sha256-4pDvzqnegAfRkPwO3wmwBhVi/Sye1mzps0zHWYnP88c=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "205b12d8b7cd4802fbcb8e8ef6a0f1408781a4f9", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1733212471, + "narHash": "sha256-M1+uCoV5igihRfcUKrr1riygbe73/dzNnzPsmaLCmpo=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "55d15ad12a74eb7d4646254e13638ad0c4128776", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs", + "treefmt-nix": "treefmt-nix" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1733222881, + "narHash": "sha256-JIPcz1PrpXUCbaccEnrcUS8jjEb/1vJbZz5KkobyFdM=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "49717b5af6f80172275d47a418c9719a31a78b53", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } }, "root": "root", "version": 7 diff --git a/flake.nix b/flake.nix index 50881c460..2d10f4df5 100644 --- a/flake.nix +++ b/flake.nix @@ -1,31 +1,66 @@ { description = "Nix User Repository"; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + flake-parts = { + url = "github:hercules-ci/flake-parts"; + inputs.nixpkgs-lib.follows = "nixpkgs"; + }; + treefmt-nix = { + url = "github:numtide/treefmt-nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + outputs = - { self }: - { + inputs@{ flake-parts, nixpkgs, ... }: + let + inherit (nixpkgs) lib; + manifest = (builtins.fromJSON (builtins.readFile ./repos.json)).repos; overlay = final: prev: { nur = import ./default.nix { nurpkgs = prev; pkgs = prev; }; }; - nixosModules.nur = - { lib, pkgs, ... }: - { - options.nur = lib.mkOption { - type = lib.mkOptionType { - name = "nur"; - description = "An instance of the Nix User repository"; - check = builtins.isAttrs; + in + flake-parts.lib.mkFlake { inherit inputs; } { + systems = builtins.filter ( + system: builtins.hasAttr system nixpkgs.legacyPackages + ) nixpkgs.lib.platforms.all; + flake = { + overlay = lib.warn "nur.overlay has been replaced by nur.overlays.default" overlay; # Added 2024-12-06 + nixosModules.nur = lib.throw "nur.nixosModules.nur has been replaced by nur.modules.nixos.default"; # Added 2024-12-06 + hmModules.nur = lib.throw "nur.hmModules.nur has been replaced by nur.modules.home-manager.default"; # Added 2024-12-06 + + overlays = { + default = overlay; + }; + modules = { + nixos = { + default = { + nixpkgs.overlays = [ overlay ]; }; - description = "Use this option to import packages from NUR"; - default = import self { - nurpkgs = pkgs; - pkgs = pkgs; + }; + home-manager = { + default = { + nixpkgs.overlays = [ overlay ]; }; }; }; - hmModules.nur = self.nixosModules.nur; + }; + imports = [ + inputs.flake-parts.flakeModules.modules + inputs.treefmt-nix.flakeModule + ]; + perSystem = + { pkgs, ... }: + { + treefmt.programs.nixfmt.enable = true; + # legacyPackages is used because nur is a package set + # This trick with the overlay is used because it allows NUR packages to depend on other NUR packages + legacyPackages = (pkgs.extend overlay).nur; + }; }; }