flake: lift the nixpkgs patching out to its own flake

i hope it's a *little* cleaner this way, but tbh i'm not really sure.
This commit is contained in:
2023-01-10 17:00:43 +00:00
parent 241f4ae58f
commit c8dcb4ac59
4 changed files with 100 additions and 24 deletions

36
flake.lock generated
View File

@@ -53,18 +53,20 @@
} }
}, },
"nixpkgs": { "nixpkgs": {
"inputs": {
"nixpkgs": [
"nixpkgs-unpatched"
]
},
"locked": { "locked": {
"lastModified": 1672953546, "lastModified": 1,
"narHash": "sha256-oz757DnJ1ITvwyTovuwG3l9cX6j9j6/DH9eH+cXFJmc=", "narHash": "sha256-5eJxyBRYQCoRt92ZFUOdT237Z0VscuNRd0pktDYWJYE=",
"owner": "NixOS", "path": "/nix/store/r17slgpq93kpiajf0vi7xdcg0q5xcqv2-source/nixpatches",
"repo": "nixpkgs", "type": "path"
"rev": "a518c77148585023ff56022f09c4b2c418a51ef5",
"type": "github"
}, },
"original": { "original": {
"id": "nixpkgs", "path": "/nix/store/r17slgpq93kpiajf0vi7xdcg0q5xcqv2-source/nixpatches",
"ref": "nixos-unstable", "type": "path"
"type": "indirect"
} }
}, },
"nixpkgs-stable": { "nixpkgs-stable": {
@@ -98,12 +100,28 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs-unpatched": {
"locked": {
"lastModified": 1673226411,
"narHash": "sha256-b6cGb5Ln7Zy80YO66+cbTyGdjZKtkoqB/iIIhDX9gRA=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "aa1d74709f5dac623adb4d48fdfb27cc2c92a4d4",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-unstable",
"type": "indirect"
}
},
"root": { "root": {
"inputs": { "inputs": {
"home-manager": "home-manager", "home-manager": "home-manager",
"mobile-nixos": "mobile-nixos", "mobile-nixos": "mobile-nixos",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"nixpkgs-stable": "nixpkgs-stable", "nixpkgs-stable": "nixpkgs-stable",
"nixpkgs-unpatched": "nixpkgs-unpatched",
"sops-nix": "sops-nix", "sops-nix": "sops-nix",
"uninsane": "uninsane" "uninsane": "uninsane"
} }

View File

@@ -5,7 +5,11 @@
{ {
inputs = { inputs = {
nixpkgs-stable.url = "nixpkgs/nixos-22.11"; nixpkgs-stable.url = "nixpkgs/nixos-22.11";
nixpkgs.url = "nixpkgs/nixos-unstable"; nixpkgs-unpatched.url = "nixpkgs/nixos-unstable";
nixpkgs = {
url = "./nixpatches";
inputs.nixpkgs.follows = "nixpkgs-unpatched";
};
mobile-nixos = { mobile-nixos = {
url = "github:nixos/mobile-nixos"; url = "github:nixos/mobile-nixos";
flake = false; flake = false;
@@ -28,29 +32,30 @@
self, self,
nixpkgs, nixpkgs,
nixpkgs-stable, nixpkgs-stable,
nixpkgs-unpatched,
mobile-nixos, mobile-nixos,
home-manager, home-manager,
sops-nix, sops-nix,
uninsane uninsane
}: let }: let
patchedPkgs = system: nixpkgs.legacyPackages.${system}.applyPatches { nixpkgsCompiledBy = local: nixpkgs.legacyPackages."${local}";
name = "nixpkgs-patched-uninsane";
src = nixpkgs;
patches = import ./nixpatches/list.nix {
inherit (nixpkgs.legacyPackages.${system}) fetchpatch;
inherit (nixpkgs.lib) fakeHash;
};
};
# return something which behaves like `pkgs`, for the provided system # return something which behaves like `pkgs`, for the provided system
# `local` = architecture of builder. `target` = architecture of the system beying deployed to # `local` = architecture of builder. `target` = architecture of the system beying deployed to
nixpkgsFor = local: target: import (patchedPkgs target) { crossSystem = target; localSystem = local; }; nixpkgsFor = local: target:
import ((nixpkgsCompiledBy local).path) {
crossSystem = target;
localSystem = local;
};
# evaluate ONLY our overlay, for the provided system # evaluate ONLY our overlay, for the provided system
customPackagesFor = local: target: import ./pkgs/overlay.nix (nixpkgsFor local target) (nixpkgsFor local target); customPackagesFor = local: target:
let pkgs = nixpkgsFor local target;
in import ./pkgs/overlay.nix pkgs pkgs;
decl-host = { name, local, target }: decl-host = { name, local, target }:
let let
nixosSystem = import ((patchedPkgs target) + "/nixos/lib/eval-config.nix"); nixosSystem = import ((nixpkgsCompiledBy local).path + "/nixos/lib/eval-config.nix");
in (nixosSystem { in (nixosSystem {
# by default the local system is the same as the target, employing emulation when they differ # we use pkgs built for and *by* the target, i.e. emulation, by default.
# cross compilation only happens on explicit access to `pkgs.cross`
system = target; system = target;
modules = [ modules = [
./modules ./modules
@@ -67,7 +72,7 @@
# for large packages like the linux kernel which are expensive to build under emulation, # for large packages like the linux kernel which are expensive to build under emulation,
# the config can explicitly pull such packages from `pkgs.cross` to do more efficient cross-compilation. # the config can explicitly pull such packages from `pkgs.cross` to do more efficient cross-compilation.
cross = (nixpkgsFor local target) // (customPackagesFor local target); cross = (nixpkgsFor local target) // (customPackagesFor local target);
stable = import nixpkgs-stable { system = target; }; stable = nixpkgs-stable.legacyPackages."${target}";
# cross-compatible packages # cross-compatible packages
# gocryptfs = cross.gocryptfs; # gocryptfs = cross.gocryptfs;
@@ -107,11 +112,12 @@
hosts.moby-cross = decl-bootable-host { name = "moby"; local = "x86_64-linux"; target = "aarch64-linux"; }; hosts.moby-cross = decl-bootable-host { name = "moby"; local = "x86_64-linux"; target = "aarch64-linux"; };
hosts.rescue = decl-bootable-host { name = "rescue"; local = "x86_64-linux"; target = "x86_64-linux"; }; hosts.rescue = decl-bootable-host { name = "rescue"; local = "x86_64-linux"; target = "x86_64-linux"; };
in { in {
# TODO: use catAttrs?
nixosConfigurations = builtins.mapAttrs (name: value: value.nixosConfiguration) hosts; nixosConfigurations = builtins.mapAttrs (name: value: value.nixosConfiguration) hosts;
imgs = builtins.mapAttrs (name: value: value.img) hosts; imgs = builtins.mapAttrs (name: value: value.img) hosts;
packages = let packages = let
allPkgsFor = sys: (customPackagesFor sys sys) // { allPkgsFor = sys: (customPackagesFor sys sys) // {
nixpkgs = nixpkgsFor sys sys; nixpkgs = nixpkgsCompiledBy sys;
uninsane = uninsane.packages."${sys}"; uninsane = uninsane.packages."${sys}";
}; };
in { in {

26
nixpatches/flake.lock generated Normal file
View File

@@ -0,0 +1,26 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1673163619,
"narHash": "sha256-B33PFBL64ZgTWgMnhFL3jgheAN/DjHPsZ1Ih3z0VE5I=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "8c54d842d9544361aac5f5b212ba04e4089e8efe",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-22.11",
"type": "indirect"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

26
nixpatches/flake.nix Normal file
View File

@@ -0,0 +1,26 @@
{
inputs = {
nixpkgs.url = "nixpkgs/nixos-22.11";
};
outputs = { self, nixpkgs }:
let
patchedPkgsFor = system: nixpkgs.legacyPackages.${system}.applyPatches {
name = "nixpkgs-patched-uninsane";
src = nixpkgs;
patches = import ./list.nix {
inherit (nixpkgs.legacyPackages.${system}) fetchpatch;
inherit (nixpkgs.lib) fakeHash;
};
};
patchedFlakeFor = system: import "${patchedPkgsFor system}/flake.nix";
patchedFlakeOutputsFor = system:
(patchedFlakeFor system).outputs { inherit self; };
in
{
legacyPackages = builtins.mapAttrs
(system: _:
(patchedFlakeOutputsFor system).legacyPackages."${system}"
)
nixpkgs.legacyPackages;
};
}