Skip to content

Commit 8a62578

Browse files
committed
Add ./cfg/nix-path.nix
The plan is to not rely on the channel, because I'm a bit annoyed by how it first have to be (globally) updated, then you try to build with it, it might fail and now you have to manually roll back the channel. The idea is to be able to deploy from arbitrary nixpkgs and have this module persist the inputs so that any later nixos-rebuild uses the last known good nixpkgs.
1 parent 9808688 commit 8a62578

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

cfg/nix-path.nix

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{ config, lib, pkgs, ... }:
2+
3+
let
4+
dummyNixChannel = pkgs.writeShellScriptBin "nix-channel" ''
5+
echo "nix-channel has been disabled on this machine." >&2
6+
exit 1
7+
'';
8+
in
9+
{
10+
nix.nixPath = [
11+
# This is a symlink that is created below. Using a symlink instead of
12+
# direct store path allows using the new nixpkgs without having to
13+
# re-login.
14+
"nixpkgs=/etc/current-nixpkgs"
15+
16+
# After initial bootstrap with `nixos-rebuild boot -I
17+
# nixos-config=/etc/nixos/$MACHINE/configuration.nix`, the machine
18+
# remembers its configuration file.
19+
"nixos-config=/etc/nixos/machines/${config.networking.hostName}/configuration.nix"
20+
];
21+
22+
# Inspired by https://github.com/NixOS/nix/pull/1731#issuecomment-558126263,
23+
# but using the option environment.etc instead of nixos internal
24+
# system.extraSystemBuilderCmds.
25+
environment.etc.current-nixpkgs.source = let
26+
# make sure store paths are not copied to the store again, which leads to
27+
# long filenames (https://github.com/NixOS/nix/issues/1728)
28+
nixpkgs_str = if lib.isStorePath pkgs.path then builtins.storePath pkgs.path else pkgs.path;
29+
in
30+
nixpkgs_str;
31+
32+
environment.systemPackages = [
33+
(lib.hiPrio dummyNixChannel)
34+
];
35+
}

0 commit comments

Comments
 (0)