use mkSystem
This commit is contained in:
parent
8a46e01ffc
commit
dce01a9832
6 changed files with 95 additions and 91 deletions
67
flake.nix
67
flake.nix
|
@ -58,63 +58,46 @@
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
outputs = inputs @ {
|
outputs = {
|
||||||
nixpkgs,
|
nixpkgs,
|
||||||
nixos-cosmic,
|
nixos-cosmic,
|
||||||
nix-index-database,
|
nix-index-database,
|
||||||
darwin,
|
darwin,
|
||||||
...
|
...
|
||||||
}: let
|
} @ inputs: let
|
||||||
overlays = [
|
overlays = [
|
||||||
inputs.zig.overlays.default
|
inputs.zig.overlays.default
|
||||||
inputs.rust-overlay.overlays.default
|
inputs.rust-overlay.overlays.default
|
||||||
inputs.chinese-fonts-overlay.overlays.default
|
inputs.chinese-fonts-overlay.overlays.default
|
||||||
inputs.nh.overlays.default
|
inputs.nh.overlays.default
|
||||||
];
|
];
|
||||||
inherit (nixpkgs) lib;
|
|
||||||
mkIfElse = p: yes: no:
|
mkSystem = import ./lib/mkSystem.nix {
|
||||||
lib.mkMerge [
|
inherit overlays nixpkgs inputs;
|
||||||
(lib.mkIf p yes)
|
};
|
||||||
(lib.mkIf (!p) no)
|
|
||||||
];
|
|
||||||
|
|
||||||
user = "nmarks";
|
user = "nmarks";
|
||||||
|
|
||||||
shared_modules = [
|
|
||||||
# {nixpkgs.overlays = overlays;}
|
|
||||||
# {programs.nix-index-database.comma.enable = true;}
|
|
||||||
# nixindex
|
|
||||||
# homemanagerModules
|
|
||||||
{
|
|
||||||
_module.args = {
|
|
||||||
inherit user;
|
|
||||||
inherit mkIfElse;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
];
|
|
||||||
in {
|
in {
|
||||||
nixosConfigurations = {
|
nixosConfigurations.nixos = mkSystem "nixos" {
|
||||||
nixos = lib.nixosSystem {
|
system = "x86_64-linux";
|
||||||
system = "x86_64-linux";
|
inherit user;
|
||||||
modules =
|
extraModules = [
|
||||||
[
|
nixos-cosmic.nixosModules.default
|
||||||
./hosts/desktop/configuration.nix
|
];
|
||||||
nixos-cosmic.nixosModules.default
|
|
||||||
]
|
|
||||||
++ shared_modules;
|
|
||||||
specialArgs = inputs;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
darwinConfigurations = {
|
darwinConfigurations."Natalies-MacBook-Air" = mkSystem "Natalies-MacBook-Air" {
|
||||||
"Natalies-MacBook-Air" = darwin.lib.darwinSystem {
|
system = "aarch64-darwin";
|
||||||
system = "aarch64-darwin";
|
inherit user;
|
||||||
specialArgs = inputs;
|
darwin = true;
|
||||||
modules =
|
|
||||||
[
|
|
||||||
./hosts/laptop/configuration.nix
|
|
||||||
]
|
|
||||||
++ shared_modules;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
# darwinConfigurations = {
|
||||||
|
# "Natalies-MacBook-Air" = darwin.lib.darwinSystem {
|
||||||
|
# system = "aarch64-darwin";
|
||||||
|
# specialArgs = inputs;
|
||||||
|
# modules = [
|
||||||
|
# ./hosts/laptop/configuration.nix
|
||||||
|
# ];
|
||||||
|
# };
|
||||||
|
# };
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
70
lib/mkSystem.nix
Normal file
70
lib/mkSystem.nix
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
# This function creates a NixOS system based on our VM setup for a
|
||||||
|
# particular architecture.
|
||||||
|
{
|
||||||
|
nixpkgs,
|
||||||
|
overlays,
|
||||||
|
inputs,
|
||||||
|
}: name: {
|
||||||
|
system,
|
||||||
|
user,
|
||||||
|
darwin ? false,
|
||||||
|
extraModules ? [],
|
||||||
|
}: let
|
||||||
|
# True if this is a WSL system.
|
||||||
|
# True if Linux, which is a heuristic for not being Darwin.
|
||||||
|
mkIfElse = p: yes: no:
|
||||||
|
nixpkgs.lib.mkMerge [
|
||||||
|
(nixpkgs.lib.mkIf p yes)
|
||||||
|
(nixpkgs.lib.mkIf (!p) no)
|
||||||
|
];
|
||||||
|
|
||||||
|
nixindex = mkIfElse darwin inputs.nix-index-database.darwinModules.nix-index inputs.nix-index-database.nixosModules.nix-index;
|
||||||
|
|
||||||
|
host = mkIfElse darwin "laptop" "desktop";
|
||||||
|
|
||||||
|
# The config files for this system.
|
||||||
|
|
||||||
|
hostConfig = ../hosts/${host}/configuration.nix;
|
||||||
|
|
||||||
|
# NixOS vs nix-darwin functions
|
||||||
|
systemFunc = mkIfElse darwin inputs.darwin.lib.darwinSystem nixpkgs.lib.nixosSystem;
|
||||||
|
home-manager =
|
||||||
|
if darwin
|
||||||
|
then inputs.home-manager.darwinModules
|
||||||
|
else inputs.home-manager.nixosModules;
|
||||||
|
in
|
||||||
|
systemFunc rec {
|
||||||
|
inherit system;
|
||||||
|
|
||||||
|
modules =
|
||||||
|
[
|
||||||
|
# Apply our overlays. Overlays are keyed by system type so we have
|
||||||
|
# to go through and apply our system type. We do this first so
|
||||||
|
# the overlays are available globally.
|
||||||
|
{nixpkgs.overlays = overlays;}
|
||||||
|
{inputs.programs.nix-index-database.comma.enable = true;}
|
||||||
|
hostConfig
|
||||||
|
nixindex
|
||||||
|
home-manager.home-manager
|
||||||
|
{
|
||||||
|
home-manager = {
|
||||||
|
useGlobalPkgs = true;
|
||||||
|
useUserPackages = true;
|
||||||
|
backupFileExtension = "hm-backup";
|
||||||
|
extraSpecialArgs = {inherit inputs;};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
# We expose some extra arguments so that our modules can parameterize
|
||||||
|
# better based on these values.
|
||||||
|
{
|
||||||
|
config._module.args = {
|
||||||
|
currentSystem = system;
|
||||||
|
currentSystemName = name;
|
||||||
|
currentSystemUser = user;
|
||||||
|
inherit inputs;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
]
|
||||||
|
++ extraModules;
|
||||||
|
}
|
|
@ -2,13 +2,8 @@
|
||||||
pkgs,
|
pkgs,
|
||||||
config,
|
config,
|
||||||
inputs,
|
inputs,
|
||||||
hostName,
|
|
||||||
mkIfElse,
|
|
||||||
darwin,
|
|
||||||
...
|
...
|
||||||
}: {
|
}: {
|
||||||
networking = {
|
networking = {
|
||||||
inherit hostName;
|
|
||||||
networkmanager = !darwin;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
{inputs, ...}: {
|
|
||||||
home-manager = {
|
|
||||||
useGlobalPkgs = true;
|
|
||||||
useUserPackages = true;
|
|
||||||
backupFileExtension = "hm-backup";
|
|
||||||
extraSpecialArgs = {inherit inputs;};
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
{
|
|
||||||
pkgs,
|
|
||||||
inputs,
|
|
||||||
config,
|
|
||||||
...
|
|
||||||
}: {
|
|
||||||
imports = [
|
|
||||||
# {pkgs.overlays = overlays;}
|
|
||||||
{programs.nix-index-database.comma.enable = true;}
|
|
||||||
config.nixindex
|
|
||||||
config.homemanagerModules
|
|
||||||
];
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
{
|
|
||||||
inputs,
|
|
||||||
pkgs,
|
|
||||||
config,
|
|
||||||
lib,
|
|
||||||
mkIfElse,
|
|
||||||
...
|
|
||||||
}: let
|
|
||||||
darwin = pkgs.stdenv.isDarwin;
|
|
||||||
homemanagerModules = mkIfElse darwin inputs.home-manager.darwinModules inputs.home-manager.nixosModules;
|
|
||||||
nixindex = mkIfElse darwin inputs.nix-index-database.darwinModules.nix-index inputs.nix-index-database.nixosModules.nix-index;
|
|
||||||
in {
|
|
||||||
config.var = {
|
|
||||||
inherit darwin homemanagerModules nixindex;
|
|
||||||
};
|
|
||||||
|
|
||||||
options = {
|
|
||||||
var = lib.mkOption {
|
|
||||||
type = lib.types.attrs;
|
|
||||||
default = {};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
Loading…
Reference in a new issue