config/flake.nix

291 lines
12 KiB
Nix
Raw Normal View History

2023-02-25 04:39:30 +01:00
{
description = "pbsds' system/home flake";
2023-02-25 04:39:30 +01:00
2023-03-19 04:23:38 +01:00
inputs = {
2024-01-11 00:05:57 +01:00
# https://github.com/nixos/nixpkgs
nixpkgs-edge.url = "github:NixOS/nixpkgs/nixos-unstable";
2023-12-10 09:47:02 +01:00
nixpkgs-2311.url = "github:NixOS/nixpkgs/nixos-23.11"; # gnome plugins broken
2024-01-10 22:21:33 +01:00
nixpkgs-2305.url = "github:NixOS/nixpkgs/nixos-23.05";
2023-10-14 18:30:34 +02:00
# https://github.com/nix-community/home-manager
2024-01-11 00:05:57 +01:00
home-manager-edge.url = "github:nix-community/home-manager/master";
home-manager-edge.inputs.nixpkgs.follows = "nixpkgs-edge";
home-manager-2311.url = "github:nix-community/home-manager/release-23.11";
home-manager-2311.inputs.nixpkgs.follows = "nixpkgs-2311";
2024-01-10 22:21:33 +01:00
home-manager-2305.url = "github:nix-community/home-manager/release-23.05";
home-manager-2305.inputs.nixpkgs.follows = "nixpkgs-2305";
2023-10-14 18:30:34 +02:00
# https://github.com/NixOS/nixos-hardware
2023-03-19 04:23:38 +01:00
nixos-hardware.url = "github:NixOS/nixos-hardware";
2023-02-25 04:39:30 +01:00
2023-10-14 18:30:34 +02:00
# https://github.com/wamserma/flake-programs-sqlite
2024-01-10 22:21:33 +01:00
flake-programs-sqlite-2311.url = "github:wamserma/flake-programs-sqlite";
flake-programs-sqlite-2311.inputs.nixpkgs.follows = "nixpkgs-2311";
2023-09-28 01:58:08 +02:00
2023-10-14 18:30:34 +02:00
# https://github.com/nix-community/nixos-generators
2024-01-10 22:21:33 +01:00
nixos-generators-2311.url = "github:nix-community/nixos-generators";
nixos-generators-2311.inputs.nixpkgs.follows = "nixpkgs-2311";
2023-10-14 18:30:34 +02:00
# https://github.com/Mic92/sops-nix
2024-01-11 00:05:57 +01:00
sops-nix-edge.url = "github:Mic92/sops-nix";
sops-nix-edge.inputs.nixpkgs.follows = "nixpkgs-edge";
sops-nix-2311.url = "github:Mic92/sops-nix";
sops-nix-2311.inputs.nixpkgs.follows = "nixpkgs-2311";
2024-01-10 22:21:33 +01:00
sops-nix-2305.url = "github:Mic92/sops-nix";
sops-nix-2305.inputs.nixpkgs.follows = "nixpkgs-2305";
2023-10-14 18:30:34 +02:00
2023-10-15 00:43:59 +02:00
/** /
2023-10-14 18:30:34 +02:00
matrix-next.url = "github:dali99/nixos-matrix-modules"; # see https://git.pvv.ntnu.no/Drift/pvv-nixos-config/src/main/flake.nix
2023-06-29 02:43:56 +02:00
#https://github.com/considerate/nixos-odroidhc4
#https://cyberchaos.dev/cyberchaoscreatures/musl-nixos/
#https://github.com/numtide/system-manager
2023-10-14 18:30:34 +02:00
nix-vscode-extensions.url = "github:nix-community/nix-vscode-extensions"
2023-07-02 09:19:35 +02:00
#https://github.com/numtide/nixpkgs-unfree # has a cache
2023-07-04 16:32:09 +02:00
#https://github.com/matthewbauer/nixiosk
2023-10-14 18:30:34 +02:00
inputs.pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
2023-02-25 04:39:30 +01:00
2023-06-18 05:10:08 +02:00
# used to host old docs
2023-10-14 18:30:34 +02:00
nixpkgs-22.url = "github:NixOS/nixpkgs/nixos-22.11";
nixpkgs-21.url = "github:NixOS/nixpkgs/nixos-21.11";
nixpkgs-20.url = "github:NixOS/nixpkgs/nixos-20.09";
nixpkgs-19.url = "github:NixOS/nixpkgs/nixos-19.09";
nixpkgs-19.flake = false; # Earlier versions are not flake-pure
/**/
2023-06-18 05:10:08 +02:00
2024-01-10 22:21:33 +01:00
#pbsds-papers.url = "git+ssh://git@github.com/pbsds/papers.git";
2023-03-19 04:23:38 +01:00
};
2023-07-05 17:30:17 +02:00
nixConfig.extra-substituters = [
"https://cuda-maintainers.cachix.org"
"https://nix-community.cachix.org"
"https://nixos-rocm.cachix.org"
"https://nixpkgs-unfree.cachix.org"
"https://numtide.cachix.org"
];
nixConfig.extra-trusted-public-keys = [
"cuda-maintainers.cachix.org-1:0dq3bujKpuEPMCX6U4WylrUDZ9JyUG0VpVZa7CNfq5E="
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
"nixos-rocm.cachix.org-1:VEpsf7pRIijjd8csKjFNBGzkBqOmw8H9PRmgAq14LnE="
"nixpkgs-unfree.cachix.org-1:hqvoInulhbV4nJ9yJOEr+4wxhDV4xq2d1DK7S6Nj6rs="
"numtide.cachix.org-1:2ps1kLBUWjxIneOy1Ik6cQjb41X0iXVXeHigGmycPPE="
];
2023-03-04 00:09:57 +01:00
outputs = {
self,
nixos-hardware,
2024-01-10 22:21:33 +01:00
nixos-generators-2311,
2023-03-04 00:09:57 +01:00
...
2024-01-10 22:21:33 +01:00
} @ inputs':
2023-02-25 04:39:30 +01:00
let
2024-01-10 22:21:33 +01:00
inputs-edge = inputs' // {
2024-01-11 00:05:57 +01:00
nixpkgs = inputs'.nixpkgs-edge;
unstable = inputs'.nixpkgs-edge;
home-manager = inputs'.home-manager-edge;
sops-nix = inputs'.sops-nix-edge;
2024-01-10 22:21:33 +01:00
};
inputs-2311 = inputs' // {
nixpkgs = inputs'.nixpkgs-2311;
2024-01-11 00:05:57 +01:00
unstable = inputs'.nixpkgs-edge;
2024-01-10 22:21:33 +01:00
home-manager = inputs'.home-manager-2311;
sops-nix = inputs'.sops-nix-2311;
2024-01-10 21:42:32 +01:00
};
2024-01-10 22:21:33 +01:00
inputs-2305 = inputs' // {
nixpkgs = inputs'.nixpkgs-2305;
unstable = inputs'.nixpkgs-2311;
home-manager = inputs'.home-manager-2305;
sops-nix = inputs'.sops-nix-2305;
};
2024-01-10 22:21:33 +01:00
mkFlakeView = inputs: system: inputs.nixpkgs.lib.mapAttrs (name: flake: {
# TODO filter non-flake inputs
2023-07-03 01:34:00 +02:00
nixos = flake.nixosModules
or null;
pkgs = flake.packages.${system}
or flake.legacyPackages.${system}
or null;
2023-07-03 01:34:00 +02:00
lib = flake.lib.${system}
or flake.lib
or null;
}) inputs;
2024-01-10 22:21:33 +01:00
forSystems = systems: f: inputs-edge.nixpkgs.lib.genAttrs systems (system: f rec {
2023-06-20 01:36:49 +02:00
inherit system;
2024-01-10 22:21:33 +01:00
inputs = inputs-edge;
pkgs = inputs.nixpkgs.legacyPackages.${system};
lib = inputs.nixpkgs.legacyPackages.${system}.lib;
2024-01-10 22:21:33 +01:00
flakes = mkFlakeView inputs system;
2023-06-20 01:36:49 +02:00
});
2023-07-03 01:34:00 +02:00
forAllSystems = forSystems [
"x86_64-linux"
"aarch64-linux"
#"riscv64-linux"
];
2023-03-09 07:03:15 +01:00
2024-01-11 15:06:19 +01:00
mkModule = domain: system: inputs: stateVersion: modules: hostname: ({ lib, ... }: {
2024-01-11 01:00:20 +01:00
system.stateVersion = lib.mkDefault stateVersion; # TODO: home-manager
2023-10-15 00:43:59 +02:00
imports = [
./base.nix
"${self}/hosts/${hostname}"
inputs.sops-nix.nixosModules.sops
inputs.home-manager.nixosModule
2023-10-15 00:43:59 +02:00
] ++ modules;
2024-01-10 22:21:33 +01:00
#++ inputs.flake-programs-sqlite.nixosModules.programs-sqlite; # TODO: make work
2023-10-15 00:43:59 +02:00
2024-01-11 01:00:20 +01:00
sops.defaultSopsFile = lib.mkIf (builtins.pathExists ./secrets/${hostname}.yaml)
2023-12-03 20:53:16 +01:00
./secrets/${hostname}.yaml;
2024-01-11 01:00:20 +01:00
sops.age.sshKeyPaths = [ "/etc/ssh/ssh_host_ed25519_key" ];
sops.age.keyFile = "/var/lib/sops-nix/key.txt";
sops.age.generateKey = true;
2023-10-14 18:30:34 +02:00
2023-10-15 03:37:29 +02:00
home-manager.useGlobalPkgs = true; # go brrr, reuse overrides
home-manager.extraSpecialArgs = {
inherit inputs;
2024-01-10 22:21:33 +01:00
flakes = mkFlakeView inputs system;
2023-10-15 03:37:29 +02:00
};
2023-12-03 20:54:20 +01:00
home-manager.sharedModules = [
2024-01-10 22:21:33 +01:00
inputs.sops-nix.homeManagerModules.sops
2023-12-03 20:54:20 +01:00
];
2023-10-15 03:37:29 +02:00
2023-10-14 18:30:34 +02:00
# still needed even if using networkd
networking.hostName = hostname;
networking.domain = domain;
networking.search = [ domain ];
nixpkgs.overlays = [
(final: prev: {
#unstable = unstable.legacyPackages.${final.system};
unstable = import inputs.unstable { inherit system; config.allowUnfree = true; }; # TODO: inherit nixos config from stable
2023-10-14 18:30:34 +02:00
})
];
# This makes commandline tools like 'nix run nixpkgs#hello'
# and 'nix-shell -p hello' use the same channel as system was built with
nix.registry.nixpkgs.flake = inputs.nixpkgs;
2023-10-14 18:30:34 +02:00
nix.registry.nixpkgs-unstable.flake = inputs.unstable;
2024-01-10 22:21:33 +01:00
nix.registry.nixpkgs-git = {
2024-01-11 01:00:20 +01:00
from.id = "nixpkgs-git";
2024-01-10 22:21:33 +01:00
from.type = "indirect";
to.type = "github";
to.owner = "NixOS";
to.repo = "nixpkgs";
to.ref = "nixpkgs-unstable-small";
};
2023-10-14 18:30:34 +02:00
nix.nixPath = [
"nixpkgs=${inputs.nixpkgs}"
"nixpkgs-unstable=${inputs.unstable}"
2024-01-10 22:21:33 +01:00
"nixpkgs-git=github:NixOS/nixpkgs/nixos-unstable-small"
2023-10-14 18:30:34 +02:00
];
});
2024-01-11 15:06:19 +01:00
mkConfig = domain: system: inputs: stateVersion: modules: hostname: inputs.nixpkgs.lib.nixosSystem {
2023-02-25 04:39:30 +01:00
inherit system;
2023-06-20 01:39:19 +02:00
specialArgs = {
inherit inputs;
2024-01-10 21:42:32 +01:00
flakes = mkFlakeView inputs system;
2023-06-20 01:39:19 +02:00
};
2024-01-11 15:06:19 +01:00
modules = [ (mkModule domain system inputs stateVersion modules hostname) ];
2023-10-14 18:30:34 +02:00
};
mkHosts = mk: let
ls = imports: { inherit imports; };
hw = nixos-hardware.nixosModules;
amd = ls [ hw.common-pc hw.common-pc-ssd hw.common-cpu-amd ];
2024-01-11 01:29:12 +01:00
intel = ls [ hw.common-pc hw.common-pc-ssd hw.common-cpu-intel ./hardware/gpu/intel.nix ];
intel-novga = ls [ hw.common-pc hw.common-pc-ssd hw.common-cpu-intel-cpu-only ];
2024-01-11 01:29:12 +01:00
cuda = ls [ ./hardware/gpu/cuda.nix hw.common-gpu-nvidia-nonprime ];
cuda-prime = ls [ ./hardware/gpu/cuda.nix hw.common-gpu-nvidia ];
rocm = ls [ ./hardware/gpu/rocm.nix hw.common-gpu-amd ];
hidpi = hw.common-hidpi;
2024-01-11 01:29:12 +01:00
p1005 = ./hardware/printer/hp-laserjet-p1005.nix;
2024-01-11 15:06:19 +01:00
in builtins.mapAttrs (hostname: curried: curried hostname) {
#hostname "domain" "system" inputs "state" [ modules ... ]
noximilien = mk "pbsds.net" "x86_64-linux" inputs-2311 "22.11" [ intel ];
brumlebasse = mk "pbsds.net" "x86_64-linux" inputs-2311 "23.11" [ amd ];
2024-01-11 16:59:08 +01:00
nord = mk "pbsds.net" "x86_64-linux" inputs-2305 "23.05" [ intel-novga hw.common-cpu-intel-sandy-bridge rocm hidpi ];
2024-01-11 15:06:19 +01:00
sopp = mk "pbsds.net" "x86_64-linux" inputs-2305 "23.05" [ intel cuda p1005 ];
bolle = mk "pbsds.net" "x86_64-linux" inputs-2311 "23.11" [ intel ];
eple = mk "pbsds.net" "x86_64-linux" inputs-2311 "23.11" [ intel ];
garp = mk "pbsds.net" "x86_64-linux" inputs-2311 "23.11" [ intel-novga cuda ];
2023-10-14 18:30:34 +02:00
#gomperud smattkuken skrytebiffen skalkesnerken balleby brumlebasse bingus skjrlaltatjlstad
#bergjlot snortheimsmoen ditlefsen skrukkerud podebusk zmaragd makrell alfnes blix urke eple hasselknippe pytte uddu imdorf rosenqvist
2023-02-25 04:39:30 +01:00
};
in {
2024-01-10 22:21:33 +01:00
inputs = inputs';
2023-12-10 09:46:02 +01:00
lib = {
2024-01-10 22:21:33 +01:00
inherit mkFlakeView forSystems;
} // forAllSystems ({ system, ... }: {
inherit mkFlakeView forSystems;
flakes = mkFlakeView inputs-edge system;
flakes-2311 = mkFlakeView inputs-2311 system;
flakes-2305 = mkFlakeView inputs-2305 system;
2023-12-10 09:46:02 +01:00
});
2024-01-11 01:00:20 +01:00
nixosModules = mkHosts mkModule;
2023-12-10 09:46:02 +01:00
nixosConfigurations = mkHosts mkConfig;
2024-01-11 15:06:37 +01:00
packages = forAllSystems ({ inputs, pkgs, lib, flakes, ... }: {
2023-12-10 09:46:02 +01:00
mpv-webm = pkgs.callPackage ./pkgs/mpv-webm.nix {}; # TODO: https://github.com/NixOS/nixpkgs/pull/238659, remove when i switch to 23.11
2023-03-09 07:03:15 +01:00
2024-01-11 15:06:37 +01:00
nixos-rebuild-nom = pkgs.writeScriptBin "nixos-rebuild" ''
exec ${lib.getExe pkgs.nixos-rebuild} "$@" |& ${lib.getExe pkgs.nix-output-monitor}
2023-07-03 01:35:05 +02:00
'';
2023-10-14 18:31:23 +02:00
# nixos-generators images
2024-01-10 22:21:33 +01:00
image-brumlebasse-openstack = nixos-generators-2311.nixosGenerate {
2023-10-14 18:31:23 +02:00
system = "x86_64-linux";
specialArgs = { inherit inputs flakes; };
modules = [ (mkHosts mkModule).brumlebasse ];
format = "openstack";
};
2023-03-19 04:23:38 +01:00
});
2023-03-09 07:03:15 +01:00
2023-07-05 00:40:34 +02:00
homeConfigurations = forAllSystems ({ pkgs, flakes, ... }: let
2024-01-10 22:21:33 +01:00
mkHome = user: home: inputs: modules: inputs.home-manager.lib.homeManagerConfiguration {
2023-06-20 01:39:35 +02:00
inherit pkgs;
modules = modules ++ [{
home.username = user;
home.homeDirectory = home;
2023-12-03 20:54:20 +01:00
home-manager.sharedModules = [
2024-01-10 22:21:33 +01:00
inputs.sops-nix.homeManagerModules.sops
2023-12-03 20:54:20 +01:00
];
2023-06-20 01:39:35 +02:00
}];
2023-10-14 18:30:34 +02:00
extraSpecialArgs = {
inherit inputs flakes;
};
2023-03-09 09:31:53 +01:00
};
2023-03-19 04:23:38 +01:00
in {
2024-01-10 22:21:33 +01:00
# TODO: pvv
pbsds-2305 = mkHome "pbsds" "/home/pbsds" inputs-2305 [ ./users/pbsds/home ];
pbsds-2311 = mkHome "pbsds" "/home/pbsds" inputs-2311 [ ./users/pbsds/home ];
pbsds = mkHome "pbsds" "/home/pbsds" inputs-edge [ ./users/pbsds/home ];
pbsds-gnome-2305 = mkHome "pbsds" "/home/pbsds" inputs-2305 [ ./users/pbsds/home/gnome.nix ];
pbsds-gnome-2311 = mkHome "pbsds" "/home/pbsds" inputs-2311 [ ./users/pbsds/home/gnome.nix ];
pbsds-gnome = mkHome "pbsds" "/home/pbsds" inputs-edge [ ./users/pbsds/home/gnome.nix ];
2023-02-25 04:39:30 +01:00
});
2023-03-09 07:03:15 +01:00
devShells = forAllSystems ({ pkgs, flakes, ... }: let
2023-07-05 17:30:17 +02:00
mkShell = packages: pkgs.mkShellNoCC { inherit packages; };
2023-06-24 19:11:49 +02:00
envrc-pkgs = [
2023-07-03 01:35:05 +02:00
flakes.self.pkgs.nixos-rebuild-nom
pkgs.home-manager
pkgs.nix-output-monitor
pkgs.cachix
2023-10-15 00:43:59 +02:00
pkgs.age
pkgs.sops
pkgs.ssh-to-age
2023-03-19 04:23:38 +01:00
];
2023-06-24 19:11:49 +02:00
in {
envrc-local = mkShell envrc-pkgs;
2023-07-03 02:23:35 +02:00
envrc-remote = mkShell (envrc-pkgs ++ [
flakes.unstable.pkgs.remote-exec # TODO: stable
pkgs.yq
pkgs.rsync
2023-06-24 19:11:49 +02:00
]);
remoteenv = mkShell [
2023-07-03 01:35:05 +02:00
flakes.self.pkgs.nixos-rebuild-nom
2023-10-15 00:43:59 +02:00
pkgs.age
pkgs.ssh-to-age
2023-03-19 04:23:38 +01:00
];
2023-02-26 21:28:44 +01:00
});
2023-03-09 07:03:15 +01:00
2023-02-25 04:39:30 +01:00
};
}