From 01b1b13b6aae521ffb6a0ba8aac19e29011f57f9 Mon Sep 17 00:00:00 2001 From: Youwen Wu Date: Thu, 24 Oct 2024 19:34:08 -0700 Subject: [PATCH] refactor: use flake-parts for configuration --- flake.lock | 43 +++++++++++++++++++++++++----- flake.nix | 77 +++++++++++++++++++++++++++++------------------------- 2 files changed, 79 insertions(+), 41 deletions(-) diff --git a/flake.lock b/flake.lock index 8bc317a..520a159 100755 --- a/flake.lock +++ b/flake.lock @@ -45,7 +45,7 @@ "viminal", "fenix" ], - "flake-parts": "flake-parts_3", + "flake-parts": "flake-parts_4", "nixpkgs": [ "viminal", "nixpkgs" @@ -400,6 +400,24 @@ } }, "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1727826117, + "narHash": "sha256-K5ZLCyfO/Zj9mPFldf3iwS6oZStJcU4tSpiXTMYaaL0=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "3d04084d54bedc3d6b8b736c70ef449225c361b1", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-parts_2": { "inputs": { "nixpkgs-lib": [ "lanzaboote", @@ -420,7 +438,7 @@ "type": "github" } }, - "flake-parts_2": { + "flake-parts_3": { "inputs": { "nixpkgs-lib": [ "viminal", @@ -444,9 +462,9 @@ "type": "github" } }, - "flake-parts_3": { + "flake-parts_4": { "inputs": { - "nixpkgs-lib": "nixpkgs-lib" + "nixpkgs-lib": "nixpkgs-lib_2" }, "locked": { "lastModified": 1727826117, @@ -684,7 +702,7 @@ "inputs": { "crane": "crane", "flake-compat": "flake-compat_2", - "flake-parts": "flake-parts", + "flake-parts": "flake-parts_2", "flake-utils": "flake-utils", "nixpkgs": [ "nixpkgs" @@ -937,7 +955,7 @@ "devenv", "flake-compat" ], - "flake-parts": "flake-parts_2", + "flake-parts": "flake-parts_3", "libgit2": "libgit2", "nixpkgs": "nixpkgs_4", "nixpkgs-23-11": "nixpkgs-23-11", @@ -1000,6 +1018,18 @@ "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz" } }, + "nixpkgs-lib_2": { + "locked": { + "lastModified": 1727825735, + "narHash": "sha256-0xHYkMkeLVQAMa7gvkddbPqpxph+hDzdu1XdGPJR+Os=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz" + } + }, "nixpkgs-regression": { "locked": { "lastModified": 1643052045, @@ -1312,6 +1342,7 @@ "apple-firmware": "apple-firmware", "apple-silicon": "apple-silicon", "catppuccin": "catppuccin", + "flake-parts": "flake-parts", "home-manager": "home-manager", "homebrew-cask": "homebrew-cask", "homebrew-core": "homebrew-core", diff --git a/flake.nix b/flake.nix index 10e21dc..2a1fff7 100755 --- a/flake.nix +++ b/flake.nix @@ -45,6 +45,8 @@ inputs.nixpkgs.follows = "nixpkgs"; }; + flake-parts.url = "github:hercules-ci/flake-parts"; + apple-silicon = { url = "github:tpwrules/nixos-apple-silicon"; inputs.nixpkgs.follows = "nixpkgs"; @@ -82,54 +84,59 @@ }; outputs = - { + inputs@{ nixpkgs, nix-darwin, + flake-parts, ... - }@inputs: - let - in - { - formatter = with nixpkgs.legacyPackages; { - x86_64-linux = x86_64-linux.nixfmt-rfc-style; - aarch64-linux = aarch64-linux.nixfmt-rfc-style; - aarch64-darwin = aarch64-darwin.nixfmt-rfc-style; - }; + }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ + "x86_64-linux" + "aarch64-linux" + "aarch64-darwin" + ]; + flake = { + nixosConfigurations = { + demeter = nixpkgs.lib.nixosSystem { + specialArgs = { + inherit inputs; + }; + modules = [ + ./hosts/demeter + ]; + }; - nixosConfigurations = { - demeter = nixpkgs.lib.nixosSystem { - specialArgs = { - inherit inputs; + callisto = nixpkgs.lib.nixosSystem { + specialArgs = { + inherit inputs; + }; + modules = [ + ./hosts/callisto + ]; + }; + adrastea = nixpkgs.lib.nixosSystem { + specialArgs = { + inherit inputs; + }; + modules = [ + ./hosts/adrastea + ]; }; - modules = [ - ./hosts/demeter - ]; }; - - callisto = nixpkgs.lib.nixosSystem { + darwinConfigurations.phobos = nix-darwin.lib.darwinSystem { specialArgs = { inherit inputs; }; modules = [ - ./hosts/callisto - ]; - }; - adrastea = nixpkgs.lib.nixosSystem { - specialArgs = { - inherit inputs; - }; - modules = [ - ./hosts/adrastea + ./hosts/phobos ]; }; }; - darwinConfigurations.phobos = nix-darwin.lib.darwinSystem { - specialArgs = { - inherit inputs; + perSystem = + { pkgs, ... }: + { + formatter = pkgs.nixfmt-rfc-style; }; - modules = [ - ./hosts/phobos - ]; - }; }; }