From ed3a2803c7313c96a7f4602b652a8378daddc434 Mon Sep 17 00:00:00 2001 From: CherryKitten Date: Sun, 21 Apr 2024 21:00:58 +0200 Subject: [PATCH] switch to flake-parts --- flake.lock | 95 +++++++++++++++++++++++- flake.nix | 140 ++++++++++++------------------------ hive.nix | 64 +++++++++++++++++ profiles/hcloud/default.nix | 2 +- 4 files changed, 205 insertions(+), 96 deletions(-) create mode 100644 hive.nix diff --git a/flake.lock b/flake.lock index 4aaa6c1..d1c52ca 100644 --- a/flake.lock +++ b/flake.lock @@ -1,9 +1,31 @@ { "nodes": { + "cherrykitten-website": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1713617763, + "narHash": "sha256-788+IcjSE/bBEu+cU3s9ScG3wBSKZFWERGDtlDgwekw=", + "ref": "nix", + "rev": "eff50d0b92a0db28c350ded871b314cbb1644241", + "revCount": 33, + "type": "git", + "url": "https://git.cherrykitten.dev/sammy/cherrykitten.dev" + }, + "original": { + "ref": "nix", + "type": "git", + "url": "https://git.cherrykitten.dev/sammy/cherrykitten.dev" + } + }, "colmena": { "inputs": { "flake-compat": "flake-compat", - "flake-utils": "flake-utils", + "flake-utils": "flake-utils_2", "nixpkgs": [ "nixpkgs" ], @@ -39,7 +61,43 @@ "type": "github" } }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1712014858, + "narHash": "sha256-sB4SWl2lX95bExY2gMFG5HIzvva5AVMJd4Igm+GpZNw=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "9126214d0a59633752a136528f5f3b9aa8565b7d", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { "locked": { "lastModified": 1659877975, "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", @@ -90,6 +148,24 @@ "type": "indirect" } }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1711703276, + "narHash": "sha256-iMUFArF0WCatKK6RzfUJknjem0H9m4KgorO/p3Dopkk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d8fe5e6c92d0d190646fb9f1056741a229980089", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs-unstable": { "locked": { "lastModified": 1713562564, @@ -107,7 +183,9 @@ }, "root": { "inputs": { + "cherrykitten-website": "cherrykitten-website", "colmena": "colmena", + "flake-parts": "flake-parts", "home-manager": "home-manager", "nixpkgs": "nixpkgs", "nixpkgs-unstable": "nixpkgs-unstable" @@ -128,6 +206,21 @@ "repo": "nixpkgs", "type": "github" } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index b4b2584..a0f6015 100644 --- a/flake.nix +++ b/flake.nix @@ -14,110 +14,62 @@ }; cherrykitten-website = { - url = "git+https://git.cherrykitten.dev/sammy/cherrykitten.dev?ref=nix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; + url = "git+https://git.cherrykitten.dev/sammy/cherrykitten.dev?ref=nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + flake-parts.url = "github:hercules-ci/flake-parts"; }; - outputs = inputs @ { self, nixpkgs, nixpkgs-unstable, home-manager, colmena, ... }: - let - inherit (self) outputs; - systems = [ "aarch64-linux" "i686-linux" "x86_64-linux" "aarch64-darwin" "x86_64-darwin" ]; - forAllSystems = lib.genAttrs systems; - lib = nixpkgs.lib // home-manager.lib; - in - rec { - inherit lib; - formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.nixpkgs-fmt); + outputs = inputs @ { self, flake-parts, nixpkgs, nixpkgs-unstable, home-manager, colmena, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + imports = [ + ./hive.nix + ]; - devShells = forAllSystems (system: - let - pkgs = import nixpkgs { system = system; }; - packages = [ pkgs.nix pkgs.colmena pkgs.just pkgs.git pkgs.home-manager pkgs.pass pkgs.nixos-rebuild ]; - in - { - default = pkgs.mkShell { - nativeBuildInputs = packages; - shellHook = "exec $SHELL"; - }; - hcloud = pkgs.mkShell { - nativeBuildInputs = packages ++ [ pkgs.hcloud ]; - shellHook = '' - export HCLOUD_TOKEN=$(pass services/hcloud/api_token) - exec $SHELL - ''; - }; - }); + systems = [ + "x86_64-linux" + "aarch64-linux" + ]; - colmena = - let - hosts = lib.genAttrs (builtins.attrNames (builtins.readDir ./hosts)) (name: { }); - in - { - meta = { - description = "All my NixoS machines"; - specialArgs = { - inherit inputs outputs; - nodes = colmenaHive.nodes; - pkgs-unstable = import nixpkgs-unstable { system = "x86_64-linux"; }; + perSystem = { config, pkgs, ... }: { + + formatter = pkgs.nixpkgs-fmt; + devShells = + let + packages = [ pkgs.nix pkgs.colmena pkgs.just pkgs.git pkgs.home-manager pkgs.pass pkgs.nixos-rebuild ]; + in + { + default = pkgs.mkShell { + nativeBuildInputs = packages; + shellHook = "exec $SHELL"; }; - nixpkgs = import nixpkgs { system = "x86_64-linux"; }; - }; - - defaults = { lib, config, name, nodes, ... }: { - imports = [ ./hosts/${name} ./profiles/base (import ./overlays) ]; - - options.cherrykitten = { - primaryIPv4 = lib.mkOption { - type = lib.types.nullOr lib.types.str; - default = - if (config.networking.interfaces ? eth0) then - (builtins.elemAt config.networking.interfaces.eth0.ipv4.addresses 0).address - else null; - }; - primaryIPv6 = lib.mkOption { - type = lib.types.nullOr lib.types.str; - default = - if (config.networking.interfaces ? eth0) then - (builtins.elemAt config.networking.interfaces.eth0.ipv6.addresses 0).address - else null; - }; + hcloud = pkgs.mkShell { + nativeBuildInputs = packages ++ [ pkgs.hcloud ]; + shellHook = '' + export HCLOUD_TOKEN=$(pass services/hcloud/api_token) + exec $SHELL + ''; }; + }; + }; - config = { - networking.hostName = name; - networking.domain = "cherrykitten.xyz"; + flake = + { + packages.x86_64-linux.iso = self.nixosConfigurations.iso.config.system.build.isoImage; - home-manager.extraSpecialArgs = { - inherit inputs outputs; + homeConfigurations = + let + pkgs = import nixpkgs { system = "x86_64-linux"; }; + in + nixpkgs.lib.genAttrs (builtins.attrNames (builtins.readDir ./users)) (name: home-manager.lib.homeManagerConfiguration { + inherit pkgs; + modules = [ ./users/${name}/home.nix ]; + extraSpecialArgs = { + inherit inputs; pkgs-unstable = import nixpkgs-unstable { system = "x86_64-linux"; }; }; - }; - }; - } // hosts; - - colmenaHive = inputs.colmena.lib.makeHive colmena; - - nixosConfigurations = { - iso = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = [ home-manager.nixosModules.home-manager ./profiles/iso ]; + }); }; - } // colmenaHive.nodes; - - packages.x86_64-linux.iso = self.nixosConfigurations.iso.config.system.build.isoImage; - - homeConfigurations = - let - pkgs = import nixpkgs { system = "x86_64-linux"; }; - in - lib.genAttrs (builtins.attrNames (builtins.readDir ./users)) (name: lib.homeManagerConfiguration { - inherit pkgs; - modules = [ ./users/${name}/home.nix ]; - extraSpecialArgs = { - inherit inputs outputs; - pkgs-unstable = import nixpkgs-unstable { system = "x86_64-linux"; }; - }; - }); }; } diff --git a/hive.nix b/hive.nix new file mode 100644 index 0000000..b5b468a --- /dev/null +++ b/hive.nix @@ -0,0 +1,64 @@ +{ inputs, self, lib, ... }: +let + inherit (inputs) nixpkgs nixpkgs-unstable; + inherit (self) outputs; + pkgs = import nixpkgs { system = "x86_64-linux"; }; + pkgs-unstable = import nixpkgs-unstable { system = "x86_64-linux"; }; +in +{ + flake = rec { + colmena = + let + hosts = lib.genAttrs (builtins.attrNames (builtins.readDir ./hosts)) (name: { }); + in + { + meta = { + description = "All my NixoS machines"; + specialArgs = { + inherit inputs outputs pkgs-unstable; + nodes = colmenaHive.nodes; + }; + nixpkgs = pkgs; + }; + + defaults = { lib, config, name, nodes, ... }: { + imports = [ ./hosts/${name} ./profiles/base (import ./overlays) ]; + + options.cherrykitten = { + primaryIPv4 = lib.mkOption { + type = lib.types.nullOr lib.types.str; + default = + if (config.networking.interfaces ? eth0) then + (builtins.elemAt config.networking.interfaces.eth0.ipv4.addresses 0).address + else null; + }; + primaryIPv6 = lib.mkOption { + type = lib.types.nullOr lib.types.str; + default = + if (config.networking.interfaces ? eth0) then + (builtins.elemAt config.networking.interfaces.eth0.ipv6.addresses 0).address + else null; + }; + }; + + config = { + networking.hostName = name; + networking.domain = "cherrykitten.xyz"; + + home-manager.extraSpecialArgs = { + inherit inputs outputs pkgs-unstable; + }; + }; + }; + } // hosts; + + colmenaHive = inputs.colmena.lib.makeHive colmena; + + nixosConfigurations = { + iso = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ inputs.home-manager.nixosModules.home-manager ./profiles/iso ]; + }; + } // colmenaHive.nodes; + }; +} diff --git a/profiles/hcloud/default.nix b/profiles/hcloud/default.nix index c33f3d4..d212e37 100644 --- a/profiles/hcloud/default.nix +++ b/profiles/hcloud/default.nix @@ -8,5 +8,5 @@ boot.initrd.kernelModules = [ "nvme" ]; deployment.targetHost = (builtins.elemAt config.networking.interfaces.eth0.ipv4.addresses 0).address; - deployment.tags = [ "hcloud" "hetzner" "cloud"]; + deployment.tags = [ "hcloud" "hetzner" "cloud" ]; }