pulled in as flake because the darwin module has not been upstreamed yet, anf or consistency sake take all modules from the same source then
219 lines
6.9 KiB
Nix
219 lines
6.9 KiB
Nix
{
|
|
description = "NixOS system flake";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
|
|
nixos-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
nixos-hardware.url = "github:NixOS/nixos-hardware/master";
|
|
home-manager = {
|
|
url = "github:nix-community/home-manager/release-25.11";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
lanzaboote = {
|
|
url = "github:nix-community/lanzaboote/v0.4.3";
|
|
# deliberately do _not_ follow the nixpkgs input here, because paranoia and test coverage
|
|
};
|
|
utils.url = "github:numtide/flake-utils";
|
|
treefmt-nix = {
|
|
url = "github:numtide/treefmt-nix";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
nix-darwin = {
|
|
url = "github:LnL7/nix-darwin/nix-darwin-25.11";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
|
|
nur.url = "github:nix-community/NUR";
|
|
# TODO: possible make this a flake as well
|
|
mysecrets = {
|
|
flake = false;
|
|
url = "git+ssh://gitea@git.orlives.de:2342/schmittlauch/home-manager_secrets.git";
|
|
};
|
|
nix-direnv = {
|
|
url = "github:nix-community/nix-direnv";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
angrr = {
|
|
url = "github:linyinfeng/angrr";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
|
|
};
|
|
|
|
outputs =
|
|
{
|
|
self,
|
|
nixpkgs,
|
|
nur,
|
|
lanzaboote,
|
|
utils,
|
|
home-manager,
|
|
treefmt-nix,
|
|
nix-darwin,
|
|
angrr,
|
|
...
|
|
}@inputs:
|
|
let
|
|
# FIXME: allow different systems
|
|
systems = utils.lib.system;
|
|
|
|
# ability to extend nixpkgs with patches, e.g. from PRs or staging. See https://ertt.ca/nix/patch-nixpkgs/
|
|
mkNixpkgs-patched =
|
|
system:
|
|
(import nixpkgs { inherit system; }).applyPatches {
|
|
name = "nixpkgs-patched";
|
|
src = nixpkgs;
|
|
patches = [ ];
|
|
};
|
|
|
|
# necessary to make the top-level inputs available to system configuration
|
|
# inspired by https://jade.fyi/blog/flakes-arent-real/
|
|
inputInjection =
|
|
{ pkgs, lib, ... }:
|
|
{
|
|
options.inputInjection = lib.mkOption {
|
|
type = with lib.types; attrsOf unspecified;
|
|
default = { };
|
|
};
|
|
config.inputInjection = {
|
|
flake-inputs = inputs;
|
|
};
|
|
};
|
|
defaultModules = system: [
|
|
inputInjection
|
|
|
|
# for some reason, `imports`-ing the home-manager module via inputInjection
|
|
# from a sub-module causes infinite recursion, so importing it here instead
|
|
home-manager.nixosModules.home-manager
|
|
];
|
|
mkSystem =
|
|
system: extraModules:
|
|
nixpkgs.lib.nixosSystem rec {
|
|
modules = (defaultModules system) ++ extraModules;
|
|
};
|
|
mkHomeManager =
|
|
confName: user: system: # unfortunately, home-manager configs are still system-specific
|
|
home-manager.lib.homeManagerConfiguration {
|
|
# XXX: when can we move to hostPlatform?
|
|
pkgs = import (mkNixpkgs-patched system) { inherit system; };
|
|
modules = [
|
|
{
|
|
imports = [
|
|
./home/common.nix
|
|
./home/${confName}.nix
|
|
];
|
|
# extends the home config
|
|
home.username = user;
|
|
}
|
|
];
|
|
# Optionally use extraSpecialArgs
|
|
# to pass through arguments to home.nix
|
|
extraSpecialArgs = {
|
|
inherit inputs;
|
|
};
|
|
};
|
|
treefmtConf =
|
|
{ pkgs, ... }:
|
|
{
|
|
projectRootFile = "flake.nix";
|
|
programs.nixfmt.enable = true;
|
|
};
|
|
in
|
|
{
|
|
overlays.default = import ./packages;
|
|
nixosConfigurations = {
|
|
thinknix = mkSystem systems.x86_64-linux [
|
|
./hosts/thinknix
|
|
inputs.nixos-hardware.nixosModules.lenovo-thinkpad-t440s
|
|
lanzaboote.nixosModules.lanzaboote
|
|
inputs.angrr.nixosModules.angrr
|
|
];
|
|
framenix = mkSystem systems.x86_64-linux [
|
|
./hosts/framenix
|
|
inputs.nixos-hardware.nixosModules.framework-13-7040-amd
|
|
lanzaboote.nixosModules.lanzaboote
|
|
inputs.angrr.nixosModules.angrr
|
|
];
|
|
};
|
|
darwinConfigurations."OS-MacBook-Pro" = nix-darwin.lib.darwinSystem {
|
|
modules = [
|
|
./darwin/configuration.nix
|
|
inputInjection
|
|
inputs.angrr.darwinModules.angrr
|
|
|
|
];
|
|
};
|
|
homeConfigurations = {
|
|
spiollinux-desktop = mkHomeManager "desktop" "spiollinux" systems.x86_64-linux;
|
|
os-workmac = mkHomeManager "workmac" "os" systems.aarch64-darwin;
|
|
};
|
|
lib = {
|
|
inherit mkHomeManager;
|
|
};
|
|
}
|
|
// utils.lib.eachDefaultSystem (
|
|
system:
|
|
let
|
|
nixpkgs = import inputs.nixpkgs {
|
|
inherit system;
|
|
overlays = nixpkgs.lib.attrValues self.overlays;
|
|
};
|
|
nixpkgs_unstable = import inputs.nixos-unstable {
|
|
inherit system;
|
|
overlays = nixpkgs.lib.attrValues self.overlays;
|
|
};
|
|
pkgs = inputs.nixpkgs.legacyPackages.${system};
|
|
pkgs_unstable = inputs.nixos-unstable.legacyPackages.${system};
|
|
treefmtEval = treefmt-nix.lib.evalModule pkgs_unstable treefmtConf;
|
|
in
|
|
{
|
|
devShells.default = pkgs.mkShell { buildInputs = [ ]; };
|
|
formatter = treefmtEval.config.build.wrapper;
|
|
checks.formatting = treefmtEval.config.build.check self;
|
|
# expose nixpkgs with overlay; TODO: figure out role of config
|
|
#legacyPackages = nixpkgs;
|
|
|
|
# inspired by https://github.com/Mic92/dotfiles/blob/main/home-manager/flake-module.nix
|
|
# run like: `nix run .#hm -- <action>`
|
|
apps.hm = {
|
|
meta.description = "Wrapper around home-manager with automatic profile selection";
|
|
type = "app";
|
|
program = "${pkgs.writeShellScriptBin "hm" ''
|
|
set -x
|
|
export PATH=${
|
|
pkgs.lib.makeBinPath [
|
|
pkgs.git
|
|
pkgs.coreutils
|
|
pkgs.findutils
|
|
pkgs.lix
|
|
pkgs.jq
|
|
pkgs.unixtools.hostname
|
|
]
|
|
}
|
|
declare -A profiles=(
|
|
["framenix"]="spiollinux-desktop"
|
|
["thinknix"]="spiollinux-desktop"
|
|
["OS MacBook Pro"]="os-workmac"
|
|
)
|
|
user=$(id -un)
|
|
host=$(hostname)
|
|
if [[ -n ''${profiles["$host-$user"]} ]]; then
|
|
profile=''${profiles["$host-$user"]};
|
|
elif [[ -n ''${profiles[$host]:-} ]]; then
|
|
profile=''${profiles[$host]}
|
|
else
|
|
echo "No suitable profile found." >2
|
|
exit 2
|
|
fi
|
|
if [[ "''${1:-}" == profile ]]; then
|
|
echo $profile
|
|
exit 0
|
|
fi
|
|
${
|
|
inputs.home-manager.packages.${system}.home-manager
|
|
}/bin/home-manager --flake "${self}#$profile" "$@"
|
|
''}/bin/hm";
|
|
};
|
|
}
|
|
);
|
|
}
|