From d80a9be8911a7027bcf3917b97afca94cd3096c8 Mon Sep 17 00:00:00 2001 From: Atridad Lahiji Date: Wed, 4 Feb 2026 14:58:17 -0700 Subject: [PATCH] Flake Experiment --- Makefile | 20 ++++++++++++++------ common.nix | 22 ++++++++++++++++++++++ flake.nix | 26 ++++++++++++++++++++++++++ modules/home.nix | 5 ----- 4 files changed, 62 insertions(+), 11 deletions(-) create mode 100644 common.nix create mode 100644 flake.nix diff --git a/Makefile b/Makefile index 78d036b..3721949 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ NIXOS_DIR := /etc/nixos REPO_DIR := $(shell pwd) SETTINGS := settings.nix +HOSTNAME := $(shell grep 'hostname =' $(SETTINGS) | cut -d '"' -f 2) # Colors for output GREEN := \033[0;32m @@ -11,12 +12,12 @@ RED := \033[0;31m NC := \033[0m # No Color help: - @echo "NixOS Config" + @echo "NixOS Config (Flake)" @echo "" @echo " make init - first time setup" @echo " make hw - generate hardware-configuration.nix" - @echo " make rebuild - rebuild nixos" - @echo " make update - upgrade + rebuild" + @echo " make rebuild - rebuild nixos configuration" + @echo " make update - update flake inputs and rebuild" @echo " make purge - garbage collect" @echo " make link - symlink to /etc/nixos" @echo " make unlink - remove symlink" @@ -48,17 +49,24 @@ unlink: fi rebuild: - sudo nixos-rebuild switch + @# Ensure hardware-configuration.nix is tracked by git (flake requirement), even if ignored + @if [ -f hardware-configuration.nix ]; then \ + git add -f -N hardware-configuration.nix; \ + fi + @echo "Rebuilding system for $(HOSTNAME)..." + sudo nixos-rebuild switch --flake .#$(HOSTNAME) update: - sudo nixos-rebuild switch --upgrade + @echo "Updating flake inputs..." + nix flake update + @$(MAKE) --no-print-directory rebuild purge: sudo nix-collect-garbage -d sudo /run/current-system/bin/switch-to-configuration boot check: - nix-instantiate '' -A system --dry-run + nix flake check hw: sudo nixos-generate-config --show-hardware-config > hardware-configuration.nix diff --git a/common.nix b/common.nix new file mode 100644 index 0000000..46741fe --- /dev/null +++ b/common.nix @@ -0,0 +1,22 @@ +{ config, pkgs, ... }: + +{ + imports = [ + # Import Modules + ./modules/boot.nix + ./modules/networking.nix + ./modules/locale.nix + ./modules/desktop.nix + ./modules/audio.nix + ./modules/users.nix + ./modules/programs.nix + ./modules/hardware.nix + ./modules/services.nix + ./modules/home.nix + ]; + + nix.settings.experimental-features = [ "nix-command" "flakes" ]; + # xdg.portal.config.common.default = [ "gnome" ]; + + system.stateVersion = "25.11"; +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..7ded4ac --- /dev/null +++ b/flake.nix @@ -0,0 +1,26 @@ +{ + description = "NixOS Configuration"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-25.11"; + home-manager = { + url = "github:nix-community/home-manager/release-25.11"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, home-manager, ... }@inputs: + let + settings = import ./settings.nix; + system = "x86_64-linux"; + in { + nixosConfigurations."${settings.hostname}" = nixpkgs.lib.nixosSystem { + inherit system; + specialArgs = { inherit inputs; }; + modules = [ + ./configuration.nix + home-manager.nixosModules.home-manager + ]; + }; + }; +} diff --git a/modules/home.nix b/modules/home.nix index 074c2e9..619ef02 100644 --- a/modules/home.nix +++ b/modules/home.nix @@ -1,7 +1,6 @@ { config, pkgs, ... }: let - home-manager = builtins.fetchTarball "https://github.com/nix-community/home-manager/archive/release-25.11.tar.gz"; settings = import ../settings.nix; homeModules = [ ./home/session.nix @@ -16,10 +15,6 @@ let ]; in { - imports = [ - (import "${home-manager}/nixos") - ]; - home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true;