Consolidate definitions

This pulls in several additional flakes to assist with per-system outputs, and largely improves readability.
This commit is contained in:
Spotlight 2024-04-11 00:14:53 -05:00
parent 1025996f60
commit 96e14ada20
Signed by: spotlight
GPG key ID: 874AA355B3209BDC
2 changed files with 118 additions and 50 deletions

48
flake.lock generated
View file

@ -1,5 +1,35 @@
{
"nodes": {
"all-systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"darwin-systems": {
"locked": {
"lastModified": 1689347925,
"narHash": "sha256-ozenz5bFe1UUqOn7f60HRmgc01BgTGIKZ4Xl+HbocGQ=",
"owner": "nix-systems",
"repo": "default-darwin",
"rev": "2235d7e6cc29ae99878133c95e9fe5e157661ffb",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default-darwin",
"type": "github"
}
},
"home-manager": {
"inputs": {
"nixpkgs": [
@ -20,6 +50,21 @@
"type": "github"
}
},
"linux-systems": {
"locked": {
"lastModified": 1689347949,
"narHash": "sha256-12tWmuL2zgBgZkdoB6qXZsgJEH9LR3oUgpaQq2RbI80=",
"owner": "nix-systems",
"repo": "default-linux",
"rev": "31732fcf5e8fea42e59c2488ad31a0e651500f68",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default-linux",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1712608508,
@ -38,7 +83,10 @@
},
"root": {
"inputs": {
"all-systems": "all-systems",
"darwin-systems": "darwin-systems",
"home-manager": "home-manager",
"linux-systems": "linux-systems",
"nixpkgs": "nixpkgs"
}
}

120
flake.nix
View file

@ -4,14 +4,26 @@
inputs = {
# Specify the source of Home Manager and Nixpkgs.
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
# Allows for easy enumeration of available Darwin and Linux systems.
all-systems.url = "github:nix-systems/default";
darwin-systems.url = "github:nix-systems/default-darwin";
linux-systems.url = "github:nix-systems/default-linux";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { nixpkgs, home-manager, ... }:
outputs = { nixpkgs, home-manager, linux-systems, darwin-systems, all-systems, ... }:
let
# TODO(spotlightishere): Is there a better way to approach this that doesn't
# involve importing so many separate flakes?
#
# (We could manually merge Darwin and Linux themselves, but this is primarily for readability.)
allSystems = nixpkgs.lib.genAttrs (import all-systems);
darwinSystems = nixpkgs.lib.genAttrs (import darwin-systems);
linuxSystems = nixpkgs.lib.genAttrs (import linux-systems);
homeManager = { system, specialArgs ? { } }:
home-manager.lib.homeManagerConfiguration {
modules = [
@ -22,64 +34,72 @@
};
in
{
packages = {
# We currently assume that all x86_64-linux devices only
# require dotfiles. For now, this is mostly true :)
x86_64-linux.homeConfigurations.spotlight = homeManager {
system = "x86_64-linux";
};
# There's a few things going on here that are all merged in the end.
# We start with system-specific packages, providing home-manager.
packages =
##########################
# Linux-specific options #
##########################
linuxSystems
(system: {
homeConfigurations = {
# First, we currently assume that Linux devices
# only require dotfiles and utilize the username `spotlight`.
#
# For now, this is effectively true, sans a few specific configurations :)
spotlight = homeManager {
system = system;
specialArgs = {
desktop = false;
gpg = false;
};
};
# Similarly (as of writing), all aarch64 Linux devices are headless
# and primarily managed by other distro package managers.
# This should likely be dealt with in the future!
aarch64-linux.homeConfigurations.spotlight = homeManager {
system = "aarch64-linux";
};
# For a special case: with the Steam Deck, we have to assume the user
# is named `deck` due to its immutable system image.
deck = homeManager {
system = system;
specialArgs = {
gpg = true;
username = "deck";
};
};
};
})
# For all architecture variants of Darwin, we don't want only dotfiles.
aarch64-darwin.homeConfigurations.spot = homeManager {
system = "aarch64-darwin";
specialArgs = {
desktop = true;
gpg = true;
//
###########################
# Darwin-specific options #
###########################
darwinSystems (system: {
# We use the username `spot` under Darwin.
# We also assume that desktop applications should be made available, alongside GPG.
homeConfigurations.spot = homeManager {
system = system;
specialArgs = {
desktop = true;
gpg = true;
};
};
};
x86_64-darwin.homeConfigurations.spot = homeManager {
system = "x86_64-darwin";
specialArgs = {
desktop = true;
gpg = true;
};
};
# For a special case: with the Steam Deck, we have to assume the user
# is named `deck` due to its immutable system image.
x86_64-linux.homeConfigurations.deck = homeManager {
system = "x86_64-linux";
specialArgs = {
gpg = true;
username = "deck";
};
};
};
});
# We provide a NixOS module for easy usage within other system flakes.
# (Again, we assume a default name of `spotlight` under Linux.)
nixosModules.default = {
imports = [
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.spotlight = import ./home/home.nix;
home-manager.extraSpecialArgs = { desktop = false; gpg = false; };
home-manager.nixosModules.home-manager {
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
users.spotlight = import ./home/home.nix;
extraSpecialArgs = { desktop = false; gpg = false; };
};
}
];
};
formatter = {
aarch64-darwin = nixpkgs.legacyPackages.aarch64-darwin.nixpkgs-fmt;
x86_64-darwin = nixpkgs.legacyPackages.x86_64-darwin.nixpkgs-fmt;
aarch64-linux = nixpkgs.legacyPackages.aarch64-linux.nixpkgs-fmt;
x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixpkgs-fmt;
};
# Lastly, ensure a formatter is available for all systems.
formatter = allSystems (system: nixpkgs.legacyPackages.${system}.nixpkgs-fmt);
};
}