Skip to content

Commit e932b1d

Browse files
author
Pacman99
committed
set nixpkgs.pkgs based on system to allow users to set architecture within hosts
1 parent d7f15a6 commit e932b1d

File tree

5 files changed

+35
-13
lines changed

5 files changed

+35
-13
lines changed

flake.nix

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@
3434

3535
extern = import ./extern { inherit inputs; };
3636

37-
pkgs' = os.mkPkgs { inherit self; };
37+
multiPkgs = os.mkPkgs { inherit self; };
3838

3939
outputs =
4040
let
41-
system = "x86_64-linux";
42-
pkgs = pkgs'.${system};
41+
defaultSystem = "x86_64-linux";
42+
pkgs = multiPkgs.${defaultSystem};
4343
in
4444
{
4545
nixosConfigurations =
4646
import ./hosts (nixos.lib.recursiveUpdate inputs {
47-
inherit pkgs system extern;
47+
inherit multiPkgs defaultSystem extern;
4848
inherit (pkgs) lib;
4949
});
5050

@@ -55,7 +55,7 @@
5555
overlay = import ./pkgs;
5656
overlays = lib.pathsToImportedAttrs (lib.pathsIn ./overlays);
5757

58-
lib = import ./lib { inherit nixos pkgs; };
58+
lib = import ./lib { inherit nixos; };
5959

6060
templates.flk.path = ./.;
6161
templates.flk.description = "flk template";
@@ -74,7 +74,7 @@
7474
};
7575

7676
systemOutputs = utils.lib.eachDefaultSystem (system:
77-
let pkgs = pkgs'.${system}; in
77+
let pkgs = multiPkgs.${system}; in
7878
{
7979
packages = utils.lib.flattenTreeSystem system
8080
(os.mkPackages {

hosts/NixOS-a64.nix

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{ suites, ... }:
2+
{
3+
### root password is empty by default ###
4+
imports = suites.base;
5+
6+
nixpkgs.system = "aarch64-linux";
7+
8+
boot.loader.systemd-boot.enable = true;
9+
boot.loader.efi.canTouchEfiVariables = true;
10+
11+
networking.networkmanager.enable = true;
12+
13+
fileSystems."/" = { device = "/dev/disk/by-label/nixos"; };
14+
}

hosts/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ that you intend to use on your machine.
2525
Additionally, this is the perfect place to import anything you might need from
2626
the [nixos-hardware][nixos-hardware] repository.
2727

28+
You can set the option `nixpkgs.system` to indicates the host system's
29+
architecture. This will result in the host getting an instance of nixpkgs for
30+
that architecture. The definition must be one exported by the nixpkgs flake.
31+
2832
## Example
2933

3034
hosts/librem.nix:

hosts/default.nix

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
, lib
44
, nixos
55
, override
6-
, pkgs
6+
, multiPkgs
77
, self
8-
, system
8+
, defaultSystem
99
, ...
1010
}:
1111
let
@@ -28,7 +28,7 @@ let
2828
modules;
2929
};
3030

31-
global = {
31+
global = { config, ... }: {
3232
home-manager.useGlobalPkgs = true;
3333
home-manager.useUserPackages = true;
3434

@@ -40,7 +40,8 @@ let
4040
"home-manager=${home}"
4141
];
4242

43-
nixpkgs = { inherit pkgs; };
43+
44+
nixpkgs.pkgs = lib.mkDefault multiPkgs.${config.nixpkgs.system};
4445

4546
nix.registry = {
4647
devos.flake = self;
@@ -62,7 +63,9 @@ let
6263
modOverrides
6364
] ++ extern.modules;
6465

65-
specialArgs = extern.specialArgs // { inherit suites; };
66+
specialArgs = extern.specialArgs // {
67+
inherit suites multiPkgs;
68+
};
6669

6770
mkHostConfig = hostName:
6871
let
@@ -75,7 +78,8 @@ let
7578
};
7679
in
7780
dev.os.devosSystem {
78-
inherit system specialArgs;
81+
inherit specialArgs;
82+
system = defaultSystem;
7983

8084
modules = modules ++ [
8185
local

lib/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
args@{ nixos, pkgs, ... }:
1+
args@{ nixos, ... }:
22
let inherit (nixos) lib; in
33
lib.makeExtensible (self:
44
let callLibs = file: import file

0 commit comments

Comments
 (0)