Skip to content

Commit 30de702

Browse files
committed
Reduce duplication with mkPkgs helper and use config.home.homeDirectory
- Add mkPkgs helper function to create pkgs/pkgs-unstable pairs - Replace hardcoded /home/${username} path with config.home.homeDirectory - This makes code.nix work correctly on both Linux and macOS
1 parent cf23a60 commit 30de702

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

components/code.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2+
config,
23
pkgs,
34
pkgs-unstable,
4-
hostConfiguration,
55
...
66
}: {
77
home.packages = [pkgs.nil];
@@ -26,7 +26,7 @@
2626
};
2727

2828
programs.vscode.profiles.default.userSettings = {
29-
vscode-neovim.neovimExecutablePaths.linux = "/home/${hostConfiguration.username}/.nix-profile/bin/nvim";
29+
vscode-neovim.neovimExecutablePaths.linux = "${config.home.homeDirectory}/.nix-profile/bin/nvim";
3030
window.autoDetectColorScheme = true;
3131
editor.cursorSurroundingLines = 8;
3232

flake.nix

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,17 @@
4646
input-fonts.acceptLicense = true;
4747
};
4848
username = "jeremy";
49+
50+
# Helper to create pkgs and pkgs-unstable for a given system
51+
mkPkgs = system: {
52+
pkgs = import inputs.nixpkgs {inherit system config;};
53+
pkgs-unstable = import inputs.nixpkgs-unstable {inherit system config;};
54+
};
4955
in
5056
{
5157
nixosConfigurations = let
5258
system = "x86_64-linux";
53-
pkgs = import inputs.nixpkgs {
54-
inherit system config;
55-
};
56-
pkgs-unstable = import inputs.nixpkgs-unstable {
57-
inherit system config;
58-
};
59+
inherit (mkPkgs system) pkgs pkgs-unstable;
5960
nixosConfig = {
6061
nixosModule,
6162
hostSpecificHomeManagerModule ? {},
@@ -100,8 +101,7 @@
100101

101102
darwinConfigurations = let
102103
system = "aarch64-darwin";
103-
pkgs = import inputs.nixpkgs {inherit system config;};
104-
pkgs-unstable = import inputs.nixpkgs-unstable {inherit system config;};
104+
inherit (mkPkgs system) pkgs pkgs-unstable;
105105
hostConfiguration = {
106106
inherit username;
107107
};
@@ -124,8 +124,7 @@
124124

125125
homeConfigurations."stefis-macbook" = let
126126
system = "aarch64-darwin";
127-
pkgs = import inputs.nixpkgs {inherit system config;};
128-
pkgs-unstable = import inputs.nixpkgs-unstable {inherit system config;};
127+
inherit (mkPkgs system) pkgs pkgs-unstable;
129128
hostConfiguration = {
130129
inherit username;
131130
};

0 commit comments

Comments
 (0)