horribly cobble together the ability to use both home-manager switch and nixos-rebuild switch against the same flake

This commit is contained in:
Jay Looney 2025-11-25 15:40:37 -06:00
parent b792e801c5
commit e3e28fa662
3 changed files with 296 additions and 136 deletions

120
flake.lock generated
View file

@ -135,6 +135,22 @@
"type": "github" "type": "github"
} }
}, },
"flake-compat_2": {
"flake": false,
"locked": {
"lastModified": 1751685974,
"narHash": "sha256-NKw96t+BgHIYzHUjkTK95FqYRVKB8DHpVhefWSz/kTw=",
"ref": "refs/heads/main",
"rev": "549f2762aebeff29a2e5ece7a7dc0f955281a1d1",
"revCount": 92,
"type": "git",
"url": "https://git.lix.systems/lix-project/flake-compat.git"
},
"original": {
"type": "git",
"url": "https://git.lix.systems/lix-project/flake-compat.git"
}
},
"flake-parts": { "flake-parts": {
"inputs": { "inputs": {
"nixpkgs-lib": [ "nixpkgs-lib": [
@ -157,6 +173,27 @@
} }
}, },
"flake-parts_2": { "flake-parts_2": {
"inputs": {
"nixpkgs-lib": [
"nvf",
"nixpkgs"
]
},
"locked": {
"lastModified": 1760948891,
"narHash": "sha256-TmWcdiUUaWk8J4lpjzu4gCGxWY6/Ok7mOK4fIFfBuU4=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "864599284fc7c0ba6357ed89ed5e2cd5040f0c04",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"flake-parts_3": {
"inputs": { "inputs": {
"nixpkgs-lib": [ "nixpkgs-lib": [
"stylix", "stylix",
@ -239,11 +276,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1762787259, "lastModified": 1762964643,
"narHash": "sha256-t2U/GLLXHa2+kJkwnFNRVc2fEJ/lUfyZXBE5iKzJdcs=", "narHash": "sha256-RYHN8O/Aja59XDji6WSJZPkJpYVUfpSkyH+PEupBJqM=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "37a3d97f2873e0f68711117c34d04b7c7ead8f4e", "rev": "827f2a23373a774a8805f84ca5344654c31f354b",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -278,13 +315,28 @@
"type": "github" "type": "github"
} }
}, },
"mnw": {
"locked": {
"lastModified": 1758834834,
"narHash": "sha256-Y7IvY4F8vajZyp3WGf+KaiIVwondEkMFkt92Cr9NZmg=",
"owner": "Gerg-L",
"repo": "mnw",
"rev": "cfbc7d1cc832e318d0863a5fc91d940a96034001",
"type": "github"
},
"original": {
"owner": "Gerg-L",
"repo": "mnw",
"type": "github"
}
},
"nixos-hardware": { "nixos-hardware": {
"locked": { "locked": {
"lastModified": 1762463231, "lastModified": 1762847253,
"narHash": "sha256-hv1mG5j5PTbnWbtHHomzTus77pIxsc4x8VrMjc7+/YE=", "narHash": "sha256-BWWnUUT01lPwCWUvS0p6Px5UOBFeXJ8jR+ZdLX8IbrU=",
"owner": "nixos", "owner": "nixos",
"repo": "nixos-hardware", "repo": "nixos-hardware",
"rev": "52113c4f5cfd1e823001310e56d9c8d0699a6226", "rev": "899dc449bc6428b9ee6b3b8f771ca2b0ef945ab9",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -295,11 +347,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1762596750, "lastModified": 1762977756,
"narHash": "sha256-rXXuz51Bq7DHBlfIjN7jO8Bu3du5TV+3DSADBX7/9YQ=", "narHash": "sha256-4PqRErxfe+2toFJFgcRKZ0UI9NSIOJa+7RXVtBhy4KE=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "b6a8526db03f735b89dd5ff348f53f752e7ddc8e", "rev": "c5ae371f1a6a7fd27823bc500d9390b38c05fa55",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -334,6 +386,30 @@
"type": "github" "type": "github"
} }
}, },
"nvf": {
"inputs": {
"flake-compat": "flake-compat_2",
"flake-parts": "flake-parts_2",
"mnw": "mnw",
"nixpkgs": [
"nixpkgs"
],
"systems": "systems"
},
"locked": {
"lastModified": 1762622004,
"narHash": "sha256-NpzzgaoMK8aRHnndHWbYNKLcZN0r1y6icCoJvGoBsoE=",
"owner": "notashelf",
"repo": "nvf",
"rev": "09470524a214ed26633ddc2b6ec0c9bf31a8b909",
"type": "github"
},
"original": {
"owner": "notashelf",
"repo": "nvf",
"type": "github"
}
},
"pre-commit-hooks-nix": { "pre-commit-hooks-nix": {
"inputs": { "inputs": {
"flake-compat": [ "flake-compat": [
@ -367,6 +443,7 @@
"lanzaboote": "lanzaboote", "lanzaboote": "lanzaboote",
"nixos-hardware": "nixos-hardware", "nixos-hardware": "nixos-hardware",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"nvf": "nvf",
"sops-nix": "sops-nix", "sops-nix": "sops-nix",
"stylix": "stylix" "stylix": "stylix"
} }
@ -399,11 +476,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1762659808, "lastModified": 1763069729,
"narHash": "sha256-2Kv2mANf+FRisqhpfeZ8j9firBxb23ZvEXwdcunbpGI=", "narHash": "sha256-A91a+K0Q9wfdPLwL06e/kbHeAWSzPYy2EGdTDsyfb+s=",
"owner": "Mic92", "owner": "Mic92",
"repo": "sops-nix", "repo": "sops-nix",
"rev": "524312bc62e3f34bd9231a2f66622663d3355133", "rev": "a2bcd1c25c1d29e22756ccae094032ab4ada2268",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -419,13 +496,13 @@
"base16-helix": "base16-helix", "base16-helix": "base16-helix",
"base16-vim": "base16-vim", "base16-vim": "base16-vim",
"firefox-gnome-theme": "firefox-gnome-theme", "firefox-gnome-theme": "firefox-gnome-theme",
"flake-parts": "flake-parts_2", "flake-parts": "flake-parts_3",
"gnome-shell": "gnome-shell", "gnome-shell": "gnome-shell",
"nixpkgs": [ "nixpkgs": [
"nixpkgs" "nixpkgs"
], ],
"nur": "nur", "nur": "nur",
"systems": "systems", "systems": "systems_2",
"tinted-foot": "tinted-foot", "tinted-foot": "tinted-foot",
"tinted-kitty": "tinted-kitty", "tinted-kitty": "tinted-kitty",
"tinted-schemes": "tinted-schemes", "tinted-schemes": "tinted-schemes",
@ -461,6 +538,21 @@
"type": "github" "type": "github"
} }
}, },
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"tinted-foot": { "tinted-foot": {
"flake": false, "flake": false,
"locked": { "locked": {

155
flake.nix
View file

@ -13,73 +13,96 @@
disko.inputs.nixpkgs.follows = "nixpkgs"; disko.inputs.nixpkgs.follows = "nixpkgs";
stylix.url = "github:nix-community/stylix"; stylix.url = "github:nix-community/stylix";
stylix.inputs.nixpkgs.follows = "nixpkgs"; stylix.inputs.nixpkgs.follows = "nixpkgs";
#obsidian-nvim.url = "github:epwalsh/obsidian.nvim";
nvf = {
url = "github:notashelf/nvf";
inputs.nixpkgs.follows = "nixpkgs";
#inputs.obsidian-nvim.follows = "obsidian-nvim";
};
}; };
# https://nix.dev/tutorials/nix-language.html#named-attribute-set-argument # https://nix.dev/tutorials/nix-language.html#named-attribute-set-argument
outputs = inputs@{self, nixpkgs, nixos-hardware, home-manager, sops-nix, lanzaboote, disko, stylix, ...}: outputs =
let inputs@{
mkSystem = (import ./lib { self,
inherit nixpkgs home-manager inputs; nixpkgs,
}).mkSystem; nixos-hardware,
in home-manager,
{ sops-nix,
lib = { lanzaboote,
mkSystem = mkSystem; disko,
stylix,
nvf,
...
}:
let
zwLib = import ./lib {
inherit nixpkgs home-manager inputs;
};
mkSystem = zwLib.mkSystem;
mkHome = zwLib.mkHome;
mkHomeConfigs = zwLib.mkHomeConfigs;
# NOTE: Currently these are exclusively user-profiles which use home-manager.
# Their home-manager specific declarations are at ../users/${username}/home.nix
system = "x86_64-linux"; # TODO: Improve this from only static x86 to dynamic.
homeUserProfiles = {
jml = mkHome {
inherit system; # inputs;
username = "jml";
extraModules = [ nvf.homeManagerModules.default ];
};
};
in
{
lib = {
mkSystem = mkSystem;
};
# NOTE: Run `nix flake show` to see what this flake has to offer.
# TODO: Enable automated formatting with something like numtide/treefmt-nix
nixosConfigurations = {
neon = mkSystem {
hostname = "neon";
users = [ "jml" ];
};
lithium = mkSystem {
hostname = "lithium";
# extraModules = [ inputs.sops-nix.nixosModules.sops ];
users = [
"jml"
"breakglass"
];
};
titanium = mkSystem {
hostname = "titanium";
users = [
"jml"
];
homeUsers = {
jml = homeUserProfiles.jml.module;
};
#extraModules = [ (import ./overlays) ];
# NOTE: If I'm using a home-manager configuration on a given host,
# I also need to include the relevant modules.
# TODO: Can I instead self-reference the homeConfigurations in this flake?
extraModules = [
stylix.nixosModules.stylix
];
};
# `nix build .#nixosConfigurations.installIso.config.system.build.isoImage`
# https://github.com/nix-community/nixos-generators
installIso = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
"${nixpkgs}/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix"
];
specialArgs = { inherit inputs; };
};
};
# For Debugging: `home-manager build --flake .` or `nix build .#homeConfigurations."jml".activationPackage`
# `home-manager switch --flake .#jml`
# https://nix-community.github.io/home-manager/options.xhtml
homeConfigurations = mkHomeConfigs homeUserProfiles;
}; };
# NOTE: Run `nix flake show` to see what this flake has to offer.
# TODO: Enable automated formatting with something like numtide/treefmt-nix
nixosConfigurations = {
neon = mkSystem {
hostname = "neon";
users = [ "jml" ];
};
lithium = mkSystem {
hostname = "lithium";
# extraModules = [ inputs.sops-nix.nixosModules.sops ];
users = [
"jml"
"breakglass"
];
};
titanium = mkSystem {
hostname = "titanium";
users = [
"jml"
];
extraModules = [
#(import ./overlays)
#stylix.nixosModules.stylix
{ nixpkgs.config.allowUnfree = true; }
lanzaboote.nixosModules.lanzaboote
disko.nixosModules.disko
./hosts/titanium/disko.nix
({ pkgs, lib, ... }: {
environment.systemPackages = [ pkgs.sbctl ];
boot.loader.systemd-boot.enable = lib.mkForce false;
boot.lanzaboote.enable = true;
boot.lanzaboote.pkiBundle = "/var/lib/sbctl";
})
];
};
cobalt = mkSystem {
hostname = "cobalt";
users = [ "jml" ];
};
# `nix build .#nixosConfigurations.installIso.config.system.build.isoImage`
# https://github.com/nix-community/nixos-generators
installIso = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
"${nixpkgs}/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix"
];
specialArgs = {inherit inputs;};
};
};
homeConfigurations = {
"jml" = home-manager.lib.homeManagerConfiguration {
modules = [
./users/jml/home.nix
];
};
};
};
} }

View file

@ -1,68 +1,113 @@
{ nixpkgs, home-manager, inputs, ... }: {
nixpkgs,
home-manager,
inputs,
...
}:
let let
allOverlays = import (../overlays) { inherit nixpkgs; }; allOverlays = import (../overlays) { inherit nixpkgs; };
in getPkgs =
{ system:
# It's not really that I care about whether a system is a desktop system or import nixpkgs {
# a server system, but moreso that I care about whether a system is headless or not.
# I also care about things like if it's darwin, or wsl.
# TODO: Expand this to actually make use of extraSpecialArgs and pass special
# args to the relevant places.
mkSystem = {
hostname,
system ? "x86_64-linux",
users ? [],
extraModules ? [],
extraSpecialArgs ? {}
}:
let
pkgs_with_overlays = import nixpkgs {
inherit system; inherit system;
overlays = allOverlays; overlays = allOverlays;
}; };
hostModule = import ../hosts/${hostname} { in
inherit inputs; {
pkgs = pkgs_with_overlays; mkSystem =
}; {
userModules = map (name: hostname,
import ../users/${name} { system ? "x86_64-linux",
pkgs = pkgs_with_overlays; users ? [ ],
lib = nixpkgs.lib; extraModules ? [ ],
} homeUsers ? { },
) users; extraSpecialArgs ? { },
}:
homeUserNames = builtins.filter (name: let
builtins.pathExists ../users/${name}/home.nix pkgs_with_overlays = import nixpkgs {
) users; inherit system;
overlays = allOverlays;
homeUsers = nixpkgs.lib.listToAttrs (map (name: {
name = name;
value = import ../users/${name}/home.nix {
username = name;
pkgs = pkgs_with_overlays;
lib = nixpkgs.lib;
}; };
}) homeUserNames); hostModule = import ../hosts/${hostname} {
in inherit inputs;
pkgs = pkgs_with_overlays;
};
userModules = map (
name:
import ../users/${name} {
pkgs = pkgs_with_overlays;
lib = nixpkgs.lib;
}
) users;
formattedHomeUsers = nixpkgs.lib.mapAttrs (username: moduleList: {
imports = moduleList;
}) homeUsers;
in
nixpkgs.lib.nixosSystem { nixpkgs.lib.nixosSystem {
inherit system; inherit system;
# pkgs = import inputs.nixpkgs { modules = [
# inherit system; hostModule
# overlays = allOverlays; ]
# config = { allowUnfree = true; nvidia.acceptLicense = true; }; ++ userModules
# }; ++ extraModules
modules = [ hostModule ] ++ (
++ userModules if homeUsers != { } then
++ extraModules [
++ (if homeUserNames != [] then [ home-manager.nixosModules.home-manager
home-manager.nixosModules.home-manager {
{ #home-manager.useGlobalPkgs = true; # NOTE: Incompatible with nixpkgs.{config,overlays}
home-manager.backupFileExtension = "hm-bak"; home-manager.useUserPackages = true;
home-manager.users = homeUsers; home-manager.backupFileExtension = "hm-bak";
}
] else []); # Directly inject the module lists? (isn't this the problem?)
home-manager.users = formattedHomeUsers;
home-manager.extraSpecialArgs = { inherit inputs; };
}
]
else
[ ]
);
specialArgs = { specialArgs = {
inherit inputs hostname; inherit inputs hostname;
} // extraSpecialArgs; }
// extraSpecialArgs;
}; };
getUserHomeModule =
username: pkgs: inputs:
import ../users/${username}/home.nix {
inherit username pkgs inputs;
lib = nixpkgs.lib;
};
/**
This function returns an attribute set { module, config }.
*/
mkHome =
{
username,
system ? "x86_64-linux",
extraModules ? [ ],
}:
let
pkgs_with_overlays = getPkgs system;
moduleList = [
(import ../users/${username}/home.nix {
inherit inputs username;
pkgs = pkgs_with_overlays;
lib = nixpkgs.lib;
})
]
++ extraModules;
in
{
module = moduleList;
config = home-manager.lib.homeManagerConfiguration {
pkgs = pkgs_with_overlays;
modules = moduleList;
};
};
mkHomeConfigs = userProfiles: nixpkgs.lib.mapAttrs (username: profile: profile.config) userProfiles;
} }