Upgrade to the new dream2nix API #26

Manually merged
tlater merged 2 commits from tlater/newdream2nix into master 2024-01-01 19:44:37 +00:00
60 changed files with 15063 additions and 24783 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
/server/target
/packages/server/target
/result
.dream2nix

View File

@ -1,80 +1,17 @@
{
"nodes": {
"all-cabal-json": {
"flake": false,
"locked": {
"lastModified": 1665552503,
"narHash": "sha256-r14RmRSwzv5c+bWKUDaze6pXM7nOsiz1H8nvFHJvufc=",
"owner": "nix-community",
"repo": "all-cabal-json",
"rev": "d7c0434eebffb305071404edcf9d5cd99703878e",
"type": "github"
},
"original": {
"owner": "nix-community",
"ref": "hackage",
"repo": "all-cabal-json",
"type": "github"
}
},
"crane": {
"flake": false,
"locked": {
"lastModified": 1681175776,
"narHash": "sha256-7SsUy9114fryHAZ8p1L6G6YSu7jjz55FddEwa2U8XZc=",
"owner": "ipetkov",
"repo": "crane",
"rev": "445a3d222947632b5593112bb817850e8a9cf737",
"type": "github"
},
"original": {
"owner": "ipetkov",
"ref": "v0.12.1",
"repo": "crane",
"type": "github"
}
},
"devshell": {
"flake": false,
"locked": {
"lastModified": 1663445644,
"narHash": "sha256-+xVlcK60x7VY1vRJbNUEAHi17ZuoQxAIH4S4iUFUGBA=",
"owner": "numtide",
"repo": "devshell",
"rev": "e3dc3e21594fe07bdb24bdf1c8657acaa4cb8f66",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "devshell",
"type": "github"
}
},
"dream2nix": {
"inputs": {
"all-cabal-json": "all-cabal-json",
"crane": "crane",
"devshell": "devshell",
"drv-parts": "drv-parts",
"flake-compat": "flake-compat",
"flake-parts": "flake-parts",
"flake-utils-pre-commit": "flake-utils-pre-commit",
"ghc-utils": "ghc-utils",
"gomod2nix": "gomod2nix",
"mach-nix": "mach-nix",
"nix-pypi-fetcher": "nix-pypi-fetcher",
"nixpkgs": "nixpkgs",
"nixpkgsV1": "nixpkgsV1",
"poetry2nix": "poetry2nix",
"pre-commit-hooks": "pre-commit-hooks",
"pruned-racket-catalog": "pruned-racket-catalog"
"purescript-overlay": "purescript-overlay",
"pyproject-nix": "pyproject-nix"
},
"locked": {
"lastModified": 1686064783,
"narHash": "sha256-qyptOk4vDut2JkRMJ+815eJNqqd8gIfjpz3l4WCCtMY=",
"lastModified": 1702457430,
"narHash": "sha256-8NQiXtYCOiC7XFayy6GPGDudCBrPROry3mfWjpdVj5g=",
"owner": "nix-community",
"repo": "dream2nix",
"rev": "0c064fa9dd025069cc215b0a8b4eb5ea734aceb0",
"rev": "262198033e23e9ee832f0cc8133d38f07598f555",
"type": "github"
},
"original": {
@ -83,35 +20,6 @@
"type": "github"
}
},
"drv-parts": {
"inputs": {
"flake-compat": [
"dream2nix",
"flake-compat"
],
"flake-parts": [
"dream2nix",
"flake-parts"
],
"nixpkgs": [
"dream2nix",
"nixpkgs"
]
},
"locked": {
"lastModified": 1680698112,
"narHash": "sha256-FgnobN/DvCjEsc0UAZEAdPLkL4IZi2ZMnu2K2bUaElc=",
"owner": "davhau",
"repo": "drv-parts",
"rev": "e8c2ec1157dc1edb002989669a0dbd935f430201",
"type": "github"
},
"original": {
"owner": "davhau",
"repo": "drv-parts",
"type": "github"
}
},
"fenix": {
"inputs": {
"nixpkgs": [
@ -120,11 +28,11 @@
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1686637310,
"narHash": "sha256-sGfKyioVsxQppDM0eDO62wtFiz+bZOD0cBMMIEjqn4I=",
"lastModified": 1704003651,
"narHash": "sha256-bA3d4E1CX5G7TVbKwJOm9jZfVOGOPp6u5CKEUzNsE8E=",
"owner": "nix-community",
"repo": "fenix",
"rev": "6fbeedcd2fc1fba77152e13fd7492824d77a4060",
"rev": "c6d82e087ac96f24b90c5787a17e29a72566c2b4",
"type": "github"
},
"original": {
@ -133,223 +41,74 @@
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1673956053,
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-parts": {
"inputs": {
"nixpkgs-lib": [
"dream2nix",
"nixpkgs"
]
},
"locked": {
"lastModified": 1675933616,
"narHash": "sha256-/rczJkJHtx16IFxMmAWu5nNYcSXNg1YYXTHoGjLrLUA=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "47478a4a003e745402acf63be7f9a092d51b83d7",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"flake-utils-pre-commit": {
"locked": {
"lastModified": 1644229661,
"narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"ghc-utils": {
"flake": false,
"locked": {
"lastModified": 1662774800,
"narHash": "sha256-1Rd2eohGUw/s1tfvkepeYpg8kCEXiIot0RijapUjAkE=",
"ref": "refs/heads/master",
"rev": "bb3a2d3dc52ff0253fb9c2812bd7aa2da03e0fea",
"revCount": 1072,
"type": "git",
"url": "https://gitlab.haskell.org/bgamari/ghc-utils"
},
"original": {
"type": "git",
"url": "https://gitlab.haskell.org/bgamari/ghc-utils"
}
},
"gomod2nix": {
"flake": false,
"locked": {
"lastModified": 1627572165,
"narHash": "sha256-MFpwnkvQpauj799b4QTBJQFEddbD02+Ln5k92QyHOSk=",
"owner": "tweag",
"repo": "gomod2nix",
"rev": "67f22dd738d092c6ba88e420350ada0ed4992ae8",
"type": "github"
},
"original": {
"owner": "tweag",
"repo": "gomod2nix",
"type": "github"
}
},
"mach-nix": {
"flake": false,
"locked": {
"lastModified": 1634711045,
"narHash": "sha256-m5A2Ty88NChLyFhXucECj6+AuiMZPHXNbw+9Kcs7F6Y=",
"owner": "DavHau",
"repo": "mach-nix",
"rev": "4433f74a97b94b596fa6cd9b9c0402104aceef5d",
"type": "github"
},
"original": {
"id": "mach-nix",
"type": "indirect"
}
},
"nix-pypi-fetcher": {
"flake": false,
"locked": {
"lastModified": 1669065297,
"narHash": "sha256-UStjXjNIuIm7SzMOWvuYWIHBkPUKQ8Id63BMJjnIDoA=",
"owner": "DavHau",
"repo": "nix-pypi-fetcher",
"rev": "a9885ac6a091576b5195d547ac743d45a2a615ac",
"type": "github"
},
"original": {
"owner": "DavHau",
"repo": "nix-pypi-fetcher",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1665580254,
"narHash": "sha256-hO61XPkp1Hphl4HGNzj1VvDH5URt7LI6LaY/385Eul4=",
"lastModified": 1702272962,
"narHash": "sha256-D+zHwkwPc6oYQ4G3A1HuadopqRwUY/JkMwHz1YF7j4Q=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "f634d427b0224a5f531ea5aa10c3960ba6ec5f0f",
"rev": "e97b3e4186bcadf0ef1b6be22b8558eab1cdeb5d",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-unstable",
"type": "indirect"
}
},
"nixpkgsV1": {
"locked": {
"lastModified": 1678500271,
"narHash": "sha256-tRBLElf6f02HJGG0ZR7znMNFv/Uf7b2fFInpTHiHaSE=",
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"rev": "5eb98948b66de29f899c7fe27ae112a47964baf8",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-22.11",
"type": "indirect"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1686513595,
"narHash": "sha256-H3JNqj7TEiMx5rd8lRiONvgFZvmf3kmwHI2umDdqgFY=",
"lastModified": 1703900474,
"narHash": "sha256-Zu+chYVYG2cQ4FCbhyo6rc5Lu0ktZCjRbSPE0fDgukI=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "bb8b5735d6f7e06b9ddd27de115b0600c1ffbdb4",
"rev": "9dd7699928e26c3c00d5d46811f1358524081062",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-23.05",
"ref": "nixos-23.11",
"repo": "nixpkgs",
"type": "github"
}
},
"poetry2nix": {
"flake": false,
"locked": {
"lastModified": 1666918719,
"narHash": "sha256-BkK42fjAku+2WgCOv2/1NrPa754eQPV7gPBmoKQBWlc=",
"owner": "nix-community",
"repo": "poetry2nix",
"rev": "289efb187123656a116b915206e66852f038720e",
"type": "github"
},
"original": {
"owner": "nix-community",
"ref": "1.36.0",
"repo": "poetry2nix",
"type": "github"
}
},
"pre-commit-hooks": {
"purescript-overlay": {
"inputs": {
"flake-utils": [
"dream2nix",
"flake-utils-pre-commit"
],
"nixpkgs": [
"dream2nix",
"nixpkgs"
]
],
"slimlock": "slimlock"
},
"locked": {
"lastModified": 1646153636,
"narHash": "sha256-AlWHMzK+xJ1mG267FdT8dCq/HvLCA6jwmx2ZUy5O8tY=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "b6bc0b21e1617e2b07d8205e7fae7224036dfa4b",
"lastModified": 1696022621,
"narHash": "sha256-eMjFmsj2G1E0Q5XiibUNgFjTiSz0GxIeSSzzVdoN730=",
"owner": "thomashoneyman",
"repo": "purescript-overlay",
"rev": "047c7933abd6da8aa239904422e22d190ce55ead",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"owner": "thomashoneyman",
"repo": "purescript-overlay",
"type": "github"
}
},
"pruned-racket-catalog": {
"pyproject-nix": {
"flake": false,
"locked": {
"lastModified": 1672537287,
"narHash": "sha256-SuOvXVcLfakw18oJB/PuRMyvGyGG1+CQD3R+TGHIv44=",
"owner": "nix-community",
"repo": "pruned-racket-catalog",
"rev": "c8b89557fb53b36efa2ee48a769c7364df0f6262",
"lastModified": 1702448246,
"narHash": "sha256-hFg5s/hoJFv7tDpiGvEvXP0UfFvFEDgTdyHIjDVHu1I=",
"owner": "davhau",
"repo": "pyproject.nix",
"rev": "5a06a2697b228c04dd2f35659b4b659ca74f7aeb",
"type": "github"
},
"original": {
"owner": "nix-community",
"ref": "catalog",
"repo": "pruned-racket-catalog",
"owner": "davhau",
"ref": "dream2nix",
"repo": "pyproject.nix",
"type": "github"
}
},
@ -363,11 +122,11 @@
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1686586902,
"narHash": "sha256-+zfBFBmUxWutKbhdntI9uvF4D5Rh7BhcByM2l+ReyTw=",
"lastModified": 1703965384,
"narHash": "sha256-3iyouqkBvhh/E48TkBlt4JmmcIEyfQwY7pokKBx9WNg=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "1f1fe81f0db301124b3026bd2940294526cdd852",
"rev": "e872f5085cf5b0e44558442365c1c033d486eff2",
"type": "github"
},
"original": {
@ -376,6 +135,28 @@
"repo": "rust-analyzer",
"type": "github"
}
},
"slimlock": {
"inputs": {
"nixpkgs": [
"dream2nix",
"purescript-overlay",
"nixpkgs"
]
},
"locked": {
"lastModified": 1688610262,
"narHash": "sha256-Wg0ViDotFWGWqKIQzyYCgayeH8s4U1OZcTiWTQYdAp4=",
"owner": "thomashoneyman",
"repo": "slimlock",
"rev": "b5c6cdcaf636ebbebd0a1f32520929394493f1a6",
"type": "github"
},
"original": {
"owner": "thomashoneyman",
"repo": "slimlock",
"type": "github"
}
}
},
"root": "root",

View File

@ -2,7 +2,7 @@
description = "tlater.net web server";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
dream2nix.url = "github:nix-community/dream2nix";
fenix = {
@ -16,21 +16,28 @@
nixpkgs,
dream2nix,
fenix,
} @ flake-inputs: let
}: let
# At the moment, we only deploy to x86_64-linux. Update when we
# care about another platform.
system = "x86_64-linux";
flakeOutputs = nixpkgs.lib.callPackageWith flake-inputs (import ./nix/packages.nix) {inherit system;};
pkgs = nixpkgs.legacyPackages.${system};
fenixPkgs = fenix.packages.${system};
ownPkgs = self.packages.${system};
in {
packages.${system} = {
server = flakeOutputs.packages.${system}.tlaternet-webserver;
templates = flakeOutputs.packages.${system}.tlaternet;
packages.${system} = dream2nix.lib.importPackages {
projectRoot = ./.;
projectRootFile = "flake.nix";
packagesDir = ./packages;
packageSets = {
nixpkgs = pkgs;
fenix = fenixPkgs;
};
};
apps.${system} = {
default = let
inherit (self.packages.${system}) server templates;
inherit (nixpkgs.legacyPackages.${system}) writeShellScript;
inherit (ownPkgs) server templates;
inherit (pkgs) writeShellScript;
in {
type = "app";
program = builtins.toString (writeShellScript "tlaternet-webserver" ''
@ -39,11 +46,7 @@
};
update = let
update-script = nixpkgs.legacyPackages.${system}.callPackage ./nix/update.nix {
cargo = flakeOutputs.rust-toolchain.cargo;
npm = nixpkgs.legacyPackages.${system}.nodePackages_latest.npm;
npm-check-updates = self.packages.${system}.templates.dependencies.npm-check-updates;
};
update-script = pkgs.callPackage ./nix/update.nix {inherit self;};
in {
type = "app";
program = "${update-script}/bin/update";
@ -53,17 +56,9 @@
nixosModules.default = import ./nix/module.nix {inherit self system;};
devShells.${system} = {
templates = flakeOutputs.devShells.${system}.tlaternet.overrideAttrs (old: {
buildInputs = with nixpkgs.legacyPackages.${system};
[
yj
]
++ old.buildInputs;
});
server = nixpkgs.legacyPackages.${system}.mkShell {
server = pkgs.mkShell {
packages = [
(flakeOutputs.rust-toolchain.withComponents [
(fenixPkgs.stable.withComponents [
"rustc"
"cargo"
"rustfmt"
@ -73,14 +68,13 @@
"rust-src"
"rust-analysis"
])
fenix.packages.${system}.rust-analyzer
fenixPkgs.rust-analyzer
];
};
};
checks.${system} = import ./nix/checks {
inherit self system;
pkgs = nixpkgs.legacyPackages.${system};
inherit self system pkgs;
};
};
}

View File

@ -1,57 +0,0 @@
{
self,
nixpkgs,
dream2nix,
fenix,
system,
...
}: let
inherit (nixpkgs.legacyPackages.${system}) runCommandLocal yj;
rust-toolchain = fenix.packages.${system}.stable;
in
dream2nix.lib.makeFlakeOutputs {
systems = [system];
config.projectRoot = self;
projects = ../projects.toml;
source = runCommandLocal "source" {nativeBuildInputs = [yj];} ''
cp -r ${self} $out/
chmod -R u+w $out
yj < $out/templates/package.yaml > $out/templates/package.json
'';
packageOverrides = {
tlaternet-webserver.set-toolchain.overrideRustToolchain = old: {
cargo = rust-toolchain.minimalToolchain;
rustc = rust-toolchain.minimalToolchain;
};
tlaternet-webserver-deps.set-toolchain.overrideRustToolchain = old: {
cargo = rust-toolchain.minimalToolchain;
rustc = rust-toolchain.minimalToolchain;
};
tlaternet = {
install-only-dist = {
installPhase = ''
cp -r $nodeModules/tlaternet/dist $out
'';
};
};
sharp = {
add-libvips = {
buildInputs = old:
old
++ (with nixpkgs.legacyPackages.${system}; [
vips
pkg-config
]);
};
};
};
}
// {
inherit rust-toolchain;
}

View File

@ -10,7 +10,7 @@ echo 'Note: Update the flake inputs with `nix flake update --commit-lockfile *fi
cd "$(git rev-parse --show-toplevel)" || exit
# Update cargo deps
cd server || exit
cd packages/server || exit
cargo update
if ! git diff --quiet Cargo.lock Cargo.toml; then

View File

@ -1,14 +1,25 @@
{
lib,
self,
system,
writeShellApplication,
cargo,
git,
nix,
npm,
npm-check-updates,
yq-go,
}:
writeShellApplication {
name = "update";
runtimeInputs = [cargo git nix npm npm-check-updates yq-go];
text = builtins.readFile ./scripts/update.sh;
}
}: let
selfPackages = self.packages.${system};
inherit (selfPackages.server.config.deps) cargo;
inherit (selfPackages.templates.config.deps) npm;
npm-check-updates =
(builtins.elemAt (lib.attrValues
selfPackages.templates.config.nodejs-granular-v3.deps.npm-check-updates)
0)
.package-func
.result;
in
writeShellApplication {
name = "update";
runtimeInputs = [cargo git nix npm npm-check-updates yq-go];
text = builtins.readFile ./scripts/update.sh;
}

View File

@ -0,0 +1,17 @@
{dream2nix, ...}: {
imports = [
dream2nix.modules.dream2nix.rust-cargo-lock
dream2nix.modules.dream2nix.rust-crane
];
deps = {fenix, ...}: {
deps.cargo = fenix.stable.minimalToolchain;
};
name = "tlaternet-webserver";
version = "0.1.0";
mkDerivation = {
src = ./.;
};
}

View File

@ -0,0 +1,44 @@
{
dream2nix,
config,
lib,
...
}: {
imports = [
dream2nix.modules.dream2nix.nodejs-package-json-v3
dream2nix.modules.dream2nix.nodejs-granular-v3
];
deps = {nixpkgs, ...}: {
inherit (nixpkgs) pkg-config runCommandLocal rsync vips yj;
};
name = "tlaternet-templates";
version = "0.1.0";
mkDerivation = {
src = config.deps.runCommandLocal "source" {nativeBuildInputs = [config.deps.yj];} ''
cp -r ${./.} $out/
chmod -R u+w $out
yj < $out/package.yaml > $out/package.json
'';
# The default phase (which is hidden in `preInstallPhases`) will
# copy the full node_modules directory to the output, and symlink
# executables and whatnot.
#
# Since this package's output is static HTML/JS, we do not want
# that.
preInstallPhases = lib.mkForce [];
installPhase = ''
cp -r dist $out
'';
};
nodejs-granular-v3.deps = {
sharp."0.28.3".mkDerivation.buildInputs = with config.deps; [
vips
pkg-config
];
};
}

14899
packages/templates/lock.json Normal file

File diff suppressed because it is too large Load Diff

View File

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -1,31 +0,0 @@
# projects.toml file describing inputs for dream2nix
#
# To re-generate this file, run:
# nix run .#detect-projects $source
# ... where `$source` points to the source of your project.
#
# If the local flake is unavailable, alternatively execute the app from the
# upstream dream2nix flake:
# nix run github:nix-community/dream2nix#detect-projects $source
[tlaternet]
name = "tlaternet"
relPath = "templates"
subsystem = "nodejs"
translator = "package-lock"
translators = [ "package-lock", "package-json",]
[tlaternet.subsystemInfo]
[tlaternet-webserver]
name = "tlaternet-webserver"
relPath = "server"
subsystem = "rust"
translator = "cargo-lock"
translators = [ "cargo-lock", "cargo-toml",]
[tlaternet-webserver.subsystemInfo]
workspaceMembers = []
[[tlaternet-webserver.subsystemInfo.crates]]
name = "tlaternet-webserver"
relPath = "server"
version = "0.1.0"

View File

@ -1,10 +0,0 @@
nix_direnv_watch_file package-lock.json
use flake ..#templates
# Update package.json
if ! cmp --silent .checksum-package.yaml <(sha256sum package.yaml); then
echo "Updating package.json"
unlink ./package.json
yj < ./package.yaml > ./package.json
sha256sum package.yaml > .checksum-package.yaml
fi

24369
templates/package-lock.json generated

File diff suppressed because it is too large Load Diff