From f670889e2986520aee40941f2396c30f6b965647 Mon Sep 17 00:00:00 2001 From: Mohammad Rafiq Date: Sun, 6 Jul 2025 22:40:22 +0800 Subject: [PATCH] build(flake): add home-manager and example config --- README.md | 8 +++++++- flake.lock | 21 +++++++++++++++++++++ flake.nix | 5 +++++ nix/files/readme.nix | 8 +++++++- nix/modules/flake/home-manager.nix | 13 +++++++++++++ 5 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 nix/modules/flake/home-manager.nix diff --git a/README.md b/README.md index 1743fbb..bc5eaa5 100644 --- a/README.md +++ b/README.md @@ -7,4 +7,10 @@ The list of generated files are: - [docs/cheatsheet.md](docs/cheatsheet.md) - [README.md](README.md) ## Structure -The system configurations are defined in [`flake.manifest`](nix/manifest.nix). + The system configurations are defined in [`flake.manifest`](nix/manifest.nix). + The attribute `flake.modules.nixos.common` provides options that will be applied to every system. +You can use it as seen [here](nix/modules/flake/home-manager.nix): + +```nix +flake.modules.nixos.common.imports = [ inputs.home-manager.nixosModules.default ]; +``` diff --git a/flake.lock b/flake.lock index 7faf2a7..b320a68 100644 --- a/flake.lock +++ b/flake.lock @@ -96,6 +96,26 @@ "type": "github" } }, + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1751810302, + "narHash": "sha256-iV3C4l4XqPFcfJIHWQTOeSTuDgFg+ESdUeiYxCSgebE=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "502d9b7d30a1f5940ecdb786b4f71ebf57b1ac13", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, "import-tree": { "locked": { "lastModified": 1751399845, @@ -154,6 +174,7 @@ "files": "files", "flake-parts": "flake-parts", "git-hooks": "git-hooks", + "home-manager": "home-manager", "import-tree": "import-tree", "make-shell": "make-shell", "nixpkgs": "nixpkgs", diff --git a/flake.nix b/flake.nix index 128171e..7434240 100644 --- a/flake.nix +++ b/flake.nix @@ -9,6 +9,11 @@ url = "github:hercules-ci/flake-parts"; inputs.nixpkgs-lib.follows = "nixpkgs"; }; + # home-manager manages our user packages and dotfiles + home-manager = { + url = "github:nix-community/home-manager"; + inputs.nixpkgs.follows = "nixpkgs"; + }; # import-tree imports all nix files in a given directory. import-tree.url = "github:vic/import-tree"; # files lets us write text files and automatically add checks for them diff --git a/nix/files/readme.nix b/nix/files/readme.nix index b4bb006..cd7ed99 100644 --- a/nix/files/readme.nix +++ b/nix/files/readme.nix @@ -8,7 +8,13 @@ ''; parts."Structure" = # markdown '' - The system configurations are defined in [`flake.manifest`](nix/manifest.nix). + The system configurations are defined in [`flake.manifest`](nix/manifest.nix). + The attribute `flake.modules.nixos.common` provides options that will be applied to every system. + You can use it as seen [here](nix/modules/flake/home-manager.nix): + + ```nix + flake.modules.nixos.common.imports = [ inputs.home-manager.nixosModules.default ]; + ``` ''; }; diff --git a/nix/modules/flake/home-manager.nix b/nix/modules/flake/home-manager.nix new file mode 100644 index 0000000..ff64300 --- /dev/null +++ b/nix/modules/flake/home-manager.nix @@ -0,0 +1,13 @@ +{ inputs, ... }: +let + hm = inputs.home-manager; + globalCfg = { + imports = [ hm.nixosModules.home-manager ]; + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + }; +in +{ + imports = [ hm.flakeModules.home-manager ]; + flake.modules.nixos.common = globalCfg; +}