refactor(nix): Use home-manager

Looks like nix-darwin is planning to drop per-user launchd (or perhaps
per-user feature entirely).
This commit is contained in:
Ahmad Ansori Palembani 2024-07-13 09:09:20 +07:00
parent dff532c060
commit 2ef4e6f407
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6
4 changed files with 75 additions and 23 deletions

View file

@ -49,16 +49,25 @@
# Set Git commit hash for darwin-version. # Set Git commit hash for darwin-version.
system.configurationRevision = vars.rev or null; system.configurationRevision = vars.rev or null;
# Used for backwards compatibility, please read the changelog before changing.
# $ darwin-rebuild changelog
system.stateVersion = 4;
# The platform the configuration will be used on. # The platform the configuration will be used on.
nixpkgs.hostPlatform = vars.arch; nixpkgs.hostPlatform = vars.arch;
# Used for backwards compatibility, please read the changelog before changing.
# $ darwin-rebuild changelog
system = {
stateVersion = 4;
};
users.users.ziro = {
name = "ziro";
home = "/Users/ziro";
};
home-manager.users.ziro = {
home.stateVersion = "22.05";
# Swap CapsLock with Esc for better vi-mode experience. # Swap CapsLock with Esc for better vi-mode experience.
launchd.user.agents.CapsEscSwap = { launchd.agents.CapsEscSwap = {
serviceConfig = { enable = true;
config = {
ProgramArguments = [ ProgramArguments = [
"/usr/bin/hidutil" "/usr/bin/hidutil"
"property" "property"
@ -68,5 +77,6 @@
RunAtLoad = true; RunAtLoad = true;
}; };
}; };
};
} }
# vim:set ts=2 sw=2 et: # vim:set ts=2 sw=2 et:

View file

@ -1,4 +1,4 @@
{ inputs, nixpkgs, nix-darwin, vars, ... }: { inputs, nixpkgs, nix-darwin, home-manager, vars, ... }:
let let
systemConfig = system: { systemConfig = system: {
@ -23,8 +23,15 @@ in
in in
nix-darwin.lib.darwinSystem { nix-darwin.lib.darwinSystem {
inherit system; inherit system;
specialArgs = { inherit inputs pkgs vars; }; specialArgs = { inherit inputs pkgs home-manager vars; };
modules = [ ./configuration.nix ]; modules = [
./configuration.nix
home-manager.darwinModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
}
];
}; };
# Imaginary M1, just for reference # Imaginary M1, just for reference
@ -35,8 +42,15 @@ in
in in
nix-darwin.lib.darwinSystem { nix-darwin.lib.darwinSystem {
inherit system; inherit system;
specialArgs = { inherit inputs pkgs vars; }; specialArgs = { inherit inputs pkgs home-manager vars; };
modules = [ ./configuration.nix ]; modules = [
./configuration.nix
home-manager.darwinModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
}
];
}; };
} }
# vim:set ts=2 sw=2 et: # vim:set ts=2 sw=2 et:

22
.config/nix/flake.lock generated
View file

@ -1,5 +1,26 @@
{ {
"nodes": { "nodes": {
"home-manager": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1720042825,
"narHash": "sha256-A0vrUB6x82/jvf17qPCpxaM+ulJnD8YZwH9Ci0BsAzE=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "e1391fb22e18a36f57e6999c7a9f966dc80ac073",
"type": "github"
},
"original": {
"owner": "nix-community",
"ref": "release-24.05",
"repo": "home-manager",
"type": "github"
}
},
"nix-darwin": { "nix-darwin": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": [
@ -38,6 +59,7 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"home-manager": "home-manager",
"nix-darwin": "nix-darwin", "nix-darwin": "nix-darwin",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
} }

View file

@ -3,11 +3,17 @@
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-24.05-darwin"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-24.05-darwin";
nix-darwin.url = "github:LnL7/nix-darwin"; nix-darwin = {
nix-darwin.inputs.nixpkgs.follows = "nixpkgs"; url = "github:LnL7/nix-darwin";
inputs.nixpkgs.follows = "nixpkgs";
};
home-manager = {
url = "github:nix-community/home-manager/release-24.05";
inputs.nixpkgs.follows = "nixpkgs";
};
}; };
outputs = inputs@{ self, nix-darwin, nixpkgs }: outputs = inputs@{ self, nix-darwin, nixpkgs, home-manager }:
let let
vars = { vars = {
rev = self.rev or self.dirtyRev or null; rev = self.rev or self.dirtyRev or null;
@ -17,7 +23,7 @@
darwinConfigurations = ( darwinConfigurations = (
import ./darwin { import ./darwin {
inherit (nixpkgs) lib; inherit (nixpkgs) lib;
inherit inputs nixpkgs nix-darwin vars; inherit inputs nixpkgs nix-darwin home-manager vars;
} }
); );
}; };