Skip to content

Commit a56fa09

Browse files
committed
add concept of private flake inputs
Inputs can now be declared without propagating to a consumers lock file by adding inputs to the flake in the private sub directory. The inputs defined here can be managed just like other flake inputs. The narHash in the main flake.nix for the private inputs must be updated anytime the private flake is touched.
1 parent 26d01ff commit a56fa09

File tree

9 files changed

+3600
-51
lines changed

9 files changed

+3600
-51
lines changed

.envrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
[ -f .envrc.local ] && source_env .envrc.local
77
DEVSHELL_TARGET=${DEVSHELL_TARGET:-default}
88

9-
. "$(nix eval .#__std.direnv_lib)"
9+
. "$(nix eval --no-write-lock-file --no-update-lock-file .#__std.direnv_lib)"
1010
use std nix "//automation/devshells:${DEVSHELL_TARGET}"

flake.nix

Lines changed: 21 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,37 @@
11
{
22
description = "Flake containing Bitte clusters";
3-
inputs.std.url = "github:divnix/std";
4-
# 21.11 doesn't yet fullfill all contracts that std consumes
5-
# inputs.std.inputs.nixpkgs.follows = "nixpkgs";
6-
inputs.n2c.url = "github:nlewo/nix2container";
7-
inputs.data-merge.url = "github:divnix/data-merge";
8-
inputs.capsules.url = "github:input-output-hk/devshell-capsules";
9-
inputs = {
10-
nixpkgs.url = "github:nixos/nixpkgs/nixos-21.11";
11-
nixpkgs-docker.url = "github:nixos/nixpkgs/ff691ed9ba21528c1b4e034f36a04027e4522c58";
12-
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable";
13-
14-
nix.url = "github:nixos/nix/2.8.1";
15-
agenix.url = "github:ryantm/agenix";
16-
agenix-cli.url = "github:cole-h/agenix-cli";
17-
ragenix.url = "github:yaxitech/ragenix";
18-
deploy.url = "github:input-output-hk/deploy-rs";
19-
20-
terranix.url = "github:terranix/terranix";
21-
terranix.inputs.nixpkgs.follows = "blank";
22-
23-
utils.url = "github:numtide/flake-utils";
24-
blank.url = "github:divnix/blank";
25-
26-
nomad-driver-nix.url = "github:input-output-hk/nomad-driver-nix";
273

28-
# Vector >= 0.20.0 versions require nomad-follower watch-config format fix
29-
nomad-follower.url = "github:input-output-hk/nomad-follower";
30-
31-
fenix = {
32-
url = "github:nix-community/fenix";
33-
inputs.nixpkgs.follows = "nixpkgs-unstable";
34-
};
4+
# --- Public Inputs --------
5+
# intended to defer locking to the consumer
6+
inputs = {
7+
nixpkgs.url = "nixos-21_11";
8+
nixpkgs-unstable.url = "nixpkgs-unstable";
9+
nix.url = "nix-2_10";
3510

3611
ops-lib = {
37-
url = "github:input-output-hk/ops-lib";
12+
url = "ops-lib";
3813
flake = false;
3914
};
40-
41-
# DEPRECATED: will be replaces by cicero soon
42-
hydra.url = "github:kreisys/hydra/hydra-server-includes";
43-
hydra.inputs.nix.follows = "nix";
44-
hydra.inputs.nixpkgs.follows = "nixpkgs";
4515
};
4616

4717
outputs = {
4818
self,
49-
hydra,
5019
nixpkgs,
5120
nixpkgs-unstable,
52-
utils,
53-
deploy,
54-
ragenix,
5521
nix,
56-
fenix,
5722
...
58-
} @ inputs:
23+
} @ pub: let
24+
inherit (inputs) std utils;
25+
26+
priv = (import ./lib/call-flake.nix) {
27+
type = "path";
28+
path = ./private;
29+
# needs to be updated any time private inputs are touched
30+
narHash = "sha256-WpyvDOGanWmgh1bk/KF8L0SL/wkJq9oB6aswlIDtNRs=";
31+
} {};
32+
33+
inputs = priv.inputs // pub;
34+
in
5935
inputs.std.growOn {
6036
inherit inputs;
6137
cellsFrom = ./nix;
@@ -86,10 +62,8 @@
8662
# soil -- TODO: remove soil
8763
(let
8864
overlays = [
89-
fenix.overlay
90-
nix.overlay
91-
hydra.overlay
92-
deploy.overlay
65+
inputs.hydra.overlay
66+
# inputs.deploy.overlay
9367
localPkgsOverlay
9468
terraformProvidersOverlay
9569
(_: prev: {inherit (self.packages."${prev.system}") bitte;})

lib/call-flake.nix

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
let
2+
url = "https://raw.githubusercontent.com/NixOS/nix/0c62b4ad0f80d2801a7e7caabf20cc8e50182540/src/libexpr/flake/call-flake.nix";
3+
callFlake = import (builtins.fetchurl {
4+
inherit url;
5+
sha256 = "sha256:1dmi01s1g3mnvb098iik3w38fxmkwg1q1ajk7mwk83kc5z13v2r7";
6+
});
7+
in
8+
# flake can either be a flake ref expressed as an attribute set or a path to source tree
9+
flake: {
10+
# subdir of source root containing the flake.nix
11+
dir ? "",
12+
}: let
13+
src = builtins.fetchTree flake;
14+
in
15+
if dir == ""
16+
then callFlake (builtins.readFile "${src}/flake.lock") src dir
17+
else callFlake (builtins.readFile "${src}/${dir}/flake.lock") src dir

lib/default.nix

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
inherit (inputs) nixpkgs deploy;
66
bitte = inputs.self;
77
in rec {
8+
callFlake = scopedImport {inherit (inputs) nix;} ./call-flake.nix;
89
terralib = import ./terralib.nix {inherit lib nixpkgs;};
910

1011
warningsModule = import ./warnings.nix;
@@ -19,7 +20,10 @@ in rec {
1920
mkBitteStack =
2021
import ./mk-bitte-stack.nix {inherit mkCluster mkDeploy lib nixpkgs bitte;};
2122
mkDeploy = import ./mk-deploy.nix {inherit deploy lib;};
22-
mkSystem = import ./mk-system.nix {inherit nixpkgs bitte;};
23+
mkSystem = import ./mk-system.nix {
24+
inherit nixpkgs bitte;
25+
priv = inputs;
26+
};
2327
mkVaultResources = kv.mkVaultResources;
2428
mkConsulResources = kv.mkConsulResources;
2529

lib/mk-system.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
nixpkgs,
33
bitte,
4+
priv,
45
}: {
56
pkgs,
67
# Different mkSystem service levels:
@@ -26,7 +27,7 @@
2627
++ modules;
2728
specialArgs = {
2829
inherit nodeName self inputs;
29-
inherit (bitte.inputs) terranix nomad-driver-nix nomad-follower;
30+
inherit (priv) terranix nomad-driver-nix nomad-follower;
3031
bittelib = bitte.lib;
3132
inherit (bitte.lib) terralib;
3233
};

nix/automation/devshells.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ in {
3030
capsules.base
3131
capsules.tools
3232
capsules.integrations
33-
capsules.hooks
3433
];
3534
};
3635
cli = std.lib.mkShell {

overlay.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ in
1212
rec {
1313
nixFlakes = nixUnstable;
1414
nixUnstable = builtins.throw "use pkgs.nix directly";
15+
inherit (inputs.nix.packages.${prev.system}) nix;
1516

1617
# Packages specifically needing an unstable nixpkgs pinned latest available version
1718
inherit

0 commit comments

Comments
 (0)