feat(nix): use flake parts

This commit is contained in:
doprz 2025-12-14 13:58:53 -06:00
parent 1a928f9c8d
commit 406d57fbe8
No known key found for this signature in database
GPG key ID: 0323AA44BA236DF7
4 changed files with 179 additions and 128 deletions

12
default.nix Normal file
View file

@ -0,0 +1,12 @@
(import (
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
nodeName = lock.nodes.root.inputs.flake-compat;
in
fetchTarball {
url =
lock.nodes.${nodeName}.locked.url
or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz";
sha256 = lock.nodes.${nodeName}.locked.narHash;
}
) { src = ./.; }).defaultNix

96
flake.lock generated
View file

@ -1,43 +1,91 @@
{ {
"nodes": { "nodes": {
"flake-utils": { "flake-compat": {
"locked": {
"lastModified": 1733328505,
"narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=",
"rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec",
"revCount": 69,
"type": "tarball",
"url": "https://api.flakehub.com/f/pinned/edolstra/flake-compat/1.1.0/01948eb7-9cba-704f-bbf3-3fa956735b52/source.tar.gz"
},
"original": {
"type": "tarball",
"url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz"
}
},
"flake-parts": {
"inputs": { "inputs": {
"systems": "systems" "nixpkgs-lib": "nixpkgs-lib"
}, },
"locked": { "locked": {
"lastModified": 1731533236, "lastModified": 1765495779,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", "narHash": "sha256-MhA7wmo/7uogLxiewwRRmIax70g6q1U/YemqTGoFHlM=",
"owner": "numtide", "owner": "hercules-ci",
"repo": "flake-utils", "repo": "flake-parts",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "rev": "5635c32d666a59ec9a55cab87e898889869f7b71",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "numtide", "owner": "hercules-ci",
"repo": "flake-utils", "repo": "flake-parts",
"type": "github" "type": "github"
} }
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1755078291, "lastModified": 1765472234,
"narHash": "sha256-Hu/gTDoi4uy6TAKISPHQusSMy8U6xUbLSDjKBYdhDIY=", "narHash": "sha256-9VvC20PJPsleGMewwcWYKGzDIyjckEz8uWmT0vCDYK0=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "3385ca0cd7e14c1a1eb80401fe011705ff012323", "rev": "2fbfb1d73d239d2402a8fe03963e37aab15abe8b",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "NixOS", "owner": "NixOS",
"ref": "nixos-25.05", "ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1761765539,
"narHash": "sha256-b0yj6kfvO8ApcSE+QmA6mUfu8IYG6/uU28OFn4PaC8M=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "719359f4562934ae99f5443f20aa06c2ffff91fc",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1761236834,
"narHash": "sha256-+pthv6hrL5VLW2UqPdISGuLiUZ6SnAXdd2DdUE+fV2Q=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "d5faa84122bc0a1fd5d378492efce4e289f8eac1",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }
}, },
"root": { "root": {
"inputs": { "inputs": {
"flake-utils": "flake-utils", "flake-compat": "flake-compat",
"nixpkgs": "nixpkgs" "flake-parts": "flake-parts",
"nixpkgs": "nixpkgs",
"systems": "systems",
"treefmt-nix": "treefmt-nix"
} }
}, },
"systems": { "systems": {
@ -54,6 +102,24 @@
"repo": "default", "repo": "default",
"type": "github" "type": "github"
} }
},
"treefmt-nix": {
"inputs": {
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1762938485,
"narHash": "sha256-AlEObg0syDl+Spi4LsZIBrjw+snSVU4T8MOeuZJUJjM=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "5b4ee75aeefd1e2d5a1cc43cf6ba65eba75e83e4",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
} }
}, },
"root": "root", "root": "root",

187
flake.nix
View file

@ -2,137 +2,98 @@
description = "The lazier way to manage everything docker"; description = "The lazier way to manage everything docker";
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils"; systems.url = "github:nix-systems/default";
flake-parts.url = "github:hercules-ci/flake-parts";
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
treefmt-nix.url = "github:numtide/treefmt-nix";
}; };
outputs = outputs =
{ inputs@{
self, self,
nixpkgs, flake-parts,
flake-utils, systems,
...
}: }:
let flake-parts.lib.mkFlake { inherit inputs; } {
supportedSystems = [ systems = import systems;
"x86_64-linux" imports = [
"aarch64-linux" inputs.treefmt-nix.flakeModule
"x86_64-darwin"
"aarch64-darwin"
]; ];
gitCommit = self.rev or self.dirtyRev or "dev"; perSystem =
version = "0.24.1"; {
self',
pkgs,
system,
...
}:
let
lazydocker = pkgs.buildGoModule rec {
pname = "lazydocker";
version = "dev";
in gitCommit = inputs.self.rev or inputs.self.dirtyRev or "dev";
flake-utils.lib.eachSystem supportedSystems (
system:
let
pkgs = import nixpkgs { inherit system; };
lazydocker = pkgs.buildGoModule rec { src = ./.;
pname = "lazydocker"; vendorHash = null;
inherit version;
src = ./.; # Disable integration tests that require specific environment
doCheck = false;
vendorHash = null; ldflags = [
"-s"
"-w"
"-X main.commit=${gitCommit}"
"-X main.version=${version}"
"-X main.buildSource=nix"
];
# Disable integration tests that require specific environment meta = {
doCheck = false; description = "The lazier way to manage everything docker";
homepage = "https://github.com/jesseduffield/lazydocker";
nativeBuildInputs = with pkgs; [ git ]; license = pkgs.lib.licenses.mit;
maintainers = [ "jesseduffield" ];
buildInputs = with pkgs; [ git ]; platforms = pkgs.lib.platforms.unix;
mainProgram = "lazydocker";
ldflags = [ };
"-s"
"-w"
"-X main.commit=${gitCommit}"
"-X main.version=${version}"
"-X main.buildSource=nix"
];
meta = with pkgs.lib; {
description = "The lazier way to manage everything docker";
homepage = "https://github.com/jesseduffield/lazydocker";
license = licenses.mit;
maintainers = [ "jesseduffield" ];
platforms = platforms.unix;
mainProgram = "lazydocker";
}; };
}; in
{
in packages = {
{ default = lazydocker;
packages = { inherit lazydocker;
default = lazydocker;
inherit lazydocker;
};
apps = {
default = flake-utils.lib.mkApp {
drv = lazydocker;
name = "lazydocker";
}; };
lazydocker = flake-utils.lib.mkApp {
drv = lazydocker; devShells.default = pkgs.mkShell {
name = "lazydocker"; name = "lazydocker-dev";
buildInputs = with pkgs; [
# Go toolchain
go
gotools
gnumake
];
# Environment variables for development
CGO_ENABLED = "0";
}; };
treefmt = {
programs.nixfmt.enable = pkgs.lib.meta.availableOn pkgs.stdenv.buildPlatform pkgs.nixfmt-rfc-style.compiler;
programs.nixfmt.package = pkgs.nixfmt-rfc-style;
programs.gofmt.enable = true;
};
checks.build = lazydocker;
}; };
devShells.default = pkgs.mkShell { flake = {
name = "lazydocker-dev"; overlays.default = final: prev: {
lazydocker = inputs.self.packages.${final.system}.lazydocker;
buildInputs = with pkgs; [
# Go toolchain
go_1_24
gotools
golangci-lint
# Development tools
git
gnumake
];
shellHook = ''
echo "Lazydocker development environment"
echo "Go version: $(go version)"
echo "Git version: $(git --version)"
echo ""
'';
# Environment variables for development
CGO_ENABLED = "0";
}; };
# Formatting check
formatter = pkgs.nixpkgs-fmt;
# Development checks
checks = {
# Ensure the package builds
build = lazydocker;
# Format check
format =
pkgs.runCommand "check-format"
{
buildInputs = [ pkgs.nixpkgs-fmt ];
}
''
nixpkgs-fmt --check ${./.}
touch $out
'';
};
}
)
// {
# Global overlay for other flakes to use
overlays.default = final: prev: {
lazydocker = self.packages.${final.system}.lazydocker;
}; };
# CI/CD support
hydraJobs = self.packages;
}; };
} }

12
shell.nix Normal file
View file

@ -0,0 +1,12 @@
(import (
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
nodeName = lock.nodes.root.inputs.flake-compat;
in
fetchTarball {
url =
lock.nodes.${nodeName}.locked.url
or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz";
sha256 = lock.nodes.${nodeName}.locked.narHash;
}
) { src = ./.; }).shellNix