-
Notifications
You must be signed in to change notification settings - Fork 4
/
flake.nix
156 lines (148 loc) · 4.97 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-24.05";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils.url = "github:numtide/flake-utils";
lanzaboote.url = "github:nix-community/lanzaboote";
nix-index-database.url = "github:nix-community/nix-index-database";
};
outputs =
{
self,
flake-utils,
lanzaboote,
nix-index-database,
...
}@inputs:
let
system = "x86_64-linux";
# We'd like to be able to add patches on top of nixpkgs, like pending pull requests.
# Source: https://github.com/NixOS/nixpkgs/pull/142273#issuecomment-948225922
nixpkgs =
let
pkgs = inputs.nixpkgs.legacyPackages.${system};
in
pkgs.applyPatches {
name = "nixpkgs-patched";
src = inputs.nixpkgs;
patches = [
# Fix openvpn3 glibc incompatibility.
(pkgs.fetchpatch {
url = "https://github.com/NixOS/nixpkgs/pull/326623.patch";
hash = "sha256-ziop85PodXV4u3zLbXSQc03xagPIbZx7fCGdFkHLl7Y=";
})
];
};
username = "bob.vanderlinden";
defaultOverlays = with self.overlays; [
default
workarounds
];
mkPkgs =
{
system ? system,
nixpkgs ? inputs.nixpkgs,
config ? {
allowUnfree = true;
},
overlays ? defaultOverlays,
...
}@options:
import nixpkgs (options // { inherit system config overlays; });
nixosSystem = import (nixpkgs + "/nixos/lib/eval-config.nix");
in
{
overlays.default = final: prev: import ./packages { pkgs = final; };
overlays.workarounds =
final: prev:
let
pkgsStable = import inputs.nixpkgs-stable {
system = prev.system;
config.allowUnfree = true;
};
in
{
_1password-cli = pkgsStable._1password;
_1password-gui = pkgsStable._1password-gui;
};
nixosModules = import ./system/modules // {
overlays = {
nixpkgs.overlays = defaultOverlays;
};
hardware-configuration = import ./system/hardware-configuration.nix;
system-configuration = import ./system/configuration.nix;
single-user = {
suites.single-user.user = username;
};
inherit (lanzaboote.nixosModules) lanzaboote;
# inherit (nix-index-database.nixosModules) nix-index;
nix-index-database-home-manager = {
home-manager.sharedModules = [ nix-index-database.hmModules.nix-index ];
};
};
# System configuration for laptop.
nixosConfigurations.nac44250 = nixosSystem {
inherit system;
specialArgs = {
inherit inputs;
};
modules = builtins.attrValues self.nixosModules;
};
homeConfigurations."${username}@nac44250" =
self.nixosConfigurations.nac44250.config.home-manager.users.${username}.home;
}
# Define outputs that allow multiple systems with for all default systems.
# This is to support OSX and RPI.
// flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = mkPkgs { inherit system; };
in
{
packages =
let
lib = pkgs.lib;
in
lib.filterAttrs (
name: package:
(package ? meta) -> (package.meta ? platforms) -> builtins.elem system package.meta.platforms
) (import ./packages { inherit pkgs; });
apps.switch = {
type = "app";
program =
let
switch = pkgs.writeShellApplication {
name = "switch";
text = ''
nom build --impure --keep-going --out-link system-result ${self}#nixosConfigurations."$(hostname)".config.system.build.toplevel
nom build --keep-going --out-link home-result ${self}#nixosConfigurations."$(hostname)".config.home-manager.users.\""$USER"\".home.activationPackage
if [[ "$(readlink --canonicalize system-result)" != "$(readlink --canonicalize /nix/var/nix/profiles/system)" ]]
then
${pkgs.coin}/bin/coin
sudo nix-env -p /nix/var/nix/profiles/system --set "$(readlink system-result)"
sudo system-result/bin/switch-to-configuration switch
fi
./home-result/activate
'';
runtimeInputs = [ pkgs.nix-output-monitor ];
};
in
"${switch}/bin/switch";
};
formatter = {
type = "app";
program = "${pkgs.nixfmt-rfc-style}/bin/nixfmt";
};
devShells.default = pkgs.mkShell {
packages = with pkgs; [
nixfmt-rfc-style
nixd
];
};
}
);
}