Skip to content

Commit

Permalink
Api change and documentation update
Browse files Browse the repository at this point in the history
  • Loading branch information
ehllie committed Nov 10, 2023
1 parent ff401c7 commit eb5b47b
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 212 deletions.
78 changes: 2 additions & 76 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,79 +44,5 @@ Some of these are features that I'd like to look into, with no guarantee they ge

## Usage

I use this module in my [own dotfiles](https://github.com/ehllie/dotfiles/blob/main/flake.nix), but here's a basic `flake.nix` structure you can use:

```nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
nixpkgs-darwin.url = "github:NixOS/nixpkgs/nixpkgs-23.05-darwin";
darwin = {
url = "github:lnl7/nix-darwin/master";
inputs.nixpkgs.follows = "nixpkgs-darwin";
};
home-manager = {
url = "github:nix-community/home-manager/release-23.05";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
ez-configs = {
url = "github:ehllie/ez-configs";
# We want to override the inputs of ez-configs
# That way you're able to update your system packages when running `nix flake update`
inputs = {
nixpkgs.follows = "nixpkgs";
nixpkgs-darwin.follows = "nixpkgs-darwin";
flake-parts.follows = "flake-parts";
darwin.follows = "darwin";
home-manager.follows = "home-manager";
};
};
};
outputs = inputs@{ flake-parts, ez-configs, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
ez-configs.flakeModule
];
# mkFlake expects this to be present,
# so even if we don't use anything from perSystem, we need to set it to something.
# You can set it to anything you want if you also want to provide perSystem outputs in your flake.
systems = [ ];
ezConfigs = {
root = ./.;
globalArgs = { inherit inputs; };
hm.users = [
# {
# name = "your-username";
# }
];
darwin.hosts = [
# {
# name = "your-macbook-name";
# arch = "aarch64";
# }
];
nixos.hosts = [
# {
# name = "your-nixos-name";
# arch = "x86_64";
# }
];
};
};
}
```

If you were previously using something like `configuration.nix` for your nixos configuratin, and `home.nix` for your home manager configuration,
you can simply place the contents of the former inside `./hosts/your-nixos-name.nix`, and contents of the former in `./users/your-username.nix`.
Your nix-darwin configuration would go into `./hosts/your-macbook-name.nix`.
If you want to reuse some of your configuration across multiple machines or users, you can extract it into `./nixos.nix`/ `./nixos/defualt.nix`,
`./darwin.nix`/ `./darwin/default.nix` or `./home.nix`/ `./home/default.nix`.
See the [example directory](https://github.com/ehllie/ez-configs/blob/main/example/flake.nix) for a documented example.
I also use this module in my [own dotfiles](https://github.com/ehllie/dotfiles/blob/main/flake.nix).
2 changes: 2 additions & 0 deletions example/darwin/default.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This is the default darwin module.
# It will be included with any darwin host configuration that has `importDefault = true`, which is the default
{ pkgs, lib, ... }:
{
services.nix-daemon.enable = true;
Expand Down
50 changes: 50 additions & 0 deletions example/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
nixpkgs-darwin.url = "github:NixOS/nixpkgs/nixpkgs-23.05-darwin";
darwin = {
url = "github:lnl7/nix-darwin/master";
inputs.nixpkgs.follows = "nixpkgs-darwin";
};
home-manager = {
url = "github:nix-community/home-manager/release-23.05";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
ez-configs = {
url = "github:ehllie/ez-configs";
# We want to override the inputs of ez-configs
# That way you're able to update your system packages when running `nix flake update`
inputs = {
nixpkgs.follows = "nixpkgs";
nixpkgs-darwin.follows = "nixpkgs-darwin";
flake-parts.follows = "flake-parts";
darwin.follows = "darwin";
home-manager.follows = "home-manager";
};
};
};

outputs = inputs@{ flake-parts, ez-configs, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
ez-configs.flakeModule
];

# mkFlake expects this to be present,
# so even if we don't use anything from perSystem, we need to set it to something.
# You can set it to anything you want if you also want to provide perSystem outputs in your flake.
systems = [ ];

ezConfigs = {
root = ./.;
globalArgs = { inherit inputs; };
hm.users.example-user = { };
nixos.hosts.example-nixos.arch = "x86_64";
darwin.hosts.example-darwin.arch = "aarch64";
};
};
}
2 changes: 2 additions & 0 deletions example/home/default.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This is the default home manager module.
# It will be included with any user configuration that has `importDefault = true`, which is the default
{
programs.git = {
enable = true;
Expand Down
1 change: 1 addition & 0 deletions example/hosts/example-darwin.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# This is the module that will be imported with the `darwinConfigurations.example-darwin` system
{ pkgs, ... }:
{
fonts = {
Expand Down
1 change: 1 addition & 0 deletions example/hosts/example-nixos.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# This is the module that will be imported with the `nixosConfigurations.example-nixos` system
{
fileSystems = {
"/" = {
Expand Down
2 changes: 2 additions & 0 deletions example/nixos/default.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This is the default nixos module.
# It will be included with any nixos host configuration that has `importDefault = true`, which is the default
{ modulesPath, ... }:
{
imports = [
Expand Down
1 change: 1 addition & 0 deletions example/users/example-user.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# This is the module that will be imported with the `homeManagerConfigurations.example-user@<system>` configuration
{ pkgs, ... }:
{
home = {
Expand Down
Loading

0 comments on commit eb5b47b

Please sign in to comment.