-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
150 lines (137 loc) · 5.23 KB
/
Copy pathflake.nix
File metadata and controls
150 lines (137 loc) · 5.23 KB
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
{
description = "devcell — container-native dev environments";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
};
outputs = {
self,
nixpkgs,
}: let
systems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"];
forAllSystems = f:
nixpkgs.lib.genAttrs systems (system:
f {
inherit system;
pkgs = import nixpkgs {inherit system;};
});
# Tight source filter — only the Go files needed to compile cell.
# Excludes test/results/, web/, docs/, etc. so each
# nix-build doesn't copy the entire repo into the store.
cellSrc = nixpkgs.lib.fileset.toSource {
root = ./.;
fileset = nixpkgs.lib.fileset.unions [
./go.mod
./go.sum
./cmd
./internal
];
};
# Version stamped into the binary via -ldflags. Consumers pinning a
# release (`nix profile install github:devcell-sh/devcell/v0.8.2#cell`)
# override this by pointing `nix build` at a tagged ref and passing
# `--override-input` or by editing this string in a release commit.
# `self.shortRev` is populated when Nix evaluates a clean flake ref
# (git tag / commit); falls back to "dirty" for uncommitted trees.
cellVersion = "v0.0.0-dev";
cellCommit = self.shortRev or self.dirtyShortRev or "unknown";
cellBuildDate = self.lastModifiedDate or "unknown";
versionPkg = "github.com/DimmKirr/devcell/internal/version";
in {
packages = forAllSystems ({
system,
pkgs,
}: rec {
# cell — devcell CLI (Go binary). buildGo126Module reads
# ${src}/go.mod, fetches the module closure via Go's tooling
# inside the nix sandbox, and pins the closure under vendorHash.
# Update vendorHash whenever go.sum changes — nix-build will
# error with the new hash to substitute.
cell = pkgs.buildGo126Module {
pname = "cell";
version = nixpkgs.lib.removePrefix "v" cellVersion;
src = cellSrc;
vendorHash = "sha256-Jl7DQv3SXJ6H/BY97LQH1Zm47nOgaYAKyN1AczTNpro=";
subPackages = ["cmd"];
# Stamp version.Version / GitCommit / BuildDate into the binary
# so `cell --version` reports the flake's tag/commit instead of
# the hardcoded "v0.0.0" defaults in internal/version/version.go.
# Mirrors Taskfile.yml CELL_LDFLAGS and .goreleaser.yaml.
ldflags = [
"-s"
"-w"
"-X ${versionPkg}.Version=${cellVersion}"
"-X ${versionPkg}.GitCommit=${cellCommit}"
"-X ${versionPkg}.BuildDate=${cellBuildDate}"
];
# Tests need Docker / GHCR auth / real /nix volumes — none of
# which the nix sandbox provides. The full suite runs via
# `task test:unit` + `task test:integration` in CI.
doCheck = false;
# Swagger docs are generated at build time by the Dockerfile
# path; the nix derivation doesn't need them. Stub the docs
# package so cmd/serve.go's import compiles.
preBuild = ''
mkdir -p docs
cat > docs/docs.go << 'EOF'
package docs
EOF
'';
# Rename the binary from "cmd" to "cell".
postInstall = ''
mv $out/bin/cmd $out/bin/cell
'';
meta = with pkgs.lib; {
description = "devcell CLI — container-native dev environments";
homepage = "https://github.com/devcell-sh/devcell";
license = licenses.mit;
mainProgram = "cell";
};
};
default = cell;
});
# Home-manager module: configure the GLOBAL devcell config declaratively.
# imports = [ devcell.homeManagerModules.default ];
# devcell = { enable = true; prompt = "..."; op.documents = [ ... ]; };
# Renders ~/.config/devcell/devcell.toml and installs the cell CLI from
# this flake (override with devcell.package). Option tree is generated
# from internal/cfg.CellConfig by `task hm:generate` — see
# nix/home-manager/options.nix.
homeManagerModules = rec {
devcell = { config, lib, pkgs, ... }: {
imports = [ ./nix/home-manager/module.nix ];
config.devcell.package =
lib.mkDefault self.packages.${pkgs.stdenv.hostPlatform.system}.cell;
};
default = devcell;
};
# `nix develop` for local hacking — provides Go 1.26 + tooling.
# nix-update rewrites `vendorHash` in this file after go.mod/go.sum
# changes; pre-commit dispatches the hook defined in
# .pre-commit-config.yaml. Both are pulled in here so contributors
# get them for free by entering the dev shell.
devShells = forAllSystems ({
system,
pkgs,
}: {
default = pkgs.mkShellNoCC {
packages = [
pkgs.go_1_26
pkgs.go-task
pkgs.nix-update
pkgs.pre-commit
pkgs.powershell
# TPM emulator for `task debug:windows:start` — the Windows debug
# VM carries its TPM state in the .utm bundle (BitLocker).
pkgs.swtpm
pkgs.cdrkit
];
shellHook = ''
if [ -d .git ] && [ -f .pre-commit-config.yaml ] && \
[ ! -f .git/hooks/pre-commit ]; then
pre-commit install --install-hooks >/dev/null
fi
'';
};
});
};
}