From dc411c006e1c52e7676ebd55e331fda52956da5e Mon Sep 17 00:00:00 2001 From: Ranomier <> Date: Mon, 28 Apr 2025 17:05:06 +0200 Subject: [PATCH] feat: split off outputs --- flake.nix | 60 +------------------------------------- hostHelper.nix | 9 ++++++ hosts/crocoite/default.nix | 8 ++--- outputs.nix | 36 +++++++++++++++++++++++ overlays/default.nix | 4 +-- 5 files changed, 52 insertions(+), 65 deletions(-) create mode 100644 hostHelper.nix create mode 100644 outputs.nix diff --git a/flake.nix b/flake.nix index 3a4de7d..eea0daf 100644 --- a/flake.nix +++ b/flake.nix @@ -1,9 +1,5 @@ { - ###### inputs = { - ###### - #nixpkgs-old.url = "github:NixOS/nixpkgs/nixos-24.05"; - # Main nix package repository nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11"; @@ -28,59 +24,5 @@ nix-flatpak.url = "github:gmodena/nix-flatpak"; }; - ####### - outputs = - ####### - { - self, - nixpkgs, - nixos-hardware, - nixos-unstable, - nix-flatpak, - home-manager, - nixos-generators, - ... - } @ inputs: let - # Supported systems for your flake packages, shell, etc. - systems = [ - #"aarch64-linux" - "x86_64-linux" - ]; - - # This is a function that generates an attribute by calling a function you - # pass to it, with each system as an argument - forAllSystems = nixpkgs.lib.genAttrs systems; - - host_helper = hostname: { - ${hostname} = nixpkgs.lib.nixosSystem { - specialArgs = {inherit inputs;}; - modules = [ - ./hosts/${hostname} - ]; - }; - }; - in { - # Your custom packages - # Accessible through 'nix build', 'nix shell', etc - #packages = forAllSystems (system: import ./pkgs nixpkgs.legacyPackages.${system}); - - # Formatter for your nix files, available through 'nix fmt' - # Other options beside 'alejandra' include 'nixpkgs-fmt' - formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.alejandra); - - # Your custom packages and modifications, exported as overlays - overlays = import ./overlays {inherit inputs;}; - - # Reusable nixos modules you might want to export - # These are usually stuff you would upstream into nixpkgs - #nixosModules = import ./modules/nixos; - - # NixOS configuration entrypoint - # Available through 'nixos-rebuild --flake .#your-hostname' - # to add more append // (host_helper example); - nixosConfigurations = - host_helper "crocoite" // - host_helper "jitsi"; - - }; + outputs = {...}@inArgs: import ./outputs.nix inArgs; } diff --git a/hostHelper.nix b/hostHelper.nix new file mode 100644 index 0000000..500d93b --- /dev/null +++ b/hostHelper.nix @@ -0,0 +1,9 @@ +inArgs: hostname: { + ${hostname} = inArgs.nixpkgs.lib.nixosSystem { + specialArgs = {inherit inArgs;}; + modules = [ + {networking.hostName = hostname;} + (./hosts/${hostname}) + ]; + }; +} diff --git a/hosts/crocoite/default.nix b/hosts/crocoite/default.nix index 40e6bdf..1929622 100644 --- a/hosts/crocoite/default.nix +++ b/hosts/crocoite/default.nix @@ -1,11 +1,11 @@ { pkgs, - inputs, + inArgs, modulesPath, nixos-unstable, ... }: { - networking.hostName = "crocoite"; # Define your hostname. + #networking.hostName = "crocoite"; # Define your hostname. # This value determines the NixOS release from which the default # settings for stateful data, like file locations and database versions @@ -18,7 +18,7 @@ #nixpkgs.overlays = [ overlays.unstable-packages ]; nixpkgs = { # You can add overlays here - overlays = with inputs.self.overlays; [ + overlays = with inArgs.self.overlays; [ # Add overlays your own flake exports (from overlays and pkgs dir): #additions #modifications @@ -56,7 +56,7 @@ # steam and other stuff seems to depend on perl #"${modulesPath}/profiles/perlless.nix" - inputs.nix-flatpak.nixosModules.nix-flatpak + inArgs.nix-flatpak.nixosModules.nix-flatpak #nixos-hardware.nixosModules.lenovo-thinkpad-t14-amd-gen1 ./hardware-configuration.nix diff --git a/outputs.nix b/outputs.nix new file mode 100644 index 0000000..54c4152 --- /dev/null +++ b/outputs.nix @@ -0,0 +1,36 @@ +inArgs: let + # Supported systems for your flake packages, shell, etc. + systems = [ + #"aarch64-linux" + "x86_64-linux" + ]; + + # This is a function that generates an attribute by calling a function you + # pass to it, with each system as an argument + forAllSystems = inArgs.nixpkgs.lib.genAttrs systems; + + hostHelper = import ./hostHelper.nix inArgs; + +in { + # NixOS configuration entrypoint + # Available through 'nixos-rebuild --flake .#your-hostname' + # to add more append // (host_helper example); + + nixosConfigurations = + (hostHelper "crocoite"); #// (host_helper2 "jitsi"); + + # Your custom packages + # Accessible through 'nix build', 'nix shell', etc + #packages = forAllSystems (system: import ./pkgs nixpkgs.legacyPackages.${system}); + + # Your custom packages and modifications, exported as overlays + overlays = import ./overlays {inherit inArgs;}; + + # Reusable nixos modules you might want to export + # These are usually stuff you would upstream into nixpkgs + #nixosModules = import ./modules/nixos; + + # Formatter for your nix files, available through 'nix fmt' + # Other options beside 'alejandra' include 'nixpkgs-fmt' + formatter = forAllSystems (system: inArgs.nixpkgs.legacyPackages.${system}.alejandra); +} diff --git a/overlays/default.nix b/overlays/default.nix index 69e7d0e..b650538 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -1,5 +1,5 @@ # This file defines overlays -{inputs, ...}: { +{inArgs, ...}: { # This one brings our custom packages from the 'pkgs' directory additions = final: _prev: import ../pkgs final.pkgs; @@ -15,7 +15,7 @@ # When applied, the unstable nixpkgs set (declared in the flake inputs) will # be accessible through 'pkgs.unstable' unstable-packages = final: _prev: { - unstable = import inputs.nixos-unstable { + unstable = import inArgs.nixos-unstable { system = final.system; config.allowUnfree = true; };